#include "ui/menudef.h"
#include "ui/menumacros.h"

// Defines //
#define WINDOW_X        0
#define WINDOW_Y        0
#define WINDOW_WIDTH    __WINDOW_WIDTH
#define WINDOW_HEIGHT   480
#define GROUP_NAME      "grpChangelogPopup"

menuDef {
	name        "changelog_popup"
	visible     0
	fullscreen  0
	rect        WINDOW_X WINDOW_Y WINDOW_WIDTH WINDOW_HEIGHT
	style       WINDOW_STYLE_FILLED
	popup
	// Restore the previously focused menu on close so the main menu music
	// does not restart when returning from the changelog browser.
	modal

	fadeClamp   0.5
	fadeAmount  0.075

	onOpen {
		// Refresh file list every time the popup opens so VFS changes are reflected.
		setitemcolor background backcolor 0 0 0 0 ;
		fadein background ;
		uiScript ChangelogInit
	}

	onEsc {
		conditionalscript ui_changelog_ingame 0
			( "close changelog_popup ; open ingame_main" )
			( "close changelog_popup" )
	}

// Background //
	itemDef {
		name        "background"
		rect        0 0 WINDOW_WIDTH WINDOW_HEIGHT
		style       WINDOW_STYLE_FILLED
		background  "ui/assets/fadebox.tga"
		backcolor   0 0 0 0
		visible     1
		decoration
	}

// Changelog tab //
#define SUBWINDOW_WIDTH     560
#define SUBWINDOW_HEIGHT    420
#define SUBWINDOW_X         .5*(WINDOW_WIDTH-SUBWINDOW_WIDTH)
#define SUBWINDOW_Y         .5*(WINDOW_HEIGHT-SUBWINDOW_HEIGHT)

	SUBWINDOWBLACK( SUBWINDOW_X, SUBWINDOW_Y, SUBWINDOW_WIDTH, SUBWINDOW_HEIGHT, _("") )

	// Dynamic popup title (CHANGELOG - filename) populated by UI_ChangelogInit/Load.
	CVARLABEL( SUBWINDOW_X+5, SUBWINDOW_Y+2, SUBWINDOW_WIDTH-10, 12, "ui_changelog_title", .19, ITEM_ALIGN_LEFT, 0, 10 )

	itemDef {
		name            "changelogContent"
		group           GROUP_NAME
		rect            $evalfloat((SUBWINDOW_X)+8) $evalfloat((SUBWINDOW_Y)+24) $evalfloat((SUBWINDOW_WIDTH)-20) $evalfloat((SUBWINDOW_HEIGHT)-24-30)
		type            ITEM_TYPE_LISTBOX
		textfont        UI_FONT_COURBD_21
		textstyle       ITEM_TEXTSTYLE_SHADOWED
		textscale       .2
		textaligny      -3
		forecolor       .6 .6 .6 1
		feeder          FEEDER_CHANGELOG
		elementtype     LISTBOX_TEXT
		elementwidth    540
		elementheight   10
		columns         1 0 540 0
		visible         1
		notselectable
	}

	BUTTON( (SUBWINDOW_X)+8, (SUBWINDOW_Y)+(SUBWINDOW_HEIGHT)-24, .333*((SUBWINDOW_WIDTH)-22), 18, _("MSGID_MENU_BACK"), .3, 14, conditionalscript ui_changelog_ingame 0 ( "close changelog_popup ; open ingame_main" ) ( "close changelog_popup" ) )
	BUTTONEXT( (SUBWINDOW_X)+8+.333*((SUBWINDOW_WIDTH)-22)+3, (SUBWINDOW_Y)+(SUBWINDOW_HEIGHT)-24, .333*((SUBWINDOW_WIDTH)-22), 18, _("MSGID_MENU_CHANGELOG_NEWER"), .3, 14, uiScript ChangelogNext, cvarTest "ui_changelog_has_prev" disableCvar { 0 } )
	BUTTONEXT( (SUBWINDOW_X)+8+2*.333*((SUBWINDOW_WIDTH)-22)+6, (SUBWINDOW_Y)+(SUBWINDOW_HEIGHT)-24, .334*((SUBWINDOW_WIDTH)-22), 18, _("MSGID_MENU_CHANGELOG_OLDER"), .3, 14, uiScript ChangelogPrevious, cvarTest "ui_changelog_has_next" disableCvar { 0 } )
}
