-
Notifications
You must be signed in to change notification settings - Fork 3
/
SpecialArgs.cpp
121 lines (102 loc) · 3.06 KB
/
SpecialArgs.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
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2002-2005 Christoph Oelckers
//
// This program 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 2
// of the License, or (at your option) any later version.
//
// This program 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.
//
// Editor configuration file parser
//
//
#include "stdafx.h"
#include "ZEd.h"
#include "sc_man.h"
#include "tarray.h"
#include "GameConfig.h"
#include "GenericTriggers.h"
#include "doomerrors.h"
class SpecialArgDialog : public wxDialog
{
wxRadioBox * m_value;
TArray<wxCheckBox*> m_flags;
ArgType * m_what;
public:
int m_Result;
SpecialArgDialog(wxWindow * parent, int value, ArgType * what);
void OnOK(wxCommandEvent & event);
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(SpecialArgDialog, wxDialog)
EVT_BUTTON(wxID_OK, SpecialArgDialog::OnOK)
END_EVENT_TABLE()
SpecialArgDialog::SpecialArgDialog(wxWindow * parent, int value, ArgType * what)
: wxDialog(parent, -1, wxString("Set Argument"))
{
wxBoxSizer * sizer = new wxBoxSizer(wxVERTICAL);
m_what=what;
if (what->values.GetCount()>0)
{
m_value = new wxRadioBox(this, -1, "", wxDefaultPosition, wxDefaultSize, what->values,
(int)(what->values.GetCount()>10 ? (what->values.GetCount()+1)/2 : what->values.GetCount()), wxRA_SPECIFY_ROWS);
sizer->Add(m_value, 0, wxALL|wxEXPAND, 4);
}
else m_value=NULL;
if (what->flags.GetCount()>0)
{
wxStaticBox * frame = new wxStaticBox(this, -1, "Flags");
wxStaticBoxSizer * box = new wxStaticBoxSizer(frame, wxVERTICAL);
for(unsigned i=0;i<what->flags.GetCount();i++)
{
wxCheckBox * check = new wxCheckBox(this, -1, what->flags[i]);
box->Add(check, 0, wxALL, 4);
m_flags.Push(check);
check->SetValue(!!(value & what->flag_values[i]));
value &= ~what->flag_values[i];
}
sizer->Add(box, 0, wxALL|wxEXPAND, 4);
}
for(unsigned i=0;i<what->value_values.Size();i++)
{
if (value==what->value_values[i])
{
m_value->SetSelection(i);
break;
}
}
sizer->Add(CreateButtonSizer(wxOK|wxCANCEL), 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 4);
SetSizerAndFit(sizer);
Layout();
Center();
}
void SpecialArgDialog::OnOK(wxCommandEvent & event)
{
int value = m_value? m_what->value_values[m_value->GetSelection()] : 0;
for(unsigned i=0;i<m_what->flag_values.Size();i++)
{
if (m_flags[i]->GetValue()) value |= m_what->flag_values[i];
}
m_Result=value;
EndModal(wxID_OK);
}
int GetSpecialArg(wxWindow * parent, int value, const wxString & name)
{
for(unsigned i=0;i<cgc->ArgTypes.Size();i++)
{
if (!name.CmpNoCase(cgc->ArgTypes[i]->name))
{
SpecialArgDialog dlg(parent, value, cgc->ArgTypes[i]);
if (dlg.ShowModal()==wxID_OK) return dlg.m_Result;
else return value;
}
}
// Handle special default dialogs here
return value;
}