#include "ui/menudef.h"


#define ICON_ALPHA 0.5
#define LINE_ALPHA 0.2
#define FADEIN_TIME 125
#define HINT_COLOR .25 .25 .25
#define HINT_FADE_TIME 125
#define TEXT_COLOR 0 0 0

#define ANGLES 7 -83

#define BEGIN_HINT(HINT_NAME)\
	itemdef {	\
	name HINT_NAME	\
	autowrapped	\
	group "hints"	\
	subgroup "fade_alpha"	\
	forecolor HINT_COLOR 1	\
	textalign ITEM_ALIGN_LEFT	\
	textalignx 6	\
	textaligny 10	\
	textscale .2	\
	alignrect "line" ITEM_ALIGN_LEFT 0 8 460 40	\
	style WINDOW_STYLE_EMPTY	\
	visible 0	\
	decoration


#define ASSIGN_HINT(HINT_NAME)\
	onFocus { show HINT_NAME ; timeFade HINT_NAME forecolor 5 5 5 1 0 HINT_FADE_TIME }	\
	leaveFocus { timeFade HINT_NAME forecolor 5 5 5 0 0 HINT_FADE_TIME }

#define BUTTON_DIMX 122
#define BUTTON_DIMY 16
#define BUTTON_SPACEX 8
#define BUTTON_SPACEY 4

#define BEGIN_CONTROL(row, idx, caption)\
    itemdef {	\
	style WINDOW_STYLE_EMPTY	\
	alignrect "serverlist_window" ITEM_ALIGN_LEFT $evalint((idx-1)*(BUTTON_DIMX+BUTTON_SPACEX)) $evalint((row-1)*(BUTTON_DIMY+BUTTON_SPACEY)+220) BUTTON_DIMX BUTTON_DIMY	\
	text caption	\
	textscale .225	\
	textalign ITEM_ALIGN_LEFT	\
	textaligny 14	\
	forecolor TEXT_COLOR 1	\
	visible 1

#define BEGIN_BUTTON(row, idx, caption)\
	BEGIN_CONTROL(row, idx, caption)	\
	type ITEM_TYPE_BUTTON	\
	textalignx 8
	
#define ADD_HEADER(idx, pos, size, caption)	\
	itemdef {	\
	name "col"#idx"_title"	\
	type ITEM_TYPE_BUTTON	\
	subgroup "fade_fore_alpha"	\
	text caption	\
	forecolor TEXT_COLOR 1	\
	style WINDOW_STYLE_EMPTY	\
	textalign ITEM_ALIGN_LEFT	\
	textscale .2	\
	textalignx 4	\
	textaligny 14	\
	alignRect serverlist_window ITEM_ALIGN_LEFT pos -16 size 16	\
	visible 1	\
	ASSIGN_HINT(Hint_Col##idx)	\
	action { uiScript ServerSort $evalint(idx-1) }	\
    }

	

{

  menuDef {
	renderpoint
	name "joinserver"
	visible MENU_FALSE				// Visible on open
	//fullScreen MENU_FALSE
	focusColor RQ3_MAIN_FOCUSCOLOR			// Menu focus color for text and items
	rect 48 44 560 440
	anglevectors ANGLES
	style WINDOW_STYLE_EMPTY
	popup
	
	onOOBClick { close _self ; open main }
	onOpen { play "sound/ui/whoosh3.wav" ; uiScript "UpdateFilter" ;
		setitemcolor hints forecolor HINT_COLOR 1 ; hide "hints" ;
	}
	onESC { uiScript closeJoin }

	onOpenSpecial {
		//normal items
		setItemColor "fade_fore_alpha" forecolor 5 5 5 0 ;
		timeFade "fade_fore_alpha" forecolor 5 5 5 1 0 FADEIN_TIME ;
		//icon - special alpha
		setItemColor "icon" forecolor 5 5 5 0 ;
		timeFade "icon" forecolor 5 5 5 ICON_ALPHA 0 FADEIN_TIME ;
		//line - special alpha; using backcolor
		setItemColor "line" backcolor 5 5 5 0 ;
		timeFade "line" backcolor 5 5 5 LINE_ALPHA 0 FADEIN_TIME ;
	}



	itemDef {
	name "paper"
	menuAnchor
	subgroup "fade_fore_alpha"
	style WINDOW_STYLE_SHADER
	background UI_ASSETS"/paper_2"
	forecolor MENUCOLOR_MOD 1
	rect -44 -60 640 696
	anglevectors ANGLES
	visible 1
	decoration
    }

	//Title

	itemdef {
	renderpoint
	name "title"
	subgroup "fade_fore_alpha"
	text "Join game:"
	forecolor .0 .0 .1 1
	style WINDOW_STYLE_EMPTY
	textalign ITEM_ALIGN_LEFT
	textalignx 4
	textaligny 24
	textscale RQ3_MAIN_TEXTSIZE
	alignRect paper ITEM_ALIGN_LEFT 72 88 480 20
	visible 1
	autowrapped
	decoration
    }

    // Server Refresh Date //

    itemdef {
	ownerdraw UI_SERVERREFRESHDATE
	style WINDOW_STYLE_EMPTY
	alignrect "title" ITEM_ALIGN_LEFT 0 28 480 16
	textscale .2
	textalign ITEM_ALIGN_LEFT
	textalignx 6
	textaligny 14
	forecolor .25 .25 .25 1
	decoration
	visible 1
    }

	//Line

	itemDef {
	name "line"
	style WINDOW_STYLE_FILLED
	backcolor .25 .25 .25 LINE_ALPHA
	alignrect "title" ITEM_ALIGN_LEFT 0 48 488 2
	visible 1
	decoration
	}




    // GO //

    itemdef {
	name "btn_run"
	subgroup "fade_fore_alpha"
	text "> ^_G^_O <"
	shortcutKey "G"
	forecolor .5 0 0 1
	type ITEM_TYPE_BUTTON
	style WINDOW_STYLE_EMPTY
	textalign ITEM_ALIGN_RIGHT
	textscale .25
	textalignx 36
	textaligny 14
	alignRect line ITEM_ALIGN_RIGHT 0 -28 40 24
	visible 1
	autowrapped
	ASSIGN_HINT(Hint_GoPlay)
	action { uiScript JoinServer }
    }


	BEGIN_HINT(Hint_GoPlay)
		text "Click to play on the chosen server"
	}

	BEGIN_HINT(Hint_ServerInfo)
		text "Click to view detailed information about the selected server"
	}

	BEGIN_HINT(Hint_Select)
		text "Select a server from the list and click ^1GO^* to join the action"
	}

	BEGIN_HINT(Hint_Password)
		text "Click to enter a password to join a private server"
	}

	BEGIN_HINT(Hint_Specify)
		text "Click to specify a server to connect to"
	}

	BEGIN_HINT(Hint_Find)
		text "Click to find a specific player"
	}

	BEGIN_HINT(Hint_AddFavorite)
		text "Click to add the selected server to the Favorites list"
	}

	BEGIN_HINT(Hint_DelFavorite)
		text "Click to delete the selected favorite"
	}

	BEGIN_HINT(Hint_NewFavorite)
		text "Click to specify a new favorite"
	}

	BEGIN_HINT(Hint_Source)
		text "Select the source from which to search for servers"
	}

	BEGIN_HINT(Hint_NewList)
		text "Click to reload the list from the selected source, whether it is Local, Internet or Favorites"
	}

	BEGIN_HINT(Hint_RefreshList)
		text "Click to refresh the current server list"
	}

	BEGIN_HINT(Hint_ServerEmpty)
		text "Enable to show empty servers on the list"
	}

	BEGIN_HINT(Hint_ServerFull)
		text "Enable to show full servers on the list"
	}

	// column headers //

	BEGIN_HINT(Hint_Col1)
		text "Click to sort servers by name"
	}
	BEGIN_HINT(Hint_Col2)
		text "Click to sort servers by map name"
	}
	BEGIN_HINT(Hint_Col3)
		text "Click to sort servers by number of players"
	}
	BEGIN_HINT(Hint_Col4)
		text "Click to sort servers by game type"
	}
	BEGIN_HINT(Hint_Col5)
		text "Click to sort servers by ping time"
	}

    itemdef {
	name serverlist_window
	group serverlist
	alignrect title ITEM_ALIGN_LEFT 0 96 488 212
	//rect 20 96 600 212
	LISTBOX_STYLE(.2, 4)
	feeder FEEDER_SERVERS
	visible 1
	columndef 5
		4 240
		4 72
		4 40
		4 56
		4 48
	//mouseenter { setitemcolor serverlist bordercolor .7 0 0 1 }
	//mouseexit { setitemcolor serverlist bordercolor .5 .5 .5 1 }
	//onFocus { show serverlist_hint ; timeFade serverlist_hint forecolor .9 .9 .9 1 0 250 }
	//leaveFocus { timeFade serverlist_hint forecolor .9 .9 .9 0 0 250 }
	ASSIGN_HINT(Hint_Select)
	doubleClick { close _self; uiScript JoinServer }
    }

    ADD_HEADER(1, 008, 72, "server name")
    ADD_HEADER(2, 250, 64, "map name")
    ADD_HEADER(3, 328, 40, "plyrs")
    ADD_HEADER(4, 372, 40, "type")
    ADD_HEADER(5, 432, 40, "ping")

    // ROW 1 //

    BEGIN_BUTTON(1, 1, "^_S^_erver info...")
	action { open "serverinfo_popmenu" }
	shortcutKey "S"
	ASSIGN_HINT(Hint_ServerInfo)
    }

    BEGIN_BUTTON(1, 2, "^_P^_assword...")
	action { open "password_popmenu" }
	shortcutKey "P"
	ASSIGN_HINT(Hint_Password)
    }

    BEGIN_BUTTON(1, 3, "^_C^_onnect to...")
	action { open "specify_popmenu" }
	shortcutKey "C"
	ASSIGN_HINT(Hint_Specify)
    }

    BEGIN_BUTTON(1, 4, "^_F^_ind a player...")
	action { open "findplayer_popmenu" }
	shortcutKey "F"
	ASSIGN_HINT(Hint_Find)
    }



    // ROW 2 //

    BEGIN_BUTTON(2, 1, "^_A^_dd Favorite")
	action { play "sound/ui/whoosh3.wav" ; uiScript AddFavorite ; uiScript UpdateFilter }
	shortcutKey "A"
	ASSIGN_HINT(Hint_AddFavorite)
    }

    BEGIN_BUTTON(2, 2, "^_D^_el. Favorite")
	action { play "sound/ui/whoosh3.wav" ; uiScript DeleteFavorite ; uiScript UpdateFilter }
	shortcutKey "D"
	ASSIGN_HINT(Hint_DelFavorite)
    }

    BEGIN_BUTTON(2, 3, "^_N^_ew Favorite...")
	action { open "createfavorite_popmenu" }
	shortcutKey "N"
	ASSIGN_HINT(Hint_NewFavorite)
    }

    BEGIN_CONTROL(2, 4, "")
	ownerdraw UI_NETSOURCE
	textalignx 8
	action { play "sound/ui/whoosh3.wav" }
	ASSIGN_HINT(Hint_Source)
    }



    // ROW 3 //

    BEGIN_BUTTON(3, 1, "^_G^_et New List")
	action { play "sound/ui/whoosh3.wav" ; uiScript RefreshServers }
	shortcutKey "G"
	ASSIGN_HINT(Hint_NewList)
    }

    BEGIN_BUTTON(3, 2, "^_R^_efresh List")
	action { play "sound/ui/whoosh3.wav" ; uiScript RefreshFilter }
	shortcutKey "R"
	ASSIGN_HINT(Hint_RefreshList)
    }

    BEGIN_CONTROL(3, 3, "View ^_E^_mpty:")
	type ITEM_TYPE_YESNO
	cvar "ui_browserShowEmpty"
	textalignx 8
	action { play "sound/ui/whoosh3.wav" ; uiScript RefreshFilter }
	shortcutKey "V"
	ASSIGN_HINT(Hint_ServerEmpty)
    }

    BEGIN_CONTROL(3, 4, "^_V^_iew Full:")
	type ITEM_TYPE_YESNO
	cvar "ui_browserShowFull"
	textalignx 8
	action { play "sound/ui/whoosh3.wav" ; uiScript RefreshFilter }
	shortcutKey "V"
	ASSIGN_HINT(Hint_ServerFull)
    }


}
