2019-11-08 22:02:52 +00:00
|
|
|
/*
|
|
|
|
** loadsavemenu.cpp
|
|
|
|
** The load game and save game menus
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2001-2010 Randy Heit
|
|
|
|
** Copyright 2010 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "menu/menu.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include "m_png.h"
|
|
|
|
#include "filesystem.h"
|
|
|
|
#include "v_text.h"
|
|
|
|
#include "d_event.h"
|
|
|
|
#include "gstrings.h"
|
|
|
|
#include "d_gui.h"
|
|
|
|
#include "v_draw.h"
|
2019-11-26 23:41:26 +00:00
|
|
|
#include "files.h"
|
|
|
|
#include "resourcefile.h"
|
|
|
|
#include "savegamehelp.h"
|
|
|
|
#include "i_specialpaths.h"
|
2019-11-08 22:02:52 +00:00
|
|
|
#include "../../platform/win32/i_findfile.h" // This is a temporary direct path. Needs to be fixed when stuff gets cleaned up.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DLoadSaveMenu : public DListMenu
|
|
|
|
{
|
2019-11-22 21:52:11 +00:00
|
|
|
using Super = DListMenu;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2019-11-30 21:46:00 +00:00
|
|
|
int Selected = 0;
|
|
|
|
int TopItem = 0;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
int savepicLeft;
|
|
|
|
int savepicTop;
|
|
|
|
int savepicWidth;
|
|
|
|
int savepicHeight;
|
|
|
|
|
|
|
|
int rowHeight;
|
|
|
|
int listboxLeft;
|
|
|
|
int listboxTop;
|
|
|
|
int listboxWidth;
|
|
|
|
|
|
|
|
int listboxRows;
|
|
|
|
int listboxHeight;
|
|
|
|
int listboxRight;
|
|
|
|
int listboxBottom;
|
|
|
|
|
|
|
|
int commentLeft;
|
|
|
|
int commentTop;
|
|
|
|
int commentWidth;
|
|
|
|
int commentHeight;
|
|
|
|
int commentRight;
|
|
|
|
int commentBottom;
|
2019-11-29 23:49:50 +00:00
|
|
|
int commentRows;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
double FontScale;
|
|
|
|
DTextEnterMenu *mInput = nullptr;
|
|
|
|
TArray<FBrokenLines> BrokenSaveComment;
|
|
|
|
bool mEntering = false;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
// End of static savegame maintenance code
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
DLoadSaveMenu()
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
savegameManager.ReadSaveStrings();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-07 00:11:19 +00:00
|
|
|
void Init(DMenu* parent, FListMenuDescriptor* desc) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
Super::Init(parent, desc);
|
|
|
|
int Width43 = screen->GetHeight() * 4 / 3;
|
|
|
|
int Left43 = (screen->GetWidth() - Width43) / 2;
|
|
|
|
float wScale = Width43 / 640.;
|
|
|
|
savepicLeft = Left43 + int(20 * wScale);
|
|
|
|
savepicTop = mDesc->mYpos * screen->GetHeight() / 200 ;
|
|
|
|
savepicWidth = int(240 * wScale);
|
|
|
|
savepicHeight = int(180 * wScale);
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
FontScale = max(screen->GetHeight() / 480, 1);
|
|
|
|
rowHeight = std::max(int((NewConsoleFont->GetHeight() + 1) * FontScale), 1);
|
|
|
|
listboxLeft = savepicLeft + savepicWidth + int(20 * wScale);
|
|
|
|
listboxTop = savepicTop;
|
|
|
|
listboxWidth = Width43 + Left43 - listboxLeft - int(30 * wScale);
|
|
|
|
int listboxHeight1 = screen->GetHeight() - listboxTop - int(20*wScale);
|
|
|
|
listboxRows = (listboxHeight1 - 1) / rowHeight;
|
|
|
|
listboxHeight = listboxRows * rowHeight + 1;
|
|
|
|
listboxRight = listboxLeft + listboxWidth;
|
|
|
|
listboxBottom = listboxTop + listboxHeight;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
commentLeft = savepicLeft;
|
|
|
|
commentTop = savepicTop + savepicHeight + int(16 * wScale);
|
|
|
|
commentWidth = savepicWidth;
|
|
|
|
commentHeight = listboxHeight - savepicHeight - (16 * wScale);
|
|
|
|
commentRight = commentLeft + commentWidth;
|
|
|
|
commentBottom = commentTop + commentHeight;
|
2019-11-30 22:45:43 +00:00
|
|
|
commentRows = commentHeight / rowHeight;
|
|
|
|
UpdateSaveComment();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
void Drawer() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
Super::Drawer();
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
int i;
|
|
|
|
unsigned j;
|
|
|
|
bool didSeeSelected = false;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
// Draw picture area
|
|
|
|
/*
|
|
|
|
if (gameaction == ga_loadgame || gameaction == ga_loadgamehidecon || gameaction == ga_savegame)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
*/
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
PalEntry frameColor(255, 80, 80, 80); // todo: pick a proper color per game.
|
|
|
|
PalEntry fillColor(160, 0, 0, 0);
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawFrame(twod, frameColor, savepicLeft, savepicTop, savepicWidth, savepicHeight, -1);
|
2019-11-29 23:49:50 +00:00
|
|
|
if (!savegameManager.DrawSavePic(savepicLeft, savepicTop, savepicWidth, savepicHeight))
|
|
|
|
{
|
2019-12-30 18:29:32 +00:00
|
|
|
twod->AddColorOnlyQuad(savepicLeft, savepicTop, savepicWidth, savepicHeight, fillColor);
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
if (savegameManager.SavegameCount() > 0)
|
|
|
|
{
|
2019-12-01 21:54:52 +00:00
|
|
|
if (Selected >= savegameManager.SavegameCount()) Selected = 0;
|
2019-11-29 23:49:50 +00:00
|
|
|
FString text = (Selected == -1 || !savegameManager.GetSavegame(Selected)->bOldVersion) ? GStrings("MNU_NOPICTURE") : GStrings("MNU_DIFFVERSION");
|
|
|
|
int textlen = NewSmallFont->StringWidth(text) * CleanXfac;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, NewSmallFont, CR_GOLD, savepicLeft + (savepicWidth - textlen) / 2,
|
2019-11-29 23:49:50 +00:00
|
|
|
savepicTop + (savepicHeight - rowHeight) / 2, text, DTA_CleanNoMove, true, TAG_DONE);
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
// Draw comment area
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawFrame(twod, frameColor, commentLeft, commentTop, commentWidth, commentHeight, -1);
|
|
|
|
twod->AddColorOnlyQuad(commentLeft, commentTop, commentWidth, commentHeight, fillColor);
|
2019-11-29 23:49:50 +00:00
|
|
|
|
|
|
|
int numlinestoprint = std::min(commentRows, (int)BrokenSaveComment.Size());
|
|
|
|
for (int i = 0; i < numlinestoprint; i++)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, NewConsoleFont, CR_ORANGE, commentLeft / FontScale, (commentTop + rowHeight * i) / FontScale, BrokenSaveComment[i].Text,
|
2019-11-29 23:49:50 +00:00
|
|
|
DTA_VirtualWidthF, screen->GetWidth() / FontScale, DTA_VirtualHeightF, screen->GetHeight() / FontScale, DTA_KeepRatio, true, TAG_DONE);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
// Draw file area
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawFrame(twod, frameColor, listboxLeft, listboxTop, listboxWidth, listboxHeight, -1);
|
|
|
|
twod->AddColorOnlyQuad(listboxLeft, listboxTop, listboxWidth, listboxHeight, fillColor);
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
if (savegameManager.SavegameCount() == 0)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
FString text = GStrings("MNU_NOFILES");
|
|
|
|
int textlen = int(NewConsoleFont->StringWidth(text) * FontScale);
|
|
|
|
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, NewConsoleFont, CR_GOLD, (listboxLeft + (listboxWidth - textlen) / 2) / FontScale, (listboxTop + (listboxHeight - rowHeight) / 2) / FontScale, text,
|
2019-11-29 23:49:50 +00:00
|
|
|
DTA_VirtualWidthF, screen->GetWidth() / FontScale, DTA_VirtualHeightF, screen->GetHeight() / FontScale, DTA_KeepRatio, true, TAG_DONE);
|
|
|
|
return;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
j = TopItem;
|
|
|
|
for (i = 0; i < listboxRows && j < savegameManager.SavegameCount(); i++)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
int colr;
|
|
|
|
auto& node = *savegameManager.GetSavegame(j);
|
|
|
|
if (node.bOldVersion)
|
|
|
|
{
|
|
|
|
colr = CR_RED;
|
|
|
|
}
|
|
|
|
else if (node.bMissingWads)
|
|
|
|
{
|
|
|
|
colr = CR_YELLOW;
|
|
|
|
}
|
|
|
|
else if (j == Selected)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
colr = CR_WHITE;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
colr = CR_TAN;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//screen->SetClipRect(listboxLeft, listboxTop+rowHeight*i, listboxRight, listboxTop+rowHeight*(i+1));
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
if ((int)j == Selected)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-12-30 18:29:32 +00:00
|
|
|
twod->AddColorOnlyQuad(listboxLeft, listboxTop + rowHeight * i, listboxWidth, rowHeight, mEntering ? PalEntry(255, 255, 0, 0) : PalEntry(255, 0, 0, 255));
|
2019-11-29 23:49:50 +00:00
|
|
|
didSeeSelected = true;
|
|
|
|
if (!mEntering)
|
|
|
|
{
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, NewConsoleFont, colr, (listboxLeft + 1) / FontScale, (listboxTop + rowHeight * i + FontScale) / FontScale, node.SaveTitle,
|
2019-11-29 23:49:50 +00:00
|
|
|
DTA_VirtualWidthF, screen->GetWidth() / FontScale, DTA_VirtualHeightF, screen->GetHeight() / FontScale, DTA_KeepRatio, true, TAG_DONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FStringf s("%s%c", mInput->GetText(), NewConsoleFont->GetCursor());
|
|
|
|
int length = int(NewConsoleFont->StringWidth(s) * FontScale);
|
|
|
|
int displacement = std::min(0, listboxWidth - 2 - length);
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, NewConsoleFont, CR_WHITE, (listboxLeft + 1 + displacement) / FontScale, (listboxTop + rowHeight * i + FontScale) / FontScale, s,
|
2019-11-29 23:49:50 +00:00
|
|
|
DTA_VirtualWidthF, screen->GetWidth() / FontScale, DTA_VirtualHeightF, screen->GetHeight() / FontScale, DTA_KeepRatio, true, TAG_DONE);
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-30 18:29:32 +00:00
|
|
|
DrawText(twod, NewConsoleFont, colr, (listboxLeft + 1) / FontScale, (listboxTop + rowHeight * i + FontScale) / FontScale, node.SaveTitle,
|
2019-11-29 23:49:50 +00:00
|
|
|
DTA_VirtualWidthF, screen->GetWidth() / FontScale, DTA_VirtualHeightF, screen->GetHeight() / FontScale, DTA_KeepRatio, true, TAG_DONE);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
//screen->ClearClipRect();
|
|
|
|
j++;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateSaveComment()
|
|
|
|
{
|
2019-11-30 22:45:43 +00:00
|
|
|
BrokenSaveComment = V_BreakLines(NewConsoleFont, int(commentWidth / FontScale), savegameManager.SaveCommentString);
|
2019-11-29 23:49:50 +00:00
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
bool MenuEvent(int mkey, bool fromcontroller) override
|
|
|
|
{
|
|
|
|
auto& manager = savegameManager;
|
|
|
|
switch (mkey)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
case MKEY_Up:
|
|
|
|
if (manager.SavegameCount() > 1)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (Selected == -1) Selected = TopItem;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (--Selected < 0) Selected = manager.SavegameCount() - 1;
|
|
|
|
if (Selected < TopItem) TopItem = Selected;
|
|
|
|
else if (Selected >= TopItem + listboxRows) TopItem = std::max(0, Selected - listboxRows + 1);
|
|
|
|
}
|
|
|
|
manager.UnloadSaveData();
|
|
|
|
manager.ExtractSaveData(Selected);
|
|
|
|
UpdateSaveComment();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case MKEY_Down:
|
|
|
|
if (manager.SavegameCount() > 1)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (Selected == -1) Selected = TopItem;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (++Selected >= manager.SavegameCount()) Selected = 0;
|
|
|
|
if (Selected < TopItem) TopItem = Selected;
|
|
|
|
else if (Selected >= TopItem + listboxRows) TopItem = std::max(0, Selected - listboxRows + 1);
|
|
|
|
}
|
|
|
|
manager.UnloadSaveData();
|
|
|
|
manager.ExtractSaveData(Selected);
|
|
|
|
UpdateSaveComment();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
return true;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
case MKEY_PageDown:
|
|
|
|
if (manager.SavegameCount() > 1)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (TopItem >= manager.SavegameCount() - listboxRows)
|
|
|
|
{
|
|
|
|
TopItem = 0;
|
|
|
|
if (Selected != -1) Selected = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TopItem = std::min(TopItem + listboxRows, int(manager.SavegameCount()) - listboxRows);
|
|
|
|
if (TopItem > Selected&& Selected != -1) Selected = TopItem;
|
|
|
|
}
|
|
|
|
manager.UnloadSaveData();
|
|
|
|
manager.ExtractSaveData(Selected);
|
|
|
|
UpdateSaveComment();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case MKEY_PageUp:
|
|
|
|
if (manager.SavegameCount() > 1)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (TopItem == 0)
|
|
|
|
{
|
|
|
|
TopItem = std::max(0, int(manager.SavegameCount()) - listboxRows);
|
|
|
|
if (Selected != -1) Selected = TopItem;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TopItem = std::max(int(TopItem - listboxRows), 0);
|
|
|
|
if (Selected >= TopItem + listboxRows) Selected = TopItem;
|
|
|
|
}
|
|
|
|
manager.UnloadSaveData();
|
|
|
|
manager.ExtractSaveData(Selected);
|
|
|
|
UpdateSaveComment();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
return true;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
case MKEY_Enter:
|
|
|
|
return false; // This event will be handled by the subclasses
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
case MKEY_MBYes:
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (Selected < manager.SavegameCount())
|
|
|
|
{
|
|
|
|
Selected = manager.RemoveSaveSlot(Selected);
|
|
|
|
UpdateSaveComment();
|
|
|
|
}
|
|
|
|
return true;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
default:
|
|
|
|
return Super::MenuEvent(mkey, fromcontroller);
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
bool MouseEvent(int type, int x, int y) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
auto& manager = savegameManager;
|
|
|
|
if (x >= listboxLeft && x < listboxLeft + listboxWidth &&
|
|
|
|
y >= listboxTop && y < listboxTop + listboxHeight)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
int lineno = (y - listboxTop) / rowHeight;
|
|
|
|
|
|
|
|
if (TopItem + lineno < manager.SavegameCount())
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
Selected = TopItem + lineno;
|
|
|
|
manager.UnloadSaveData();
|
|
|
|
manager.ExtractSaveData(Selected);
|
|
|
|
UpdateSaveComment();
|
|
|
|
if (type == MOUSE_Release)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (MenuEvent(MKEY_Enter, true))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
else Selected = -1;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
else Selected = -1;
|
2019-11-29 23:49:50 +00:00
|
|
|
|
|
|
|
return Super::MouseEvent(type, x, y);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
bool Responder(event_t * ev) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
auto& manager = savegameManager;
|
|
|
|
if (ev->type == EV_GUI_Event)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (ev->subtype == EV_GUI_KeyDown)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if ((unsigned)Selected < manager.SavegameCount())
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
switch (ev->data1)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
case GK_F1:
|
|
|
|
manager.SetFileInfo(Selected);
|
|
|
|
UpdateSaveComment();
|
|
|
|
return true;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
case GK_DEL:
|
|
|
|
case '\b':
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
|
|
|
FString EndString;
|
|
|
|
EndString.Format("%s" TEXTCOLOR_WHITE "%s" TEXTCOLOR_NORMAL "?\n\n%s",
|
2019-11-29 23:49:50 +00:00
|
|
|
GStrings("MNU_DELETESG"), manager.GetSavegame(Selected)->SaveTitle.GetChars(), GStrings("PRESSYN"));
|
2019-11-30 09:03:20 +00:00
|
|
|
M_StartMessage(EndString, 0, -1);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
return true;
|
2019-11-29 23:49:50 +00:00
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
else if (ev->subtype == EV_GUI_WheelUp)
|
|
|
|
{
|
|
|
|
if (TopItem > 0) TopItem--;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ev->subtype == EV_GUI_WheelDown)
|
|
|
|
{
|
|
|
|
if (TopItem < manager.SavegameCount() - listboxRows) TopItem++;
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
return Super::Responder(ev);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
};
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class DSaveMenu : public DLoadSaveMenu
|
|
|
|
{
|
2019-11-22 21:52:11 +00:00
|
|
|
using Super = DLoadSaveMenu;
|
2019-11-29 23:49:50 +00:00
|
|
|
FString mSaveName;
|
2019-11-08 22:02:52 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
DSaveMenu()
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
savegameManager.InsertNewSaveNode();
|
|
|
|
TopItem = 0;
|
|
|
|
Selected = savegameManager.ExtractSaveData (-1);
|
|
|
|
UpdateSaveComment();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
void Destroy() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (savegameManager.RemoveNewSaveNode())
|
|
|
|
{
|
|
|
|
Selected--;
|
|
|
|
}
|
|
|
|
Super::Destroy();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
bool MenuEvent (int mkey, bool fromcontroller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (Super::MenuEvent(mkey, fromcontroller))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Selected == -1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mkey == MKEY_Enter)
|
|
|
|
{
|
|
|
|
FString SavegameString = (Selected != 0)? savegameManager.GetSavegame(Selected)->SaveTitle : FString();
|
|
|
|
mInput = new DTextEnterMenu(this, NewConsoleFont, SavegameString, listboxWidth, false, false);
|
|
|
|
M_ActivateMenu(mInput);
|
|
|
|
mEntering = true;
|
|
|
|
}
|
|
|
|
else if (mkey == MKEY_Input)
|
|
|
|
{
|
|
|
|
mEntering = false;
|
|
|
|
mSaveName = mInput->GetText();
|
|
|
|
mInput = nullptr;
|
|
|
|
}
|
|
|
|
else if (mkey == MKEY_Abort)
|
|
|
|
{
|
|
|
|
mEntering = false;
|
|
|
|
mInput = nullptr;
|
|
|
|
}
|
|
|
|
return false;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
bool MouseEvent(int type, int x, int y) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (mSaveName.Len() > 0)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
// Do not process events when saving is in progress to avoid update of the current index,
|
|
|
|
// i.e. Selected member variable must remain unchanged
|
|
|
|
return true;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
return Super::MouseEvent(type, x, y);
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
bool Responder (event_t *ev) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (ev->subtype == EV_GUI_KeyDown)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (Selected != -1)
|
|
|
|
{
|
|
|
|
switch (ev->data1)
|
|
|
|
{
|
|
|
|
case GK_DEL:
|
|
|
|
case '\b':
|
|
|
|
// cannot delete 'new save game' item
|
|
|
|
if (Selected == 0) return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'N':
|
|
|
|
Selected = TopItem = 0;
|
|
|
|
savegameManager.UnloadSaveData();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
return Super::Responder(ev);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
void Ticker() override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (mSaveName.Len() > 0)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
savegameManager.DoSave(Selected, mSaveName);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
|
|
|
|
};
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
class DLoadMenu : public DLoadSaveMenu
|
|
|
|
{
|
2019-11-22 21:52:11 +00:00
|
|
|
using Super = DLoadSaveMenu;
|
2019-11-08 22:02:52 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
DLoadMenu()
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
TopItem = 0;
|
|
|
|
Selected = savegameManager.ExtractSaveData(-1);
|
|
|
|
UpdateSaveComment();
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
//=============================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//=============================================================================
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
bool MenuEvent(int mkey, bool fromcontroller) override
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
if (Super::MenuEvent(mkey, fromcontroller))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Selected == -1 || savegameManager.SavegameCount() == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-29 23:49:50 +00:00
|
|
|
if (mkey == MKEY_Enter)
|
2019-11-08 22:02:52 +00:00
|
|
|
{
|
2019-11-29 23:49:50 +00:00
|
|
|
savegameManager.LoadSavegame(Selected);
|
|
|
|
return true;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
return false;
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
2019-11-29 23:49:50 +00:00
|
|
|
};
|
2019-11-08 22:02:52 +00:00
|
|
|
|
2019-11-28 22:27:10 +00:00
|
|
|
static TMenuClassDescriptor<DLoadMenu> _lm("LoadMenu");
|
|
|
|
static TMenuClassDescriptor<DSaveMenu> _sm("SaveMenu");
|
|
|
|
|
2019-11-28 23:37:19 +00:00
|
|
|
void RegisterLoadsaveMenus()
|
2019-11-28 22:27:10 +00:00
|
|
|
{
|
|
|
|
menuClasses.Push(&_sm);
|
|
|
|
menuClasses.Push(&_lm);
|
|
|
|
}
|