Simplify CurrentMenu.
This should be used in many places in menus.c where currently a superflux FindMenu() is used...
This commit is contained in:
parent
dd9c11b812
commit
07bfdd8b4a
3 changed files with 25 additions and 48 deletions
src
|
@ -250,7 +250,7 @@ typedef struct _menus_ {
|
|||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
extern const char *CurrentMenu; /// Currently processed menu
|
||||
extern Menu *CurrentMenu; /// Currently processed menu
|
||||
extern char ScenSelectFullPath[1024]; /// Full path to currently selected map
|
||||
extern MapInfo *ScenSelectPudInfo; /// MapInfo of currently selected map
|
||||
|
||||
|
@ -284,7 +284,7 @@ extern void InitMenuFuncHash(void);
|
|||
extern void InitMenus(unsigned int race);
|
||||
|
||||
/// Draw menu
|
||||
extern void DrawMenu(const char *MenuId);
|
||||
extern void DrawMenu(Menu *menu);
|
||||
/// Draw menu button
|
||||
extern void DrawMenuButton(MenuButtonId button,unsigned flags,unsigned w,unsigned h,unsigned x,unsigned y,const int font,const unsigned char *text);
|
||||
/// Set menu backgound and draw it
|
||||
|
|
|
@ -74,7 +74,7 @@ global struct {
|
|||
/**
|
||||
** The currently processed menu
|
||||
*/
|
||||
global const char *CurrentMenu = NULL;
|
||||
global Menu *CurrentMenu;
|
||||
|
||||
/**
|
||||
** The background picture used by menus
|
||||
|
@ -543,13 +543,12 @@ local void DrawInput(Menuitem *mi, unsigned mx, unsigned my)
|
|||
**
|
||||
** @param menu_id The menu number to display
|
||||
*/
|
||||
global void DrawMenu(const char *menu_id)
|
||||
global void DrawMenu(Menu *menu)
|
||||
{
|
||||
int i, n, l;
|
||||
Menu *menu;
|
||||
Menuitem *mi, *mip;
|
||||
|
||||
if (menu_id == NULL || !(menu = FindMenu(menu_id))) {
|
||||
if (menu == NULL) {
|
||||
MustRedraw &= ~RedrawMenu;
|
||||
return;
|
||||
}
|
||||
|
@ -668,17 +667,12 @@ local void MenuHandleKeyDown(unsigned key,unsigned keychar)
|
|||
Menuitem *mi;
|
||||
Menu *menu;
|
||||
|
||||
HandleKeyModifiersDown(key,keychar);
|
||||
HandleKeyModifiersDown(key, keychar);
|
||||
|
||||
if (CurrentMenu == NULL) { // < 0
|
||||
if (CurrentMenu == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
menu = FindMenu(CurrentMenu);
|
||||
if (menu == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
menu = CurrentMenu;
|
||||
if (MenuButtonCurSel != -1 && menu->items[MenuButtonCurSel].mitype == MI_TYPE_INPUT) {
|
||||
mi = menu->items + MenuButtonCurSel;
|
||||
if (!(mi->flags & MenuButtonDisabled)) {
|
||||
|
@ -914,20 +908,13 @@ local void MenuHandleKeyUp(unsigned key,unsigned keychar)
|
|||
*/
|
||||
local void MenuHandleKeyRepeat(unsigned key,unsigned keychar)
|
||||
{
|
||||
Menu *menu;
|
||||
|
||||
HandleKeyModifiersDown(key,keychar);
|
||||
|
||||
if (CurrentMenu == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
menu = FindMenu(CurrentMenu);
|
||||
if (menu == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (MenuButtonCurSel != -1 && menu->items[MenuButtonCurSel].mitype == MI_TYPE_INPUT) {
|
||||
if (MenuButtonCurSel != -1 && CurrentMenu->items[MenuButtonCurSel].mitype == MI_TYPE_INPUT) {
|
||||
MenuHandleKeyDown(key,keychar);
|
||||
}
|
||||
}
|
||||
|
@ -955,10 +942,7 @@ local void MenuHandleMouseMove(int x,int y)
|
|||
return;
|
||||
}
|
||||
|
||||
menu = FindMenu(CurrentMenu);
|
||||
if (menu == NULL) {
|
||||
return;
|
||||
}
|
||||
menu = CurrentMenu;
|
||||
|
||||
n = menu->nitems;
|
||||
MenuButtonUnderCursor = -1;
|
||||
|
@ -1232,10 +1216,7 @@ local void MenuHandleButtonDown(unsigned b __attribute__((unused)))
|
|||
return;
|
||||
}
|
||||
|
||||
menu = FindMenu(CurrentMenu);
|
||||
if (menu == NULL) {
|
||||
return;
|
||||
}
|
||||
menu = CurrentMenu;
|
||||
|
||||
if (MouseButtons&(LeftButton<<MouseHoldShift))
|
||||
return;
|
||||
|
@ -1317,10 +1298,7 @@ local void MenuHandleButtonUp(unsigned b)
|
|||
return;
|
||||
}
|
||||
|
||||
menu = FindMenu(CurrentMenu);
|
||||
if (menu == NULL) {
|
||||
return;
|
||||
}
|
||||
menu = CurrentMenu;
|
||||
|
||||
if ((1<<b) == LeftButton) {
|
||||
n = menu->nitems;
|
||||
|
@ -1446,9 +1424,8 @@ global void EndMenu(void)
|
|||
global void ProcessMenu(const char *menu_id, int loop)
|
||||
{
|
||||
int i, oldncr;
|
||||
Menu *menu;
|
||||
Menuitem *mi;
|
||||
const char *CurrentMenuSave = NULL;
|
||||
Menu *menu, *CurrentMenuSave = NULL;
|
||||
int MenuButtonUnderCursorSave = -1;
|
||||
int MenuButtonCurSelSave = -1;
|
||||
|
||||
|
@ -1473,7 +1450,7 @@ global void ProcessMenu(const char *menu_id, int loop)
|
|||
if (menu == NULL) {
|
||||
return;
|
||||
}
|
||||
CurrentMenu = menu_id;
|
||||
CurrentMenu = menu;
|
||||
MenuButtonCurSel = -1;
|
||||
for (i = 0; i < menu->nitems; ++i) {
|
||||
mi = menu->items + i;
|
||||
|
|
|
@ -1775,8 +1775,8 @@ local void GameMenuEndScenario(void)
|
|||
*/
|
||||
local void EndScenarioRestart(void)
|
||||
{
|
||||
RestartScenario=1;
|
||||
GameRunning=0;
|
||||
RestartScenario = 1;
|
||||
GameRunning = 0;
|
||||
EndMenu();
|
||||
}
|
||||
|
||||
|
@ -1785,8 +1785,8 @@ local void EndScenarioRestart(void)
|
|||
*/
|
||||
local void EndScenarioSurrender(void)
|
||||
{
|
||||
GameResult=GameDefeat;
|
||||
GameRunning=0;
|
||||
GameResult = GameDefeat;
|
||||
GameRunning = 0;
|
||||
EndMenu();
|
||||
}
|
||||
|
||||
|
@ -1795,8 +1795,8 @@ local void EndScenarioSurrender(void)
|
|||
*/
|
||||
local void EndScenarioQuitMenu(void)
|
||||
{
|
||||
QuitToMenu=1;
|
||||
GameRunning=0;
|
||||
QuitToMenu = 1;
|
||||
GameRunning = 0;
|
||||
EndMenu();
|
||||
}
|
||||
|
||||
|
@ -1805,10 +1805,10 @@ local void EndScenarioQuitMenu(void)
|
|||
*/
|
||||
local void GameMenuEnd(void)
|
||||
{
|
||||
InterfaceState=IfaceStateNormal;
|
||||
GameRunning=0;
|
||||
CursorOn=CursorOnUnknown;
|
||||
CurrentMenu=NULL;
|
||||
InterfaceState = IfaceStateNormal;
|
||||
GameRunning = 0;
|
||||
CursorOn = CursorOnUnknown;
|
||||
CurrentMenu = NULL;
|
||||
}
|
||||
|
||||
local void KeystrokeHelpMenu(void)
|
||||
|
@ -4936,7 +4936,7 @@ local void EditorEditAiPropertiesCancel(void)
|
|||
*/
|
||||
local void EditorQuitMenu(void)
|
||||
{
|
||||
EditorRunning=0;
|
||||
EditorRunning = 0;
|
||||
GameMenuReturn();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue