-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetDBP_DLG_ItemIO.cpp
145 lines (145 loc) · 3.73 KB
/
GetDBP_DLG_ItemIO.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
#include "GetDBP_DLG.h"
s32 GetDBP_DLG::dNewDBP( DBP dbp )
{
s32 index = -1;
s32 count = dGetCount();
if ( count < 65535 )
{
dDBPList.push_back( dbp );
index = count;
}
return index;
}
s32 GetDBP_DLG::dNewDBI( DBI* dbi )
{
s32 index = -1;
s32 count = dDBPName_LB->GetCount();
if ( count < 65535 )
{
DBI* now = dGetDBI( dbi );
DBP dbp = dGetDBP( now->index );
xStr text;
if ( dbp.area > 0u && AREA_COUNT > 0 )
{
xAStr txtArray = gGetArea();
u32* hexArray = gGetAreas();
text = wxT( " ( " ) + txtArray[ 0 ];
for ( s32 i = 1; i < AREA_COUNT; ++i )
{
if ( ( dbp.area & hexArray[ i ] ) > 0u )
text += wxT( ", " ) + txtArray[ i ];
}
text += wxT( " )" );
}
index = dDBPName_LB->Append( dbp.nowName + text, now );
}
return index;
}
void GetDBP_DLG::dSetDBP( s32 index, DBP dbp )
{
if ( index < 0 || index >= dGetCount() )
throw std::out_of_range( "Tried to set DBP outside range" );
dDBPList[ index ] = dbp;
}
void GetDBP_DLG::dSetDBI( s32 index, DBI* dbi )
{
if ( index < 0 || index >= ( s32 )dDBPName_LB->GetCount() )
throw std::out_of_range( "Tried to set DBI outside range" );
DBI* now = dGetDBI( dbi );
DBP dbp = dGetDBP( dbi->index );
xStr text;
if ( dbp.area > 0u && AREA_COUNT > 0 )
{
xAStr txtArray = gGetArea();
u32* hexArray = gGetAreas();
text = wxT( " ( " ) + txtArray[ 0 ];
for ( s32 i = 1; i < AREA_COUNT; ++i )
{
if ( ( dbp.area & hexArray[ i ] ) > 0u )
text += wxT( ", " ) + txtArray[ i ];
}
text += wxT( " )" );
}
dDBPName_LB->SetString( index, dbp.nowName + text );
dDBPName_LB->SetClientObject( index, now );
}
DBP& GetDBP_DLG::dGetDBP( s32 index )
{
if ( index < 0 || index >= dGetCount() )
throw std::out_of_range( "Tried to get DBP outside range" );
u16 safe_index = index;
return dDBPList[ safe_index ];
}
DBP GetDBP_DLG::dGetDBP( void )
{
xStr text;
DBP dbp;
dbp.isDefault = false;
text = dDBPName_TXT->GetValue();
if ( !text.IsEmpty() )
{
dbp.nowName = text;
dbp.oldName = text;
}
text = dDBPFile_TXT->GetValue();
if ( !text.IsEmpty() )
{
dbp.nowFile = text;
dbp.oldFile = text;
}
dbp.PID = GetHex( dDBPPID_TXT->GetValue(), 2u );
dbp.SID = dDBPSID_TXT->GetValue();
dbp.notes = dDBPNotes_TA->GetValue();
return dbp;
}
DBI* GetDBP_DLG::dGetDBI( DBI* dbi )
{
DBI* now = new DBI;
now->index = dbi->index;
return now;
}
DBI* GetDBP_DLG::dGetDBI( s32 index )
{
if ( index < 0 || index >= ( s32 )dDBPName_LB->GetCount() )
throw std::out_of_range( "Tried to get DBI outside range" );
return ( DBI* )dDBPName_LB->GetClientObject( index );
}
void GetDBP_DLG::dDelDBI( s32 index )
{
DBI* dbi = dGetDBI( index );
DBP dbp = dGetDBP( dbi->index );
if ( dbp.isDefault ) return;
dDelDBP( dbi->index );
dLoadDBI();
if ( index < 1 ) dDBPName_LB->Select( 0 );
else dDBPName_LB->Select( index - 1 );
isModified = true;
}
void GetDBP_DLG::dDelDBP( s32 index )
{
if ( index < 0 || index >= dGetCount() ) return;
DBP dbp = dGetDBP( index );
if ( dbp.isDefault ) return;
dDBPList.erase( dDBPList.begin() + index );
}
s32 GetDBP_DLG::dGetCount( void )
{
s32 count = dDBPList.size();
return count;
}
void GetDBP_DLG::dShowDBP( void )
{
s32 index = dDBPName_LB->GetSelection();
if ( index < 0 ) return;
DBI* dbi = dGetDBI( index );
DBP& dbp = dGetDBP( dbi->index );
dDBPName_TXT->ChangeValue( dbp.nowName );
dDBPFile_TXT->ChangeValue( dbp.nowFile );
xStr text;
text.Printf( hex16, dbp.PID );
dDBPPID_TXT->ChangeValue( text );
dDBPSID_TXT->ChangeValue( dbp.SID );
dDBPNotes_TA->ChangeValue( dbp.notes );
gSetDBP( dbp );
dSetDBP_P->Enable( !dbp.isDefault );
}