-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanHack.cpp
205 lines (205 loc) · 4.32 KB
/
cleanHack.cpp
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
#include "G.h"
#include "SetHack_DLG.h"
xTreeID G::mSetHack( xTreeID id, HACK* hack )
{
xTreeID kid;
HACK* data = mGetHack( hack );
try
{
tree_T->SetItemData( id, data );
kid = id;
}
catch ( s64 error )
{
delete data;
}
return kid;
}
HACK* G::mGetHack( HACK* hack )
{
HACK* data = new HACK;
s8 index = 0;
s8 count = hack->GetCount();
data->id = hack->id;
data->use = hack->use;
data->SetCount( count );
for ( ; index < count; ++index )
{
( *data )[ index ] = ( *hack )[ index ];
}
return data;
}
HACK* G::mGetHack( xTreeID id )
{
HACK* data;
if ( !id.IsOk() )
std::invalid_argument( "There is no Hack with this ID" );
data = ( HACK* )tree_T->GetItemData( id );
return data;
}
xTreeID G::GetHackID( void )
{
return tree_T->GetSelection();
}
xTreeID G::GetHackRoot( void )
{
return tree_T->GetRootItem();
}
xTreeID G::GetHackRoot( xTreeID id )
{
xTreeID kid;
if ( id.IsOk() )
{
kid = tree_T->GetItemParent( id );
}
if ( !kid.IsOk() )
{
kid = GetHackRoot();
}
return kid;
}
void G::mDelHack( xTreeID id )
{
tree_T->Delete( id );
}
void G::mMoveHack( xTreeID from, xTreeID to )
{
xStr name;
HACK* hack;
xTreeID idf;
xTreeID idt;
xTreeIDV tiv;
while ( tree_T->HasChildren( from ) )
{
idf = tree_T->GetFirstChild( from, tiv );
name = tree_T->GetItemText( idf );
hack = mGetHack( idf );
idt = mNewHack( to, name, hack, idt, ADD_BOTTOM );
mMoveHack( idf, idt );
}
mDelHack( from );
}
void G::mMoveHack( xTreeID tid, s32 direction )
{
if ( tid.IsOk() )
{
xTreeID id;
xTreeID root = GetHackRoot( tid );
xStr name = tree_T->GetItemText( tid );
HACK* hack = mGetHack( tid );
switch ( direction )
{
case WXK_UP:
id = tree_T->GetPrevSibling( tid );
id = mNewHack( root, name, hack, id, ADD_PREV );
break;
case WXK_LEFT:
id = mNewHack( GetHackRoot( root ), name, hack, root, ADD_PREV );
break;
case WXK_DOWN:
id = tree_T->GetNextSibling( tid );
id = mNewHack( root, name, hack, id, ADD_NEXT );
break;
case WXK_RIGHT:
xStr text;
HACK* data = new HACK;
text.Printf( wxT( "New Hack %i" ), tree_T->GetCount() );
id = tree_T->GetNextSibling( tid );
if ( !id.IsOk() )
root = mNewHack( root, text, data, tid, ADD_TOP );
else root = id;
id = mNewHack( root, name, hack, id, ADD_TOP );
delete data;
}
mMoveHack( tid, id );
tree_T->Expand( id );
tree_T->SelectItem( id );
}
}
void G::NewHack_BOnClick( wxCommandEvent& event )
{
s8 mode = NewHack_D->GetSelection();
HACK* hack = new HACK;
xStr name;
xTreeID root;
xTreeID id;
if ( NewHack_CB->GetValue() )
{
root = GetHackID();
}
else
{
id = GetHackID();
root = GetHackRoot( id );
}
name.Printf( wxT( "New Hack %i" ), tree_T->GetCount() );
mNewHack( root, name, hack, id, mode );
delete hack;
}
void G::UseHack_BOnClick( wxCommandEvent& event )
{
xTreeID now = GetHackID();
if ( !now.IsOk() ) return;
HACK* hack = mGetHack( now );
if ( hack->id > 0u )
{
xTreeID root = GetHackRoot( now );
HACK* tmp = mGetHack( root );
if ( tmp->useRB )
{
xTreeID kid;
xTreeIDV cookie;
for
(
kid = tree_T->GetFirstChild( root, cookie );
kid.IsOk();
kid = tree_T->GetNextChild( root, cookie )
)
{
tmp = mGetHack( kid );
tmp->use = false;
}
}
}
hack->use = mUseHack_CB->GetValue();
}
void G::DelHack_BOnClick( wxCommandEvent& event )
{
xTreeID id = tree_T->GetSelection();
if ( !id.IsOk() ) return;
HACK* hack = mGetHack( id );
if ( hack->id == 0u )
{
hack->Clear();
return;
}
tree_T->Delete( id );
}
void G::MoveHack_BOnClick( wxCommandEvent& event )
{
s32 dir;
switch ( MoveHack_D->GetSelection() )
{
case 0: dir = WXK_UP; break;
case 2: dir = WXK_LEFT; break;
case 3: dir = WXK_RIGHT; break;
default: dir = WXK_DOWN;
}
mMoveHack( GetHackID(), dir );
}
void G::GetHacks_BOnClick( wxCommandEvent& event )
{
mLoadHack();
}
void G::SetHacks_BOnClick( wxCommandEvent& event )
{
mSaveHack();
}
void G::mShowHack_OnClick( wxCommandEvent& event )
{
xTreeID id = tree_T->GetSelection();
gSetHack( mGetHack( id ) );
SetHack_DLG dlg( this );
if ( dlg.ShowModal() == wxID_OK )
mShowHack();
}