#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>

AdlibRegister("_countdown", 1000)

Local $run1, $run2, $run3, $run4, $run5, $run6, $run7

FileInstall("bass31.wav",@TempDir & "\bass31.wav")

GUICreate("Powerleveltool by Raydok", 400, 400)
GUICtrlCreateLabel("Spielername", 10, 10, 80, 20)
GUICtrlCreateLabel("Timeleft", 350, 10, 50, 20)
GUICtrlCreateLabel("Zeit (mm:ss)", 120, 10, 60, 20)
GUICtrlCreateLabel("Special thanks to www.autoit.de-community!", 100, 250, 1000, 20)
GUICtrlCreateInput("", 10, 50, 100, 20)
GUICtrlCreateInput("", 10, 70, 100, 20)
GUICtrlCreateInput("", 10, 90, 100, 20)
GUICtrlCreateInput("", 10, 110, 100, 20)
GUICtrlCreateInput("", 10, 130, 100, 20)
GUICtrlCreateInput("", 10, 150, 100, 20)
GUICtrlCreateInput("", 10, 170, 100, 20)
$Time1 = GUICtrlCreateInput("", 120, 50, 100, 20)
$Time2 = GUICtrlCreateInput("", 120, 70, 100, 20)
$Time3 = GUICtrlCreateInput("", 120, 90, 100, 20)
$Time4 = GUICtrlCreateInput("", 120, 110, 100, 20)
$Time5 = GUICtrlCreateInput("", 120, 130, 100, 20)
$Time6 = GUICtrlCreateInput("", 120, 150, 100, 20)
$Time7 = GUICtrlCreateInput("", 120, 170, 100, 20)
$Start1 = GUICtrlCreateButton("Start", 250, 50, 40, 20)
$Start2 = GUICtrlCreateButton("Start", 250, 70, 40, 20)
$Start3 = GUICtrlCreateButton("Start", 250, 90, 40, 20)
$Start4 = GUICtrlCreateButton("Start", 250, 110, 40, 20)
$Start5 = GUICtrlCreateButton("Start", 250, 130, 40, 20)
$Start6 = GUICtrlCreateButton("Start", 250, 150, 40, 20)
$Start7 = GUICtrlCreateButton("Start", 250, 170, 40, 20)
$Stop1 = GUICtrlCreateButton("Stop", 300, 50, 40, 20)
$Stop2 = GUICtrlCreateButton("Stop", 300, 70, 40, 20)
$Stop3 = GUICtrlCreateButton("Stop", 300, 90, 40, 20)
$Stop4 = GUICtrlCreateButton("Stop", 300, 110, 40, 20)
$Stop5 = GUICtrlCreateButton("Stop", 300, 130, 40, 20)
$Stop6 = GUICtrlCreateButton("Stop", 300, 150, 40, 20)
$Stop7 = GUICtrlCreateButton("Stop", 300, 170, 40, 20)
$labelTime1 = GUICtrlCreateLabel("", 360, 52.5, 40, 20)
$labelTime2 = GUICtrlCreateLabel("", 360, 72.5, 40, 20)
$labelTime3 = GUICtrlCreateLabel("", 360, 92.5, 40, 20)
$labelTime4 = GUICtrlCreateLabel("", 360, 112.5, 40, 20)
$labelTime5 = GUICtrlCreateLabel("", 360, 132.5, 40, 20)
$labelTime6 = GUICtrlCreateLabel("", 360, 152.5, 40, 20)
$labelTime7 = GUICtrlCreateLabel("", 360, 172.5, 40, 20)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            FileDelete(@TempDir & "\testsound.wav")
            Exit
        Case $Start1
            If StringRegExp(GUICtrlRead($Time1), "[0-9][0-9]\:[0-5][0-9]") Then
                GUICtrlSetData($labelTime1, GUICtrlRead($Time1))
                $run1 = 1
            Else
                MsgBox(48, "Fehler", "Falsches Zeitformat")
            EndIf
        Case $Start2
            If StringRegExp(GUICtrlRead($Time2), "[0-9][0-9]\:[0-5][0-9]") Then
                GUICtrlSetData($labelTime2, GUICtrlRead($Time2))
                $run2 = 1
            Else
                MsgBox(48, "Fehler", "Falsches Zeitformat")
            EndIf
        Case $Start3
            If StringRegExp(GUICtrlRead($Time3), "[0-9][0-9]\:[0-5][0-9]") Then
                GUICtrlSetData($labelTime3, GUICtrlRead($Time3))
                $run3 = 1
            Else
                MsgBox(48, "Fehler", "Falsches Zeitformat")
            EndIf
        Case $Start4
            If StringRegExp(GUICtrlRead($Time4), "[0-9][0-9]\:[0-5][0-9]") Then
                GUICtrlSetData($labelTime4, GUICtrlRead($Time4))
                $run4 = 1
            Else
                MsgBox(48, "Fehler", "Falsches Zeitformat")
            EndIf
        Case $Start5
            If StringRegExp(GUICtrlRead($Time5), "[0-9][0-9]\:[0-5][0-9]") Then
                GUICtrlSetData($labelTime5, GUICtrlRead($Time5))
                $run5 = 1
            Else
                MsgBox(48, "Fehler", "Falsches Zeitformat")
            EndIf
        Case $Start6
            If StringRegExp(GUICtrlRead($Time6), "[0-9][0-9]\:[0-5][0-9]") Then
                GUICtrlSetData($labelTime6, GUICtrlRead($Time6))
                $run6 = 1
            Else
                MsgBox(48, "Fehler", "Falsches Zeitformat")
            EndIf
        Case $Start7
            If StringRegExp(GUICtrlRead($Time7), "[0-9][0-9]\:[0-5][0-9]") Then
                GUICtrlSetData($labelTime7, GUICtrlRead($Time7))
                $run7 = 1
            Else
                MsgBox(48, "Fehler", "Falsches Zeitformat")
            EndIf

        Case $Stop1
            $run1 = 0
        Case $Stop2
            $run2 = 0
        Case $Stop3
            $run3 = 0
        Case $Stop4
            $run4 = 0
        Case $Stop5
            $run5 = 0
        Case $Stop6
            $run6 = 0
        Case $Stop7
            $run7 = 0
    EndSwitch
WEnd

Func _countdown()
    If $run1 == 1 Then
        $run1 = _setNewTimer($Time1, $labelTime1)
    EndIf
    If $run2 == 1 Then
        $run2 = _setNewTimer($Time2, $labelTime2)
    EndIf
    If $run3 == 1 Then
        $run3 = _setNewTimer($Time3, $labelTime3)
    EndIf
    If $run4 == 1 Then
        $run4 = _setNewTimer($Time4, $labelTime4)
    EndIf
    If $run5 == 1 Then
        $run5 = _setNewTimer($Time5, $labelTime5)
    EndIf
    If $run6 == 1 Then
        $run6 = _setNewTimer($Time6, $labelTime6)
    EndIf
    If $run7 == 1 Then
        $run7 = _setNewTimer($Time7, $labelTime7)
    EndIf
EndFunc   ;==>_countdown

Func _setNewTimer($input, $label)
    $minSecLeft = StringSplit(GUICtrlRead($label), ":")
    If IsArray($minSecLeft) Then
        If StringCompare($minSecLeft[1], "00") == 0 And StringCompare($minSecLeft[2], "00") == 0 Then
            SoundPlay(@TempDir & "\bass31.wav")
            Return 0
        EndIf
        If StringCompare($minSecLeft[2], "00") == 0 Then
            $minSecLeft[1] -= 1
            $minSecLeft[2] = 59
        Else
            $minSecLeft[2] -= 1
        EndIf
        If StringLen($minSecLeft[1]) < 2 Then
            $minSecLeft[1] = "0" & $minSecLeft[1]
        EndIf
        If StringLen($minSecLeft[2]) < 2 Then
            $minSecLeft[2] = "0" & $minSecLeft[2]
        EndIf
        GUICtrlSetData($label, $minSecLeft[1] & ":" & $minSecLeft[2])
        Return 1
    EndIf
EndFunc   ;==>_setNewTimer