summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/CmpFileDlg.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-01 21:23:39 +0200
committerAki <please@ignore.pl>2022-04-01 21:23:39 +0200
commit3c487c5cd69c53d6fea948643c0a76df03516605 (patch)
tree72730c7b8b26a5ef8fc9a987ec4c16129efd5aac /StarsEx/CmpFileDlg.cpp
parent8f353abd0bfe18baddd8a8250ab7c4f2d1c83a6e (diff)
downloadstarshatter-3c487c5cd69c53d6fea948643c0a76df03516605.zip
starshatter-3c487c5cd69c53d6fea948643c0a76df03516605.tar.gz
starshatter-3c487c5cd69c53d6fea948643c0a76df03516605.tar.bz2
Moved Stars45 to StarsEx
Diffstat (limited to 'StarsEx/CmpFileDlg.cpp')
-rw-r--r--StarsEx/CmpFileDlg.cpp189
1 files changed, 189 insertions, 0 deletions
diff --git a/StarsEx/CmpFileDlg.cpp b/StarsEx/CmpFileDlg.cpp
new file mode 100644
index 0000000..1f359e5
--- /dev/null
+++ b/StarsEx/CmpFileDlg.cpp
@@ -0,0 +1,189 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Mission Select Dialog Active Window class
+*/
+
+#include "CmpFileDlg.h"
+#include "CmpnScreen.h"
+#include "Starshatter.h"
+#include "Campaign.h"
+#include "CampaignSaveGame.h"
+#include "CombatGroup.h"
+
+#include "Game.h"
+#include "DataLoader.h"
+#include "Button.h"
+#include "EditBox.h"
+#include "ListBox.h"
+#include "Slider.h"
+#include "Video.h"
+#include "Keyboard.h"
+#include "Mouse.h"
+#include "FormatUtil.h"
+#include "ParseUtil.h"
+
+// +--------------------------------------------------------------------+
+// DECLARE MAPPING FUNCTIONS:
+
+DEF_MAP_CLIENT(CmpFileDlg, OnSave);
+DEF_MAP_CLIENT(CmpFileDlg, OnCancel);
+DEF_MAP_CLIENT(CmpFileDlg, OnCampaign);
+
+// +--------------------------------------------------------------------+
+
+CmpFileDlg::CmpFileDlg(Screen* s, FormDef& def, CmpnScreen* mgr)
+: FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
+exit_latch(false), btn_save(0), btn_cancel(0), edt_name(0), lst_campaigns(0)
+{
+ Init(def);
+}
+
+CmpFileDlg::~CmpFileDlg()
+{
+}
+
+// +--------------------------------------------------------------------+
+
+void
+CmpFileDlg::RegisterControls()
+{
+ btn_save = (Button*) FindControl(1);
+ btn_cancel = (Button*) FindControl(2);
+
+ if (btn_save)
+ REGISTER_CLIENT(EID_CLICK, btn_save, CmpFileDlg, OnSave);
+
+ if (btn_cancel)
+ REGISTER_CLIENT(EID_CLICK, btn_cancel, CmpFileDlg, OnCancel);
+
+ edt_name = (EditBox*) FindControl(200);
+
+ if (edt_name)
+ edt_name->SetText("");
+
+ lst_campaigns = (ListBox*) FindControl(201);
+
+ if (lst_campaigns)
+ REGISTER_CLIENT(EID_SELECT, lst_campaigns, CmpFileDlg, OnCampaign);
+}
+
+// +--------------------------------------------------------------------+
+
+void
+CmpFileDlg::Show()
+{
+ FormWindow::Show();
+
+ if (lst_campaigns) {
+ lst_campaigns->ClearItems();
+ lst_campaigns->SetLineHeight(12);
+
+ List<Text> save_list;
+
+ CampaignSaveGame::GetSaveGameList(save_list);
+ save_list.sort();
+
+ for (int i = 0; i < save_list.size(); i++)
+ lst_campaigns->AddItem(*save_list[i]);
+
+ save_list.destroy();
+ }
+
+ if (edt_name) {
+ char save_name[256];
+ save_name[0] = 0;
+
+ campaign = Campaign::GetCampaign();
+ if (campaign && campaign->GetPlayerGroup()) {
+ const char* op_name = campaign->Name();
+ char day[32];
+ CombatGroup* group = campaign->GetPlayerGroup();
+
+ if (strstr(op_name, "Operation "))
+ op_name += 10;
+
+ FormatDay(day, campaign->GetTime());
+
+ sprintf_s(save_name, "%s %s (%s)",
+ op_name,
+ day,
+ group->GetRegion().data());
+ }
+
+ edt_name->SetText(save_name);
+ edt_name->SetFocus();
+ }
+}
+
+// +--------------------------------------------------------------------+
+
+void
+CmpFileDlg::ExecFrame()
+{
+ if (Keyboard::KeyDown(VK_RETURN)) {
+ OnSave(0);
+ }
+
+ if (Keyboard::KeyDown(VK_ESCAPE)) {
+ if (!exit_latch)
+ OnCancel(0);
+
+ exit_latch = true;
+ }
+ else {
+ exit_latch = false;
+ }
+}
+
+// +--------------------------------------------------------------------+
+
+void
+CmpFileDlg::OnSave(AWEvent* event)
+{
+ if (edt_name && edt_name->GetText().length() > 0) {
+ campaign = Campaign::GetCampaign();
+ CampaignSaveGame save(campaign);
+
+ char filename[256];
+ strcpy_s(filename, edt_name->GetText());
+ char* newline = strchr(filename, '\n');
+ if (newline)
+ *newline = 0;
+
+ save.Save(filename);
+ save.SaveAuto();
+
+ if (manager)
+ manager->HideCmpFileDlg();
+ }
+}
+
+void
+CmpFileDlg::OnCancel(AWEvent* event)
+{
+ if (manager)
+ manager->HideCmpFileDlg();
+}
+
+// +--------------------------------------------------------------------+
+
+void
+CmpFileDlg::OnCampaign(AWEvent* event)
+{
+ int n = lst_campaigns->GetSelection();
+
+ if (n >= 0) {
+ Text cmpn = lst_campaigns->GetItemText(n);
+
+ if (edt_name)
+ edt_name->SetText(cmpn);
+ }
+} \ No newline at end of file