:-dynamic taomarker/2.
:-[data].


/** 
	@descr	shows the status of each player (numbers of tao tokens, qi tokens,yin-yang token,buddha figurine). 
	
	@form	playersGroup
**/ 

playersGroup :-
	free(@statusPlayer1),
	free(@statusPlayer2),
	free(@statusPlayer3),
	free(@statusPlayer4),
	free(@player1),
	free(@player2),
	free(@player3),
	free(@player4),
	free(@playersgroup),
	new(@playersgroup,dialog_group(spielerinfo)),
	new(@player1,label(player1)),
	new(@player2,label(player2)),
	new(@player3,label(player3)),
	new(@player4,label(player4)),
	send(@playersgroup,gap,size(4,2)),
	new(@statusPlayer1,label(status)),
	new(@statusPlayer2,label(status2)),
	new(@statusPlayer3,label(status3)),
	new(@statusPlayer4,label(status4)),
	/*send(@player1,value,player1),
	send(@player1,colour,red),
	send(@player2,value,player2),
	send(@player2,colour,blue),
	send(@player3,value,player3),
	send(@player3,colour,green),
	send(@player4,value,player4),
	send(@player4,colour,yellow),*/
	refresh_player_labels,
	send(@playersgroup,append,@player1),
	send(@playersgroup,append,@statusPlayer1,below),
	send(@playersgroup,append,@player2,below),
	send(@playersgroup,append,@statusPlayer2,below),
	send(@playersgroup,append,@player3,below),
	send(@playersgroup,append,@statusPlayer3,below),
	send(@playersgroup,append,@player4,below),
	send(@playersgroup,append,@statusPlayer4,below),
	send(@playersgroup,area,area(0,0,300,190)).


/**
	@descr set the current numbers of Tao and Qi tokens for all players.

**/

set_label_all:-
	set_label(yellow),
	set_label(red),
	set_label(green),
	set_label(blue).

/**
	@descr set the current numbers of Tao an Qi tokens for one player
	@form set_label(Statusplayer)
	Statusplayer: the label of player X, @statusPlayerX, X = {1,2,3,4} 
	
**/


set_label(ColourPlayer):-
	label_player(ColourPlayer,Statusplayer),
	taomarker(ColourPlayer,[Qi,Yellow,Red,Green,Blue,Black]),
	new(S,string('Gelb: %d  Rot: %d  Grün: %d  Blau: %d  Schwarz: %d  Qi: %d',Yellow,Red,Green,Blue,Black,Qi)),
	get(S,value,V),
	send(Statusplayer,value,V).

/**
	@descr change the number of tao tokens, the numbers are saved in a list
	@form change_taomaker(Player,ListOfNumbers)
	
**/

gui_set_taomarker_and_qi(ColourPlayer,[A,B,C,D,E,F]):-
	retract(taomarker(ColourPlayer,_)),
	assert(taomarker(ColourPlayer,[A,B,C,D,E,F])),
	set_label(ColourPlayer).

set_active_player(Colour):-
	free(@circle),
	active(_,Player,Colour,X,Y,_),
	new(@circle,circle(10)),
	send(@circle,colour,Colour),
	send(@circle,fill_pattern,colour(Colour)),
	send(Player,font,bold),
	% message to status bar
	string(message,currentPlayer,Current1),
	concat(Current1,Colour,Current2),
	displayStatusMessage(Current2),
	player(me,MeColour),
	player(current,CurrentColour),
	(CurrentColour = MeColour) ->
	(   
	    string(message,yourTurn,YourTurn1),
	    concat(Current2,YourTurn1,YourTurn2),
	    displayStatusMessage(YourTurn2)
	),
	send(@playersgroup,display,@circle,point(X,Y)),
	send(@playersgroup,append,Player).

reset_active_player(Player):-
	free(@circle),
	active(_,Player,Colour,_,_,PlayerName),
	send(Player,value,PlayerName),
	send(Player,font,normal),
	send(Player,colour,colour(Colour)),
	send(@playersgroup,append,Player).

refresh_player_labels:-
	refresh_player_label(@player1),
	refresh_player_label(@player2),
	refresh_player_label(@player3),
	refresh_player_label(@player4).
	
refresh_player_label(PlayerLabel):-
	active(_,PlayerLabel,Colour,_,_,Nickname),
	concat('        ', Nickname, Foo),
	send(PlayerLabel,value,Foo),
	send(PlayerLabel,colour,colour(Colour)).

gui_set_player_name(Colour,NewName):-
	retract(active(PlayerNo,PlayerLabel,Colour,X,Y,_)),
	assert(active(PlayerNo,PlayerLabel,Colour,X,Y,NewName)),
	refresh_player_label(PlayerLabel).


	
	



