Skyscraper 2.0
actionviewer.cpp
Go to the documentation of this file.
1/*
2 Skyscraper 2.0 Alpha - Action Viewer
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(ActionViewer)
24#include <wx/intl.h>
25#include <wx/string.h>
26//*)
27#include <wx/app.h>
28
29#include "globals.h"
30#include "sbs.h"
31#include "action.h"
32#include "debugpanel.h"
33#include "actionviewer.h"
34
35using namespace SBS;
36
37namespace Skyscraper {
38
39//(*IdInit(ActionViewer)
40const long ActionViewer::ID_ActionList = wxNewId();
41const long ActionViewer::ID_bDelete = wxNewId();
42const long ActionViewer::ID_bRun = wxNewId();
43const long ActionViewer::ID_bOK = wxNewId();
44const long ActionViewer::ID_STATICTEXT1 = wxNewId();
45const long ActionViewer::ID_tName = wxNewId();
46const long ActionViewer::ID_STATICTEXT2 = wxNewId();
47const long ActionViewer::ID_tParentName = wxNewId();
48const long ActionViewer::ID_STATICTEXT3 = wxNewId();
49const long ActionViewer::ID_tType = wxNewId();
50const long ActionViewer::ID_STATICTEXT4 = wxNewId();
51const long ActionViewer::ID_tCommand = wxNewId();
52const long ActionViewer::ID_STATICTEXT5 = wxNewId();
53const long ActionViewer::ID_tParameters = wxNewId();
54//*)
55
56BEGIN_EVENT_TABLE(ActionViewer,wxDialog)
57 //(*EventTable(ActionViewer)
58 //*)
59END_EVENT_TABLE()
60
61ActionViewer::ActionViewer(DebugPanel* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
62{
63 //(*Initialize(ActionViewer)
64 wxBoxSizer* BoxSizer1;
65 wxBoxSizer* BoxSizer2;
66 wxFlexGridSizer* FlexGridSizer1;
67 wxFlexGridSizer* FlexGridSizer2;
68 wxFlexGridSizer* FlexGridSizer3;
69
70 Create(parent, wxID_ANY, _("Action Viewer"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
71 BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
72 FlexGridSizer1 = new wxFlexGridSizer(0, 1, 0, 0);
73 ActionList = new wxListBox(this, ID_ActionList, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_ActionList"));
74 ActionList->SetMinSize(wxSize(300,300));
75 FlexGridSizer1->Add(ActionList, 1, wxALL|wxALIGN_LEFT|wxALIGN_TOP, 5);
76 BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
77 bDelete = new wxButton(this, ID_bDelete, _("Delete"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_bDelete"));
78 BoxSizer2->Add(bDelete, 1, wxALL|wxALIGN_TOP, 5);
79 bRun = new wxButton(this, ID_bRun, _("Run Action"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_bRun"));
80 BoxSizer2->Add(bRun, 1, wxALL|wxALIGN_TOP, 5);
81 bOK = new wxButton(this, ID_bOK, _("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_bOK"));
82 BoxSizer2->Add(bOK, 1, wxALL|wxALIGN_TOP, 5);
83 FlexGridSizer1->Add(BoxSizer2, 1, wxALL|wxALIGN_TOP|wxALIGN_CENTER_HORIZONTAL, 5);
84 BoxSizer1->Add(FlexGridSizer1, 1, wxALL|wxEXPAND, 5);
85 FlexGridSizer2 = new wxFlexGridSizer(0, 1, 0, 0);
86 FlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
87 StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Name:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
88 FlexGridSizer3->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
89 tName = new wxTextCtrl(this, ID_tName, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY, wxDefaultValidator, _T("ID_tName"));
90 tName->SetMinSize(wxSize(200,-1));
91 FlexGridSizer3->Add(tName, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
92 StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Parent Name(s):"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
93 FlexGridSizer3->Add(StaticText2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
94 tParentName = new wxTextCtrl(this, ID_tParentName, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY, wxDefaultValidator, _T("ID_tParentName"));
95 FlexGridSizer3->Add(tParentName, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 5);
96 StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("Parent Type(s):"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
97 FlexGridSizer3->Add(StaticText3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
98 tType = new wxTextCtrl(this, ID_tType, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY, wxDefaultValidator, _T("ID_tType"));
99 FlexGridSizer3->Add(tType, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 5);
100 StaticText4 = new wxStaticText(this, ID_STATICTEXT4, _("Command:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
101 FlexGridSizer3->Add(StaticText4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
102 tCommand = new wxTextCtrl(this, ID_tCommand, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY, wxDefaultValidator, _T("ID_tCommand"));
103 FlexGridSizer3->Add(tCommand, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND, 5);
104 FlexGridSizer2->Add(FlexGridSizer3, 1, wxALIGN_LEFT|wxALIGN_TOP, 5);
105 StaticText5 = new wxStaticText(this, ID_STATICTEXT5, _("Parameters:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
106 FlexGridSizer2->Add(StaticText5, 1, wxTOP|wxLEFT|wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
107 tParameters = new wxTextCtrl(this, ID_tParameters, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY, wxDefaultValidator, _T("ID_tParameters"));
108 tParameters->SetMinSize(wxSize(200,100));
109 FlexGridSizer2->Add(tParameters, 1, wxALL|wxEXPAND, 5);
110 BoxSizer1->Add(FlexGridSizer2, 1, wxALL|wxEXPAND, 5);
111 SetSizer(BoxSizer1);
112 BoxSizer1->Fit(this);
113 BoxSizer1->SetSizeHints(this);
114 Center();
115
116 Connect(ID_ActionList,wxEVT_COMMAND_LISTBOX_SELECTED,(wxObjectEventFunction)&ActionViewer::On_ActionList_Select);
117 Connect(ID_bDelete,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ActionViewer::On_bDelete_Click);
118 Connect(ID_bRun,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ActionViewer::On_bRun_Click);
119 Connect(ID_bOK,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&ActionViewer::On_bOK_Click);
120 //*)
121
122 lastcount = 0;
123 Simcore = 0;
124 panel = parent;
125}
126
128{
129 //(*Destroy(ActionViewer)
130 //*)
131}
132
134{
135 if (Simcore != panel->GetSystem())
136 {
137 //if active engine has changed, refresh values
139 lastcount = 0;
140 }
141
142 if (!Simcore)
143 return;
144
146 {
148
149 //clear values
150 ActionList->Clear();
151 tName->Clear();
152 tParentName->Clear();
153 tType->Clear();
154 tCommand->Clear();
155 tParameters->Clear();
156
157 for (int i = 0; i < Simcore->GetActionCount(); i++)
158 ActionList->Append(ToString(i + 1) + wxT(" - ") + Simcore->GetAction(i)->GetName());
159 }
160}
161
162void ActionViewer::On_bRun_Click(wxCommandEvent& event)
163{
164 int selection = ActionList->GetSelection();
165 if (selection >= 0)
166 Simcore->RunAction(selection);
167}
168
169void ActionViewer::On_bOK_Click(wxCommandEvent& event)
170{
171 this->Close();
172}
173
174void ActionViewer::On_ActionList_Select(wxCommandEvent& event)
175{
176 int selection = ActionList->GetSelection();
177 if (selection < 0)
178 return;
179
180 Action *action = Simcore->GetAction(selection);
181 if (action)
182 {
183 tName->SetValue(action->GetName());
184 tParentName->Clear();
185 tType->Clear();
186
187 for (int i = 0; i < action->GetParentCount(); i++)
188 {
189 wxString index = ToString(i + 1);
190 tParentName->AppendText(index + wxT(": ") + action->GetParentName(i) + wxT("\n"));
191 tType->AppendText(index + wxT(": ") + action->GetParentType(i) + wxT("\n"));
192 }
193
194 tCommand->SetValue(action->GetCommandName());
195
196 tParameters->Clear();
197 for (int i = 0; i < action->GetParameterCount(); i++)
198 tParameters->AppendText(action->GetParameter(i) + wxT("\n"));
199 }
200}
201
202void ActionViewer::On_bDelete_Click(wxCommandEvent& event)
203{
204 int selection = ActionList->GetSelection();
205 if (selection < 0)
206 return;
207
208 Action *action = Simcore->GetAction(selection);
209 if (action)
210 Simcore->RemoveAction(action);
211}
212
213}
214
std::string GetCommandName()
Definition action.cpp:82
std::string GetParentName(int number)
Definition action.cpp:1037
int GetParentCount()
Definition action.cpp:1024
std::string GetParameter(int index)
Definition action.cpp:1062
int GetParameterCount()
Definition action.cpp:1057
std::string GetParentType(int number)
Definition action.cpp:1047
const std::string & GetName()
Definition object.cpp:53
bool RunAction(const std::string &name)
Definition sbs.cpp:3867
std::vector< Action * > GetAction(std::string name)
Definition sbs.cpp:3431
int GetActionCount()
Definition sbs.cpp:3454
bool RemoveAction(std::string name)
Definition sbs.cpp:3515
void On_bRun_Click(wxCommandEvent &event)
static const long ID_ActionList
static const long ID_STATICTEXT3
static const long ID_STATICTEXT4
void On_bDelete_Click(wxCommandEvent &event)
static const long ID_tParentName
static const long ID_STATICTEXT1
void On_bOK_Click(wxCommandEvent &event)
static const long ID_tParameters
static const long ID_tType
static const long ID_bOK
static const long ID_STATICTEXT5
static const long ID_bDelete
static const long ID_tCommand
static const long ID_tName
void On_ActionList_Select(wxCommandEvent &event)
static const long ID_STATICTEXT2
static const long ID_bRun
SBS::SBS * GetSystem()
Definition debugpanel.h:131
std::string ToString(int number)
Definition globals.cpp:279