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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/* 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
========
Operational Command Dialog Active Window class
*/
#include "CmdDlg.h"
#include "CmpFileDlg.h"
#include "CmpnScreen.h"
#include "Starshatter.h"
#include "Campaign.h"
#include "Combatant.h"
#include "CombatGroup.h"
#include "CombatUnit.h"
#include "ShipDesign.h"
#include "Game.h"
#include "DataLoader.h"
#include "Button.h"
#include "Video.h"
#include "Keyboard.h"
#include "Mouse.h"
#include "ParseUtil.h"
#include "FormatUtil.h"
// +--------------------------------------------------------------------+
CmdDlg::CmdDlg(CmpnScreen* mgr)
: cmpn_screen(mgr),
txt_group(0), txt_score(0), txt_name(0), txt_time(0),
btn_save(0), btn_exit(0), stars(0), campaign(0), mode(0)
{
stars = Starshatter::GetInstance();
campaign = Campaign::GetCampaign();
for (int i = 0; i < 5; i++)
btn_mode[i] = 0;
}
CmdDlg::~CmdDlg()
{
}
// +--------------------------------------------------------------------+
void
CmdDlg::RegisterCmdControls(FormWindow* win)
{
btn_save = (Button*) win->FindControl( 1);
btn_exit = (Button*) win->FindControl( 2);
for (int i = 0; i < 5; i++) {
btn_mode[i] = (Button*) win->FindControl(100 + i);
}
txt_group = win->FindControl(200);
txt_score = win->FindControl(201);
txt_name = win->FindControl(300);
txt_time = win->FindControl(301);
}
// +--------------------------------------------------------------------+
void
CmdDlg::ShowCmdDlg()
{
campaign = Campaign::GetCampaign();
if (txt_name) {
if (campaign)
txt_name->SetText(campaign->Name());
else
txt_name->SetText("No Campaign Selected");
}
ShowMode();
if (btn_save)
btn_save->SetEnabled(!campaign->IsTraining());
if (btn_mode[MODE_FORCES]) btn_mode[MODE_FORCES]->SetEnabled(!campaign->IsTraining());
if (btn_mode[MODE_INTEL]) btn_mode[MODE_INTEL]->SetEnabled(!campaign->IsTraining());
}
// +--------------------------------------------------------------------+
void
CmdDlg::ExecFrame()
{
CombatGroup* g = campaign->GetPlayerGroup();
if (g && txt_group)
txt_group->SetText(g->GetDescription());
if (txt_score) {
char score[32];
sprintf_s(score, "Team Score: %d", campaign->GetPlayerTeamScore()); txt_score->SetText(score); txt_score->SetTextAlign(DT_RIGHT);
}
if (txt_time) {
double t = campaign->GetTime();
char daytime[32];
FormatDayTime(daytime, t);
txt_time->SetText(daytime);
}
int unread = campaign->CountNewEvents();
if (btn_mode[MODE_INTEL]) {
if (unread > 0) {
char text[64];
sprintf_s(text, "INTEL (%d)", unread);
btn_mode[MODE_INTEL]->SetText(text);
}
else {
btn_mode[MODE_INTEL]->SetText("INTEL");
}
}
}
// +--------------------------------------------------------------------+
void
CmdDlg::ShowMode()
{
for (int i = 0; i < 5; i++) {
if (btn_mode[i]) btn_mode[i]->SetButtonState(0);
}
if (mode < 0 || mode > 4)
mode = 0;
if (btn_mode[mode]) btn_mode[mode]->SetButtonState(1);
}
void
CmdDlg::OnMode(AWEvent* event)
{
for (int i = MODE_ORDERS; i < NUM_MODES; i++) {
Button* btn = btn_mode[i];
if (event->window == btn) {
mode = i;
}
}
switch (mode) {
case MODE_ORDERS: cmpn_screen->ShowCmdOrdersDlg(); break;
case MODE_THEATER: cmpn_screen->ShowCmdTheaterDlg(); break;
case MODE_FORCES: cmpn_screen->ShowCmdForceDlg(); break;
case MODE_INTEL: cmpn_screen->ShowCmdIntelDlg(); break;
case MODE_MISSIONS: cmpn_screen->ShowCmdMissionsDlg(); break;
default: cmpn_screen->ShowCmdOrdersDlg(); break;
}
}
void
CmdDlg::OnSave(AWEvent* event)
{
if (campaign && cmpn_screen) {
CmpFileDlg* fdlg = cmpn_screen->GetCmpFileDlg();
cmpn_screen->ShowCmpFileDlg();
}
}
void
CmdDlg::OnExit(AWEvent* event)
{
if (stars) {
Mouse::Show(false);
stars->SetGameMode(Game::MENU_MODE);
}
}
// +--------------------------------------------------------------------+
|