-
Notifications
You must be signed in to change notification settings - Fork 2
/
frmTMDObjList.cs
222 lines (176 loc) · 7.49 KB
/
frmTMDObjList.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
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
using System;
using System.IO;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KimeraCS
{
using static FrmSkeletonEditor;
using static FF7Skeleton;
using static FF7PModel;
using static FF7TMDModel;
using static Utils;
using static FileTools;
public partial class FrmTMDObjList : Form
{
readonly private FrmSkeletonEditor frmSkelEdit;
public FrmTMDObjList(FrmSkeletonEditor frmSkelEdit)
{
InitializeComponent();
this.frmSkelEdit = frmSkelEdit;
Owner = frmSkelEdit;
}
public void RepositionTMD()
{
Location = new Point(Owner.Location.X + Owner.Width - Width,
Owner.Location.Y + Owner.Height - Height);
}
private void FrmTMDObjList_Load(object sender, EventArgs e)
{
RepositionTMD();
lbTMDObjectList.SelectedIndex = 0;
if (bConverted2Float) cbConvertToFloat.Checked = true;
else cbConvertToFloat.Checked = false;
}
private void BtnClose_Click(object sender, EventArgs e)
{
Close();
}
public void PopulateTMDObjList()
{
string strObjectName;
lbTMDObjectList.Items.Clear();
for (int i = 0; i < mTMDModel.TMDHeader.nObjects; i++)
{
strObjectName = "Object " + (i + 1).ToString("000");
if (TMDHasTextureUVs(mTMDModel.TMDObjectList[i].TMDPrimitiveList[0]))
{
strObjectName += " (TX)";
}
lbTMDObjectList.Items.Add(strObjectName);
}
}
private void LbTMDObjectList_DoubleClick(object sender, EventArgs e)
{
Point3D p_min = new Point3D();
Point3D p_max = new Point3D();
if (lbTMDObjectList.SelectedIndex > -1)
{
// Close previous P Editor if any.
if (FindWindowOpened("FrmPEditor")) frmSkelEdit.frmPEdit.Close();
// Now let's convert the TMD model into P model.
DestroyPModelResources(ref fPModel);
fPModel = new PModel()
{
fileName = Path.GetFileNameWithoutExtension(strGlobalTMDModelName) + "_" + (lbTMDObjectList.SelectedIndex + 1).ToString("000"),
};
ConvertTMD2PModel(ref fPModel, mTMDModel, lbTMDObjectList.SelectedIndex);
ComputePModelBoundingBox(fPModel, ref p_min, ref p_max);
diameter = ComputeDiameter(fPModel.BoundingBox);
// Set frame values in frame editor groupbox...
frmSkelEdit.SetFrameEditorFields();
// Enable texture group if TMD object has texture coordinates
//if (TMDHasTextureUVs(mTMDModel.TMDObjectList[lbTMDObjectList.SelectedIndex].TMDPrimitiveList[0]))
//{
// // Set texture values in texture editor groupbox...
// frmSkelEdit.gbTexturesFrame.Visible = true;
// frmSkelEdit.gbTexturesFrame.Enabled = true;
// frmSkelEdit.gbTexturesFrame.Location = new Point(frmSkelEdit.gbTexturesFrame.Location.X,
// 0);
// frmSkelEdit.SetTextureEditorFields();
//}
//else
//{
// frmSkelEdit.gbTexturesFrame.Visible = false;
// frmSkelEdit.gbTexturesFrame.Enabled = false;
// frmSkelEdit.gbTexturesFrame.Location = new Point(frmSkelEdit.gbTexturesFrame.Location.X,
// 193);
// frmSkelEdit.SetTextureEditorFields();
//}
// PostLoadModelPreparations
frmSkelEdit.PostLoadModelPreparations(ref p_min, ref p_max);
// We can draw the model in panel
frmSkelEdit.PanelModel_Paint(null, null);
}
}
private void FrmTMDObjList_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason != CloseReason.FormOwnerClosing)
{
Hide();
e.Cancel = true;
}
}
private void BtnSaveInfo_Click(object sender, EventArgs e)
{
WriteTMDLOG();
}
private void BtnSaveTMD_Click(object sender, EventArgs e)
{
//string saveAnimationFileName;
int iSaveResult;
// Set filter options and filter index depending on modelType
// Check Initial Directory
saveFile.Title = "Save TMD File As...";
saveFile.Filter = "TMD|*.TMD|All files|*.*";
if (strGlobalPathTMDModelFolder == "")
strGlobalPathTMDModelFolder = strGlobalPath;
saveFile.FileName = strGlobalTMDModelName.ToUpper();
saveFile.FilterIndex = 1;
saveFile.InitialDirectory = strGlobalPathTMDModelFolder;
try
{
// Process input if the user clicked OK.
if (saveFile.ShowDialog() == DialogResult.OK)
{
if (IsTMDModel)
{
// I don't think it is needed when saving
//AddStateToBuffer(this);
strGlobalPathSaveTMDFolder = Path.GetDirectoryName(saveFile.FileName);
saveFile.FileName = strGlobalPathSaveTMDFolder + "\\" + Path.GetFileName(saveFile.FileName).ToUpper();
// We save the TMD Object Pack.
iSaveResult = WriteTMD(saveFile.FileName);
if (iSaveResult == 1)
{
MessageBox.Show("The TMD file " + Path.GetFileName(saveFile.FileName).ToUpper() + " has been saved.",
"Information");
}
else
{
MessageBox.Show("Error saving the TMD file " + Path.GetFileName(saveFile.FileName).ToUpper() + ".",
"Error");
return;
}
}
WriteCFGFile();
}
}
catch
{
MessageBox.Show("Error exception saving the TMD file as... " + Path.GetFileName(saveFile.FileName) + ".",
"Error");
return;
}
}
private void BtnCommitPModel_Click(object sender, EventArgs e)
{
if (lbTMDObjectList.SelectedIndex > -1)
{
ConvertPModel2TMD(fPModel, lbTMDObjectList.SelectedIndex);
LbTMDObjectList_DoubleClick(lbTMDObjectList, EventArgs.Empty);
}
}
private void CbConvertToFloat_CheckedChanged(object sender, EventArgs e)
{
bConverted2Float = cbConvertToFloat.Checked;
if (bConverted2Float) mTMDModel.TMDHeader.version = 0xFF;
else mTMDModel.TMDHeader.flags = 0x41;
RecalculateOffsets();
}
}
}