Added Menu::Background
This commit is contained in:
parent
203cb2bf74
commit
2ee9c062b8
4 changed files with 51 additions and 114 deletions
src
|
@ -297,14 +297,16 @@ typedef struct _menuitem_ {
|
|||
*/
|
||||
typedef struct _menus_ {
|
||||
/// @todo char* Name; ///< menu name
|
||||
int X; ///< menu area x pos
|
||||
int Y; ///< menu area y pos
|
||||
int Width; ///< menu area width
|
||||
int Height; ///< menu area height
|
||||
char* Panel; ///< optional background panel
|
||||
int DefSel; ///< initial selected item number (or -1)
|
||||
int NumItems; ///< number of items to follow
|
||||
Menuitem* Items; ///< buttons, etc
|
||||
int X; ///< menu area x pos
|
||||
int Y; ///< menu area y pos
|
||||
int Width; ///< menu area width
|
||||
int Height; ///< menu area height
|
||||
char* Panel; ///< optional background panel
|
||||
char* Background; ///< optional background image behind the menu panel
|
||||
Graphic* BackgroundG;///< optional background image behind the menu panel
|
||||
int DefSel; ///< initial selected item number (or -1)
|
||||
int NumItems; ///< number of items to follow
|
||||
Menuitem* Items; ///< buttons, etc
|
||||
void (*NetAction)(void); ///< network action callback
|
||||
} Menu;
|
||||
|
||||
|
|
|
@ -91,14 +91,6 @@ global Menu* CurrentMenu;
|
|||
*/
|
||||
local Graphic* Menusbgnd;
|
||||
|
||||
/**
|
||||
** X, Y, Width, and Height of menu are to redraw
|
||||
*/
|
||||
local int MenuRedrawX;
|
||||
local int MenuRedrawY;
|
||||
local int MenuRedrawW;
|
||||
local int MenuRedrawH;
|
||||
|
||||
local int MenuButtonUnderCursor = -1;
|
||||
local int MenuButtonCurSel = -1;
|
||||
|
||||
|
@ -182,11 +174,6 @@ global void MenusSetBackground(void)
|
|||
VideoDrawSubClip(Menusbgnd, 0, 0,
|
||||
Menusbgnd->Width, Menusbgnd->Height,
|
||||
(VideoWidth - Menusbgnd->Width) / 2, (VideoHeight - Menusbgnd->Height) / 2);
|
||||
|
||||
MenuRedrawX = 0;
|
||||
MenuRedrawY = 0;
|
||||
MenuRedrawW = VideoWidth;
|
||||
MenuRedrawH = VideoHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -987,9 +974,9 @@ local void DrawInput(Menuitem* mi, int mx, int my)
|
|||
|
||||
|
||||
/**
|
||||
** Draw a menu.
|
||||
** Draw a menu.
|
||||
**
|
||||
** @param menu The menu number to display (NULL allowed)
|
||||
** @param menu The menu number to display (NULL allowed)
|
||||
*/
|
||||
global void DrawMenu(Menu* menu)
|
||||
{
|
||||
|
@ -1007,35 +994,38 @@ global void DrawMenu(Menu* menu)
|
|||
return;
|
||||
}
|
||||
|
||||
MenuRedrawX = menu->X;
|
||||
MenuRedrawY = menu->Y;
|
||||
MenuRedrawW = menu->Width;
|
||||
MenuRedrawH = menu->Height;
|
||||
if (menu->Background) {
|
||||
if (!menu->BackgroundG) {
|
||||
menu->BackgroundG = LoadGraphic(menu->Background);
|
||||
ResizeGraphic(menu->BackgroundG, VideoWidth, VideoHeight);
|
||||
}
|
||||
VideoDraw(menu->BackgroundG, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (menu->Panel && !strcmp(menu->Panel, ScPanel)) {
|
||||
// Background
|
||||
VideoFillTransRectangle(ColorBlack, MenuRedrawX + 1,
|
||||
MenuRedrawY + 1, MenuRedrawW - 2, MenuRedrawH - 2, 50);
|
||||
VideoDrawHLineClip(ColorBlue, MenuRedrawX + 3, MenuRedrawY, MenuRedrawW - 6);
|
||||
VideoDrawHLineClip(ColorBlue, MenuRedrawX + 3, MenuRedrawY + MenuRedrawH - 1, MenuRedrawW - 6);
|
||||
VideoDrawVLineClip(ColorBlue, MenuRedrawX, MenuRedrawY + 3, MenuRedrawH - 6);
|
||||
VideoDrawVLineClip(ColorBlue, MenuRedrawX + MenuRedrawW - 1, MenuRedrawY + 3, MenuRedrawH - 6);
|
||||
VideoFillTransRectangle(ColorBlack, menu->X + 1,
|
||||
menu->Y + 1, menu->Width - 2, menu->Height - 2, 50);
|
||||
VideoDrawHLineClip(ColorBlue, menu->X + 3, menu->Y, menu->Width - 6);
|
||||
VideoDrawHLineClip(ColorBlue, menu->X + 3, menu->Y + menu->Height - 1, menu->Width - 6);
|
||||
VideoDrawVLineClip(ColorBlue, menu->X, menu->Y + 3, menu->Height - 6);
|
||||
VideoDrawVLineClip(ColorBlue, menu->X + menu->Width - 1, menu->Y + 3, menu->Height - 6);
|
||||
// top left
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + 1, MenuRedrawY + 1);
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + 2, MenuRedrawY + 1);
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + 1, MenuRedrawY + 2);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + 1, menu->Y + 1);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + 2, menu->Y + 1);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + 1, menu->Y + 2);
|
||||
// top right
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + MenuRedrawW - 3, MenuRedrawY + 1);
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + MenuRedrawW - 2, MenuRedrawY + 1);
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + MenuRedrawW - 2, MenuRedrawY + 2);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + menu->Width - 3, menu->Y + 1);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + menu->Width - 2, menu->Y + 1);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + menu->Width - 2, menu->Y + 2);
|
||||
// bottom left
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + 1, MenuRedrawY + MenuRedrawH - 3);
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + 1, MenuRedrawY + MenuRedrawH - 2);
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + 2, MenuRedrawY + MenuRedrawH - 2);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + 1, menu->Y + menu->Height - 3);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + 1, menu->Y + menu->Height - 2);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + 2, menu->Y + menu->Height - 2);
|
||||
// bottom right
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + MenuRedrawW - 3, MenuRedrawY + MenuRedrawH - 2);
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + MenuRedrawW - 2, MenuRedrawY + MenuRedrawH - 2);
|
||||
VideoDrawPixelClip(ColorBlue, MenuRedrawX + MenuRedrawW - 2, MenuRedrawY + MenuRedrawH - 3);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + menu->Width - 3, menu->Y + menu->Height - 2);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + menu->Width - 2, menu->Y + menu->Height - 2);
|
||||
VideoDrawPixelClip(ColorBlue, menu->X + menu->Width - 2, menu->Y + menu->Height - 3);
|
||||
} else if (menu->Panel) {
|
||||
MenuPanel* menupanel;
|
||||
|
||||
|
|
|
@ -782,28 +782,26 @@ global void InitMenuFuncHash(void)
|
|||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Button action handler and Init/Exit functions
|
||||
-- Button action handler and Init/Exit functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
** Draw the version and copyright at bottom of the screen.
|
||||
** Also include now the license.
|
||||
** Draw the version, copyright, and license at bottom of the screen.
|
||||
*/
|
||||
local void NameLineDrawFunc(Menuitem * mi __attribute__ ((unused)))
|
||||
local void NameLineDrawFunc(Menuitem* mi __attribute__ ((unused)))
|
||||
{
|
||||
char* nc;
|
||||
char* rc;
|
||||
|
||||
GetDefaultTextColors(&nc, &rc);
|
||||
MenusSetBackground();
|
||||
SetDefaultTextColors(rc, rc);
|
||||
|
||||
if (SoundFildes == -1 && !SoundOff) {
|
||||
VideoDrawText(16, 16, LargeFont, "Sound disabled, please check!");
|
||||
}
|
||||
|
||||
VideoDrawTextCentered(VideoWidth/2, TheUI.Offset480Y + 440, GameFont, NameLine);
|
||||
VideoDrawTextCentered(VideoWidth/2, TheUI.Offset480Y + 456, GameFont,
|
||||
VideoDrawTextCentered(VideoWidth / 2, TheUI.Offset480Y + 440, GameFont, NameLine);
|
||||
VideoDrawTextCentered(VideoWidth / 2, TheUI.Offset480Y + 456, GameFont,
|
||||
"Engine distributed under the terms of the GNU General Public License.");
|
||||
SetDefaultTextColors(nc, rc);
|
||||
}
|
||||
|
@ -1735,8 +1733,6 @@ local void GlobalOptionsResolutionGem(Menuitem *mi)
|
|||
InitVideo();
|
||||
// Force Update Background Size
|
||||
SetClipping(0,0,VideoWidth - 1,VideoHeight - 1);
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
CleanModules();
|
||||
LoadCcl();
|
||||
PreMenuSetup();
|
||||
|
@ -2754,18 +2750,15 @@ local void SinglePlayerGameMenu(void)
|
|||
}
|
||||
|
||||
/**
|
||||
** Show the campaign select menu.
|
||||
** Show the campaign select menu.
|
||||
**
|
||||
** Look which campaigns are available and how they are called.
|
||||
** Look which campaigns are available and how they are called.
|
||||
*/
|
||||
local void CampaignGameMenu(void)
|
||||
{
|
||||
int i;
|
||||
Menu* menu;
|
||||
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
|
||||
menu = FindMenu("menu-campaign-select");
|
||||
DebugPrint("%d campaigns available\n" _C_ NumCampaigns);
|
||||
#ifdef DEBUG
|
||||
|
@ -2777,7 +2770,7 @@ local void CampaignGameMenu(void)
|
|||
#endif
|
||||
|
||||
//
|
||||
// Setup campaign name.
|
||||
// Setup campaign name.
|
||||
//
|
||||
for (i = 0; i < NumCampaigns && i < 4; ++i) {
|
||||
char* s;
|
||||
|
@ -2812,9 +2805,6 @@ local void CampaignGameMenu(void)
|
|||
*/
|
||||
local void StartCampaignFromMenu(int number)
|
||||
{
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
|
||||
#if 0
|
||||
// JOHNS: this is currently not needed:
|
||||
|
||||
|
@ -2828,10 +2818,6 @@ local void StartCampaignFromMenu(int number)
|
|||
PlayCampaign(Campaigns[number].Ident);
|
||||
GuiGameStarted = 1;
|
||||
|
||||
MenusSetBackground();
|
||||
VideoClearScreen();
|
||||
Invalidate();
|
||||
|
||||
// FIXME: johns otherwise crash in UpdateDisplay -> DrawMinimapCursor
|
||||
EndMenu();
|
||||
}
|
||||
|
@ -2944,9 +2930,6 @@ local void JoinNetGameMenu(void)
|
|||
char *port;
|
||||
Menu *menu;
|
||||
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
|
||||
//
|
||||
// Prepare enter ip/hostname menu
|
||||
//
|
||||
|
@ -2976,8 +2959,6 @@ local void JoinNetGameMenu(void)
|
|||
|
||||
ProcessMenu("menu-enter-server", 1);
|
||||
|
||||
MenusSetBackground();
|
||||
|
||||
if (menu->Items[1].d.input.nch == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -2991,7 +2972,6 @@ local void JoinNetGameMenu(void)
|
|||
server_host_buffer[menu->Items[1].d.input.nch] = 0;
|
||||
if (NetworkSetupServerAddress(server_host_buffer)) {
|
||||
NetErrorMenu("Unable to lookup host.");
|
||||
MenusSetBackground();
|
||||
return;
|
||||
}
|
||||
NetworkInitClientConnect();
|
||||
|
@ -3009,8 +2989,6 @@ local void JoinNetGameMenu(void)
|
|||
ProcessMenu("menu-net-connecting", 1);
|
||||
|
||||
if (GuiGameStarted) {
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
EndMenu();
|
||||
}
|
||||
}
|
||||
|
@ -3038,7 +3016,6 @@ local void NetConnectingExit(Menuitem *mi)
|
|||
*/
|
||||
local void NetConnectingCancel(void)
|
||||
{
|
||||
MenusSetBackground();
|
||||
NetworkExitClientConnect();
|
||||
// Trigger TerminateNetConnect() to call us again and end the menu
|
||||
NetLocalState = ccs_usercanceled;
|
||||
|
@ -3129,11 +3106,8 @@ local void CreateInternetGameMenu(void)
|
|||
*/
|
||||
local void MultiGameStart(void)
|
||||
{
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
|
||||
if (MetaServerInUse) {
|
||||
SendMetaCommand("StartGame","");
|
||||
SendMetaCommand("StartGame", "");
|
||||
}
|
||||
|
||||
GameSettings.Presets[0].Race = SettingsPresetMapDefault;
|
||||
|
@ -3150,10 +3124,7 @@ local void MultiGameStart(void)
|
|||
local void MultiPlayerGameMenu(void)
|
||||
{
|
||||
char NameBuf[32];
|
||||
Menu *menu;
|
||||
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
Menu* menu;
|
||||
|
||||
menu = FindMenu("menu-enter-name");
|
||||
menu->Items[1].d.input.buffer = NameBuf;
|
||||
|
@ -3165,8 +3136,6 @@ local void MultiPlayerGameMenu(void)
|
|||
|
||||
ProcessMenu("menu-enter-name", 1);
|
||||
|
||||
MenusSetBackground();
|
||||
|
||||
if (menu->Items[1].d.input.nch == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -3785,7 +3754,6 @@ local void ScenSelectCancel(void)
|
|||
*/
|
||||
local void GameCancel(void)
|
||||
{
|
||||
MenusSetBackground();
|
||||
FreeMapInfo(MenuMapInfo);
|
||||
MenuMapInfo = NULL;
|
||||
EndMenu();
|
||||
|
@ -3892,7 +3860,6 @@ local void GameDrawFunc(Menuitem *mi __attribute__((unused)))
|
|||
char buffer[32];
|
||||
|
||||
GetDefaultTextColors(&nc, &rc);
|
||||
MenusSetBackground();
|
||||
SetDefaultTextColors(rc, rc);
|
||||
l = VideoTextLength(GameFont, "Scenario:");
|
||||
VideoDrawText(TheUI.Offset640X + 16, TheUI.Offset480Y + 360, GameFont, "Scenario:");
|
||||
|
@ -4750,9 +4717,6 @@ global void NetClientUpdateState(void)
|
|||
*/
|
||||
local void StartEditor(void)
|
||||
{
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
|
||||
SetupEditor();
|
||||
|
||||
EditorRunning = 1;
|
||||
|
@ -4814,9 +4778,6 @@ local void EditorNewMap(void)
|
|||
char height[10];
|
||||
char description[36];
|
||||
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
|
||||
EditorCancelled = 0;
|
||||
|
||||
menu = FindMenu("menu-editor-new");
|
||||
|
@ -4836,7 +4797,6 @@ local void EditorNewMap(void)
|
|||
ProcessMenu("menu-editor-new", 1);
|
||||
|
||||
if (EditorCancelled) {
|
||||
MenusSetBackground();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -4860,7 +4820,6 @@ local void EditorNewMap(void)
|
|||
*/
|
||||
local void EditorNewDrawFunc(Menuitem *mi __attribute__((unused)))
|
||||
{
|
||||
MenusSetBackground();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4954,7 +4913,6 @@ local void EditorMainLoadMap(void)
|
|||
GetInfoFromSelectPath();
|
||||
|
||||
if (EditorCancelled) {
|
||||
MenusSetBackground();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5557,7 +5515,6 @@ local void EditorMapPropertiesOk(void)
|
|||
*/
|
||||
local void EditorPlayerPropertiesDrawFunc(Menuitem *mi __attribute__((unused)))
|
||||
{
|
||||
MenusSetBackground();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6279,10 +6236,6 @@ local void ReplayGameMenu(void)
|
|||
#endif
|
||||
*ScenSelectDisplayPath = '\0';
|
||||
|
||||
VideoClearScreen();
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
|
||||
GuiGameStarted = 0;
|
||||
ProcessMenu("menu-replay-game", 1);
|
||||
if (GuiGameStarted) {
|
||||
|
@ -6792,8 +6745,6 @@ global void InitMenuData(void)
|
|||
local void MultiGameMasterReport(void)
|
||||
{
|
||||
// EndMenu();
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
|
||||
ProcessMenu("metaserver-list", 1);
|
||||
if (GuiGameStarted) {
|
||||
|
@ -6808,8 +6759,6 @@ local void MultiGameMasterReport(void)
|
|||
local void ShowMetaServerList(void)
|
||||
{
|
||||
EndMenu();
|
||||
Invalidate();
|
||||
MenusSetBackground();
|
||||
|
||||
GuiGameStarted = 0;
|
||||
ProcessMenu("metaserver-list", 1);
|
||||
|
@ -6922,8 +6871,6 @@ local void MultiMetaServerGameSetupExit(Menuitem *mi)
|
|||
{
|
||||
// TODO: how to free stuff?
|
||||
// EndMenu();
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
// EndMenu();
|
||||
}
|
||||
|
||||
|
@ -6938,8 +6885,6 @@ local void SelectGameServer(Menuitem *mi)
|
|||
|
||||
j = mi - mi->menu->Items;
|
||||
mi->menu->Items[j].d.gem.state = MI_GSTATE_UNCHECKED;
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
EndMenu();
|
||||
|
||||
strcpy(server_host_buffer, mi->menu->Items[j - 4].d.text.text);
|
||||
|
@ -6954,7 +6899,6 @@ local void SelectGameServer(Menuitem *mi)
|
|||
// server_host_buffer[menu->Items[1].d.input.nch] = 0;
|
||||
if (NetworkSetupServerAddress(server_host_buffer)) {
|
||||
NetErrorMenu("Unable to lookup host.");
|
||||
MenusSetBackground();
|
||||
ProcessMenu("metaserver-list", 1);
|
||||
return;
|
||||
}
|
||||
|
@ -6973,8 +6917,6 @@ local void SelectGameServer(Menuitem *mi)
|
|||
ProcessMenu("menu-net-connecting", 1);
|
||||
|
||||
if (GuiGameStarted) {
|
||||
MenusSetBackground();
|
||||
Invalidate();
|
||||
EndMenu();
|
||||
}
|
||||
}
|
||||
|
@ -7028,7 +6970,6 @@ local int MetaServerConnectError(void)
|
|||
{
|
||||
Invalidate();
|
||||
NetErrorMenu("Cannot Connect to Meta-Server");
|
||||
MenusSetBackground();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -2385,6 +2385,8 @@ local int CclDefineMenu(lua_State* l)
|
|||
if (strcmp(LuaToString(l, j + 1), "none")) {
|
||||
item.Panel = strdup(LuaToString(l, j + 1));
|
||||
}
|
||||
} else if (!strcmp(value, "background")) {
|
||||
item.Background = strdup(LuaToString(l, j + 1));
|
||||
} else if (!strcmp(value, "default")) {
|
||||
item.DefSel = LuaToNumber(l, j + 1);
|
||||
/*
|
||||
|
@ -2414,6 +2416,8 @@ local int CclDefineMenu(lua_State* l)
|
|||
int mitype;
|
||||
|
||||
free(menu->Panel);
|
||||
free(menu->Background);
|
||||
VideoSafeFree(menu->BackgroundG);
|
||||
for (i = 0; i < menu->NumItems; ++i) {
|
||||
mitype = menu->Items[i].mitype;
|
||||
if (mitype == MI_TYPE_TEXT) {
|
||||
|
|
Loading…
Add table
Reference in a new issue