-
Notifications
You must be signed in to change notification settings - Fork 12
/
LevelSettingsForm.cs
188 lines (158 loc) · 7.15 KB
/
LevelSettingsForm.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
/*
Copyright 2012 Kuribo64
This file is part of SM64DSe.
SM64DSe is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
SM64DSe is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with SM64DSe. If not, see http://www.gnu.org/licenses/.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SM64DSe
{
public partial class LevelSettingsForm : Form
{
private Level m_Level;
private LevelSettings m_LevelSettings;
public LevelSettingsForm(Level level)
{
InitializeComponent();
m_Level = level;
m_LevelSettings = level.m_LevelSettings;
}
private void LevelSettingsForm_Load(object sender, EventArgs e)
{
string[][] bankobjs = new string[8][];
bankobjs[0] = new string[7];
bankobjs[1] = new string[7];
bankobjs[2] = new string[7];
bankobjs[3] = new string[7];
bankobjs[4] = new string[7];
bankobjs[5] = new string[7];
bankobjs[6] = new string[7];
bankobjs[7] = new string[53];
foreach (string[] foo in bankobjs)
for (int i = 0; i < foo.Length; i++)
foo[i] = "";
foreach (ObjectDatabase.ObjectInfo obj in ObjectDatabase.m_ObjectInfo)
{
if (obj.m_BankRequirement != 1)
continue;
bankobjs[obj.m_NumBank][obj.m_BankSetting] += obj.m_ID.ToString() + ",";
}
ComboBox[] combos = { cbxBank0, cbxBank1, cbxBank2, cbxBank3, cbxBank4, cbxBank5, cbxBank6, cbxBank7 };
for (int b = 0; b < 8; b++)
{
for (int i = 0; i < bankobjs[b].Length; i++)
{
string txt = string.Format("[{0}] - ", i);
string[] objs = bankobjs[b][i].Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
if (objs.Length > 0)
{
foreach (string _objid in objs)
{
int objid = int.Parse(_objid);
txt += string.Format("{0} ({1}), ", ObjectDatabase.m_ObjectInfo[objid].m_Name, objid);
}
txt = txt.Substring(0, txt.Length - 2);
}
else
txt += "(none)";
combos[b].Items.Add(txt);
}
combos[b].SelectedIndex = (int)m_LevelSettings.ObjectBanks[b];
}
cbxBackground.SelectedIndex = m_LevelSettings.Background;
nudGeneralMinimumNumberOfAreas.Value = m_Level.m_NumAreas;
txtMusicByte01.Text = m_LevelSettings.MusicBytes[0].ToString();
txtMusicByte02.Text = m_LevelSettings.MusicBytes[1].ToString();
txtMusicByte03.Text = m_LevelSettings.MusicBytes[2].ToString();
Program.m_ROM.BeginRW();
txtActSelectorID.Text = Program.m_ROM.Read8((uint)(Helper.GetActSelectorIDTableAddress() +
((LevelEditorForm)Owner).m_LevelID)).ToString();
Program.m_ROM.EndRW();
}
private void cbxBankX_MeasureItem(object sender, MeasureItemEventArgs e)
{
ComboBox cbx = (ComboBox)sender;
e.ItemWidth = cbx.Width;
string txt = (string)cbx.Items[e.Index];
int width = e.ItemWidth - (int)e.Graphics.MeasureString(txt.Substring(0, 6), cbx.Font).Width;
e.ItemHeight = (int)e.Graphics.MeasureString(txt.Substring(6), cbx.Font, width).Height;
}
private void cbxBankX_DrawItem(object sender, DrawItemEventArgs e)
{
ComboBox cbx = (ComboBox)sender;
Color txtcolor;
if ((e.State & DrawItemState.ComboBoxEdit) != 0)
{
e.Graphics.FillRectangle(new SolidBrush(SystemColors.ControlLightLight), e.Bounds);
txtcolor = SystemColors.ControlText;
}
else
{
e.DrawBackground();
if ((e.State & (DrawItemState.Focus | DrawItemState.Selected)) != 0)
txtcolor = SystemColors.HighlightText;
else
txtcolor = SystemColors.ControlText;
}
Brush txtbrush = new SolidBrush(txtcolor);
string txt = (string)cbx.Items[e.Index];
int margin = (int)e.Graphics.MeasureString(txt.Substring(0, 6), cbx.Font).Width;
RectangleF rect = e.Bounds;
rect.X += margin;
rect.Width -= margin;
e.Graphics.DrawString(txt.Substring(0, 6), cbx.Font, txtbrush, e.Bounds.Location);
e.Graphics.DrawString(txt.Substring(6), cbx.Font, txtbrush, rect);
e.DrawFocusRectangle();
}
private void btnOk_Click(object sender, EventArgs e)
{
m_LevelSettings.Background = (byte)cbxBackground.SelectedIndex;
m_Level.m_NumAreas = (byte)(nudGeneralMinimumNumberOfAreas.Value);
m_LevelSettings.ObjectBanks[0] = (uint)cbxBank0.SelectedIndex;
m_LevelSettings.ObjectBanks[1] = (uint)cbxBank1.SelectedIndex;
m_LevelSettings.ObjectBanks[2] = (uint)cbxBank2.SelectedIndex;
m_LevelSettings.ObjectBanks[3] = (uint)cbxBank3.SelectedIndex;
m_LevelSettings.ObjectBanks[4] = (uint)cbxBank4.SelectedIndex;
m_LevelSettings.ObjectBanks[5] = (uint)cbxBank5.SelectedIndex;
m_LevelSettings.ObjectBanks[6] = (uint)cbxBank6.SelectedIndex;
m_LevelSettings.ObjectBanks[7] = (uint)cbxBank7.SelectedIndex;
try
{
m_LevelSettings.MusicBytes[0] = byte.Parse(txtMusicByte01.Text);
m_LevelSettings.MusicBytes[1] = byte.Parse(txtMusicByte02.Text);
m_LevelSettings.MusicBytes[2] = byte.Parse(txtMusicByte03.Text);
}
catch { }
try
{
Program.m_ROM.BeginRW();
Program.m_ROM.Write8((uint)(Helper.GetActSelectorIDTableAddress() + ((LevelEditorForm)Owner).m_LevelID),
byte.Parse(txtActSelectorID.Text));
Program.m_ROM.EndRW();
}
catch { }
}
private void cbxBackground_SelectedIndexChanged(object sender, EventArgs e)
{
((LevelEditorForm)Owner).UpdateSkybox(cbxBackground.SelectedIndex);
}
private void LevelSettingsForm_FormClosed(object sender, FormClosedEventArgs e)
{
((LevelEditorForm)Owner).UpdateSkybox(-1);
}
}
}