#include "ui/menudef.h"
#include "ui_mp/main.inc"
#include "ui_mp/popup.inc"

#define SV_INFO_FIELD_Y(i)							(0 + (i * 20))
#define SV_INFO_FIELD_ORIGIN(i)						12 SV_INFO_FIELD_Y(i)
#define SV_INFO_FIELD_RECT(i)						SV_INFO_FIELD_ORIGIN(i) 310 20 HORIZONTAL_ALIGN_SUBLEFT VERTICAL_ALIGN_SUBTOP

#define SV_INFO_FIELD(itemIndex, textArg, dvarArg) \
		SV_INFO_FIELD_VIS(itemIndex, textArg, dvarArg, 1)

#define SV_INFO_FIELD_VIS(itemIndex, textArg, dvarArg, visArg) \
	itemDef \
	{ \
		rect										SV_INFO_FIELD_RECT(itemIndex) \
		style										WINDOW_STYLE_FILLED \
		foreColor									CHOICE_TEXTCOLOR \
		backColor									0 0 0 0.8 \
		background									"menu_setting_selection_bar" \
		textFont									UI_FONT_NORMAL \
		textScale									0.35 \
		textAlignY									18 \
		decoration									\
		visible										visArg \
		exp											text(textArg) \
	} \
	itemDef \
	{ \
		rect										SV_INFO_FIELD_RECT(itemIndex) \
		foreColor									CHOICE_TEXTCOLOR \
		textFont									UI_FONT_NORMAL \
		textScale									0.35 \
		textAlign									ITEM_ALIGN_LEGACY_RIGHT \
		textAlignX									-40 \
		textAlignY									18 \
		decoration									\
		visible										visArg \
		exp											text(dvarArg) \
	}

#define SV_INFO_MAP_PREVIEW_VIS(materialArg, visArg) \
	itemDef \
	{ \
		name										"mappreview" \
		rect										332 22 176 100 HORIZONTAL_ALIGN_SUBLEFT VERTICAL_ALIGN_SUBTOP \
		style										WINDOW_STYLE_SHADER \
		visible										visArg \
		exp											material(materialArg) \
	} \
	itemDef \
	{ \
		rect										332 22 176 14 HORIZONTAL_ALIGN_SUBLEFT VERTICAL_ALIGN_SUBTOP \
		style										WINDOW_STYLE_FILLED \
		backColor									0 0 0 0.4 \
		textScale									0.3 \
		textAlign									ITEM_ALIGN_LEGACY_RIGHT \
		textAlignX									-4 \
		textAlignY									13 \
		decoration									\
		visible										visArg \
		exp											text(dvarString("uiSi_MapNameLoc")) \
	} \
	itemDef \
	{ \
		rect										332 108 176 14 HORIZONTAL_ALIGN_SUBLEFT VERTICAL_ALIGN_SUBTOP \
		style										WINDOW_STYLE_FILLED \
		backColor									0 0 0 0.4 \
		textScale									0.3 \
		textAlign									ITEM_ALIGN_LEGACY_RIGHT \
		textAlignX									-4 \
		textAlignY									14 \
		decoration									\
		visible										visArg \
		exp											text(dvarString("uiSi_GameType")) \
	}

#define SV_INFO_SECURITY_LEVEL_VIS(itemIndex, visArg) \
	itemDef \
	{ \
		rect										332 121 176 20 HORIZONTAL_ALIGN_SUBLEFT VERTICAL_ALIGN_SUBTOP \
		style										WINDOW_STYLE_FILLED \
		foreColor									CHOICE_TEXTCOLOR \
		backColor									0 0 0 0.8 \
		background									"menu_setting_selection_bar" \
		textFont									UI_FONT_NORMAL \
		textScale									0.35 \
		textAlignY									18 \
		decoration									\
		visible										visArg \
		exp											text("@MPUI_SECURITY_LEVEL") \
	} \
	itemDef \
	{ \
		rect										332 121 176 20 HORIZONTAL_ALIGN_SUBLEFT VERTICAL_ALIGN_SUBTOP \
		foreColor									CHOICE_TEXTCOLOR \
		textFont									UI_FONT_NORMAL \
		textScale									0.35 \
		textAlign									ITEM_ALIGN_LEGACY_RIGHT \
		textAlignX									-20 \
		textAlignY									18 \
		decoration									\
		visible										visArg \
		exp											text(dvarString("uiSi_SecurityLevel")) \
	}

#define SV_INFO_TABLE_POS_X							12
#define SV_INFO_TABLE_POS_Y							164

#define SV_INFO_TABLE_WIDTH							496
#define SV_INFO_TABLE_HEIGHT						160

#define SV_INFO_TABLE_HEADER \
	itemDef \
	{ \
		name										"num" \
		rect										(SV_INFO_TABLE_POS_X + 4) (SV_INFO_TABLE_POS_Y - 2) 30 18 0 0 \
		foreColor									CHOICE_TEXTCOLOR \
		textFont									UI_FONT_NORMAL \
		textScale									0.3 \
		textAlignX									4 \
		decoration									\
		visible										1 \
		text										"#" \
	} \
	itemDef \
	{ \
		name										"name" \
		rect										88 (SV_INFO_TABLE_POS_Y - 2) 30 18 0 0 \
		foreColor									CHOICE_TEXTCOLOR \
		textFont									UI_FONT_NORMAL \
		textScale									0.3 \
		textAlignX									4 \
		decoration									\
		visible										1 \
		text										"@MENU_NAME" \
	} \
	itemDef \
	{ \
		name										"score" \
		rect										353 (SV_INFO_TABLE_POS_Y - 2) 30 18 0 0 \
		foreColor									CHOICE_TEXTCOLOR \
		textFont									UI_FONT_NORMAL \
		textScale									0.3 \
		textAlignX									4 \
		decoration									\
		visible										1 \
		text										"@MPUI_SCORE" \
	} \
	itemDef \
	{ \
		name										"ping" \
		rect										455 (SV_INFO_TABLE_POS_Y - 2) 30 18 0 0 \
		foreColor									CHOICE_TEXTCOLOR \
		textFont									UI_FONT_NORMAL \
		textScale									0.3 \
		textAlignX									4 \
		decoration									\
		visible										1 \
		text										"@MENU_PING" \
	}

#define MENU_NAME									"serverinfo_popmenu"

#define KEYINT_F5									171

#define POPMENU_POS_X								-250
#define POPMENU_POS_Y								-204

#define POPMENU_WIDTH								520
#define POPMENU_HEIGHT								370

#define POPMENU_RECT								POPMENU_POS_X POPMENU_POS_Y POPMENU_WIDTH POPMENU_HEIGHT HORIZONTAL_ALIGN_CENTER VERTICAL_ALIGN_CENTER

#define ON_MENU_OPEN \
	uiScript										"ServerStatus"; \
	setLocalVarInt									"ui_centerPopup" (1);

#define ON_MENU_CLOSE \
	setLocalVarInt									"ui_centerPopup" (0);

#define ON_MENU_ESC \
	close											self;

#define ON_KEY_PRESS_F5 \
	uiScript										"ServerStatus";

menuDef
{
	name											MENU_NAME
	rect											POPMENU_RECT
	popup
	legacySplitScreenScale
	style											WINDOW_STYLE_FILLED
	foreColor										CHOICE_TEXTCOLOR
	focusColor										CHOICE_TEXTCOLOR
	backColor										1 1 1 1
	background										"white"
	MENU_ON_OPEN(ON_MENU_OPEN)
	MENU_ON_CLOSE(ON_MENU_CLOSE)
	MENU_ON_ESC(ON_MENU_ESC)
	MENU_EXEC_KEYINT(KEYINT_F5, ON_KEY_PRESS_F5)

	POPUP_BACKGROUND_BASE
	POPUP_TITLE(dvarString("uiSi_ServerName"))

	SV_INFO_FIELD(1, "@MPUI_MAX_CLIENTS", dvarString("uiSi_MaxClients"))
	SV_INFO_FIELD(2, "@MPUI_IS_PRIVATE", dvarString("uiSi_isPrivate"))
	SV_INFO_FIELD(3, "@MPUI_RULES_HARDCORE", dvarString("uiSi_Hardcore"))
	SV_INFO_FIELD(4, "@MPUI_RULES_KILLCAM", dvarString("uiSi_KillCam"))
	SV_INFO_FIELD(5, "@MPUI_RULES_FRIENDLY_FIRE", dvarString("uiSi_ffType"))
	SV_INFO_FIELD(6, "@MPUI_MOD", dvarString("uiSi_ModName"))

	SV_INFO_MAP_PREVIEW_VIS(("loadscreen_mp_bonusmaps"), when(dvarString("uiSi_MapName") == ""))
	SV_INFO_MAP_PREVIEW_VIS(("preview_" + dvarString("uiSi_MapName")), when(dvarString("uiSi_MapName") != ""))

	SV_INFO_SECURITY_LEVEL_VIS(6, 1)

	SV_INFO_TABLE_HEADER

	itemDef
	{
		rect										SV_INFO_TABLE_POS_X SV_INFO_TABLE_POS_Y SV_INFO_TABLE_WIDTH SV_INFO_TABLE_HEIGHT
		type										ITEM_TYPE_LISTBOX
		style										WINDOW_STYLE_FILLED
		foreColor									CHOICE_TEXTCOLOR
		backColor									0 0 0 0.5
		textFont									UI_FONT_NORMAL
		textScale									.25
		border										1
		borderSize									1
		borderColor									1 1 1 0.1
		feeder										FEEDER_SERVERSTATUS
		elementWidth								120
		elementHeight								16
		notselectable
		visible										1
//		numcols					xpos			xwidth			textlen			alignment
		columns 4				8				2				2				0
								80				16				16				0
								345				4				4				0
								447				4				4				0
	}

	POPUP_BUTTON_FOOTER(330, "@PLATFORM_REFRESH", uiScript "ServerStatus";)
	POPUP_BUTTON_FOOTER(350, "@MENU_CLOSE", close self;)
}
