-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmWIMEEditorMain.vb
340 lines (338 loc) · 17.2 KB
/
frmWIMEEditorMain.vb
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
'Option Explicit On
'Option Strict On
Imports System
Imports System.IO
Imports System.Xml
Public Class frmWIMEEditorMain
'Public saveBinaryIn As New BinaryReader(New FileStream(strFilename, FileMode.OpenOrCreate, FileAccess.Read))
'Public saveBinaryIn As BinaryReader
'Public readStream As FileStream
' *** frmWIMEEditorMaiin ***
' Form for the Main Editor
Dim strFirstTime As String
Dim blnProgramLoaded As Boolean = False
Dim intMapSize As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
setFileFormats()
frmOverview.TopMost = False
If File.Exists("WIMEConfig.xml") Then ' If there is a config file, then open the savegame file from the config
OpenSaveGameFile()
Else
SaveGameFileDialog()
WIMEAppSettings.applicationDirectory = System.Environment.CurrentDirectory
WIMEAppSettings.dataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
WIMEAppSettings.WIMEDirectory = System.IO.Path.GetDirectoryName(strFilename)
WIMEAppSettings.savegameFilename = strFilename
WIMEAppSettings.savegameFileFormat = WIMESaveGameFileFormat
WIMEAppSettings.mapTilesize = 16
WriteXMLConfig() ' Writes data to the XML config file.
End If
SplitContainer1.SplitterDistance = 300
Me.WindowState = FormWindowState.Maximized
OpenWIMEConfig()
Call ReadSaveGameFile() ' Call subroutine to read the savegame file
Call ProcessSaveGameData() ' Call subroutine to process the savegame file
OpenWIMEConfig()
Call WriteSaveGameDatabase() ' Call subroutine to write the data to a tab delimited file
Dim intCurrentFillRecord As Integer = 0
Call FillOverViewList()
frmOverview.TopLevel = False
SplitContainer1.Panel2.Controls.Add(frmOverview)
frmOverview.Show()
RemoveHandler txtCurrentChar.TextChanged, AddressOf txtCurrentChar_TextChanged
txtCurrentChar.Text = "Character " & intCurrentCharacter & " of 194"
AddHandler txtCurrentChar.TextChanged, AddressOf txtCurrentChar_TextChanged
blnProgramLoaded = True
End Sub
' ============================ OPEN SAVEGAME FILE SUBROUTINE ==========================================================================
Public Sub OpenSaveGameFile()
' *************** OpenSaveGameFile Subroutine *******************
' Opens the config file to automatically load savegame file name
' stored upon startup if config file exists.
' ***************************************************************
OpenWIMEConfig()
If WIMEAppReadSettings.savegameFilename = "" Then Call SaveGameFileDialog()
If WIMEAppReadSettings.WIMEDirectory = "" Then Call SaveGameFileDialog()
'FileClose(1)
'FileOpen(1, WIMEAppReadSettings.savegameFilename, OpenMode.Binary) ' Opens savegame file using data read and interpreted from XML config.
readStream = New FileStream(WIMEAppReadSettings.savegameFilename, FileMode.Open)
Call SaveGameHeaderCheck()
UpdateFormat()
End Sub
Public Sub SaveGameFileDialog()
' =============================== SAVEGAMEFILEDIALOG SUB ======================================================================
' Contains subroutine handling dialog box called when user wants to open a savegame file.
' =============================================================================================================================
Dim BOMbigEndian As New System.Text.UnicodeEncoding(True, True)
Dim BOMlittleEndian As New System.Text.UnicodeEncoding(False, True)
OpenFD.Title = "Select the Savegame File to Edit"
OpenFD.Filter = "WIME Save Game|*.dat|All Files|*.*"
OpenFD.RestoreDirectory = False
OpenFD.ShowDialog()
strFilename = OpenFD.FileName
readStream = New FileStream(strFilename, FileMode.Open)
Call SaveGameHeaderCheck()
WIMEAppSettings.applicationDirectory = System.Environment.CurrentDirectory
WIMEAppSettings.dataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
WIMEAppSettings.WIMEDirectory = System.IO.Path.GetDirectoryName(strFilename)
WIMEAppSettings.savegameFilename = strFilename
WIMEAppSettings.savegameFileFormat = currentFileFormat.formatID
WIMEAppSettings.resourceAMAPFilename = currentFileFormat.mapResourceFilename
WIMEAppSettings.mapTilesize = 16
WIMEAppSettings.resourceTileFilename = currentFileFormat.tileResourceFilename
WriteXMLConfig()
OpenWIMEConfig()
UpdateFormat()
If blnProgramLoaded = True Then
OpenWIMEConfig()
Call ReadSaveGameFile() ' Call subroutine to read the savegame file
Call ProcessSaveGameData() ' Call subroutine to process the savegame file
Call WriteSaveGameDatabase() ' Call subroutine to write the data to a tab delimited file
strFirstTime = ""
Call FillOverViewList()
lvwCharacterOverview.Show()
lvwCharacterOverview.Refresh()
frmOverview.TopLevel = False
SplitContainer1.Panel2.Controls.Add(frmOverview)
frmOverview.Show()
txtCurrentChar.Text = "Character " & intCurrentCharacter & " of 194"
WriteXMLConfig()
UpdateFormat()
End If
End Sub
Public Sub SaveGameHeaderCheck()
Dim saveHeaderCheck As Integer
' ========================================= SAVEGAMEHEADERCHECK SUB =========================================================
' Subroutine which checks the header of a file opened through the savegame dialog box to ensure it is the proper file.
' ===========================================================================================================================
Dim readBinary As New BinaryReader(readStream)
Dim skint As Int64
Dim skbyte As Byte
saveHeaderCheck = readBinary.ReadInt32
For j As Integer = 0 To 3
skint = readBinary.ReadInt64
Next j
skbyte = readBinary.ReadByte
chRead.characterValue(0) = readBinary.ReadInt16
Select Case Hex$(saveHeaderCheck)
Case fileFormatPC.saveHeaderCheckByte
currentFileFormat = fileFormatPC
Case fileFormatIIGS.saveHeaderCheckByte
currentFileFormat = fileFormatIIGS
Case fileFormatAMIGA.saveHeaderCheckByte
currentFileFormat = fileFormatAMIGA
Case Else
WIMESaveGameFileFormat = "UNKNOWN"
MsgBox("Invalid Savegame File. Please select another file!")
Call SaveGameFileDialog()
End Select
readBinary.Close()
FillXML()
WIMEAppSettings.resourceAMAPFilename = currentFileFormat.mapResourceFilename
WIMEAppSettings.savegameFileFormat = currentFileFormat.formatID
WriteXMLConfig()
End Sub
Public Sub SaveGameOpenRoutines()
Call frmOverview.SaveFormCheck()
frmOverview.Close()
lvwCharacterOverview.Clear()
lvwCharacterOverview.Hide()
SaveGameFileDialog()
'OpenSaveGameFile()
OpenWIMEConfig()
Call ReadSaveGameFile() ' Call subroutine to read the savegame file
Call ProcessSaveGameData() ' Call subroutine to process the savegame file
Call WriteSaveGameDatabase() ' Call subroutine to write the data to a tab delimited file
strFirstTime = ""
Call FillOverViewList()
lvwCharacterOverview.Show()
lvwCharacterOverview.Refresh()
frmOverview.TopLevel = False
SplitContainer1.Panel2.Controls.Add(frmOverview)
frmOverview.Show()
txtCurrentChar.Text = "Character " & intCurrentCharacter & " of 194"
WriteXMLConfig()
UpdateFormat()
End Sub
' ========================================== MENU ITEMS ======================================================================
Private Sub mnuPCOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPCOpen.Click
WIMESaveGameFileFormat = fileFormatPC.formatID
Call SaveGameOpenRoutines()
End Sub
Private Sub mnuIIGSOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuIIGSOpen.Click
WIMESaveGameFileFormat = fileFormatIIGS.formatID
Call SaveGameOpenRoutines()
End Sub
Private Sub Amiga16bitDefaultStartToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles Amiga16bitDefaultStartToolStripMenuItem.Click
WIMESaveGameFileFormat = fileFormatAMIGA.formatID
Call SaveGameOpenRoutines()
End Sub
Private Sub Amiga16bitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles Amiga16bitToolStripMenuItem.Click
WIMESaveGameFileFormat = fileFormatAMIGA.formatID
Call SaveGameOpenRoutines()
End Sub
Private Sub mnuProgramOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuProgramOptions.Click
Dim Form5 As New frmProgramSettings
frmProgramSettings.Show()
End Sub
Private Sub mnuExitProgram_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExitProgram.Click
FileClose()
Close()
End
End Sub
Private Sub mnuMapView(ByVal sender As System.Object, ByVal e As System.EventArgs)
frmAmapViewer.Show()
End Sub
Private Sub mnuCopyProtection(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyProtectionCodesToolStripMenuItem.Click
frmCoordinates.Show()
End Sub
Private Sub mnuSaveDataOverview(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveGameOverview.Click
frmSaveSummary.Show()
End Sub
'=================================================== TOOL STRIP ITEMS ===========================================================
Private Sub stpOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stpOpenFile.Click
SaveGameFileDialog()
End Sub
Private Sub stpSaveFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stpSaveFile.Click
frmOverview.WriteSaveGameFile(intCurrentFillRecord)
isDataSaved = True
frmOverview.StatusBarUpdate()
MsgBox("Saved!")
End Sub
Private Sub mnuCloseFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCloseFile.Click
CloseSGFile()
frmOverview.Close()
End Sub
Private Sub stpSettingsPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stpProgramSettings.Click
Dim Form5 As New frmProgramSettings
frmProgramSettings.Show()
End Sub
Private Sub FillOverViewList()
' ****************** FILL OVERVIEWLIST SUBROUTINE *********************************
If strFirstTime = "" Then ' Check string and if empty, then run as it will indicate first time
' Fill Listview for Character Overview
lvwCharacterOverview.Show()
lvwCharacterOverview.Columns.Clear()
lvwCharacterOverview.View = View.Details
lvwCharacterOverview.FullRowSelect = True
lvwCharacterOverview.HideSelection = False
lvwCharacterOverview.Columns.Add("Number", 50)
lvwCharacterOverview.Columns.Add("Character/Army Name", 140)
lvwCharacterOverview.Columns.Add("File Offset", 60)
lvwCharacterOverview.Height = SplitContainer1.Panel1.Height - 20
lvwCharacterOverview.Width = 272
intCNum(0) = 0
For intFormFill As Integer = 1 To characterEntryMax
intCNum(intFormFill) = Str(intFormFill)
Dim lv As ListViewItem = lvwCharacterOverview.Items.Add(intCNum(intFormFill))
'The remaining columns are subitems
lv.SubItems.Add(chRead.strArmyName(intFormFill))
lv.SubItems.Add(Hex$(chRead.intFileStart(intFormFill)) & "h")
Next
For intFormFill As Integer = 1 To characterEntryMax
If Val(chRead.valueMobilize(intFormFill)) = 99 Then
lvwCharacterOverview.Items(intFormFill - 1).ForeColor = Color.Blue
End If
If Val(chRead.valueMobilize(intFormFill)) = 1 Then
lvwCharacterOverview.Items(intFormFill - 1).ForeColor = Color.Blue
End If
If Val(chRead.valueMobilize(intFormFill)) = 0 Then
lvwCharacterOverview.Items(intFormFill - 1).ForeColor = Color.Red
End If
Next
strFirstTime = "NO" ' Add value to the first time string to prevent filling after every form change.
Else
End If
End Sub
Public Sub lvwCharacterOverview_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvwCharacterOverview.DoubleClick
Dim objDrawingPoint As Drawing.Point
Dim objListViewItem As ListViewItem
objDrawingPoint = lvwCharacterOverview.PointToClient(Cursor.Position)
If Not IsNothing(objDrawingPoint) Then
With objDrawingPoint
objListViewItem = lvwCharacterOverview.GetItemAt(.X, .Y)
End With
If Not IsNothing(objListViewItem) Then
intCurrentCharacter = objListViewItem.Text
txtCurrentChar.Text = "Character " & intCurrentCharacter & " of " & characterEntryMax
End If
End If
End Sub
' =================================================== STATUS BAR SUBROUTINES ============================================================
Public Sub txtCurrentChar_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCurrentChar.TextChanged
If isDataSaved = False Then
frmOverview.SaveFormCheck()
End If
frmOverview.ReloadCharacterForm()
End Sub
Public Sub UpdateFormat()
If WIMEAppReadSettings.savegameFileFormat = fileFormatPC.formatID Then
stpFileFormat.Text = fileFormatPC.formatDescription
stpFileFormat.Image = fileFormatPC.FileIcon
End If
If WIMEAppReadSettings.savegameFileFormat = fileFormatIIGS.formatID Then
stpFileFormat.Text = fileFormatIIGS.formatDescription
stpFileFormat.Image = fileFormatIIGS.FileIcon
End If
End Sub
Private Sub ResourceViewerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Call frmResourceView.Show()
End Sub
Private Sub CityEditorToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CityEditor.Click
frmOverview.Hide()
Dim oForm As frmCityEditor
oForm = New frmCityEditor
oForm.Show()
oForm = Nothing
frmOverview.Show()
End Sub
Private Sub WIMEAMAPResourceViewerToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles TileView.Click
frmAmapViewer.Show()
End Sub
Private Sub wimeMap3XSize_Click(sender As System.Object, e As System.EventArgs) Handles wimeMap3XSize.Click
OpenWIMEConfig()
FillXML()
WIMEAppSettings.mapTilesize = 48
WriteXMLConfig()
Dim oForm As New frmNewMap
oForm = frmNewMap
oForm.Show()
End Sub
Private Sub wimeMapOriginalSize_Click(sender As System.Object, e As System.EventArgs) Handles wimeMapOriginalSize.Click
OpenWIMEConfig()
FillXML()
WIMEAppSettings.mapTilesize = 16
WriteXMLConfig()
Dim oForm As New frmNewMap
oForm = frmNewMap
oForm.Show()
End Sub
Private Sub WorldBuilderToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs)
Dim wForm As New frmWorldBuilder
wForm = frmWorldBuilder
wForm.Show()
End Sub
Private Sub WIMEMap2XSizeToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles WIMEMap2XSizeToolStripMenuItem.Click
OpenWIMEConfig()
FillXML()
WIMEAppSettings.mapTilesize = 32
WriteXMLConfig()
Dim oForm As New frmNewMap
oForm = frmNewMap
oForm.Show()
End Sub
Private Sub ScrollerToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs)
Dim sForm As New frmScroll
sForm = frmScroll
sForm.Show()
End Sub
Private Sub AboutTheWIMESavegameEditorToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles AboutTheWIMESavegameEditorToolStripMenuItem.Click
Dim aForm As New WIMESplashScreen
aForm = WIMESplashScreen
aForm.Show()
End Sub
Private Sub IBMPC16bitDefaultStartToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles IBMPC16bitDefaultStartToolStripMenuItem.Click
WIMESaveGameFileFormat = fileFormatPC.formatID
Call SaveGameOpenRoutines()
End Sub
End Class