*+--------------------+
*|                    |
*|    GUI: TopLeft    |
*|                    |
*+--------------------+
*
* The C3 GUI cos file referred to this part of the GUI as "the topleft parts" or something very similar! Well, I've taken that nickname
* and made it the actual name for these bits! :)
*
*
** Create the GUI TopLeft
new: comp 1 2 14 "ds gui" 1 3 8900
imsk 8
attr 308
perm 60
clac -1
** TopLeft Background
pat: dull 1 "ds gui" 32 6 6 -1
part 1
alph 128 1
** Selected Creature (Button)
pat: butt 2 "blnk" 0 1 6 3 0 [] 1001 0
** Selected Creature Name (Display)
pat: fixd 3 "ds gui" 12 8 75 0 "WhiteOnTransparentChars"
part 3
frmt 2 2 0 0 0 0 0
** Selected Creature Gender (Display)
pat: dull 4 "gender" 0 33 50 10
** Load Creature History for Selected Creature (Button)
pat: butt 5 "ds gui" 12 1 8 75 0 [] 1002 0
** Agent Help (Button)
pat: butt 6 "ds gui" 5 2 72 9 1 [] 1000 0
part 6
pose 0
** Connect to Creature Labs (Button)
pat: butt 7 "ds gui" 56 2 109 75 1 [] 1003 0
** Network Status (Display)
pat: butt 8 "ds gui" 68 9 101 68 0 [] 1003 0
part 8
** Save to a game Variable
seta game "ds_gui_topleft" targ
flto 0 -3

** The first few scripts below this point are mostly unchanged from Creatures 3.

** Creature History for Selected Creature (change name)
scrp 1 2 14 1002
	inst
	doif norn ne null
		targ norn
		seta va05 targ
		new: comp 1 2 23 "ds_creature_history" 32 0 8520
		mesg wrt+ targ 1000 va05 1001 0
	endi
endm

*********icons creature data change
scrp 1 2 14 127
	inst
	doif norn ne null
		rtar 1 2 13
		doif targ ne null
			part 4
			pose 1
		endi
		targ norn
*string value sprite file name
		sets va98 face
*image number of face
		setv va99 face
*pigmentation
		setv va41 tint 1
		setv va42 tint 2
		setv va43 tint 3
		setv va44 tint 4
		setv va45 tint 5
*get the moniker
		sets va01 gtos 0
		doif ooww va01 eq 3
*get the name
			sets va02 hist name va01
			doif va02 eq ""
				sets va02 "?"
			endi

*display the name
			targ ownr
			part 3
			ptxt va02

*display the face
			part 2
			doif gall <> va98 or abba <> va99
				gall va98 va99
				doif game "creature_hud_tint" = 1
					tino va41 va42 va43 va44 va45
				endi
			endi
		else
			norn null
			targ ownr
			part 2
			gall "blnk" 0
			part 3
			ptxt ""
			part 4
			pose 0
		endi
	else
		targ ownr
		part 2
		gall "blnk" 0
		part 3
		ptxt ""
		part 4
		pose 0
	endi
	rtar 1 2 35
	doif targ ne null
		mesg writ targ 120
	endi
endm
*******icons enter scope
scrp 1 2 14 8
	mesg writ ownr 127
endm

**********ICONS selected creature changed event
scrp 1 2 14 120
	inst
	doif norn ne null
* camera to and track the norn
		targ norn
		trck null 0 0 0 0
		doif hhld <> targ
			doif room targ <> -1 and carr <> game "c3_inventory"
				cmrt 0
			endi
		endi
		trck norn 70 70 1 0


*mae the export button available
		rtar 1 2 13
		doif targ ne null
			part 4
			pose 1
		endi
		targ norn
*string value sprite file name
		sets va98 face
*image number of face
		setv va99 face
*pigmentation
		setv va41 tint 1
		setv va42 tint 2
		setv va43 tint 3
		setv va44 tint 4
		setv va45 tint 5
*get the gender
		setv va97 spcs
*get the moniker
		sets va01 gtos 0
*get the name
		sets va02 hist name va01
		doif va02 eq ""
			sets va02 "?"
		endi

*display the name
		targ ownr
		part 3
		ptxt va02
*display the gender
		part 4
		pose va97
*display the face
		part 2
		doif gall <> va98 or abba <> va99
			gall va98 va99
			doif game "creature_hud_tint" = 1
				tino va41 va42 va43 va44 va45
			endi
		endi
	else
**otherwise no selected creature

		targ ownr
		part 2
		gall "blnk" 0
		part 3
		ptxt ""
		part 4
		pose 0
	endi
endm

*HELP mode button
scrp 1 2 14 1000
**OV00 is whether in help mode or normal
*0=normal, 1=help mode
	targ pntr
	doif held ne null
		sndc "buzz"
	else
		targ ownr
		doif ov00 eq 0
			setv ov00 1
			part 6
			pose 1
			wait 1
*	target the help watcher
			rtar 1 2 4
			mesg wrt+ targ 73 112 0 0
		else
			setv ov00 0
			part 6
			pose 0
			wait 1
			rtar 1 2 4
			mesg wrt+ targ 73 112 0 0
		endi
	endi
endm
***Selected Creature face
scrp 1 2 14 1001
	inst
	doif norn ne null
		targ norn
		doif room targ <> -1 and carr <> game "c3_inventory"
			cmrt 0
		endi
	else
		sndc "buzz"
	endi
endm
scrp 1 2 14 76
	inst
	doif _p1_ = 2
		doif pure = 0
			targ pntr
			doif held = null
				doif hots = ownr
					rtar 1 2 6
					doif targ <> null
						mesg wrt+ targ 73 9 0 0
					endi
				endi
			endi
		endi
	endi
endm


** Scripts for agent 1 2 14 after this point are new for Docking Station. Login / Connect GUI Scripts are all located
** in the zzz_gamestart_login.cos file.

** Connect to the DS Server GUI
scrp 1 2 14 1003
	lock
	inst
	sets va00 ""
	sets va01 ""
	doif game "status" = "offline"
		sndc "yes_"
		sets game "status" "pending"
** Does this world already have a user?
		doif game "user_of_this_world" = ""
			snde "buzz"
			inst
			enum 4 0 0
				doif targ <> null
					sezz "ooh! you bypassed the initial login!"
				endi
			next
			stop
		endi
** 		Has the password been saved?
		doif game "engine_netbabel_save_passwords" = 1
			sets va00 game "user_of_this_world"
			sets va01 ""
			net: pass va00 va01
			lock
			gsub guion
			net: line 1
			gsub guioff
			doif net: line = 1
*				The user has chosen to remember the password and it has been accessed successfully.
				sets game "status" "online"
				targ game "ds_gui_topleft"
				part 7
				pose 1
			else
*				The user has chosen to remember the password but there was a failure in the attempt to access it.
				setv ov80 1
				gsub password
			endi
		else
*			The user has chosen not to remember the password.
			gsub password
		endi
	elif game "status" = "online"
		sndc "no__"
		net: line 0
		part 7
		pose 0
		sets game "status" "offline"
** Kill all chat windows and minimised chat windows too! :-)
		enum 1 1 210
			kill targ
		next
		enum 1 1 217
			kill targ
		next
	elif game "status" = "pending"
		inst
		enum 1 2 206
			kill targ
		next
		part 7
		pose 0
		gsub guioff
		sets game "status" "offline"
	endi
	subr password
		setv va80 ov80
** Create Connect GUI
		new: comp 1 2 206 "connect gui" 0 0 9000
		attr 304
*** Display the Nickname.
		pat: fixd 1 "connect gui" 8 90 118 10 "GreyOnTransChars"
		part 1
		frmt 1 5 0 1 1 1 0
** Update the display with the User of this World
		ptxt game "user_of_this_world"
** ask for the password..
		pat: text 2 "connect gui" 8 90 170 0 1002 "whiteontransparentpasswordchars"
		part 2
		frmt 1 5 0 1 1 1 0
		fcus
** Save password?
		pat: butt 3 "connect gui" 5 2 84 215 5 [] 1010 0
** Info / Error Display
		pat: fixd 4 "connect gui" 7 0 0 0 "GreyOnTransChars"
** Save the Password display
		pat: fixd 5 "connect gui" 9 117 215 0 "WhiteOnTransparentChars"
		part 5
		frmt 0 7 0 0 0 0 0
		ptxt "Save the Password?"
** Tick Button
		pat: butt 6 "connect gui" 1 2 80 248 1 [] 1023 0
** Cancel Button
		pat: butt 7 "connect gui" 3 2 252 248 1 [] 1024 0
** Enter Nickname
		pat: fixd 8 "connect gui" 8 75 96 1 "WhiteOnTransparentChars"
** Enter Password
		pat: fixd 9 "connect gui" 8 75 149 1 "WhiteOnTransparentChars"

		doif game "engine_netbabel_save_passwords" = 0
			part 3
			pose 1
		elif game "engine_netbabel_save_passwords" = 1
			part 3
			pose 0
		endi
** Ask user to input Nickname and Password
		part 4
		frmt 25 22 19 0 2 0 0
		doif va80 = 0
			ptxt read "Login Misc Messages" 4
		elif va80 = 1
			ptxt read "Login Error Messages" 2
		endi
** Display Nickname
		part 8
		frmt 1 5 0 1 1 1 0
		ptxt read "Login Misc Messages" 3
** Ask for Password
		part 9
		frmt 1 5 0 1 1 1 0
		ptxt read "Login Misc Messages" 2
* Move!
		flto 250 150
	retn
*	turn 'something is arriving' gui on
	subr guion
		targ ownr
		part 8
		anim [1 2 3 4 5 6 7 8 255]
	retn
*	turn 'something is arriving' gui off
	subr guioff
		targ ownr
		part 8
		pose 0
	retn

endm

* Go Online!
scrp 1 2 14 135
	inst
*	go online!
	sets game "status" "online"
	targ game "ds_gui_topleft"
	part 7
	pose 1
endm

* Go Offline!
scrp 1 2 14 136
	inst
*	go offline!
	sets game "status" "offline"
	targ game "ds_gui_topleft"
	part 7
	pose 0
** Kill all chat windows and minimised chat windows too! :-)
	enum 1 1 210
		kill targ
	next
	enum 1 1 217
		kill targ
	next
endm

* creature arriving event - display icon
scrp 1 2 14 1004
	inst
	part 8
	anim [1 2 3 4 5 6 7 8 255]
endm

* cancel creature arriving warning
scrp 1 2 14 1005
	inst
	part 8
	pose 0
endm


rscr
** Kill the GUI TopLeft
enum 1 2 14
	kill targ
next
* Kill any Connect GUI
enum 1 2 206
	kill targ
next

** Go offline
net: line 0