;GUI Timer
If ms-timer_gui>=25 Then
	timer_gui=ms
	timer_gui_run=1
	gui_blink = gui_blink + 1
	If gui_blink >= 20 Then gui_blink=0
Else
	timer_gui_run=0
EndIf

;Kompass
RotateSprite gui_kompass,-EntityYaw(camera)

;Tool
DrawImage gfx_gui_popup, opt_sx-73, opt_sy-73, pl_tool+2
Color 0,0,0
Rect opt_sx-61, opt_sy-20, 42, 5, 0
Color 100,255,100
pro#=Float(pl_toolakt)/Float(pl_tooltotal)
pro#=pro#*40.0
Rect opt_sx-60, opt_sy-19, 40-pro#, 3, 1

;GUI Progressbar
If pl_actiontotal>0 Then
	pl_toolmsg$=pl_action$
	pro#=Float(pl_actionakt)/Float(pl_actiontotal)
	pro#=pro#*100.0
	Select pl_action$
		Case "hochklettern" : a_climb(0)
		Case "runterklettern" : a_climb(1)
	End Select
	If pro#>=100 Then
		pl_actiontotal=0
		Select pl_action$
			Case "suchen" : a_search(1)
			Case "angeln" : a_angeln(1)
		End Select
	EndIf
	Color 0,0,0
	Rect opt_sx/2-51, opt_sy/2+50, 102, 10, 0
	Color 100,255,100
	Rect opt_sx/2-50, opt_sy/2+51, pro#, 8, 1
EndIf

;Scripts
If timer_gui_run Then
	If script>0 Then
		If script_icon<73 Then script_icon=script_icon+5
	Else
		If script_icon>0 Then
			script_icon=script_icon-5
		EndIf
	EndIf
EndIf
If script_icon>0 Then
	DrawImage gfx_gui_popup, opt_sx-73, -68+script_icon, 1
EndIf

;Health
If pl_health<0 Then
	pl_health=0
ElseIf pl_health>pl_health_max Then
	pl_health=pl_health_max
EndIf

;Tired
If pl_tired<0 Then
	pl_tired=0
ElseIf pl_tired>100 Then
	pl_tired=100
EndIf

;Hunger
If pl_hunger<0 Then
	pl_hunger=0
ElseIf pl_hunger>100 Then
	pl_hunger=100
EndIf

;Thirst
If pl_thirst<0 Then
	pl_thirst=0
ElseIf pl_thirst>100 Then
	pl_thirst=100
EndIf

;Energieanzeige
;x=-145+gui_offset
x=0
y=((opt_sy-73)+gui_offset)-148
DrawImage gfx_gui_popup, x, y, 0
If pl_health<20 And gui_blink<10 Then Color 100,255,100 Else Color 0,0,0
Rect x+12, y+8, 42, 10, 0
If pl_tired>90 And gui_blink<10 Then Color 100,255,100 Else Color 0,0,0
Rect x+12, y+23, 42, 5, 0
If pl_hunger>90 And gui_blink<10 Then Color 100,255,100 Else Color 0,0,0
Rect x+12, y+33, 42, 5, 0
If pl_thirst>90 And gui_blink<10 Then Color 100,255,100 Else Color 0,0,0
Rect x+12, y+43, 42, 5, 0
Color 255,0,0 : Rect x+13, y+9, (Float(pl_health)/Float(pl_health_max))*40, 8
Color 125,0,0 : Rect x+13, y+24, pl_tired/2.5, 3
Color 0,255,0 : Rect x+13, y+34, pl_hunger/2.5, 3
Color 100,100,255 : Rect x+13, y+44, pl_thirst/2.5, 3

;GUI Menü
If gui_on=1 Or gui_offset<148 Then
	If timer_gui_run Then
		If gui_on=1 Then
			If gui_offset>0 Then gui_offset=gui_offset-10
		Else	
			If gui_offset<148 Then gui_offset=gui_offset+10
		EndIf
	EndIf
	gui_mx=3
	gui_my=opt_sy+gui_offset-150
	DrawImage gfx_gui_back, gui_mx, gui_my
	If md Then
		If mx>=gui_mx+60 And mx<=gui_mx+95 And my>=gui_my+10 And my<gui_my<=50 Then gui_menu=0
		If mx>=gui_mx+40 And mx<=gui_mx+85 And my>=gui_my+51 And my<gui_my<=90 Then gui_menu=1
		If mx>=gui_mx+45 And mx<=gui_mx+95 And my>=gui_my+91 And my<gui_my<=130 Then gui_menu=2
		If mx>gui_mx+506 Or my<gui_my And gui_paperoffset<((opt_sy/2)-300) Then gui_on=0
	EndIf
	;DrawImage gfx_gui_popup, opt_sx-73, opt_sy-73, 0
	mh=MouseHit(1)
	Select gui_menu
	
	
		;GUI Menü 0 (Spieler Menü)
		Case 0
			DrawImage gfx_gui_back_m1, 3, opt_sy+gui_offset-150
			If pl_health<20 And gui_blink<10 Then Color 100,255,100 Else Color 0,0,0
			Rect gui_mx+120, gui_my+23, 102, 10, 0
			If pl_tired>90 And gui_blink<10 Then Color 100,255,100 Else Color 0,0,0
			Rect gui_mx+120, gui_my+38, 102, 10, 0
			If pl_hunger>90 And gui_blink<10 Then Color 100,255,100 Else Color 0,0,0
			Rect gui_mx+120, gui_my+53, 102, 10, 0
			If pl_thirst>90 And gui_blink<10 Then Color 100,255,100 Else Color 0,0,0
			Rect gui_mx+120, gui_my+68, 102, 10, 0
			SetFont font_norm
			Color 0,0,0
			Text gui_mx+223, gui_my+20, "Energie ("+pl_health+"/"+pl_health_max+")"
			Text gui_mx+223, gui_my+35, "Müde ("+pl_tired+"%)"
			Text gui_mx+223, gui_my+50, "Hunger ("+pl_hunger+"%)"
			Text gui_mx+223, gui_my+65, "Durst ("+pl_thirst+"%)"
			Text gui_mx+120, gui_my+85, "Tag "+gt_day
			m$=gt_hour
			s$=gt_min
			If Len(m$)=1 Then m$="0"+m$
			If Len(s$)=1 Then s$="0"+s$
			Text gui_mx+120, gui_my+100, m$+":"+s$+" Uhr"
			Text gui_mx+223, gui_my+85, "Energie Up: "+pl_health_up+"/"+pl_skillup
			Text gui_mx+223, gui_my+100, "Kraft Up: "+pl_power_up+"/"+pl_skillup+"("+pl_power+")"
			Text gui_mx+350, gui_my+20, "Vefügbare Aktionen:"
			Color 255,0,0 : Rect gui_mx+121, gui_my+24, (Float(pl_health)/Float(pl_health_max))*100, 8
			Color 125,0,0 : Rect gui_mx+121, gui_my+39, pl_tired, 8
			Color 0,255,0 : Rect gui_mx+121, gui_my+54, pl_hunger, 8
			Color 100,100,255 : Rect gui_mx+121, gui_my+69, pl_thirst, 8
			y=20 : If gui_button(350, 20+y, "schlafen") Then sleep(0)
			y=35 : If gui_button(350, 20+y, "suchen") Then a_search()
			If pl_tileflora=2 And pl_tilebuild=2 And pl_tilebuildb=0 Then
				If EntityY(pivot)-TerrainY(terrain, EntityX(pivot),0,EntityZ(pivot))<30 Then
					y=y+15 : If gui_button(350, 20+y, "hochklettern") Then a_climb(0,1)
				Else
					y=y+15 : If gui_button(350, 20+y, "runterklettern") Then a_climb(1,1)
				EndIf
			EndIf
			If pl_tilebuild=4 And pl_tilebuildb=0 Then
				If pl_drive=0 Then
					y=y+15 : If gui_button(350, 20+y, "Floß fahren") Then a_drive(1)
				Else
					y=y+15 : If gui_button(350, 20+y, "absteigen") Then a_drive(0)
				EndIf
			EndIf
			If pl_trade=1 Then
				y=y+15 : If gui_button(350, 20+y, "Hanf verkaufen") Then message_set(50)
			EndIf
			If pl_train=1 Then
				y=y+15 : If gui_button(350, 20+y, "Ausbilden lassen") Then message_set(51)
			EndIf
			
			
		;GUI Menü 1 (Inventar)
		Case 1
			gui_iteminf1$=""
			gui_iteminf2$=""
			DrawImage gfx_gui_back_m2, 3, opt_sy+gui_offset-150
			i=0
			pl_itemsgew=0
			pl_itemssel=0
			SetFont font_tiny
			For x=0 To 7
				For y=0 To 1
					If pl_item(i)>0 Then DrawImage gfx_gui_items, gui_mx+120+x*27, gui_my+20+y*27, pl_item(i)-1
					If pl_items(i) Then Color 100,255,100: pl_itemssel=pl_itemssel+1 Else Color 0,0,0
					Rect gui_mx+120+x*27, gui_my+20+y*27, 25, 25, 0
					If pl_itemc(i) Then Text gui_mx+122+x*27, gui_my+31+y*27, pl_itemc(i)
					If pl_item(i)>0 Then pl_itemsgew=pl_itemsgew+(pl_itemc(i)*item_gew(pl_item(i)-1))
					If mx>=gui_mx+120+x*27 And mx<=gui_mx+120+25+x*27 And my>=gui_my+20+y*27 And my<=gui_my+20+25+y*27
						If mh Then
							pl_items(i)=1-pl_items(i)
						EndIf
						If pl_item(i)>0 Then
							gui_iteminf1$=pl_itemc(i)+"x "+item_name$(pl_item(i)-1)+", "+(pl_itemc(i)*item_gew(pl_item(i)-1))+"g"
							gui_iteminf2$=item_info$(pl_item(i)-1)
						Else
							gui_iteminf1$="Leerer Platz"
							gui_iteminf2$="Hier kannst du ein Item ablegen!"
						EndIf
					EndIf
					i=i+1
				Next
			Next
			SetFont font_norm
			Color 0,0,0
			Text gui_mx+120, gui_my+85, gui_iteminf1$
			Text gui_mx+120, gui_my+100, gui_iteminf2$
			If ((pl_take+(pl_power*100))-pl_itemsgew)<1000 And gui_blink<10 Then Color 100,255,100 Else Color 0,0,0
			Text gui_mx+120, gui_my+115, "Gewicht: "+pl_itemsgew+"/"+(pl_take+(pl_power*100))+"g Frei: "+((pl_take+(pl_power*100))-pl_itemsgew)+"g"
			Color 0,0,0
			If pl_itemssel>=1 Then i=0 Else i=1
			If gui_button(350, 20, "kombinieren",i) Then items_combine()
			If pl_itemssel=1 Then i=0 Else i=1
			If gui_button(350, 35, "wegwerfen", i) Then items_delete(1)
			If gui_button(350, 50, "benutzen", i) Then items_use()
			If gui_button(350, 65, "essen", i) Then items_eat()
			If pl_tilebuild=6 And pl_itemssel=1 Then i=0 Else i=1
			If gui_button(350, 80, "einlagern", i) Then items_store()
		
			
		;GUI Menü 2 (Spiel Menü)
		Case 2
			DrawImage gfx_gui_back_m3, 3, opt_sy+gui_offset-150
			SetFont font_norm
			Color 0,0,0
			Text gui_mx+120, gui_my+20, "Spiel:"
			Text gui_mx+330, gui_my+20, "Hilfe:"
			If gui_button(120, 35, "Speichern") Then message_set(200)
			If gui_button(120, 50, "Laden") Then message_set(201)
			If gui_button(120, 65, "Beenden") Then StopChannel sfx_track:clear():menu_set(0):Exit
			If gui_button(330, 35, "Steuerung") Then message_set(205)
			If gui_button(330, 50, "Anzeigen") Then  message_set(206)
			
	End Select

;Crosshair	
Else
	If pl_toolmsg$<>"" Then
		If script=0 Then
			DrawImage gfx_gui_ch, opt_sx/2, opt_sy/2, 1
			SetFont font_tiny
			Color 0,0,0
			Text opt_sx/2,opt_sy/2+30, pl_toolmsg$, 1
		EndIf
	Else
		DrawImage gfx_gui_ch, opt_sx/2, opt_sy/2, 0
	EndIf
	If pl_menaction=1 Then
		SetFont font_menu
		Color 100,255,100
		Text opt_sx/2,opt_sy/2-12, "A", 1
	EndIf
EndIf

;Nachricht
message_draw(gui_message)


;Nachrichten links oben
SetFont font_norm
For i=0 To 5
	If gui_msgt(i)<500 Then
		If timer_gui_run Then
			gui_msgt(i)=gui_msgt(i)+3
			If gui_msgt(i)>=500 Then gui_msg$(i)=""
		EndIf
		Select gui_msgc(i)
			Case 0 Color 255,255,255
			Case 1 Color 100,255,100
			Case 2 Color 255,0,0
			Case 3 Color 255,255,0
		End Select
		If gui_msgt(i)<=250 Then
			Text 5, 100+i*20, gui_msg$(i)
		Else
			Text 5-(gui_msgt(i)-250), 100+i*20, gui_msg$(i)
		EndIf
	EndIf
Next