From f9a101486ca402cf14c4185a63eda13809c30552 Mon Sep 17 00:00:00 2001 From: elasota Date: Mon, 9 Nov 2020 01:57:49 -0500 Subject: [PATCH] Add delete to resume game UI --- ApplicationResourcePatches/DITL/2001.json | 12 +++++-- ApplicationResourcePatches/DITL/2008.json | 29 +++++++++++++++ ApplicationResourcePatches/manifest.json | 1 + PortabilityLayer/FileBrowserUI.cpp | 44 +++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 ApplicationResourcePatches/DITL/2008.json diff --git a/ApplicationResourcePatches/DITL/2001.json b/ApplicationResourcePatches/DITL/2001.json index e4b9dc1..be6fe54 100644 --- a/ApplicationResourcePatches/DITL/2001.json +++ b/ApplicationResourcePatches/DITL/2001.json @@ -22,7 +22,7 @@ "itemType" : "CustomControl", "pos" : [ 17, 33 ], "size" : [ 401, 190 ], - "id" : 2, + "id" : 3, "enabled" : true }, { @@ -30,9 +30,17 @@ "itemType" : "CustomControl", "pos" : [ 418, 32 ], "size" : [ 16, 192 ], - "id" : 3, + "id" : 4, "enabled" : true }, + { + "name" : "Delete", + "itemType" : "Button", + "pos" : [ 228, 240 ], + "size" : [ 58, 20 ], + "id" : 5, + "enabled" : false + }, { "name" : "^0", "itemType" : "Label", diff --git a/ApplicationResourcePatches/DITL/2008.json b/ApplicationResourcePatches/DITL/2008.json new file mode 100644 index 0000000..6fae094 --- /dev/null +++ b/ApplicationResourcePatches/DITL/2008.json @@ -0,0 +1,29 @@ +{ + "items" : + [ + { + "name" : "No", + "itemType" : "Button", + "pos" : [ 253, 99 ], + "size" : [ 58, 20 ], + "id" : 1, + "enabled" : true + }, + { + "name" : "Yes", + "itemType" : "Button", + "pos" : [ 184, 99 ], + "size" : [ 58, 20 ], + "id" : 2, + "enabled" : true + }, + { + "name" : "Are you sure that you want to delete this file?", + "itemType" : "Label", + "pos" : [ 16, 16 ], + "size" : [ 295, 74 ], + "id" : 0, + "enabled" : false + } + ] +} \ No newline at end of file diff --git a/ApplicationResourcePatches/manifest.json b/ApplicationResourcePatches/manifest.json index 2ae2da2..2bf078e 100644 --- a/ApplicationResourcePatches/manifest.json +++ b/ApplicationResourcePatches/manifest.json @@ -10,6 +10,7 @@ "DITL/2005.json" : "ApplicationResourcePatches/DITL/2005.json", "DITL/2006.json" : "ApplicationResourcePatches/DITL/2006.json", "DITL/2007.json" : "ApplicationResourcePatches/DITL/2007.json", + "DITL/2008.json" : "ApplicationResourcePatches/DITL/2008.json", "PICT/1300.bmp" : "ApplicationResourcePatches/PICT/1300.bmp", "PICT/1301.bmp" : "ApplicationResourcePatches/PICT/1301.bmp", "PICT/1302.bmp" : "ApplicationResourcePatches/PICT/1302.bmp", diff --git a/PortabilityLayer/FileBrowserUI.cpp b/PortabilityLayer/FileBrowserUI.cpp index 06de308..3a074f3 100644 --- a/PortabilityLayer/FileBrowserUI.cpp +++ b/PortabilityLayer/FileBrowserUI.cpp @@ -37,11 +37,13 @@ static const int kCancelButton = 2; static const int kFileList = 3; static const int kFileListScrollBar = 4; static const int kFileNameEditBox = 5; +static const int kDeleteButton = 5; static const int kFileBrowserUIOpenDialogTemplateID = 2001; static const int kFileBrowserUISaveDialogTemplateID = 2002; static const int kFileBrowserUIOverwriteDialogTemplateID = 2003; static const int kFileBrowserUIBadNameDialogTemplateID = 2004; static const int kFileBrowserUISaveDialogUnobstructiveTemplateID = 2007; +static const int kFileBrowserUIDeleteDialogTemplateID = 2008; static const int kOverwriteNoButton = 1; @@ -72,6 +74,8 @@ namespace PortabilityLayer PLPasStr GetSelectedFileName() const; + void RemoveSelectedFile(); + static int16_t PopUpAlert(const Rect &rect, int dialogResID, const DialogTextSubstitutions *substitutions); private: @@ -248,6 +252,22 @@ namespace PortabilityLayer return (*m_names)[m_selectedIndex].ToShortStr(); } + void FileBrowserUIImpl::RemoveSelectedFile() + { + if (m_selectedIndex < 0) + return; + + NameStr_t *names = *m_names; + for (size_t i = m_selectedIndex; i < m_numNames - 1; i++) + names[i] = names[i + 1]; + + m_numNames--; + PortabilityLayer::MemoryManager::GetInstance()->ResizeHandle(m_names.MMBlock(), sizeof(NameStr_t) * m_numNames); + + m_selectedIndex = -1; + DrawFileList(); + } + void FileBrowserUIImpl::ScrollBarCallback(Widget *control, int part) { const int pageStepping = 5; @@ -273,6 +293,8 @@ namespace PortabilityLayer SetScrollOffset(control->GetState()); } + static FileBrowserUI::Mode gs_currentFileBrowserUIMode; + int16_t FileBrowserUIImpl::FileBrowserUIFilter(Dialog *dialog, const TimeTaggedVOSEvent *evt) { bool handledIt = false; @@ -373,6 +395,9 @@ namespace PortabilityLayer dialog->GetItems()[kOkayButton - 1].GetWidget()->SetEnabled(selection >= 0); + if (gs_currentFileBrowserUIMode == FileBrowserUI::Mode_Open) + dialog->GetItems()[kDeleteButton - 1].GetWidget()->SetEnabled(selection >= 0); + DrawFileList(); } @@ -633,6 +658,8 @@ namespace PortabilityLayer WindowManager::GetInstance()->SwapExclusiveWindow(exclWindow); + gs_currentFileBrowserUIMode = mode; + do { hit = dialog->ExecuteModal(&uiImpl, FileBrowserUIImpl::PubFileBrowserUIFilter); @@ -664,6 +691,23 @@ namespace PortabilityLayer hit = -1; } } + + if (mode == Mode_Open && hit == kDeleteButton) + { + PortabilityLayer::HostSystemServices::GetInstance()->Beep(); + int16_t subHit = FileBrowserUIImpl::PopUpAlert(Rect::Create(0, 0, 135, 327), kFileBrowserUIDeleteDialogTemplateID, &substitutions); + + if (subHit == kOverwriteYesButton) + { + PLPasStr uiFileName = uiImpl.GetSelectedFileName(); + + PortabilityLayer::FileManager::GetInstance()->DeleteFile(dirID, uiFileName); + uiImpl.RemoveSelectedFile(); + dialog->GetItems()[kOkayButton - 1].GetWidget()->SetEnabled(false); + dialog->GetItems()[kDeleteButton - 1].GetWidget()->SetEnabled(false); + } + hit = -1; + } } while (hit != kOkayButton && hit != kCancelButton); WindowManager::GetInstance()->SwapExclusiveWindow(exclWindow);