summaryrefslogtreecommitdiffhomepage
path: root/Stars45/FirstTimeDlg.cpp
blob: a0672396d9fe7495041739c8dc666d40d82c4afc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*  Project Starshatter 4.5
	Destroyer Studios LLC
	Copyright © 1997-2004. All Rights Reserved.

	SUBSYSTEM:    Stars.exe
	FILE:         FirstTimeDlg.cpp
	AUTHOR:       John DiCamillo


	OVERVIEW
	========
	Main Menu Dialog Active Window class
*/

#include "MemDebug.h"
#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();
}