Antwort auf: Buttongruppe auf Handy – anderes Verhalten als in der IDE

Startseite Foren Deutsches LiveCode-Forum Buttongruppe auf Handy – anderes Verhalten als in der IDE Antwort auf: Buttongruppe auf Handy – anderes Verhalten als in der IDE

#13573
gfz
Teilnehmer

    Werde da mal die Skripte posten:

    Das ist im Stack:

    global preRecPath
    global appMode
    global soundList
    
    on openStack
       setPath2preRec
       fillSoundList
    end openStack
    
    on setPath2preRec
       
       if the environment is "mobile" then
          put specialFolderPath("engine") into thisAppPath
       else
          put the filename of this stack into thisAppPath
          set the itemDelimiter to "/"
          delete the last item of thisAppPath
       end if
       put thisAppPath&"/wav/" into preRecPath
       
    end setPath2preRec
    
    on fillSoundList
       put files(preRecPath) into soundList
    end fillSoundList
    

    Und das in der Card:

    global preRecPath
    global appMode
    global listOfButtons
    global exitLearning
    global stopListening
    global startTest
    -- Modes: learn, checkMe
    
    on openCard
       put false into exitLearning
       put false into stopListening
       put false into startTest
       initStartView
       fillBtnList
    end openCard
    
    on initStartView
       put "learn" into appMode
       set the hilitedItem of widget "navBar" of me to 1
       setDisplayToLearnMode
    end initStartView
    
    on setDisplayToLearnMode
       set the visible of group "grpPlayAll" of me to true
       set the visible of group "grpPlaySingle" of me to true
       put empty into field "LetterOutput" of me
       set the visible of field "LetterOutput" of me to true
       set the visible of field "userInstructions" of me to false
       set the visible of field "myGuess" of me to false
       set the visible of field "correctLetter" of me to false
       set the visible of group "cyrillicKeyboard" of me to true
       disable group "cyrillicKeyboard" of me
       set the visible of field "inCorrect" of me to false
       set the visible of field "inTotal" of me to false
       set the visible of field "outFrom" of me to false
       set the visible of field "outRight" of me to false
       set the visible of group "grpStartTest" of me to false
       set the visible of field "numOfTriesLabel" of me to false
       set the visible of field "numOfTry" of me to false
    end setDisplayToLearnMode
    
    on setDisplayToTestMode
       set the visible of group "grpPlayAll" of me to false
       set the visible of group "grpPlaySingle" of me to false
       set the visible of field "userInstructions" of me to false
       set the visible of field "myGuess" of me to true
       set the visible of field "correctLetter" of me to true
       set the visible of group "cyrillicKeyboard" of me to true
       enable group "cyrillicKeyboard" of me
       set the visible of field "inCorrect" of me to true
       put 0 into field "inCorrect" of me
       set the visible of field "inTotal" of me to true
       put 0 into field "inTotal" of me
       set the visible of field "outFrom" of me to true
       set the visible of field "outRight" of me to true
       set the visible of field "LetterOutput" of me to false
       put empty into field "myGuess" of me
       put empty into field "correctLetter" of me
       set the visible of group "grpStartTest" of me to true
       set the visible of field "numOfTriesLabel" of me to true
       set the visible of field "numOfTry" of me to true
       put 0 into field "numOfTry" of me
    end setDisplayToTestMode
    
    on fillBtnList
       set the itemDelimiter to space
       put 0 into tX
       repeat with x = 1 to the number of buttons of me
          put the name of btn(x) into tN
          --put tN after msg
          if item 2 of tN contains "LETTER_" then
             add 1 to tX
             if tX = 1 then
                put item 2 of tN into tLi
                replace quote with empty in tLi
                put tLi into listOfButtons
             else
                put item 2 of tN into tLi
                replace quote with empty in tLi
                put return & tLi after listOfButtons
             end if
             enable button tLi of me
          end if
       end repeat
       --put listOfButtons
    end fillBtnList
    
    on modeChanged
       if appMode is "learn" then
          
          setDisplayToLearnMode
          
       else
          
          setDisplayToTestMode
          
       end if
    end modeChanged
    
    on mouseUp
       if appMode is "learn" then
          
          if "LETTER_" is in the target then
             set the itemDelimiter to space
             put item 2 of the target into tBtn
             replace quote with empty in tBtn
             --put tBtn after msg
             put preRecPath & tBtn & ".wav" into tSound
             set the backgroundColor of button tBtn of this card to "#A0FFA0"
             put the label of the target into field "LetterOutput" of this card
             play tSound
             wait until the sound is done with messages
             set the backgroundColor of button tBtn of this card to empty
          end if
          
       end if
       
       if appMode is "checkMe" then
          
          if "LETTER_" is in the target then
             put the label of the target into field "myGuess" of this card
          end if
          
       end if
       
    end mouseUp
    

    Damit schalte ich zwischen den beiden Modi um mittels Navigation Bar Widget:

    global appMode
    
    on hiliteChanged
       put the hilitedItemName of me into appMode
       send "modeChanged" to me
    end hiliteChanged

    Damit schalte ich im Lernmodus die Wiedergabe aller Buchstaben ein. Dazu habe ich eine Gruppe aus einem Button und einem SVG Widget erstellt und das Skript ist in der Gruppe plaziert:

    global preRecPath
    global listOfButtons
    global exitLearning
    
    on mouseUp
       
       if not exitLearning then
          put true into exitLearning
          set the backgroundColor of button "btnPlayAll" of me to empty
       else
          put false into exitLearning
          set the backgroundColor of button "btnPlayAll" of me to "#A0FFA0"
          
          repeat for each line tL in listOfButtons
             --put line(tL) of listOfButtons into tBtn
             put preRecPath & tL & ".wav" into tSound
             put the label of button tL of this card into field "LetterOutput" of this card
             set the backgroundColor of button tL of this card to "#A0FFA0"
             play tSound
             wait until the sound is done with messages
             set the backgroundColor of button tL of this card to empty
             
             if exitLearning then
                put empty into field "LetterOutput" of this card
                exit repeat
             end if
             
          end repeat
          
       end if
       
       
    end mouseUp
    

    Ebenso im Lernmodus jene Funktion, mit der ich auf Tastendruck den Buchstaben vorgelesen bekomme, wieder als Gruppe von Button und SVG Widget. Skript befindet sich in der Gruppe:

    global preRecPath
    global listOfButtons
    global exitLearning
    global stopListening
    
    on mouseUp
       
       if not stopListening then
          put true into stopListening
          disable group "cyrillicKeyboard" of this card
          set the backgroundColor of button "btnPlaySingle" of me to empty
          put empty into field "LetterOutput" of this card
       else
          put false into stopListening
          enable group "cyrillicKeyboard" of this card
          set the backgroundColor of button "btnPlaySingle" of me to "#A0FFA0"
          
       end if
       
       pass mouseUp
       
    end mouseUp

    Hier noch die Funktionalität des Testmodus. Wieder als Gruppe von Button und SVG Widget. Skript ist wieder in dieser Gruppe abgelegt:

    global preRecPath
    global startTest
    
    on mouseUp
       put files(preRecPath) into tRecordedLetters
       sort lines of tRecordedLetters by random(500)
       
       if startTest then
          put false into startTest
          set the backgroundColor of button "btnStartTest" of me to empty
          disable group "cyrillicKeyboard" of this card
          set the visible of field "userInstructions" of this card to false
       else
          put true into startTest
          set the backgroundColor of button "btnStartTest" of me to "#A0FFA0"
          set the visible of field "userInstructions" of this card to false
          disable group "cyrillicKeyboard" of this card
          put the number of lines in tRecordedLetters into field "inTotal" of this card
          
          put 0 into tX
          repeat for each line tSoundFile in tRecordedLetters
             put empty into field "myGuess" of this card
             put empty into field "correctLetter" of this card
             add 1 to tX
             put tX into field "numOfTry" of this card
             put tSoundFile into tLetter
             replace ".wav" with empty in tLetter
             put the label of button tLetter of this card into tLetter
             --put return & tLetter after msg
             put preRecPath & tSoundFile into tSound
             --put return & tSound after msg
             play tSound
             wait until the sound is done with messages
             enable group "cyrillicKeyboard" of this card
             show field "userInstructions" of this card
             wait 3 seconds with messages
             disable group "cyrillicKeyboard" of this card
             hide field "userInstructions" of this card
             put tLetter into field "correctLetter" of this card
             wait 0.5 seconds with messages
             
             if not startTest then
                put empty into field "myGuess" of this card
                put empty into field "correctLetter" of this card
                put 0 into field "inCorrect" of this card
                put 0 into field "inTotal" of this card
                put 0 into field "numOfTry" of this card
                exit repeat
             end if
             
             if field "myGuess" of this card is not empty then
                put field "myGuess" of this card into tUsersGuess
                if tUsersGuess = tLetter then
                   add 1 to field "inCorrect" of this card
                end if
             end if
             
             
          end repeat
          
       end if
       
    end mouseUp
    

    cyrillicKeyboard fasst alle 32 Buchstabenbuttons zu einer Gruppe zusammen.

    liebe Grüße,
    Georg