| 1 |
/* Copyright (C) 2025 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 "ActorEditorListCtrl.h" |
| 21 |
|
| 22 |
#include "tools/atlas/AtlasObject/AtlasObject.h" |
| 23 |
#include "tools/atlas/AtlasUI/ActorEditor/AnimListEditor.h" |
| 24 |
#include "tools/atlas/AtlasUI/ActorEditor/PropListEditor.h" |
| 25 |
#include "tools/atlas/AtlasUI/ActorEditor/TexListEditor.h" |
| 26 |
#include "tools/atlas/AtlasUI/CustomControls/DraggableListCtrl/DraggableListCtrl.h" |
| 27 |
#include "tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.h" |
| 28 |
|
| 29 |
#include <cstddef> |
| 30 |
#include <string> |
| 31 |
#include <vector> |
| 32 |
#include <wx/chartype.h> |
| 33 |
#include <wx/colour.h> |
| 34 |
#include <wx/defs.h> |
| 35 |
#include <wx/toolbar.h> |
| 36 |
#include <wx/translation.h> |
| 37 |
|
| 38 |
class wxWindow; |
| 39 |
|
| 40 |
ActorEditorListCtrl::ActorEditorListCtrl(wxWindow* parent) |
| 41 |
: DraggableListCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, |
| 42 |
wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | wxLC_SINGLE_SEL) |
| 43 |
{ |
| 44 |
// Set colors for row backgrounds (which vary depending on what columns |
| 45 |
// have some data) |
| 46 |
#define COLOR(name, c0, c1) \ |
| 47 |
m_ListItemAttr_##name[0].SetBackgroundColour(wxColor c0); \ |
| 48 |
m_ListItemAttr_##name[1].SetBackgroundColour(wxColor c1) |
| 49 |
|
| 50 |
const int f=0xFF, e=0xEE, c=0xCC; |
| 51 |
COLOR(Model, (f,f,e), (f,f,c)); |
| 52 |
COLOR(Texture, (f,e,e), (f,c,c)); |
| 53 |
COLOR(Anim, (e,f,e), (c,f,c)); |
| 54 |
COLOR(Prop, (e,e,f), (c,c,f)); |
| 55 |
COLOR(Color, (f,e,f), (f,c,f)); |
| 56 |
COLOR(None, (f,f,f), (f,f,f)); |
| 57 |
|
| 58 |
#undef COLOR |
| 59 |
|
| 60 |
AddColumnType(_("Group"), 50, "@group", new FieldEditCtrl_Boolean()); |
| 61 |
AddColumnType(_("Variant"), 90, "@name", new FieldEditCtrl_Text()); |
| 62 |
AddColumnType(_("Base File"), 90, "@file", new FieldEditCtrl_File(_T("art/variants/"), _("Variants (*.xml)|*.xml|All files (*.*)|*.*"))); |
| 63 |
AddColumnType(_("Ratio"), 50, "@frequency", new FieldEditCtrl_Text()); |
| 64 |
AddColumnType(_("Min Quality"),50, "@minquality",new FieldEditCtrl_Text()); |
| 65 |
AddColumnType(_("Max Quality"),50, "@maxquality",new FieldEditCtrl_Text()); |
| 66 |
AddColumnType(_("Model"), 140, "mesh", new FieldEditCtrl_File(_T("art/meshes/"), _("Mesh files (*.pmd, *.dae)|*.pmd;*.dae|All files (*.*)|*.*"))); |
| 67 |
AddColumnType(_("Particles"), 90, "particles", new FieldEditCtrl_File(_T("art/particles/"), _("Particle file (*.xml)|*.xml|All files (*.*)|*.*"))); |
| 68 |
AddColumnType(_("Textures"), 250, "textures", new FieldEditCtrl_Dialog(&TexListEditor::Create)); |
| 69 |
AddColumnType(_("Animations"), 250, "animations", new FieldEditCtrl_Dialog(&AnimListEditor::Create)); |
| 70 |
AddColumnType(_("Props"), 220, "props", new FieldEditCtrl_Dialog(&PropListEditor::Create)); |
| 71 |
AddColumnType(_("Color"), 80, "color", new FieldEditCtrl_Color()); |
| 72 |
} |
| 73 |
|
| 74 |
void ActorEditorListCtrl::DoImport(AtObj& in) |
| 75 |
{ |
| 76 |
DeleteData(); |
| 77 |
|
| 78 |
for (AtIter group = in["group"]; group.defined(); ++group) |
| 79 |
{ |
| 80 |
for (AtIter variant = group["variant"]; variant.defined(); ++variant) |
| 81 |
AddRow(variant); |
| 82 |
|
| 83 |
AtObj gr = *group; |
| 84 |
gr.add("@group", "true"); |
| 85 |
AddRow(gr); |
| 86 |
} |
| 87 |
|
| 88 |
UpdateDisplay(); |
| 89 |
} |
| 90 |
|
| 91 |
AtObj ActorEditorListCtrl::DoExport() |
| 92 |
{ |
| 93 |
AtObj out; |
| 94 |
|
| 95 |
AtObj group; |
| 96 |
|
| 97 |
for (size_t i = 0; i < m_ListData.size(); ++i) |
| 98 |
{ |
| 99 |
if (std::string(m_ListData[i]["@group"]) == "true") |
| 100 |
{ |
| 101 |
if (group.defined()) |
| 102 |
{ |
| 103 |
group.unset("@group"); |
| 104 |
if (m_ListData[i]["@minquality"].hasContent()) |
| 105 |
group.set("@minquality", m_ListData[i]["@minquality"]); |
| 106 |
if (m_ListData[i]["@maxquality"].hasContent()) |
| 107 |
group.set("@maxquality", m_ListData[i]["@maxquality"]); |
| 108 |
out.add("group", group); |
| 109 |
} |
| 110 |
group = AtObj(); |
| 111 |
} |
| 112 |
else |
| 113 |
{ |
| 114 |
AtObj variant = AtlasObject::TrimEmptyChildren(m_ListData[i]); |
| 115 |
group.add("variant", variant); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
if (group.defined()) |
| 120 |
out.add("group", group); |
| 121 |
|
| 122 |
return out; |
| 123 |
} |
| 124 |
|
| 125 |
wxListItemAttr* ActorEditorListCtrl::OnGetItemAttr(long item) const |
| 126 |
{ |
| 127 |
if (item >= 0 && item < (int)m_ListData.size()) |
| 128 |
{ |
| 129 |
AtObj row (m_ListData[item]); |
| 130 |
|
| 131 |
// Color-code the row, depending on the first non-empty column, |
| 132 |
// and also alternate between light/dark. |
| 133 |
|
| 134 |
if (row["mesh"].hasContent()) |
| 135 |
return const_cast<wxListItemAttr*>(&m_ListItemAttr_Model[item%2]); |
| 136 |
else if (row["textures"].hasContent()) |
| 137 |
return const_cast<wxListItemAttr*>(&m_ListItemAttr_Texture[item%2]); |
| 138 |
else if (row["animations"].hasContent()) |
| 139 |
return const_cast<wxListItemAttr*>(&m_ListItemAttr_Anim[item%2]); |
| 140 |
else if (row["props"].hasContent()) |
| 141 |
return const_cast<wxListItemAttr*>(&m_ListItemAttr_Prop[item%2]); |
| 142 |
else if (row["color"].hasContent()) |
| 143 |
return const_cast<wxListItemAttr*>(&m_ListItemAttr_Color[item%2]); |
| 144 |
} |
| 145 |
|
| 146 |
return const_cast<wxListItemAttr*>(&m_ListItemAttr_None[item%2]); |
| 147 |
} |