From 3c487c5cd69c53d6fea948643c0a76df03516605 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 1 Apr 2022 21:23:39 +0200 Subject: Moved Stars45 to StarsEx --- StarsEx/FirstTimeDlg.cpp | 145 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 StarsEx/FirstTimeDlg.cpp (limited to 'StarsEx/FirstTimeDlg.cpp') diff --git a/StarsEx/FirstTimeDlg.cpp b/StarsEx/FirstTimeDlg.cpp new file mode 100644 index 0000000..4376243 --- /dev/null +++ b/StarsEx/FirstTimeDlg.cpp @@ -0,0 +1,145 @@ +/* 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 + ======== + Main Menu Dialog Active Window class +*/ + +#include "FirstTimeDlg.h" +#include "Player.h" +#include "MenuScreen.h" +#include "Ship.h" +#include "Starshatter.h" +#include "KeyMap.h" +#include "Random.h" + +#include "DataLoader.h" +#include "Button.h" +#include "EditBox.h" +#include "ComboBox.h" +#include "Video.h" +#include "Keyboard.h" +#include "MachineInfo.h" + +// +--------------------------------------------------------------------+ +// DECLARE MAPPING FUNCTIONS: + +DEF_MAP_CLIENT(FirstTimeDlg, OnApply); + +// +--------------------------------------------------------------------+ + +FirstTimeDlg::FirstTimeDlg(Screen* s, FormDef& def, MenuScreen* mgr) +: FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr) +{ + Init(def); +} + +FirstTimeDlg::~FirstTimeDlg() +{ +} + +// +--------------------------------------------------------------------+ + +void +FirstTimeDlg::RegisterControls() +{ + edt_name = (EditBox*) FindControl(200); + cmb_playstyle = (ComboBox*) FindControl(201); + cmb_experience = (ComboBox*) FindControl(202); + + btn_apply = (Button*) FindControl(1); + REGISTER_CLIENT(EID_CLICK, btn_apply, FirstTimeDlg, OnApply); +} + +// +--------------------------------------------------------------------+ + +void +FirstTimeDlg::Show() +{ + if (!IsShown()) + FormWindow::Show(); + + if (edt_name) + edt_name->SetText("Noobie"); +} + +// +--------------------------------------------------------------------+ + +void +FirstTimeDlg::ExecFrame() +{ +} + +// +--------------------------------------------------------------------+ + +void +FirstTimeDlg::OnApply(AWEvent* event) +{ + Starshatter* stars = Starshatter::GetInstance(); + Player* player = Player::GetCurrentPlayer(); + + if (player) { + if (edt_name) { + char password[16]; + sprintf_s(password, "%08x", (DWORD) Random(0, 2e9)); + + player->SetName(edt_name->GetText()); + player->SetPassword(password); + } + + if (cmb_playstyle) { + // ARCADE: + if (cmb_playstyle->GetSelectedIndex() == 0) { + player->SetFlightModel(2); + player->SetLandingModel(1); + player->SetHUDMode(0); + player->SetGunsight(1); + + if (stars) { + KeyMap& keymap = stars->GetKeyMap(); + + keymap.Bind(KEY_CONTROL_MODEL, 1, 0); + keymap.SaveKeyMap("key.cfg", 256); + + stars->MapKeys(); + } + + Ship::SetControlModel(1); + } + + // HARDCORE: + else { + player->SetFlightModel(0); + player->SetLandingModel(0); + player->SetHUDMode(0); + player->SetGunsight(0); + + if (stars) { + KeyMap& keymap = stars->GetKeyMap(); + + keymap.Bind(KEY_CONTROL_MODEL, 0, 0); + keymap.SaveKeyMap("key.cfg", 256); + + stars->MapKeys(); + } + + Ship::SetControlModel(0); + } + } + + if (cmb_experience && cmb_experience->GetSelectedIndex() > 0) { + player->SetRank(2); // Lieutenant + player->SetTrained(255); // Fully Trained + } + + Player::Save(); + } + + manager->ShowMenuDlg(); +} -- cgit v1.1