#include <GuiConstants.au3>
Global $butt_x, $butt_y, $var, $path, $game, $c_game, $room, $c_room, $i

If FileExists(@ScriptDir & "\" & "carom_again.INI") Then
	$path = IniRead(@ScriptDir & "\" & "carom_again.INI", "path", "appl", "")
	$var = IniReadSection(@ScriptDir & "\" & "carom_again.INI", "practicebutton")
	$butt_x = $var[1][1]
	$butt_y = $var[2][1]
	$game = IniReadSection(@ScriptDir & "\" & "carom_again.INI", "game")
	$room = IniReadSection(@ScriptDir & "\" & "carom_again.INI", "room")
Else
	MsgBox(4096, "Achtung !  Fehlende Datei!", "Die Datei: <carom_again.INI> ist nicht im Ordner: <" & @ScriptDir & "\" & "> enthalten!" & @LF & @LF & "Ohne diese Datei kann das Programm nicht ausgeführt werden!")
	Exit
EndIf

$gui= GuiCreate("Einstellungen Carom3D mit Wiederholung", 392, 329,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$Group_appl = GuiCtrlCreateGroup("Anwendung", 30, 10, 340, 50)
$Input_appl = GuiCtrlCreateInput("", 40, 30, 220, 20)
$Button_appl_chg = GuiCtrlCreateButton("Ändern", 280, 30, 80, 20)
$Group_button = GuiCtrlCreateGroup("Position <PRACTICE> Button", 30, 80, 340, 50)
$Input_button = GuiCtrlCreateInput("", 40, 100, 220, 20)
$Button_button_chg = GuiCtrlCreateButton("Ändern", 280, 100, 80, 20)
$Group_game = GuiCtrlCreateGroup("Game Typ", 30, 150, 340, 50)
$Combo_game = GuiCtrlCreateCombo("", 40, 170, 320, 21)
$Group_room = GuiCtrlCreateGroup("Room Typ", 30, 220, 340, 50)
$Combo_room = GuiCtrlCreateCombo("", 40, 240, 320, 21)
$Button_esc = GuiCtrlCreateButton("Abbrechen", 30, 290, 110, 20)
$Button_set = GuiCtrlCreateButton("Übernehmen", 260, 290, 110, 20)

_FillCombos()
GUICtrlSetData($Input_appl, $path)
GUICtrlSetData($Input_button, "x: " & $butt_x & ", y: " & $butt_y)
GuiSetState()

While 1
	$msg = GuiGetMsg()
	Select
	Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_esc
		ExitLoop
	Case $msg = $Button_appl_chg
		$var = FileOpenDialog("","C:\Program Files\Carom3D\", "(*.exe)")
		If $var <> ""  And $var <> 1 Then				
			GUICtrlSetData($Input_appl, $var)
		EndIf
	Case $msg = $Button_button_chg
		HotKeySet("!y", "_MausPos")		; Hotkey für Bestätigung <ALT>+<y>
		MsgBox(0,"Position 'PRACTICE' - Button", "Bitte Carom3D starten!" & @LF  & @LF & "Den Mauszeiger mittig über dem <PRACTICE> Button positionieren (NICHT klicken!)."  & @LF  & @LF & "Die Position mit <ALT>+<y> bestätigen.")
		GUISetState(@SW_MINIMIZE, $gui)		
		WinWaitActive($gui)
		HotKeySet("!y", "_Blind")
	Case $msg = $Button_set
		$path = GUICtrlRead($Input_appl)
		$c_game = GUICtrlRead($Combo_game)
		$c_room = GUICtrlRead($Combo_room)
		If $c_game = "6-Ball" Or $c_game = "9-Ball" Or $c_game = "Rotation" Or $c_game = "Normal-Snooker" Or $c_game = "Short-Snooker" Then
			MsgBox(4096, "Hinweis", "Für das gewählte Spiel: <" & $c_game & "> muß der Anwendungspfad auf" & @LF & @LF & "die Installation: Carom3D-Full-Practice verweisen." & @LF & @LF & "Sollte das nicht der Fall sein, wird das Tool nicht funktionieren.")
		EndIf
		_WriteINI()
		Exit
	EndSelect
WEnd
Exit

Func _FillCombos()
Dim $c_game = $game[10][1], $c_room = $room[9][1], $tmp
	GUICtrlSetData($Combo_game, "")
	For $i = 1 To $game[0][0]-1
		$tmp = $game[$i][0]
		GUICtrlSetData($Combo_game, $tmp, $c_game)
	Next
	GUICtrlSetData($Combo_room, "")
	For $i = 1 To $room[0][0]-1
		$tmp = $room[$i][0]
		GUICtrlSetData($Combo_room, $tmp, $c_room)
	Next
EndFunc

Func _MausPos()
	$pos = MouseGetPos()
	$butt_x = $pos[0]
	$butt_y = $pos[1]
	GUICtrlSetData($Input_button, "x: " & $butt_x & ", y: " & $butt_y)	
	GUISetState(@SW_RESTORE, $gui)		
EndFunc

Func _WriteINI()
	IniWrite(@ScriptDir & "\" & "carom_again.INI", "path", "appl", $path)
	IniWrite(@ScriptDir & "\" & "carom_again.INI", "practicebutton", "pos_x", $butt_x)
	IniWrite(@ScriptDir & "\" & "carom_again.INI", "practicebutton", "pos_y", $butt_y)	
	IniWrite(@ScriptDir & "\" & "carom_again.INI", "game", "Current_Game", $c_game)
	IniWrite(@ScriptDir & "\" & "carom_again.INI", "room", "Current_Room", $c_room)
	IniWrite(@ScriptDir & "\" & "carom_again.INI", "set", "done", 1)
EndFunc

Func _Blind()
	; ohne Funktion - nur Aufhebung Hotkey
EndFunc		