-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.cpp
More file actions
267 lines (212 loc) · 6.89 KB
/
editor.cpp
File metadata and controls
267 lines (212 loc) · 6.89 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#include "editor.h"
#include "ui_editor.h"
Editor::Editor(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Editor)
{
ui->setupUi(this);
// Setup the application details and window title
qApp->setApplicationName("EHM 2007 Hardcode Editor");
qApp->setApplicationVersion("0.0.3");
this->setWindowTitle(qApp->applicationName() + " v" + qApp->applicationVersion());
this->setMinimumSize(1024, 700);
// Application icon
qApp->setWindowIcon(QIcon("tbl.ico"));
// Application images
ui->logoContainer->setPixmap(QPixmap(":/images/logo_128.png"));
// Default file name and path
fileName_ = "ehm2007.exe";
filePath_ = "C:/Program Files (x86)/Sports Interactive/NHL Eastside Hockey Manager 2007/";
// Status bar
statusBar()->addPermanentWidget(&statusBar_);
// Setup the UI
editorCompNames_ = new EditorCompNames((*ui->tabCompNames));
editorCompRules_ = new EditorCompRules((*ui->tabCompRules));
editorCompStructs_ = new EditorCompStructs((*ui->tabCompStructs));
editorFolderPaths_ = new EditorFolderPaths((*ui->tabFolderPaths));
initEditor(false);
}
Editor::~Editor()
{
initEditor(false);
delete ui;
}
/* ================================== */
/* Initialisation Functions */
/* ================================== */
// Initialise the editor
bool Editor::initEditor(bool enabled)
{
initData(enabled);
initUI(enabled);
return enabled;
}
// Initialise the data
void Editor::initData(bool enabled)
{
// If disabled, clear all data
if(!enabled) {
data_.clear();
return;
}
// Else initialise the data
CompRules::init(data_);
CompStructs::init(data_);
Text::init(data_);
editorCompNames_->init();
editorCompRules_->init();
editorCompStructs_->init();
editorFolderPaths_->init();
}
// Initialise the UI
void Editor::initUI(bool enabled)
{
// Menu items
ui->actionSave->setEnabled(enabled);
ui->actionSave_As->setEnabled(enabled);
// Tab widget
ui->tabWidget->setCurrentIndex(0);
/* for(unsigned char i = 1; i <= ui->tabWidget->count(); ++i)
ui->tabWidget->setTabEnabled(i, enabled);
*/
// Disable the UI
if(!enabled) {
// Status bar
statusBar_.setText(tr("No file loaded."));
return;
}
// Else enable the UI
ui->actionOpen->setEnabled(false);
updateStatusBar();
}
/* ======================= */
/* I/O Functions */
/* ======================= */
// Open exe file and read the data
bool Editor::openFile()
{
data_.clear();
QFile file(filePath_ + fileName_);
if(!file.open(QIODevice::ReadOnly) || file.size() == 0) {
QMessageBox::critical(this, tr("Error"), tr("Unable to open file."));
return false;
}
data_ = file.readAll();
file.close();
return initEditor(verifyFile()); // Verify the file, initialise the data and return whether or not it is valid
}
// Save exe file to disk
bool Editor::saveFile()
{
QFile file(filePath_ + fileName_);
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QMessageBox::critical(this, tr("Error"), tr("Unable to save file."));
return false;
}
file.write(data_);
file.close();
return true;
}
// Verify file
bool Editor::verifyFile()
{
if(data_.size() != 9531392) {
QMessageBox::critical(this, tr("Error"), tr("Unexpected file size."));
data_.clear();
return false;
}
return true;
}
/* ==================== */
/* Menu Items */
/* ==================== */
// File -> Open
void Editor::on_actionOpen_triggered()
{
fileName_ = QFileDialog::getOpenFileName(this, tr("Open EHM 2007 Executable (v3.0.4)"),
filePath_,
tr("EHM 2007 Executable (*.exe)"));
if(!fileName_.isEmpty()) {
QFileInfo file(fileName_);
filePath_ = file.path() + "/";
fileName_ = file.fileName();
openFile(); // Open the file
}
}
// File -> Save
void Editor::on_actionSave_triggered()
{
saveFile();
}
// File -> Save As
void Editor::on_actionSave_As_triggered()
{
QString fileSaveAs = QFileDialog::getSaveFileName(this, tr("Save EHM 2007 Executable (v3.0.4)"),
(filePath_ + fileName_),
tr("EHM 2007 Executable (*.exe)"));
if(!fileSaveAs.isEmpty()) {
QFileInfo file(fileSaveAs);
filePath_ = file.path();
filePath_ += "/";
fileName_ = file.fileName();
saveFile();
}
updateStatusBar();
}
/* ================== */
/* Set Data */
/* ================== */
// Update the status bar
void Editor::updateStatusBar()
{
QLocale locale;
QString fileSize = locale.toString(data_.size());
statusBar_.setText(filePath_ + fileName_ + " (" + fileSize + " bytes)");
}
/* =============================== */
/* About the Application */
/* =============================== */
// --- About the EHM Updater --- //
void Editor::on_actionAbout_triggered()
{
QMessageBox *about = new QMessageBox;
about->setIconPixmap(QPixmap(":/images/logo_64.png"));
about->setWindowTitle("About EHM 2007 Hardcode Editor");
about->setText("<font size='4'><b>" + qApp->applicationName() + "</b></font>");
about->setInformativeText("Version " + qApp->applicationVersion() + " (" + QString::fromLocal8Bit(BUILDDATE) + " " + QString::fromLocal8Bit(BUILDTIME) + ")<br /><br />By Archibalduk<br /><br /><a href='mailto:archibalduk@gmail.com'>archibalduk@gmail.com</a><br /><a href='http://www.ehmtheblueline.com'>http://www.ehmtheblueline.com</a>");
about->setStandardButtons(QMessageBox::Ok);
about->setDefaultButton(QMessageBox::Ok);
about->show();
about->exec();
}
// --- About Qt --- //
void Editor::on_actionAbout_Qt_triggered()
{
QMessageBox::aboutQt(this,tr("About Qt"));
}
// --- Visit the forum --- //
void Editor::on_actionVisit_EHM_Hardcode_Editor_Forum_triggered()
{
QUrl urlForum("http://www.ehmtheblueline.com/ehmhardcode");
QDesktopServices::openUrl(urlForum);
}
/* ============================== */
/* Exit the Application */
/* ============================== */
// --- Exit application --- //
void Editor::on_actionExit_triggered()
{
this->close();
}
// --- Detect any attempt to close the application and prompt the user to confirm he wishes to exit (only if the there is data loaded) --- //
void Editor::closeEvent(QCloseEvent *event)
{
// Accept the close event if no data has been loaded
if(data_.size() < 1)
event->accept();
// Else ask the user if he wants to close
else if(QMessageBox::Yes == QMessageBox::question(this, tr("Exit"), tr("Are you sure you wish to exit the Hardcode Editor?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No))
event->accept();
else
event->ignore();
}