-
Notifications
You must be signed in to change notification settings - Fork 3
/
IWADSelect.cpp
188 lines (146 loc) · 4.5 KB
/
IWADSelect.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
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2005-2006 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.
//
// IWADSelect.cpp : Implements dialog for IWAD selection
//
#include "stdafx.h"
#include "sc_man.h"
#include "cmdlib.h"
#include "ZEd.h"
const int WL_WADLIST=100;
//==========================================================================
//
//
//
//==========================================================================
class CIWADSelect : public wxDialog
{
wxListCtrl * m_GameList;
void OnDblclkListctrl(wxListEvent & event);
void GetWADs();
public:
CIWADSelect(wxWindow *parent);
~CIWADSelect();
DECLARE_EVENT_TABLE()
};
//==========================================================================
//
//
//
//==========================================================================
BEGIN_EVENT_TABLE(CIWADSelect, wxDialog)
EVT_LIST_ITEM_ACTIVATED(WL_WADLIST, CIWADSelect::OnDblclkListctrl)
END_EVENT_TABLE()
//==========================================================================
//
//
//
//==========================================================================
CIWADSelect::CIWADSelect(wxWindow *parent) : wxDialog(parent, -1, wxString(_T("Select IWADs")))
{
//wxPanel * Panel = new wxPanel(this, -1);
wxDialog * Panel=this;
wxBoxSizer * Sizer_Vert = new wxBoxSizer(wxVERTICAL);
Panel->SetSizer(Sizer_Vert);
m_GameList = new wxListCtrl(Panel, WL_WADLIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL );
Sizer_Vert->Add(m_GameList, 1, wxEXPAND|wxALL, 4);
m_GameList->InsertColumn(0, "Game Configuration", wxLIST_FORMAT_LEFT, 250);
m_GameList->InsertColumn(1, "Selected IWAD", wxLIST_FORMAT_LEFT, 250);
GetWADs();
wxBoxSizer * ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
Sizer_Vert->Add(ButtonSizer, 0, wxALIGN_CENTRE);
wxButton * ButtonClose = new wxButton(Panel, wxID_CANCEL, "Close", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
ButtonSizer->Add(ButtonClose, 0, wxALL|wxALIGN_CENTRE, 4);
Layout();
SetSize(600, 400);
Center();
}
//==========================================================================
//
//
//
//==========================================================================
CIWADSelect::~CIWADSelect()
{
}
//==========================================================================
//
//
//
//==========================================================================
void CIWADSelect::GetWADs()
{
wxDir dir;
int i=0;
bool isdir = false;
wxString fn = GetConfigDir();
if (dir.Open(fn))
{
wxString filename;
config.SetSection("IWADs", true);
for(bool cont = dir.GetFirst(&filename, "*.cfg"); cont = dir.GetNext(&filename); )
{
wxString path = fn + filename;
ScriptMan sc;
sc.SC_OpenFile(path.c_str());
if (sc.SC_GetString())
{
if (sc.SC_Compare("MAPFORMAT"))
{
wxString configname = wxFileName(path).GetName();
m_GameList->InsertItem(i, configname);
const char * iwad = config.GetValueForKey(configname.c_str());
if (iwad!=NULL)
{
m_GameList->SetItem(i, 1, iwad);
}
i++;
}
}
sc.SC_Close();
}
}
}
//==========================================================================
//
//
//
//==========================================================================
void CIWADSelect::OnDblclkListctrl(wxListEvent & event)
{
int index = m_GameList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (index>=0)
{
DirectorySaver ds("IWADSelect");
wxFileDialog fdlg (this, "Select an IWAD", ds.Dir(), "", "WAD Files|*.wad||",
wxOPEN|wxFILE_MUST_EXIST|wxCHANGE_DIR);
if (fdlg.ShowModal()==wxID_OK)
{
config.SetSection("IWADs", true);
config.SetValueForKey(m_GameList->GetItemText(index).c_str(), fdlg.GetPath().c_str());
m_GameList->SetItem(index, 1, fdlg.GetPath());
}
}
}
//==========================================================================
//
//
//
//==========================================================================
void RunIWADSelect(wxWindow * parent)
{
CIWADSelect is(parent);
is.ShowModal();
}