1 /* Copyright (C) 2009 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "PropListEditor.h"
21 
22 #include "EditableListCtrl/FieldEditCtrl.h"
23 #include "AtlasObject/AtlasObject.h"
24 
25 //////////////////////////////////////////////////////////////////////////
26 
PropListEditor(wxWindow * parent)27 PropListEditor::PropListEditor(wxWindow* parent)
28 	: AtlasDialog(parent, _("Prop editor"), wxSize(400, 280))
29 {
30 	m_MainListBox = new PropListEditorListCtrl(m_MainPanel);
31 
32 	wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
33 	sizer->Add(m_MainListBox,
34 		wxSizerFlags().Proportion(1).Expand().Border(wxALL, 5));
35 
36 	m_MainPanel->SetSizer(sizer);
37 }
38 
ThawData(AtObj & in)39 void PropListEditor::ThawData(AtObj& in)
40 {
41 	m_MainListBox->ThawData(in);
42 }
43 
FreezeData()44 AtObj PropListEditor::FreezeData()
45 {
46 	return m_MainListBox->FreezeData();
47 }
48 
ImportData(AtObj & in)49 void PropListEditor::ImportData(AtObj& in)
50 {
51 	m_MainListBox->ImportData(in);
52 }
53 
ExportData()54 AtObj PropListEditor::ExportData()
55 {
56 	return m_MainListBox->ExportData();
57 }
58 
59 //////////////////////////////////////////////////////////////////////////
60 
PropListEditorListCtrl(wxWindow * parent)61 PropListEditorListCtrl::PropListEditorListCtrl(wxWindow* parent)
62 : DraggableListCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
63 					wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | wxLC_SINGLE_SEL)
64 {
65 	AddColumnType(_("Attachment point"), 100, "@attachpoint",	new FieldEditCtrl_List("attachpoints"));
66 	AddColumnType(_("Prop model"),		 200, "@actor",			new FieldEditCtrl_File(_T("art/actors/"), _("Actor files (*.xml)|*.xml|All files (*.*)|*.*")));
67 	AddColumnType(_("Min Height"),		 100, "@minheight", new FieldEditCtrl_Text());
68 	AddColumnType(_("Max Height"),		 200, "@maxheight",	new FieldEditCtrl_Text());
69 }
70 
DoImport(AtObj & in)71 void PropListEditorListCtrl::DoImport(AtObj& in)
72 {
73 	for (AtIter prop = in["prop"]; prop.defined(); ++prop)
74 		AddRow(prop);
75 
76 	UpdateDisplay();
77 }
78 
DoExport()79 AtObj PropListEditorListCtrl::DoExport()
80 {
81 	AtObj out;
82 	for (size_t i = 0; i < m_ListData.size(); ++i)
83 		out.add("prop", m_ListData[i]);
84 	return out;
85 }
86