-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTourForm.cs
182 lines (163 loc) · 5.8 KB
/
TourForm.cs
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
/*
* YOGEME.exe, All-in-one Mission Editor for the X-wing series, XW through XWA
* Copyright (C) 2007-2024 Michael Gaisser (mjgaisser@gmail.com)
* Licensed under the MPL v2.0 or later
*
* VERSION: 1.16
*
* CHANGELOG
* v1.16, 241013
* [UPD] cleanup
* v1.12, 220103
* - Release
*/
using Idmr.LfdReader;
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
namespace Idmr.Yogeme
{
public partial class TourForm : Form
{
readonly LfdFile _missions;
Text _tour;
int _tourIndex;
public TourForm()
{
InitializeComponent();
var config = Settings.GetInstance();
if (!config.XwingInstalled)
{
MessageBox.Show("X-wing installation not found, Tour function not available", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
return;
}
else
{
bool remastered = Directory.Exists(config.XwingPath + "\\X-wing Data");
_missions = new LfdFile(config.XwingPath + (remastered ? "\\X-Wing Data" : "") + "\\RESOURCE\\MISSIONS.LFD");
opnMission.InitialDirectory = config.XwingPath + (remastered ? "\\X-Wing Data" : "") + "\\MISSION";
_tourIndex = 1;
loadTour();
}
}
void loadTour()
{
_tour = (Text)_missions.Resources["TEXTtour" + _tourIndex];
lstMiss.Items.Clear();
lstMiss.Items.AddRange(_tour.Strings[0].Split('\0'));
lstMiss.SelectedIndex = 0;
lblTour.Text = "Tour " + _tourIndex;
}
void cmdAdd_Click(object sender, EventArgs e) => opnMission.ShowDialog();
void cmdCancel_Click(object sender, EventArgs e) => Close();
void cmdMoveDown_Click(object sender, EventArgs e)
{
int missIndex = lstMiss.SelectedIndex;
if (missIndex == -1 || missIndex == lstMiss.Items.Count - 1) return;
string strTemp = _tour.Strings[2 + missIndex]; //description
_tour.Strings[2 + missIndex] = _tour.Strings[2 + missIndex + 1];
_tour.Strings[2 + missIndex + 1] = strTemp;
string[] arrTemp = _tour.Strings[1].Split('\0'); // title
strTemp = arrTemp[missIndex];
arrTemp[missIndex] = arrTemp[missIndex + 1];
arrTemp[missIndex + 1] = strTemp;
_tour.Strings[1] = string.Join("\0", arrTemp);
arrTemp = _tour.Strings[0].Split('\0'); // mission
strTemp = arrTemp[missIndex];
arrTemp[missIndex] = arrTemp[missIndex + 1];
arrTemp[missIndex + 1] = strTemp;
_tour.Strings[0] = string.Join("\0", arrTemp);
lstMiss.Items.RemoveAt(missIndex);
lstMiss.Items.Insert(missIndex + 1, strTemp);
lstMiss.SelectedIndex = missIndex + 1;
}
void cmdMoveUp_Click(object sender, EventArgs e)
{
int missIndex = lstMiss.SelectedIndex;
if (missIndex < 1) return;
string strTemp = _tour.Strings[2 + missIndex]; //description
_tour.Strings[2 + missIndex] = _tour.Strings[2 + missIndex - 1];
_tour.Strings[2 + missIndex - 1] = strTemp;
string[] arrTemp = _tour.Strings[1].Split('\0'); // title
strTemp = arrTemp[missIndex];
arrTemp[missIndex] = arrTemp[missIndex - 1];
arrTemp[missIndex - 1] = strTemp;
_tour.Strings[1] = string.Join("\0", arrTemp);
arrTemp = _tour.Strings[0].Split('\0'); // mission
strTemp = arrTemp[missIndex];
arrTemp[missIndex] = arrTemp[missIndex - 1];
arrTemp[missIndex - 1] = strTemp;
_tour.Strings[0] = string.Join("\0", arrTemp);
lstMiss.Items.RemoveAt(missIndex);
lstMiss.Items.Insert(missIndex - 1, strTemp);
lstMiss.SelectedIndex = missIndex - 1;
}
void cmdNext_Click(object sender, EventArgs e)
{
if (_tourIndex < 5) _tourIndex++; // LFD suggests there's up to 8, but there's only details for 5
loadTour();
}
void cmdOK_Click(object sender, EventArgs e)
{
_missions.Write();
Close();
}
void cmdPrev_Click(object sender, EventArgs e)
{
if (_tourIndex > 1) _tourIndex--;
loadTour();
}
void cmdRemove_Click(object sender, EventArgs e)
{
if (lstMiss.SelectedIndex == -1) return;
int index = lstMiss.SelectedIndex;
_tour.Strings[0] = _tour.Strings[0].Replace(lstMiss.SelectedItem.ToString(), "").Replace("\0\0", "\0").Trim('\0');
_tour.Strings[1] = _tour.Strings[1].Replace(txtTitle.Text, "").Replace("\0\0", "\0").Trim('\0');
for (int i = index + 2; i < _tour.NumberOfStrings - 1; i++) _tour.Strings[i] = _tour.Strings[i + 1];
_tour.NumberOfStrings--;
lstMiss.Items.RemoveAt(index);
try { lstMiss.SelectedIndex = index; }
catch (ArgumentOutOfRangeException) { lstMiss.SelectedIndex = index - 1; }
}
void lstMiss_SelectedIndexChanged(object sender, EventArgs e)
{
if (lstMiss.SelectedIndex == -1) return;
int missIndex = lstMiss.SelectedIndex;
string desc = _tour.Strings[2 + missIndex].Replace("\0", "\r\n");
desc = desc.Replace(Convert.ToChar(1), ']');
desc = desc.Replace(Convert.ToChar(2), '[');
txtDesc.Text = desc;
txtTitle.Text = _tour.Strings[1].Split('\0')[missIndex];
}
void opnMission_FileOk(object sender, CancelEventArgs e)
{
string strMission = opnMission.FileName;
strMission = strMission.Remove(0, strMission.LastIndexOf("\\") + 1);
strMission = strMission.Remove(strMission.Length - 4, 4);
lstMiss.Items.Add(strMission);
_tour.Strings[0] += "\0" + strMission;
_tour.Strings[1] += "\0" + "<Enter Title>";
_tour.NumberOfStrings++;
_tour.Strings[_tour.NumberOfStrings - 1] = "<Enter Description>";
lstMiss.SelectedIndex = lstMiss.Items.Count - 1;
}
void txtDesc_TextChanged(object sender, EventArgs e)
{
if (lstMiss.SelectedIndex == -1) return;
int missIndex = lstMiss.SelectedIndex;
string desc = txtDesc.Text.Replace("\r\n", "\0");
desc = desc.Replace(']', Convert.ToChar(1));
desc = desc.Replace('[', Convert.ToChar(2));
_tour.Strings[2 + missIndex] = desc;
}
void txtTitle_TextChanged(object sender, EventArgs e)
{
if (lstMiss.SelectedIndex == -1) return;
string[] titles = _tour.Strings[1].Split('\0');
titles[lstMiss.SelectedIndex] = txtTitle.Text;
_tour.Strings[1] = string.Join("\0", titles);
}
}
}