- scriptified DLoadSaveMenu::MenuEvent.

This commit is contained in:
Christoph Oelckers 2017-02-18 17:35:01 +01:00
parent ee6a90deec
commit 4a6d0f1fa5
3 changed files with 138 additions and 130 deletions

View file

@ -105,6 +105,14 @@ int FSavegameManager::RemoveSaveSlot(int index)
return 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]; return SaveGames[i];
} }
@ -764,8 +772,6 @@ public:
void OnDestroy() override; void OnDestroy() override;
void Drawer (); void Drawer ();
bool MenuEvent (int mkey, bool fromcontroller);
bool MouseEvent(int type, int x, int y);
}; };
IMPLEMENT_CLASS(DLoadSaveMenu, false, false) 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<int>(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, SaveTitle);
DEFINE_FIELD(FSaveGameNode, Filename); DEFINE_FIELD(FSaveGameNode, Filename);

View file

@ -100,7 +100,7 @@ public:
void DrawSaveComment(FFont *font, int cr, int x, int y, int scalefactor); void DrawSaveComment(FFont *font, int cr, int x, int y, int scalefactor);
void SetFileInfo(int Selected); void SetFileInfo(int Selected);
unsigned SavegameCount(); unsigned SavegameCount();
FSaveGameNode *GetSavegame(unsigned i); FSaveGameNode *GetSavegame(int i);
void InsertNewSaveNode(); void InsertNewSaveNode();
bool RemoveNewSaveNode(); bool RemoveNewSaveNode();

View file

@ -51,7 +51,7 @@ struct SavegameManager native
//void ReadSaveStrings(); //void ReadSaveStrings();
native void UnloadSaveData(); native void UnloadSaveData();
//int RemoveSaveSlot(int index); native int RemoveSaveSlot(int index);
native void LoadSavegame(int Selected); native void LoadSavegame(int Selected);
native void DoSave(int Selected, String savegamestring); native void DoSave(int Selected, String savegamestring);
native int ExtractSaveData(int index); native int ExtractSaveData(int index);
@ -100,6 +100,133 @@ class LoadSaveMenu : ListMenu native
//=============================================================================
//
//
//
//=============================================================================
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);
}
//============================================================================= //=============================================================================
// //
// //