From e33e19d0587146859d48a134ec9fd94e7b7ba5cd Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Thu, 8 Dec 2011 14:53:40 +0000 Subject: Initial upload --- Stars45/CmdMissionsDlg.cpp | 325 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 325 insertions(+) create mode 100644 Stars45/CmdMissionsDlg.cpp (limited to 'Stars45/CmdMissionsDlg.cpp') diff --git a/Stars45/CmdMissionsDlg.cpp b/Stars45/CmdMissionsDlg.cpp new file mode 100644 index 0000000..2df5ebd --- /dev/null +++ b/Stars45/CmdMissionsDlg.cpp @@ -0,0 +1,325 @@ +/* Project Starshatter 4.5 + Destroyer Studios LLC + Copyright © 1997-2004. All Rights Reserved. + + SUBSYSTEM: Stars.exe + FILE: CmdMissionsDlg.cpp + AUTHOR: John DiCamillo + + + OVERVIEW + ======== + Operational Command Dialog (Mission List Tab) +*/ + +#include "MemDebug.h" +#include "CmdMissionsDlg.h" +#include "CmpnScreen.h" +#include "Starshatter.h" +#include "Campaign.h" +#include "Combatant.h" +#include "CombatAssignment.h" +#include "CombatGroup.h" +#include "CombatUnit.h" +#include "CombatZone.h" +#include "Mission.h" +#include "ShipDesign.h" +#include "Player.h" + +#include "Game.h" +#include "DataLoader.h" +#include "Button.h" +#include "ComboBox.h" +#include "ListBox.h" +#include "Slider.h" +#include "Video.h" +#include "Keyboard.h" +#include "Mouse.h" +#include "ParseUtil.h" +#include "FormatUtil.h" + +// +--------------------------------------------------------------------+ +// DECLARE MAPPING FUNCTIONS: + +DEF_MAP_CLIENT(CmdMissionsDlg, OnMode); +DEF_MAP_CLIENT(CmdMissionsDlg, OnSave); +DEF_MAP_CLIENT(CmdMissionsDlg, OnExit); +DEF_MAP_CLIENT(CmdMissionsDlg, OnMission); +DEF_MAP_CLIENT(CmdMissionsDlg, OnAccept); + +// +--------------------------------------------------------------------+ + +CmdMissionsDlg::CmdMissionsDlg(Screen* s, FormDef& def, CmpnScreen* mgr) + : FormWindow(s, 0, 0, s->Width(), s->Height()), CmdDlg(mgr), manager(mgr), + lst_missions(0), txt_desc(0), btn_accept(0), + stars(0), campaign(0), mission(0) +{ + stars = Starshatter::GetInstance(); + campaign = Campaign::GetCampaign(); + + Init(def); +} + +CmdMissionsDlg::~CmdMissionsDlg() +{ +} + +// +--------------------------------------------------------------------+ + +void +CmdMissionsDlg::RegisterControls() +{ + lst_missions = (ListBox*) FindControl(401); + txt_desc = FindControl(402); + btn_accept = (Button*) FindControl(403); + + RegisterCmdControls(this); + + if (btn_save) + REGISTER_CLIENT(EID_CLICK, btn_save, CmdMissionsDlg, OnSave); + + if (btn_exit) + REGISTER_CLIENT(EID_CLICK, btn_exit, CmdMissionsDlg, OnExit); + + for (int i = 0; i < 5; i++) { + if (btn_mode[i]) + REGISTER_CLIENT(EID_CLICK, btn_mode[i], CmdMissionsDlg, OnMode); + } + + if (lst_missions) { + REGISTER_CLIENT(EID_SELECT, lst_missions, CmdMissionsDlg, OnMission); + } + + if (btn_accept) { + btn_accept->SetEnabled(false); + REGISTER_CLIENT(EID_CLICK, btn_accept, CmdMissionsDlg, OnAccept); + } +} + +// +--------------------------------------------------------------------+ + +void +CmdMissionsDlg::Show() +{ + mode = MODE_MISSIONS; + + FormWindow::Show(); + ShowCmdDlg(); + + campaign = Campaign::GetCampaign(); + + if (campaign) { + if (lst_missions) { + lst_missions->ClearItems(); + + Player* player = Player::GetCurrentPlayer(); + List& missions = campaign->GetMissionList(); + for (int i = 0; i < missions.size(); i++) { + MissionInfo* info = missions[i]; + lst_missions->AddItemWithData(info->name, info->id); + + Mission* m = info->mission; + if (m) { + if (m->Type() == Mission::TRAINING && player->HasTrained(m->Identity())) { + lst_missions->SetItemText(i, 1, Game::GetText("CmdMissionsDlg.training")); + } + else { + lst_missions->SetItemText(i, 1, m->TypeName()); + } + } + + char start_time[64]; + FormatDayTime(start_time, info->start); + lst_missions->SetItemText(i, 2, start_time); + } + } + } +} + +void +CmdMissionsDlg::ExecFrame() +{ + CmdDlg::ExecFrame(); + + if (campaign) { + List& missions = campaign->GetMissionList(); + Player* player = Player::GetCurrentPlayer(); + + if (missions.size() > lst_missions->NumItems()) { + while (missions.size() > lst_missions->NumItems()) { + MissionInfo* info = missions[lst_missions->NumItems()]; + int i = lst_missions->AddItemWithData(info->name, info->id) - 1; + + Mission* m = info->mission; + if (m) { + if (m->Type() == Mission::TRAINING && player->HasTrained(m->Identity())) { + lst_missions->SetItemText(i, 1, Game::GetText("CmdMissionsDlg.training")); + } + else { + lst_missions->SetItemText(i, 1, m->TypeName()); + } + } + + char start_time[64]; + FormatDayTime(start_time, info->start); + lst_missions->SetItemText(i, 2, start_time); + } + } + + else if (missions.size() < lst_missions->NumItems()) { + lst_missions->ClearItems(); + + for (int i = 0; i < missions.size(); i++) { + MissionInfo* info = missions[i]; + lst_missions->AddItemWithData(info->name, info->id); + + Mission* m = info->mission; + if (m) { + if (m->Type() == Mission::TRAINING && player->HasTrained(m->Identity())) { + lst_missions->SetItemText(i, 1, Game::GetText("CmdMissionsDlg.training")); + } + else { + lst_missions->SetItemText(i, 1, m->TypeName()); + } + } + + char start_time[64]; + FormatDayTime(start_time, info->start); + lst_missions->SetItemText(i, 2, start_time); + } + } + + else if (missions.size() > 0 && lst_missions->NumItems() > 0) { + int id = lst_missions->GetItemData(0); + MissionInfo* info = campaign->GetMissionInfo(id); + + if (!info) { + int seln = -1; + int seln_id = 0; + + for (int i = 0; i < lst_missions->NumItems(); i++) + if (lst_missions->IsSelected(i)) + seln = i; + + if (seln >= 0) + seln_id = lst_missions->GetItemData(seln); + + lst_missions->ClearItems(); + seln = -1; + + for (i = 0; i < missions.size(); i++) { + MissionInfo* info = missions[i]; + lst_missions->AddItemWithData(info->name, info->id); + + Mission* m = info->mission; + if (m) { + if (m->Type() == Mission::TRAINING && player->HasTrained(m->Identity())) { + lst_missions->SetItemText(i, 1, Game::GetText("CmdMissionsDlg.training")); + } + else { + lst_missions->SetItemText(i, 1, m->TypeName()); + } + } + + char start_time[64]; + FormatDayTime(start_time, info->start); + lst_missions->SetItemText(i, 2, start_time); + + if (info->id == seln_id) + seln = i; + } + + if (seln >= 0) + lst_missions->SetSelected(seln); + } + } + + bool found = false; + + for (int i = 0; i < missions.size() && !found; i++) { + MissionInfo* info = missions[i]; + if (info->mission == mission) + found = true; + } + + if (!found) { + mission = 0; + txt_desc->SetText(""); + btn_accept->SetEnabled(false); + } + } +} + +// +--------------------------------------------------------------------+ + +void +CmdMissionsDlg::OnSave(AWEvent* event) +{ + CmdDlg::OnSave(event); +} + +void +CmdMissionsDlg::OnExit(AWEvent* event) +{ + CmdDlg::OnExit(event); +} + +void +CmdMissionsDlg::OnMode(AWEvent* event) +{ + CmdDlg::OnMode(event); +} + + +// +--------------------------------------------------------------------+ + +void +CmdMissionsDlg::OnMission(AWEvent* event) +{ + if (campaign && lst_missions) { + MissionInfo* info = 0; + mission = 0; + + for (int i = 0; i < lst_missions->NumItems(); i++) { + if (lst_missions->IsSelected(i)) { + int id = lst_missions->GetItemData(i); + info = campaign->GetMissionInfo(id); + } + } + + btn_accept->SetEnabled((info != 0) ? true : false); + + if (info) { + Text desc(""); + desc += info->name; + desc += "\n\n"; + desc += info->player_info; + desc += "\n\n"; + desc += info->description; + + txt_desc->SetText(desc); + mission = info->mission; + } + else { + txt_desc->SetText(" "); + } + } +} + +// +--------------------------------------------------------------------+ + +void +CmdMissionsDlg::OnAccept(AWEvent* event) +{ + if (!campaign || !mission) { + ::Print(" ERROR CMD::Accept campaign=0x%08x mission=0x%08x\n", campaign, mission); + return; + } + + ::Print(" CMD::Accept Mission %d\n", mission->Identity()); + + Mouse::Show(false); + campaign->SetMissionId(mission->Identity()); + campaign->StartMission(); + stars->SetGameMode(Starshatter::PREP_MODE); +} -- cgit v1.1