From d17521c8b9085a91d08fecfd0b51bbbf7b1dccac Mon Sep 17 00:00:00 2001 From: "milo24x7@gmail.com" Date: Sun, 7 Jul 2013 22:08:49 +0000 Subject: Updated open source license declaration and fixed some formatting issues. --- Stars45/MsnEditNavDlg.cpp | 624 ++++++++++++++++++++++++---------------------- 1 file changed, 324 insertions(+), 300 deletions(-) (limited to 'Stars45/MsnEditNavDlg.cpp') diff --git a/Stars45/MsnEditNavDlg.cpp b/Stars45/MsnEditNavDlg.cpp index 5be7807..63e5eb1 100644 --- a/Stars45/MsnEditNavDlg.cpp +++ b/Stars45/MsnEditNavDlg.cpp @@ -1,300 +1,324 @@ -/* Project Starshatter 4.5 - Destroyer Studios LLC - Copyright (C) 1997-2004. All Rights Reserved. - - SUBSYSTEM: Stars.exe - FILE: MsnEditNavDlg.cpp - AUTHOR: John DiCamillo - - - OVERVIEW - ======== - Mission Briefing Dialog Active Window class -*/ - -#include "MemDebug.h" -#include "MsnEditNavDlg.h" -#include "MsnEditDlg.h" -#include "MenuScreen.h" -#include "Campaign.h" -#include "Galaxy.h" -#include "Instruction.h" -#include "Mission.h" -#include "Ship.h" -#include "ShipDesign.h" -#include "StarSystem.h" - -// +--------------------------------------------------------------------+ -// DECLARE MAPPING FUNCTIONS: -DEF_MAP_CLIENT(MsnEditNavDlg, OnCommit); -DEF_MAP_CLIENT(MsnEditNavDlg, OnCancel); -DEF_MAP_CLIENT(MsnEditNavDlg, OnTabButton); -DEF_MAP_CLIENT(MsnEditNavDlg, OnSystemSelect); - -// +--------------------------------------------------------------------+ - -MsnEditNavDlg::MsnEditNavDlg(Screen* s, FormDef& def, MenuScreen* mgr) -: NavDlg(s, def, mgr), menu_screen(mgr), mission_info(0), -btn_accept(0), btn_cancel(0), btn_sit(0), btn_pkg(0), btn_map(0) -{ - RegisterControls(); -} - -MsnEditNavDlg::~MsnEditNavDlg() -{ -} - -// +--------------------------------------------------------------------+ - -void -MsnEditNavDlg::RegisterControls() -{ - btn_accept = (Button*) FindControl( 1); - btn_cancel = (Button*) FindControl( 2); - btn_sit = (Button*) FindControl(301); - btn_pkg = (Button*) FindControl(302); - btn_map = (Button*) FindControl(303); - - txt_name = (EditBox*) FindControl(201); - cmb_type = (ComboBox*) FindControl(202); - cmb_system = (ComboBox*) FindControl(203); - cmb_region = (ComboBox*) FindControl(204); - - if (btn_accept) - REGISTER_CLIENT(EID_CLICK, btn_accept, MsnEditNavDlg, OnCommit); - - if (btn_cancel) - REGISTER_CLIENT(EID_CLICK, btn_cancel, MsnEditNavDlg, OnCancel); - - if (btn_sit) - REGISTER_CLIENT(EID_CLICK, btn_sit, MsnEditNavDlg, OnTabButton); - - if (btn_pkg) - REGISTER_CLIENT(EID_CLICK, btn_pkg, MsnEditNavDlg, OnTabButton); - - if (btn_map) - REGISTER_CLIENT(EID_CLICK, btn_map, MsnEditNavDlg, OnTabButton); - - if (cmb_system) - REGISTER_CLIENT(EID_SELECT, cmb_system, MsnEditNavDlg, OnSystemSelect); -} - -// +--------------------------------------------------------------------+ - -void -MsnEditNavDlg::Show() -{ - bool need_tab_update = !shown; - - NavDlg::Show(); - - if (txt_name && cmb_type) { - txt_name->SetText(""); - - if (cmb_system) { - cmb_system->ClearItems(); - - Galaxy* galaxy = Galaxy::GetInstance(); - ListIter iter = galaxy->GetSystemList(); - while (++iter) { - cmb_system->AddItem(iter->Name()); - } - } - - if (mission) { - int i; - - txt_name->SetText(mission->Name()); - cmb_type->SetSelection(mission->Type()); - - StarSystem* sys = mission->GetStarSystem(); - if (sys && cmb_system && cmb_region) { - for (i = 0; i < cmb_system->NumItems(); i++) { - if (!strcmp(cmb_system->GetItem(i), sys->Name())) { - cmb_system->SetSelection(i); - break; - } - } - - cmb_region->ClearItems(); - int sel_rgn = 0; - - List regions; - regions.append(sys->AllRegions()); - regions.sort(); - - i = 0; - ListIter iter = regions; - while (++iter) { - OrbitalRegion* region = iter.value(); - cmb_region->AddItem(region->Name()); - - if (!strcmp(mission->GetRegion(), region->Name())) { - sel_rgn = i; - } - - i++; - } - - cmb_region->SetSelection(sel_rgn); - } - } - } - - if (need_tab_update) { - ShowTab(2); - } - - exit_latch = true; -} - -void -MsnEditNavDlg::SetMissionInfo(MissionInfo* m) -{ - mission_info = m; -} - -// +--------------------------------------------------------------------+ - -void -MsnEditNavDlg::ScrapeForm() -{ - if (mission) { - if (txt_name) { - mission->SetName(txt_name->GetText()); - } - - if (cmb_type) { - mission->SetType(cmb_type->GetSelectedIndex()); - - if (mission_info) - mission_info->type = cmb_type->GetSelectedIndex(); - } - - Galaxy* galaxy = Galaxy::GetInstance(); - StarSystem* system = 0; - - if (galaxy && cmb_system) - system = galaxy->GetSystem(cmb_system->GetSelectedItem()); - - if (system) { - mission->ClearSystemList(); - mission->SetStarSystem(system); - - if (mission_info) - mission_info->system = system->Name(); - } - - if (cmb_region) { - mission->SetRegion(cmb_region->GetSelectedItem()); - - if (mission_info) - mission_info->region = cmb_region->GetSelectedItem(); - } - - SetSystem(system); - } -} - -// +--------------------------------------------------------------------+ - -void -MsnEditNavDlg::ShowTab(int tab) -{ - if (tab < 0 || tab > 2) - tab = 0; - - if (btn_sit) btn_sit->SetButtonState(tab == 0 ? 1 : 0); - if (btn_pkg) btn_pkg->SetButtonState(tab == 1 ? 1 : 0); - if (btn_map) btn_map->SetButtonState(tab == 2 ? 1 : 0); - - if (tab != 2) { - MsnEditDlg* msnEditDlg = menu_screen->GetMsnEditDlg(); - - if (msnEditDlg) - msnEditDlg->ShowTab(tab); - - menu_screen->ShowMsnEditDlg(); - } -} - -// +--------------------------------------------------------------------+ - -void -MsnEditNavDlg::OnTabButton(AWEvent* event) -{ - if (!event) return; - - if (event->window == btn_sit) - ShowTab(0); - - else if (event->window == btn_pkg) - ShowTab(1); - - else if (event->window == btn_map) - ShowTab(2); -} - -void -MsnEditNavDlg::OnSystemSelect(AWEvent* event) -{ - StarSystem* sys = 0; - - if (cmb_system) { - const char* name = cmb_system->GetSelectedItem(); - - Galaxy* galaxy = Galaxy::GetInstance(); - ListIter iter = galaxy->GetSystemList(); - while (++iter) { - StarSystem* s = iter.value(); - - if (!strcmp(s->Name(), name)) { - sys = s; - break; - } - } - } - - if (sys && cmb_region) { - cmb_region->ClearItems(); - - List regions; - regions.append(sys->AllRegions()); - regions.sort(); - - ListIter iter = regions; - while (++iter) { - OrbitalRegion* region = iter.value(); - cmb_region->AddItem(region->Name()); - } - } - - ScrapeForm(); -} - - -// +--------------------------------------------------------------------+ - -void -MsnEditNavDlg::OnCommit(AWEvent* event) -{ - if (mission) { - ScrapeForm(); - - if (mission_info) - mission_info->name = mission->Name(); - - mission->Save(); - } - - menu_screen->ShowMsnSelectDlg(); -} - -void -MsnEditNavDlg::OnCancel(AWEvent* event) -{ - if (mission) - mission->Load(); - - menu_screen->ShowMsnSelectDlg(); -} +/* Starshatter OpenSource Distribution + Copyright (c) 1997-2004, Destroyer Studios LLC. + All Rights Reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * 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. + * Neither the name "Destroyer Studios" nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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. + + SUBSYSTEM: Stars.exe + FILE: MsnEditNavDlg.cpp + AUTHOR: John DiCamillo + + + OVERVIEW + ======== + Mission Briefing Dialog Active Window class +*/ + +#include "MemDebug.h" +#include "MsnEditNavDlg.h" +#include "MsnEditDlg.h" +#include "MenuScreen.h" +#include "Campaign.h" +#include "Galaxy.h" +#include "Instruction.h" +#include "Mission.h" +#include "Ship.h" +#include "ShipDesign.h" +#include "StarSystem.h" + +// +--------------------------------------------------------------------+ +// DECLARE MAPPING FUNCTIONS: +DEF_MAP_CLIENT(MsnEditNavDlg, OnCommit); +DEF_MAP_CLIENT(MsnEditNavDlg, OnCancel); +DEF_MAP_CLIENT(MsnEditNavDlg, OnTabButton); +DEF_MAP_CLIENT(MsnEditNavDlg, OnSystemSelect); + +// +--------------------------------------------------------------------+ + +MsnEditNavDlg::MsnEditNavDlg(Screen* s, FormDef& def, MenuScreen* mgr) +: NavDlg(s, def, mgr), menu_screen(mgr), mission_info(0), +btn_accept(0), btn_cancel(0), btn_sit(0), btn_pkg(0), btn_map(0) +{ + RegisterControls(); +} + +MsnEditNavDlg::~MsnEditNavDlg() +{ +} + +// +--------------------------------------------------------------------+ + +void +MsnEditNavDlg::RegisterControls() +{ + btn_accept = (Button*) FindControl( 1); + btn_cancel = (Button*) FindControl( 2); + btn_sit = (Button*) FindControl(301); + btn_pkg = (Button*) FindControl(302); + btn_map = (Button*) FindControl(303); + + txt_name = (EditBox*) FindControl(201); + cmb_type = (ComboBox*) FindControl(202); + cmb_system = (ComboBox*) FindControl(203); + cmb_region = (ComboBox*) FindControl(204); + + if (btn_accept) + REGISTER_CLIENT(EID_CLICK, btn_accept, MsnEditNavDlg, OnCommit); + + if (btn_cancel) + REGISTER_CLIENT(EID_CLICK, btn_cancel, MsnEditNavDlg, OnCancel); + + if (btn_sit) + REGISTER_CLIENT(EID_CLICK, btn_sit, MsnEditNavDlg, OnTabButton); + + if (btn_pkg) + REGISTER_CLIENT(EID_CLICK, btn_pkg, MsnEditNavDlg, OnTabButton); + + if (btn_map) + REGISTER_CLIENT(EID_CLICK, btn_map, MsnEditNavDlg, OnTabButton); + + if (cmb_system) + REGISTER_CLIENT(EID_SELECT, cmb_system, MsnEditNavDlg, OnSystemSelect); +} + +// +--------------------------------------------------------------------+ + +void +MsnEditNavDlg::Show() +{ + bool need_tab_update = !shown; + + NavDlg::Show(); + + if (txt_name && cmb_type) { + txt_name->SetText(""); + + if (cmb_system) { + cmb_system->ClearItems(); + + Galaxy* galaxy = Galaxy::GetInstance(); + ListIter iter = galaxy->GetSystemList(); + while (++iter) { + cmb_system->AddItem(iter->Name()); + } + } + + if (mission) { + int i; + + txt_name->SetText(mission->Name()); + cmb_type->SetSelection(mission->Type()); + + StarSystem* sys = mission->GetStarSystem(); + if (sys && cmb_system && cmb_region) { + for (i = 0; i < cmb_system->NumItems(); i++) { + if (!strcmp(cmb_system->GetItem(i), sys->Name())) { + cmb_system->SetSelection(i); + break; + } + } + + cmb_region->ClearItems(); + int sel_rgn = 0; + + List regions; + regions.append(sys->AllRegions()); + regions.sort(); + + i = 0; + ListIter iter = regions; + while (++iter) { + OrbitalRegion* region = iter.value(); + cmb_region->AddItem(region->Name()); + + if (!strcmp(mission->GetRegion(), region->Name())) { + sel_rgn = i; + } + + i++; + } + + cmb_region->SetSelection(sel_rgn); + } + } + } + + if (need_tab_update) { + ShowTab(2); + } + + exit_latch = true; +} + +void +MsnEditNavDlg::SetMissionInfo(MissionInfo* m) +{ + mission_info = m; +} + +// +--------------------------------------------------------------------+ + +void +MsnEditNavDlg::ScrapeForm() +{ + if (mission) { + if (txt_name) { + mission->SetName(txt_name->GetText()); + } + + if (cmb_type) { + mission->SetType(cmb_type->GetSelectedIndex()); + + if (mission_info) + mission_info->type = cmb_type->GetSelectedIndex(); + } + + Galaxy* galaxy = Galaxy::GetInstance(); + StarSystem* system = 0; + + if (galaxy && cmb_system) + system = galaxy->GetSystem(cmb_system->GetSelectedItem()); + + if (system) { + mission->ClearSystemList(); + mission->SetStarSystem(system); + + if (mission_info) + mission_info->system = system->Name(); + } + + if (cmb_region) { + mission->SetRegion(cmb_region->GetSelectedItem()); + + if (mission_info) + mission_info->region = cmb_region->GetSelectedItem(); + } + + SetSystem(system); + } +} + +// +--------------------------------------------------------------------+ + +void +MsnEditNavDlg::ShowTab(int tab) +{ + if (tab < 0 || tab > 2) + tab = 0; + + if (btn_sit) btn_sit->SetButtonState(tab == 0 ? 1 : 0); + if (btn_pkg) btn_pkg->SetButtonState(tab == 1 ? 1 : 0); + if (btn_map) btn_map->SetButtonState(tab == 2 ? 1 : 0); + + if (tab != 2) { + MsnEditDlg* msnEditDlg = menu_screen->GetMsnEditDlg(); + + if (msnEditDlg) + msnEditDlg->ShowTab(tab); + + menu_screen->ShowMsnEditDlg(); + } +} + +// +--------------------------------------------------------------------+ + +void +MsnEditNavDlg::OnTabButton(AWEvent* event) +{ + if (!event) return; + + if (event->window == btn_sit) + ShowTab(0); + + else if (event->window == btn_pkg) + ShowTab(1); + + else if (event->window == btn_map) + ShowTab(2); +} + +void +MsnEditNavDlg::OnSystemSelect(AWEvent* event) +{ + StarSystem* sys = 0; + + if (cmb_system) { + const char* name = cmb_system->GetSelectedItem(); + + Galaxy* galaxy = Galaxy::GetInstance(); + ListIter iter = galaxy->GetSystemList(); + while (++iter) { + StarSystem* s = iter.value(); + + if (!strcmp(s->Name(), name)) { + sys = s; + break; + } + } + } + + if (sys && cmb_region) { + cmb_region->ClearItems(); + + List regions; + regions.append(sys->AllRegions()); + regions.sort(); + + ListIter iter = regions; + while (++iter) { + OrbitalRegion* region = iter.value(); + cmb_region->AddItem(region->Name()); + } + } + + ScrapeForm(); +} + + +// +--------------------------------------------------------------------+ + +void +MsnEditNavDlg::OnCommit(AWEvent* event) +{ + if (mission) { + ScrapeForm(); + + if (mission_info) + mission_info->name = mission->Name(); + + mission->Save(); + } + + menu_screen->ShowMsnSelectDlg(); +} + +void +MsnEditNavDlg::OnCancel(AWEvent* event) +{ + if (mission) + mission->Load(); + + menu_screen->ShowMsnSelectDlg(); +} -- cgit v1.1