From 4a6d0f1fa5695bb9ef0129a1eb19c6f32dc93c95 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Feb 2017 17:35:01 +0100 Subject: [PATCH] - scriptified DLoadSaveMenu::MenuEvent. --- src/menu/loadsavemenu.cpp | 137 ++------------------ src/menu/menu.h | 2 +- wadsrc/static/zscript/menu/loadsavemenu.txt | 129 +++++++++++++++++- 3 files changed, 138 insertions(+), 130 deletions(-) diff --git a/src/menu/loadsavemenu.cpp b/src/menu/loadsavemenu.cpp index 4bfc8c50e..f085fa252 100644 --- a/src/menu/loadsavemenu.cpp +++ b/src/menu/loadsavemenu.cpp @@ -105,6 +105,14 @@ int FSavegameManager::RemoveSaveSlot(int index) return index; } +DEFINE_ACTION_FUNCTION(FSavegameManager, RemoveSaveSlot) +{ + PARAM_SELF_STRUCT_PROLOGUE(FSavegameManager); + PARAM_INT(sel); + ACTION_RETURN_INT(self->RemoveSaveSlot(sel)); +} + + //============================================================================= // // @@ -664,7 +672,7 @@ DEFINE_ACTION_FUNCTION(FSavegameManager, SavegameCount) // //============================================================================= -FSaveGameNode *FSavegameManager::GetSavegame(unsigned i) +FSaveGameNode *FSavegameManager::GetSavegame(int i) { return SaveGames[i]; } @@ -764,8 +772,6 @@ public: void OnDestroy() override; void Drawer (); - bool MenuEvent (int mkey, bool fromcontroller); - bool MouseEvent(int type, int x, int y); }; IMPLEMENT_CLASS(DLoadSaveMenu, false, false) @@ -925,131 +931,6 @@ void DLoadSaveMenu::Drawer () } } -//============================================================================= -// -// -// -//============================================================================= - -bool DLoadSaveMenu::MenuEvent (int mkey, bool fromcontroller) -{ - switch (mkey) - { - case MKEY_Up: - if (manager->SavegameCount() > 1) - { - if (Selected == -1) Selected = TopItem; - else - { - if (--Selected < 0) Selected = manager->SavegameCount()-1; - if (Selected < TopItem) TopItem = Selected; - else if (Selected >= TopItem + listboxRows) TopItem = MAX(0, Selected - listboxRows + 1); - } - manager->UnloadSaveData (); - manager->ExtractSaveData (Selected); - } - return true; - - case MKEY_Down: - if (manager->SavegameCount() > 1) - { - if (Selected == -1) Selected = TopItem; - else - { - if (unsigned(++Selected) >= manager->SavegameCount()) Selected = 0; - if (Selected < TopItem) TopItem = Selected; - else if (Selected >= TopItem + listboxRows) TopItem = MAX(0, Selected - listboxRows + 1); - } - manager->UnloadSaveData (); - manager->ExtractSaveData (Selected); - } - return true; - - case MKEY_PageDown: - if (manager->SavegameCount() > 1) - { - if (TopItem >= (int)manager->SavegameCount() - listboxRows) - { - TopItem = 0; - if (Selected != -1) Selected = 0; - } - else - { - TopItem = MIN(TopItem + listboxRows, manager->SavegameCount() - listboxRows); - if (TopItem > Selected && Selected != -1) Selected = TopItem; - } - manager->UnloadSaveData (); - manager->ExtractSaveData (Selected); - } - return true; - - case MKEY_PageUp: - if (manager->SavegameCount() > 1) - { - if (TopItem == 0) - { - TopItem = manager->SavegameCount() - listboxRows; - if (Selected != -1) Selected = TopItem; - } - else - { - TopItem = MAX(TopItem - listboxRows, 0); - if (Selected >= TopItem + listboxRows) Selected = TopItem; - } - manager->UnloadSaveData (); - manager->ExtractSaveData (Selected); - } - return true; - - case MKEY_Enter: - return false; // This event will be handled by the subclasses - - case MKEY_MBYes: - { - if ((unsigned)Selected < manager->SavegameCount()) - { - Selected = manager->RemoveSaveSlot (Selected); - } - return true; - } - - default: - return Super::MenuEvent(mkey, fromcontroller); - } -} - -//============================================================================= -// -// -// -//============================================================================= - -bool DLoadSaveMenu::MouseEvent(int type, int x, int y) -{ - if (x >= listboxLeft && x < listboxLeft + listboxWidth && - y >= listboxTop && y < listboxTop + listboxHeight) - { - int lineno = (y - listboxTop) / rowHeight; - - if (TopItem + lineno < (int)manager->SavegameCount()) - { - Selected = TopItem + lineno; - manager->UnloadSaveData (); - manager->ExtractSaveData (Selected); - if (type == MOUSE_Release) - { - if (MenuEvent(MKEY_Enter, true)) - { - return true; - } - } - } - else Selected = -1; - } - else Selected = -1; - - return Super::MouseEvent(type, x, y); -} DEFINE_FIELD(FSaveGameNode, SaveTitle); DEFINE_FIELD(FSaveGameNode, Filename); diff --git a/src/menu/menu.h b/src/menu/menu.h index 2241513cb..dd06dc605 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -100,7 +100,7 @@ public: void DrawSaveComment(FFont *font, int cr, int x, int y, int scalefactor); void SetFileInfo(int Selected); unsigned SavegameCount(); - FSaveGameNode *GetSavegame(unsigned i); + FSaveGameNode *GetSavegame(int i); void InsertNewSaveNode(); bool RemoveNewSaveNode(); diff --git a/wadsrc/static/zscript/menu/loadsavemenu.txt b/wadsrc/static/zscript/menu/loadsavemenu.txt index a52c8191b..b97042cf7 100644 --- a/wadsrc/static/zscript/menu/loadsavemenu.txt +++ b/wadsrc/static/zscript/menu/loadsavemenu.txt @@ -51,7 +51,7 @@ struct SavegameManager native //void ReadSaveStrings(); native void UnloadSaveData(); - //int RemoveSaveSlot(int index); + native int RemoveSaveSlot(int index); native void LoadSavegame(int Selected); native void DoSave(int Selected, String savegamestring); native int ExtractSaveData(int index); @@ -99,6 +99,133 @@ class LoadSaveMenu : ListMenu native native TextEnterMenu mInput; + + //============================================================================= + // + // + // + //============================================================================= + + override bool MenuEvent (int mkey, bool fromcontroller) + { + switch (mkey) + { + case MKEY_Up: + if (manager.SavegameCount() > 1) + { + if (Selected == -1) Selected = TopItem; + else + { + if (--Selected < 0) Selected = manager.SavegameCount()-1; + if (Selected < TopItem) TopItem = Selected; + else if (Selected >= TopItem + listboxRows) TopItem = MAX(0, Selected - listboxRows + 1); + } + manager.UnloadSaveData (); + manager.ExtractSaveData (Selected); + } + return true; + + case MKEY_Down: + if (manager.SavegameCount() > 1) + { + if (Selected == -1) Selected = TopItem; + else + { + if (++Selected >= manager.SavegameCount()) Selected = 0; + if (Selected < TopItem) TopItem = Selected; + else if (Selected >= TopItem + listboxRows) TopItem = MAX(0, Selected - listboxRows + 1); + } + manager.UnloadSaveData (); + manager.ExtractSaveData (Selected); + } + return true; + + case MKEY_PageDown: + if (manager.SavegameCount() > 1) + { + if (TopItem >= manager.SavegameCount() - listboxRows) + { + TopItem = 0; + if (Selected != -1) Selected = 0; + } + else + { + TopItem = MIN(TopItem + listboxRows, manager.SavegameCount() - listboxRows); + if (TopItem > Selected && Selected != -1) Selected = TopItem; + } + manager.UnloadSaveData (); + manager.ExtractSaveData (Selected); + } + return true; + + case MKEY_PageUp: + if (manager.SavegameCount() > 1) + { + if (TopItem == 0) + { + TopItem = MAX(0, manager.SavegameCount() - listboxRows); + if (Selected != -1) Selected = TopItem; + } + else + { + TopItem = MAX(TopItem - listboxRows, 0); + if (Selected >= TopItem + listboxRows) Selected = TopItem; + } + manager.UnloadSaveData (); + manager.ExtractSaveData (Selected); + } + return true; + + case MKEY_Enter: + return false; // This event will be handled by the subclasses + + case MKEY_MBYes: + { + if (Selected < manager.SavegameCount()) + { + Selected = manager.RemoveSaveSlot (Selected); + } + return true; + } + + default: + return Super.MenuEvent(mkey, fromcontroller); + } + } + + //============================================================================= + // + // + // + //============================================================================= + + override bool MouseEvent(int type, int x, int y) + { + if (x >= listboxLeft && x < listboxLeft + listboxWidth && + y >= listboxTop && y < listboxTop + listboxHeight) + { + int lineno = (y - listboxTop) / rowHeight; + + if (TopItem + lineno < manager.SavegameCount()) + { + Selected = TopItem + lineno; + manager.UnloadSaveData (); + manager.ExtractSaveData (Selected); + if (type == MOUSE_Release) + { + if (MenuEvent(MKEY_Enter, true)) + { + return true; + } + } + } + else Selected = -1; + } + else Selected = -1; + + return Super.MouseEvent(type, x, y); + } + //============================================================================= //