palette_creature.h

main 232 lines · 7.1 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#ifndef RME_TILESET_CREATURE_H_
19#define RME_TILESET_CREATURE_H_
20
21#include "palette_common.h"
22#include <wx/longlong.h>
23
24// New class for seamless grid view of creature sprites with direct rendering
25class CreatureSeamlessGridPanel : public wxScrolledWindow {
26public:
27 CreatureSeamlessGridPanel(wxWindow* parent);
28 virtual ~CreatureSeamlessGridPanel();
29
30 void Clear();
31 void LoadCreatures(const BrushVector& brushlist);
32 Brush* GetSelectedBrush() const;
33 bool SelectBrush(const Brush* brush);
34 void EnsureVisible(const Brush* brush);
35 void SelectIndex(int index);
36
37 // Getter for sprite size
38 int GetSpriteSize() const { return sprite_size; }
39
40 // Drawing handlers
41 void OnPaint(wxPaintEvent& event);
42 void OnSize(wxSizeEvent& event);
43 void OnScroll(wxScrollWinEvent& event);
44 void OnMouseClick(wxMouseEvent& event);
45 void OnMouseMove(wxMouseEvent& event);
46 void OnTimer(wxTimerEvent& event);
47
48 // Creature brushes in this panel
49 BrushVector creatures;
50
51 // Friend class declaration to allow access to protected members
52 friend class CreaturePalettePanel;
53
54protected:
55 void RecalculateGrid();
56 int GetSpriteIndexAt(int x, int y) const;
57 int GetCreatureNaturalSize(CreatureType* ctype) const;
58 void DrawCreature(wxDC& dc, int x, int y, CreatureType* ctype, bool selected = false);
59 void DrawItemsToPanel(wxDC& dc);
60 void UpdateViewableItems();
61 void StartProgressiveLoading();
62
63 int columns;
64 int sprite_size;
65 int selected_index;
66 int hover_index;
67 wxBitmap* buffer;
68 std::map<size_t, int> sprite_dimensions; // Maps creature index to natural size
69
70 // Viewport and loading management
71 int first_visible_row;
72 int last_visible_row;
73 int visible_rows_margin;
74 int total_rows;
75 bool need_full_redraw;
76
77 // Progressive loading properties
78 bool use_progressive_loading;
79 bool is_large_tileset;
80 int loading_step;
81 int max_loading_steps;
82 wxTimer* loading_timer;
83 static const int LARGE_TILESET_THRESHOLD = 200;
84
85 DECLARE_EVENT_TABLE();
86};
87
88// Original class for grid view of creature sprites with padding
89class CreatureSpritePanel : public wxScrolledWindow {
90public:
91 CreatureSpritePanel(wxWindow* parent);
92 virtual ~CreatureSpritePanel();
93
94 void Clear();
95 void LoadCreatures(const BrushVector& brushlist);
96 Brush* GetSelectedBrush() const;
97 bool SelectBrush(const Brush* brush);
98 void EnsureVisible(const Brush* brush);
99 void SelectIndex(int index);
100
101 // Getter for sprite size
102 int GetSpriteSize() const;
103
104 // Drawing handlers
105 void OnPaint(wxPaintEvent& event);
106 void OnSize(wxSizeEvent& event);
107 void OnScroll(wxScrollWinEvent& event);
108 void OnMouseClick(wxMouseEvent& event);
109 void OnMouseMove(wxMouseEvent& event);
110
111 // Creature brushes in this panel
112 BrushVector creatures;
113
114 // Friend class declaration to allow access to protected members
115 friend class CreaturePalettePanel;
116
117protected:
118 void RecalculateGrid();
119 int GetSpriteIndexAt(int x, int y) const;
120 void DrawSprite(wxDC& dc, int x, int y, CreatureType* ctype, bool selected = false);
121
122 int columns;
123 int sprite_size;
124 int padding;
125 int selected_index;
126 int hover_index;
127 wxBitmap* buffer;
128
129 DECLARE_EVENT_TABLE();
130};
131
132class CreaturePalettePanel : public PalettePanel {
133public:
134 CreaturePalettePanel(wxWindow* parent, wxWindowID id = wxID_ANY);
135 virtual ~CreaturePalettePanel();
136
137 PaletteType GetType() const;
138
139 // Select the first brush
140 void SelectFirstBrush();
141 // Returns the currently selected brush (first brush if panel is not loaded)
142 Brush* GetSelectedBrush() const;
143 // Returns the currently selected brush size
144 int GetSelectedBrushSize() const;
145 // Select the brush in the parameter, this only changes the look of the panel
146 bool SelectBrush(const Brush* whatbrush);
147
148 // Updates the palette window to use the current brush size
149 void OnUpdateBrushSize(BrushShape shape, int size);
150 // Called when this page is displayed
151 void OnSwitchIn();
152 // Called sometimes?
153 void OnUpdate();
154
155protected:
156 void SelectTileset(size_t index);
157 void SelectCreature(size_t index);
158 void SelectCreature(std::string name);
159 // Switch between list view and sprite view modes
160 void SetViewMode(bool use_sprites);
161 // Set view style (regular grid vs seamless grid)
162 void SetViewStyle(bool use_seamless);
163 // Set large sprite mode (64x64 vs 32x32)
164 void SetLargeSpriteMode(bool use_large);
165 // Set zoom level for sprites
166 void SetZoomLevel(int zoom_factor);
167
168public:
169 // Event handling
170 void OnChangeSpawnTime(wxSpinEvent& event);
171 void OnChangeSpawnSize(wxSpinEvent& event);
172
173 void OnTilesetChange(wxCommandEvent& event);
174 void OnListBoxChange(wxCommandEvent& event);
175 void OnClickCreatureBrushButton(wxCommandEvent& event);
176 void OnClickSpawnBrushButton(wxCommandEvent& event);
177 void OnClickLoadNPCsButton(wxCommandEvent& event);
178 void OnClickLoadMonstersButton(wxCommandEvent& event);
179 void OnClickPurgeCreaturesButton(wxCommandEvent& event);
180 void OnClickSearchButton(wxCommandEvent& event);
181 void OnSearchFieldText(wxCommandEvent& event);
182 void OnSearchFieldFocus(wxFocusEvent& event);
183 void OnSearchFieldKillFocus(wxFocusEvent& event);
184 void OnSearchFieldKeyDown(wxKeyEvent& event);
185 void OnClickViewToggle(wxCommandEvent& event);
186 void OnClickViewStyleToggle(wxCommandEvent& event);
187 void OnClickLargeSpritesToggle(wxCommandEvent& event);
188 void OnClickZoomButton(wxCommandEvent& event);
189 void OnSpriteSelected(wxCommandEvent& event);
190
191protected:
192 void SelectCreatureBrush();
193 void SelectSpawnBrush();
194 bool LoadNPCsFromFolder(const wxString& folder);
195 bool LoadMonstersFromFolder(const wxString& folder);
196 bool PurgeCreaturePalettes();
197 void FilterCreatures(const wxString& search_text);
198
199 wxChoice* tileset_choice;
200 SortableListBox* creature_list;
201 CreatureSpritePanel* sprite_panel;
202 CreatureSeamlessGridPanel* seamless_panel;
203 wxToggleButton* view_toggle;
204 wxToggleButton* view_style_toggle;
205 wxToggleButton* large_sprites_toggle;
206 wxButton* zoom_button;
207 wxSizer* view_sizer;
208 bool use_sprite_view;
209 bool use_seamless_view;
210 bool use_large_sprites;
211 int zoom_factor;
212 bool handling_event;
213
214 wxTextCtrl* search_field;
215 wxButton* search_button;
216 wxButton* load_npcs_button;
217 wxButton* load_monsters_button;
218 wxButton* purge_creatures_button;
219
220 wxSpinCtrl* creature_spawntime_spin;
221 wxSpinCtrl* spawn_size_spin;
222 wxToggleButton* creature_brush_button;
223 wxToggleButton* spawn_brush_button;
224
225private:
226 static wxLongLong last_search_click; // For tracking double-clicks on search button
227
228 DECLARE_EVENT_TABLE();
229};
230
231#endif
232
Top