tileset_window.cpp

main 127 lines · 5 KB Raw
Alex Alex Commit Map Editor 18/10/2026 23:40
1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor 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 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor 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 this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#include "main.h"
19
20#include <wx/grid.h>
21
22#include "tile.h"
23#include "item.h"
24#include "complexitem.h"
25#include "town.h"
26#include "house.h"
27#include "map.h"
28#include "editor.h"
29#include "creature.h"
30#include "materials.h"
31#include "tileset.h"
32
33#include "gui.h"
34#include "application.h"
35#include "tileset_window.h"
36#include "container_properties_window.h"
37
38// ============================================================================
39// Tileset Window
40
41BEGIN_EVENT_TABLE(TilesetWindow, wxDialog)
42EVT_BUTTON(wxID_OK, TilesetWindow::OnClickOK)
43EVT_BUTTON(wxID_CANCEL, TilesetWindow::OnClickCancel)
44END_EVENT_TABLE()
45
46static constexpr int OUTFIT_COLOR_MAX = 133;
47
48TilesetWindow::TilesetWindow(wxWindow* win_parent, const Map* map, const Tile* tile_parent, Item* item, wxPoint pos) :
49 ObjectPropertiesWindowBase(win_parent, "Move to Tileset", map, tile_parent, item, pos),
50 palette_field(nullptr),
51 tileset_field(nullptr) {
52 ASSERT(edit_item);
53
54 wxSizer* topsizer = newd wxBoxSizer(wxVERTICAL);
55 wxString description = "Move to Tileset";
56
57 wxSizer* boxsizer = newd wxStaticBoxSizer(wxVERTICAL, this, description);
58
59 wxFlexGridSizer* subsizer = newd wxFlexGridSizer(2, 10, 10);
60 subsizer->AddGrowableCol(1);
61
62 subsizer->Add(newd wxStaticText(this, wxID_ANY, "ID " + i2ws(item->getID())));
63 subsizer->Add(newd wxStaticText(this, wxID_ANY, "\"" + wxstr(item->getName()) + "\""));
64
65 subsizer->Add(newd wxStaticText(this, wxID_ANY, "Palette"));
66 palette_field = newd wxChoice(this, wxID_ANY);
67
68 palette_field->Append("Terrain", newd int(TILESET_TERRAIN));
69 palette_field->Append("Collections", newd int(TILESET_COLLECTION));
70 palette_field->Append("Doodad", newd int(TILESET_DOODAD));
71 palette_field->Append("Item", newd int(TILESET_ITEM));
72 palette_field->Append("Raw", newd int(TILESET_RAW));
73 palette_field->SetSelection(3);
74
75 palette_field->Connect(wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(TilesetWindow::OnChangePalette), NULL, this);
76 subsizer->Add(palette_field, wxSizerFlags(1).Expand());
77
78 subsizer->Add(newd wxStaticText(this, wxID_ANY, "Tileset"));
79 tileset_field = newd wxChoice(this, wxID_ANY);
80
81 for (TilesetContainer::iterator iter = g_materials.tilesets.begin(); iter != g_materials.tilesets.end(); ++iter) {
82 tileset_field->Append(wxstr(iter->second->name), newd std::string(iter->second->name));
83 }
84 tileset_field->SetSelection(0);
85 subsizer->Add(tileset_field, wxSizerFlags(1).Expand());
86
87 boxsizer->Add(subsizer, wxSizerFlags(1).Expand());
88
89 topsizer->Add(boxsizer, wxSizerFlags(0).Expand().Border(wxLEFT | wxRIGHT, 20));
90
91 wxSizer* subsizer_ = newd wxBoxSizer(wxHORIZONTAL);
92 subsizer_->Add(newd wxButton(this, wxID_OK, "OK"), wxSizerFlags(1).Center().Border(wxTOP | wxBOTTOM, 10));
93 subsizer_->Add(newd wxButton(this, wxID_CANCEL, "Cancel"), wxSizerFlags(1).Center().Border(wxTOP | wxBOTTOM, 10));
94 topsizer->Add(subsizer_, wxSizerFlags(0).Center().Border(wxLEFT | wxRIGHT, 20));
95
96 SetSizerAndFit(topsizer);
97 Centre(wxBOTH);
98}
99
100void TilesetWindow::OnChangePalette(wxCommandEvent& WXUNUSED(event)) {
101 tileset_field->Clear();
102
103 for (TilesetContainer::iterator iter = g_materials.tilesets.begin(); iter != g_materials.tilesets.end(); ++iter) {
104 if (iter->second->getCategory(TilesetCategoryType(*static_cast<int*>(palette_field->GetClientData(palette_field->GetSelection()))))->brushlist.size() > 0) {
105 tileset_field->Append(wxstr(iter->second->name), newd std::string(iter->second->name));
106 }
107 }
108
109 tileset_field->SetSelection(0);
110}
111
112void TilesetWindow::OnClickOK(wxCommandEvent& WXUNUSED(event)) {
113 if (edit_item) {
114 TilesetCategoryType categoryType = TilesetCategoryType(*reinterpret_cast<int*>(palette_field->GetClientData(palette_field->GetSelection())));
115 std::string tilesetName = *static_cast<std::string*>(tileset_field->GetClientData(tileset_field->GetSelection()));
116
117 g_materials.addToTileset(tilesetName, edit_item->getID(), categoryType);
118 g_gui.PopupDialog("Added to Tileset", "'" + edit_item->getName() + "' has been added to tileset '" + tilesetName + "' of palette '" + palette_field->GetStringSelection() + "'", wxOK);
119 }
120 EndModal(1);
121}
122
123void TilesetWindow::OnClickCancel(wxCommandEvent& WXUNUSED(event)) {
124 // Just close this window
125 EndModal(0);
126}
127
Top