Skyscraper 2.0
peoplemanager.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 Alpha - People Manager Dialog
3 Copyright (C)2003-2024 Ryan Thoryk
4 https://www.skyscrapersim.net
5 https://sourceforge.net/projects/skyscraper/
6 Contact - ryan@skyscrapersim.net
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21*/
22
23//(*InternalHeaders(PeopleManager)
24#include <wx/intl.h>
25#include <wx/string.h>
26//*)
27#include "globals.h"
28#include "sbs.h"
29#include "person.h"
30#include "debugpanel.h"
31#include "peoplemanager.h"
32
33namespace Skyscraper {
34
35//(*IdInit(PeopleManager)
36const long PeopleManager::ID_PersonList = wxNewId();
37const long PeopleManager::ID_STATICTEXT1 = wxNewId();
38const long PeopleManager::ID_tName = wxNewId();
39const long PeopleManager::ID_bSetName = wxNewId();
40const long PeopleManager::ID_STATICTEXT2 = wxNewId();
41const long PeopleManager::ID_tFloor = wxNewId();
42const long PeopleManager::ID_bSetFloor = wxNewId();
43const long PeopleManager::ID_STATICTEXT3 = wxNewId();
44const long PeopleManager::ID_tDestination = wxNewId();
45const long PeopleManager::ID_bGo = wxNewId();
46const long PeopleManager::ID_STATICTEXT5 = wxNewId();
47const long PeopleManager::ID_tRouteActive = wxNewId();
48const long PeopleManager::ID_bStop = wxNewId();
49const long PeopleManager::ID_STATICTEXT4 = wxNewId();
50const long PeopleManager::ID_txtLobby = wxNewId();
51const long PeopleManager::ID_bLobby = wxNewId();
52const long PeopleManager::ID_STATICLINE1 = wxNewId();
53const long PeopleManager::ID_STATICLINE2 = wxNewId();
54const long PeopleManager::ID_STATICLINE3 = wxNewId();
55const long PeopleManager::ID_tStatus = wxNewId();
56const long PeopleManager::ID_chkRandom = wxNewId();
57const long PeopleManager::ID_chkService = wxNewId();
58const long PeopleManager::ID_bNew = wxNewId();
59const long PeopleManager::ID_bDelete = wxNewId();
60const long PeopleManager::ID_bOK = wxNewId();
61//*)
62
63BEGIN_EVENT_TABLE(PeopleManager,wxDialog)
64 //(*EventTable(PeopleManager)
65 //*)
66END_EVENT_TABLE()
67
68PeopleManager::PeopleManager(DebugPanel* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
69{
70 //(*Initialize(PeopleManager)
71 wxBoxSizer* BoxSizer1;
72 wxBoxSizer* BoxSizer2;
73 wxBoxSizer* BoxSizer3;
74 wxBoxSizer* BoxSizer4;
75 wxFlexGridSizer* FlexGridSizer1;
76 wxFlexGridSizer* FlexGridSizer2;
77 wxFlexGridSizer* FlexGridSizer3;
78 wxFlexGridSizer* FlexGridSizer4;
79
80 Create(parent, wxID_ANY, _("People Manager"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
81 FlexGridSizer1 = new wxFlexGridSizer(0, 1, 0, 0);
82 FlexGridSizer4 = new wxFlexGridSizer(0, 2, 0, 0);
83 BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
84 PersonList = new wxListBox(this, ID_PersonList, wxDefaultPosition, wxSize(150,150), 0, 0, 0, wxDefaultValidator, _T("ID_PersonList"));
85 BoxSizer1->Add(PersonList, 1, wxALL|wxEXPAND, 5);
86 FlexGridSizer4->Add(BoxSizer1, 1, wxALL|wxEXPAND, 5);
87 FlexGridSizer3 = new wxFlexGridSizer(0, 1, 0, 0);
88 FlexGridSizer2 = new wxFlexGridSizer(0, 3, 0, 0);
89 StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Name:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
90 FlexGridSizer2->Add(StaticText1, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
91 tName = new wxTextCtrl(this, ID_tName, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_tName"));
92 tName->SetMinSize(wxSize(90,-1));
93 FlexGridSizer2->Add(tName, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
94 bSetName = new wxButton(this, ID_bSetName, _("Set"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_bSetName"));
95 FlexGridSizer2->Add(bSetName, 1, wxBOTTOM|wxLEFT|wxEXPAND, 5);
96 StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Floor:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
97 FlexGridSizer2->Add(StaticText2, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
98 tFloor = new wxTextCtrl(this, ID_tFloor, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_tFloor"));
99 tFloor->SetMinSize(wxSize(90,-1));
100 FlexGridSizer2->Add(tFloor, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
101 bSetFloor = new wxButton(this, ID_bSetFloor, _("Set"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_bSetFloor"));
102 FlexGridSizer2->Add(bSetFloor, 1, wxBOTTOM|wxLEFT|wxEXPAND, 5);
103 StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("Destination:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
104 FlexGridSizer2->Add(StaticText3, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
105 tDestination = new wxTextCtrl(this, ID_tDestination, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_tDestination"));
106 tDestination->SetMinSize(wxSize(90,-1));
107 FlexGridSizer2->Add(tDestination, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
108 bGo = new wxButton(this, ID_bGo, _("Go"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_bGo"));
109 FlexGridSizer2->Add(bGo, 1, wxBOTTOM|wxLEFT|wxEXPAND, 5);
110 StaticText5 = new wxStaticText(this, ID_STATICTEXT5, _("Route Active:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
111 FlexGridSizer2->Add(StaticText5, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
112 tRouteActive = new wxTextCtrl(this, ID_tRouteActive, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY, wxDefaultValidator, _T("ID_tRouteActive"));
113 tRouteActive->SetMinSize(wxSize(90,-1));
114 FlexGridSizer2->Add(tRouteActive, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
115 bStop = new wxButton(this, ID_bStop, _("Stop"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_bStop"));
116 FlexGridSizer2->Add(bStop, 1, wxBOTTOM|wxLEFT|wxEXPAND, 5);
117 StaticText4 = new wxStaticText(this, ID_STATICTEXT4, _("Lobby:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
118 FlexGridSizer2->Add(StaticText4, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
119 txtLobby = new wxTextCtrl(this, ID_txtLobby, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_txtLobby"));
120 txtLobby->SetMinSize(wxSize(90,-1));
121 FlexGridSizer2->Add(txtLobby, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
122 bLobby = new wxButton(this, ID_bLobby, _("Set"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT, wxDefaultValidator, _T("ID_bLobby"));
123 FlexGridSizer2->Add(bLobby, 1, wxBOTTOM|wxLEFT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
124 StaticLine1 = new wxStaticLine(this, ID_STATICLINE1, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE1"));
125 FlexGridSizer2->Add(StaticLine1, 1, wxTOP|wxEXPAND, 5);
126 StaticLine2 = new wxStaticLine(this, ID_STATICLINE2, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE2"));
127 FlexGridSizer2->Add(StaticLine2, 1, wxTOP|wxEXPAND, 5);
128 StaticLine3 = new wxStaticLine(this, ID_STATICLINE3, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE3"));
129 FlexGridSizer2->Add(StaticLine3, 1, wxTOP|wxEXPAND, 5);
130 FlexGridSizer3->Add(FlexGridSizer2, 1, wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
131 tStatus = new wxTextCtrl(this, ID_tStatus, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxTE_CENTRE, wxDefaultValidator, _T("ID_tStatus"));
132 FlexGridSizer3->Add(tStatus, 1, wxBOTTOM|wxEXPAND, 5);
133 BoxSizer2 = new wxBoxSizer(wxVERTICAL);
134 chkRandom = new wxCheckBox(this, ID_chkRandom, _("Random Activity"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_chkRandom"));
135 chkRandom->SetValue(false);
136 BoxSizer2->Add(chkRandom, 1, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
137 chkService = new wxCheckBox(this, ID_chkService, _("Service Access"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_chkService"));
138 chkService->SetValue(false);
139 BoxSizer2->Add(chkService, 1, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
140 FlexGridSizer3->Add(BoxSizer2, 1, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
141 BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
142 bNew = new wxButton(this, ID_bNew, _("New"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_bNew"));
143 BoxSizer3->Add(bNew, 1, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
144 bDelete = new wxButton(this, ID_bDelete, _("Delete"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_bDelete"));
145 BoxSizer3->Add(bDelete, 1, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
146 FlexGridSizer3->Add(BoxSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
147 FlexGridSizer4->Add(FlexGridSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
148 FlexGridSizer1->Add(FlexGridSizer4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
149 BoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
150 bOK = new wxButton(this, ID_bOK, _("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_bOK"));
151 BoxSizer4->Add(bOK, 1, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
152 FlexGridSizer1->Add(BoxSizer4, 1, wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
153 SetSizer(FlexGridSizer1);
154 FlexGridSizer1->SetSizeHints(this);
155 Center();
156
157 Connect(ID_bSetName,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&PeopleManager::On_bSetName_Click);
158 Connect(ID_bSetFloor,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&PeopleManager::On_bSetFloor_Click);
159 Connect(ID_bGo,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&PeopleManager::On_bGo_Click);
160 Connect(ID_bStop,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&PeopleManager::On_bStop_Click);
161 Connect(ID_bLobby,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&PeopleManager::On_bLobby_Click);
162 Connect(ID_chkRandom,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&PeopleManager::On_chkRandom_Click);
163 Connect(ID_chkService,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&PeopleManager::On_chkService_Click);
164 Connect(ID_bNew,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&PeopleManager::On_bNew_Click);
165 Connect(ID_bDelete,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&PeopleManager::On_bDelete_Click);
166 Connect(ID_bOK,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&PeopleManager::On_bOK_Click);
167 //*)
168
169 lastcount = 0;
170 Simcore = 0;
171 person = 0;
172 floor = -1;
173 dest_floor = -1;
174 panel = parent;
175}
176
178{
179 //(*Destroy(PeopleManager)
180 //*)
181}
182
184{
185 bool reset = false;
186
187 if (Simcore != panel->GetSystem())
188 {
189 //if active engine has changed, refresh values
191 txtLobby->SetValue(SBS::ToString(Simcore->Lobby));
192 }
193
194 if (!Simcore)
195 return;
196
197 BuildList();
198
199 int selection = PersonList->GetSelection();
200
201 if (selection >= 0)
202 {
203 SBS::Person *newperson = Simcore->GetPerson(selection);
204
205 //if a new person has been selected, update values
206 if (newperson && person != newperson)
207 {
208 person = Simcore->GetPerson(selection);
209
210 tName->SetValue(person->GetName());
212 chkService->SetValue(person->GetServiceAccess());
213 reset = true;
214 }
215 }
216 else
217 person = 0;
218
219 if (!person)
220 return;
221
222 //set dynamic values
223
224 if (person->IsRouteActive() == true)
225 tRouteActive->SetValue("True");
226 else
227 tRouteActive->SetValue("False");
228
229 if (person->GetFloor() != floor || reset == true)
230 {
231 floor = person->GetFloor();
232 tFloor->SetValue(SBS::ToString(floor));
233 }
234
235 if (person->GetDestinationFloor() != dest_floor || reset == true)
236 {
239 }
240
241 if (person->GetStatus() != status || reset == true)
242 {
244 tStatus->SetValue(status);
245 }
246}
247
248void PeopleManager::On_bSetName_Click(wxCommandEvent& event)
249{
250 if (person)
251 {
252 person->SetName(std::string(tName->GetValue()));
253 lastcount = 0;
254 BuildList(true);
255 }
256}
257
258void PeopleManager::On_bSetFloor_Click(wxCommandEvent& event)
259{
260 if (person)
261 person->SetFloor(atoi(tFloor->GetValue()));
262}
263
264void PeopleManager::On_bGo_Click(wxCommandEvent& event)
265{
266 if (person)
267 person->GotoFloor(atoi(tDestination->GetValue()));
268}
269
270void PeopleManager::On_bNew_Click(wxCommandEvent& event)
271{
273}
274
275void PeopleManager::On_bDelete_Click(wxCommandEvent& event)
276{
277 if (person)
279 person = 0;
280 BuildList(true);
281}
282
283void PeopleManager::On_bOK_Click(wxCommandEvent& event)
284{
285 this->Close();
286}
287
288void PeopleManager::On_chkRandom_Click(wxCommandEvent& event)
289{
290 if (person)
292}
293
294void PeopleManager::On_chkService_Click(wxCommandEvent& event)
295{
296 if (person)
297 person->SetServiceAccess(chkService->GetValue());
298}
299
300void PeopleManager::On_bStop_Click(wxCommandEvent& event)
301{
302 if (person)
303 person->Stop();
304}
305
306void PeopleManager::BuildList(bool restore_selection)
307{
308 int count = Simcore->GetPersonCount();
309
310 if (count != lastcount)
311 {
312 lastcount = count;
313 int old_selection = PersonList->GetSelection();
314 PersonList->Clear();
315
316 for (int i = 0; i < count; i++)
317 PersonList->Append(SBS::ToString(i + 1) + wxT(": ") + Simcore->GetPerson(i)->GetName());
318
319 if (count > 0)
320 {
321 if (restore_selection == true)
322 {
323 if (old_selection < PersonList->GetCount())
324 PersonList->SetSelection(old_selection);
325 else
326 PersonList->SetSelection(count - 1);
327 }
328 else
329 {
330 if (old_selection < PersonList->GetCount())
331 PersonList->SetSelection(count - 1);
332 else
333 PersonList->SetSelection(0);
334 }
335 }
336 else
337 {
338 //clear values
339 tName->Clear();
340 tRouteActive->Clear();
341 tFloor->Clear();
342 tDestination->Clear();
343 tStatus->Clear();
344 chkRandom->SetValue(false);
345 chkService->SetValue(false);
346 }
347 }
348}
349
350void PeopleManager::On_bLobby_Click(wxCommandEvent& event)
351{
352 Simcore->Lobby = atoi(tDestination->GetValue());
353}
354
355}
const std::string & GetName()
Definition object.cpp:53
void SetName(const std::string &name)
Definition object.cpp:72
int GetFloor()
Definition person.h:48
bool IsRouteActive()
Definition person.h:44
void Stop()
Definition person.cpp:437
int GetDestinationFloor()
Definition person.h:49
void EnableRandomActivity(bool value)
Definition person.cpp:101
bool IsRandomActivityEnabled()
Definition person.cpp:508
void GotoFloor(int floor)
Definition person.cpp:121
void SetFloor(int value)
Definition person.cpp:425
std::string GetStatus()
Definition person.cpp:452
void SetServiceAccess(bool value)
Definition person.h:50
bool GetServiceAccess()
Definition person.h:51
int Lobby
Definition sbs.h:198
Person * CreatePerson(std::string name="", int floor=0, bool service_access=false)
Definition sbs.cpp:4217
bool DeleteObject(Object *object)
Definition sbs.cpp:2567
Person * GetPerson(int number)
Definition sbs.cpp:4279
int GetPersonCount()
Definition sbs.cpp:4523
SBS::SBS * GetSystem()
Definition debugpanel.h:131
static const long ID_PersonList
static const long ID_STATICLINE2
static const long ID_bLobby
static const long ID_tDestination
void On_bOK_Click(wxCommandEvent &event)
static const long ID_STATICLINE3
static const long ID_bSetFloor
static const long ID_STATICTEXT1
void On_bNew_Click(wxCommandEvent &event)
void On_bGo_Click(wxCommandEvent &event)
static const long ID_STATICTEXT2
static const long ID_tName
void On_bLobby_Click(wxCommandEvent &event)
static const long ID_STATICTEXT3
static const long ID_STATICTEXT4
void On_bStop_Click(wxCommandEvent &event)
static const long ID_STATICLINE1
void On_chkService_Click(wxCommandEvent &event)
void On_chkRandom_Click(wxCommandEvent &event)
static const long ID_chkRandom
void On_bSetName_Click(wxCommandEvent &event)
static const long ID_txtLobby
static const long ID_bSetName
static const long ID_chkService
void BuildList(bool restore_selection=false)
void On_bDelete_Click(wxCommandEvent &event)
static const long ID_bStop
static const long ID_tRouteActive
static const long ID_tStatus
void On_bSetFloor_Click(wxCommandEvent &event)
static const long ID_bDelete
static const long ID_bNew
static const long ID_STATICTEXT5
static const long ID_tFloor
static const long ID_bOK
static const long ID_bGo
std::string ToString(int number)
Definition globals.cpp:279