forked from Wirless/IdlersMapEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathborder_editor_window.cpp
More file actions
2331 lines (1904 loc) · 92.4 KB
/
border_editor_window.cpp
File metadata and controls
2331 lines (1904 loc) · 92.4 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
// Remere's Map Editor 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 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor 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.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#include "main.h"
#include "border_editor_window.h"
#include "browse_tile_window.h"
#include "find_item_window.h"
#include "common_windows.h"
#include "graphics.h"
#include "gui.h"
#include "artprovider.h"
#include "items.h"
#include "brush.h"
#include "ground_brush.h"
#include <wx/sizer.h>
#include <wx/gbsizer.h>
#include <wx/statline.h>
#include <wx/tglbtn.h>
#include <wx/dcbuffer.h>
#include <wx/filename.h>
#include <wx/filepicker.h>
#include <pugixml.hpp>
#define BORDER_GRID_SIZE 32
#define BORDER_PREVIEW_SIZE 192
#define BORDER_GRID_CELL_SIZE 32
#define ID_BORDER_GRID_SELECT wxID_HIGHEST + 1
#define ID_GROUND_ITEM_LIST wxID_HIGHEST + 2
// Utility functions for edge string/position conversion
BorderEdgePosition edgeStringToPosition(const std::string& edgeStr) {
if (edgeStr == "n") return EDGE_N;
if (edgeStr == "e") return EDGE_E;
if (edgeStr == "s") return EDGE_S;
if (edgeStr == "w") return EDGE_W;
if (edgeStr == "cnw") return EDGE_CNW;
if (edgeStr == "cne") return EDGE_CNE;
if (edgeStr == "cse") return EDGE_CSE;
if (edgeStr == "csw") return EDGE_CSW;
if (edgeStr == "dnw") return EDGE_DNW;
if (edgeStr == "dne") return EDGE_DNE;
if (edgeStr == "dse") return EDGE_DSE;
if (edgeStr == "dsw") return EDGE_DSW;
return EDGE_NONE;
}
std::string edgePositionToString(BorderEdgePosition pos) {
switch (pos) {
case EDGE_N: return "n";
case EDGE_E: return "e";
case EDGE_S: return "s";
case EDGE_W: return "w";
case EDGE_CNW: return "cnw";
case EDGE_CNE: return "cne";
case EDGE_CSE: return "cse";
case EDGE_CSW: return "csw";
case EDGE_DNW: return "dnw";
case EDGE_DNE: return "dne";
case EDGE_DSE: return "dse";
case EDGE_DSW: return "dsw";
default: return "";
}
}
// Add a helper function at the top of the file to get item ID from brush
uint16_t GetItemIDFromBrush(Brush* brush) {
if (!brush) {
wxLogDebug("GetItemIDFromBrush: Brush is null");
OutputDebugStringA("GetItemIDFromBrush: Brush is null\n");
return 0;
}
uint16_t id = 0;
wxLogDebug("GetItemIDFromBrush: Checking brush type: %s", wxString(brush->getName()).c_str());
OutputDebugStringA(wxString::Format("GetItemIDFromBrush: Checking brush type: %s\n", wxString(brush->getName()).c_str()).mb_str());
// First prioritize RAW brush - this is the most direct approach
if (brush->isRaw()) {
RAWBrush* rawBrush = brush->asRaw();
if (rawBrush) {
id = rawBrush->getItemID();
wxLogDebug("GetItemIDFromBrush: Found RAW brush ID: %d", id);
OutputDebugStringA(wxString::Format("GetItemIDFromBrush: Found RAW brush ID: %d\n", id).mb_str());
if (id > 0) {
return id;
}
}
}
// Then try getID which sometimes works directly
id = brush->getID();
if (id > 0) {
wxLogDebug("GetItemIDFromBrush: Got ID from brush->getID(): %d", id);
OutputDebugStringA(wxString::Format("GetItemIDFromBrush: Got ID from brush->getID(): %d\n", id).mb_str());
return id;
}
// Try getLookID which works for most other brush types
id = brush->getLookID();
if (id > 0) {
wxLogDebug("GetItemIDFromBrush: Got ID from getLookID(): %d", id);
OutputDebugStringA(wxString::Format("GetItemIDFromBrush: Got ID from getLookID(): %d\n", id).mb_str());
return id;
}
// Try specific brush type methods - when all else fails
if (brush->isGround()) {
wxLogDebug("GetItemIDFromBrush: Detected Ground brush");
OutputDebugStringA("GetItemIDFromBrush: Detected Ground brush\n");
GroundBrush* groundBrush = brush->asGround();
if (groundBrush) {
// For ground brush, id is usually the server_lookid from grounds.xml
// Try to find something else
wxLogDebug("GetItemIDFromBrush: Failed to get ID for Ground brush");
OutputDebugStringA("GetItemIDFromBrush: Failed to get ID for Ground brush\n");
}
}
else if (brush->isWall()) {
wxLogDebug("GetItemIDFromBrush: Detected Wall brush");
OutputDebugStringA("GetItemIDFromBrush: Detected Wall brush\n");
WallBrush* wallBrush = brush->asWall();
if (wallBrush) {
wxLogDebug("GetItemIDFromBrush: Failed to get ID for Wall brush");
OutputDebugStringA("GetItemIDFromBrush: Failed to get ID for Wall brush\n");
}
}
else if (brush->isDoodad()) {
wxLogDebug("GetItemIDFromBrush: Detected Doodad brush");
OutputDebugStringA("GetItemIDFromBrush: Detected Doodad brush\n");
DoodadBrush* doodadBrush = brush->asDoodad();
if (doodadBrush) {
wxLogDebug("GetItemIDFromBrush: Failed to get ID for Doodad brush");
OutputDebugStringA("GetItemIDFromBrush: Failed to get ID for Doodad brush\n");
}
}
if (id == 0) {
wxLogDebug("GetItemIDFromBrush: Failed to get item ID from brush %s", wxString(brush->getName()).c_str());
OutputDebugStringA(wxString::Format("GetItemIDFromBrush: Failed to get item ID from brush %s\n", wxString(brush->getName()).c_str()).mb_str());
}
return id;
}
// Event table for BorderEditorDialog
BEGIN_EVENT_TABLE(BorderEditorDialog, wxDialog)
EVT_BUTTON(wxID_ADD, BorderEditorDialog::OnAddItem)
EVT_BUTTON(wxID_CLEAR, BorderEditorDialog::OnClear)
EVT_BUTTON(wxID_SAVE, BorderEditorDialog::OnSave)
EVT_BUTTON(wxID_CLOSE, BorderEditorDialog::OnClose)
EVT_BUTTON(wxID_FIND, BorderEditorDialog::OnBrowse)
EVT_COMBOBOX(wxID_ANY, BorderEditorDialog::OnLoadBorder)
EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, BorderEditorDialog::OnPageChanged)
EVT_BUTTON(wxID_ADD + 100, BorderEditorDialog::OnAddGroundItem)
EVT_BUTTON(wxID_REMOVE, BorderEditorDialog::OnRemoveGroundItem)
EVT_BUTTON(wxID_FIND + 100, BorderEditorDialog::OnGroundBrowse)
EVT_COMBOBOX(wxID_ANY + 100, BorderEditorDialog::OnLoadGroundBrush)
END_EVENT_TABLE()
// Event table for BorderItemButton
BEGIN_EVENT_TABLE(BorderItemButton, wxButton)
EVT_PAINT(BorderItemButton::OnPaint)
END_EVENT_TABLE()
// Event table for BorderGridPanel
BEGIN_EVENT_TABLE(BorderGridPanel, wxPanel)
EVT_PAINT(BorderGridPanel::OnPaint)
EVT_LEFT_UP(BorderGridPanel::OnMouseClick)
EVT_LEFT_DOWN(BorderGridPanel::OnMouseDown)
END_EVENT_TABLE()
// Event table for BorderPreviewPanel
BEGIN_EVENT_TABLE(BorderPreviewPanel, wxPanel)
EVT_PAINT(BorderPreviewPanel::OnPaint)
END_EVENT_TABLE()
BorderEditorDialog::BorderEditorDialog(wxWindow* parent, const wxString& title) :
wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxSize(650, 520),
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
m_nextBorderId(1),
m_activeTab(0) {
CreateGUIControls();
LoadExistingBorders();
LoadExistingGroundBrushes();
LoadTilesets(); // Load available tilesets
// Set ID to next available ID
m_idCtrl->SetValue(m_nextBorderId);
// Center the dialog
CenterOnParent();
}
BorderEditorDialog::~BorderEditorDialog() {
// Nothing to destroy manually
}
void BorderEditorDialog::CreateGUIControls() {
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
// Common properties - more compact horizontal layout
wxStaticBoxSizer* commonPropertiesSizer = new wxStaticBoxSizer(wxVERTICAL, this, "Common Properties");
wxBoxSizer* commonPropertiesHorizSizer = new wxBoxSizer(wxHORIZONTAL);
// Name field
wxBoxSizer* nameSizer = new wxBoxSizer(wxVERTICAL);
nameSizer->Add(new wxStaticText(this, wxID_ANY, "Name:"), 0);
m_nameCtrl = new wxTextCtrl(this, wxID_ANY);
m_nameCtrl->SetToolTip("Descriptive name for the border/brush");
nameSizer->Add(m_nameCtrl, 0, wxEXPAND | wxTOP, 2);
commonPropertiesHorizSizer->Add(nameSizer, 1, wxEXPAND | wxRIGHT, 10);
// ID field
wxBoxSizer* idSizer = new wxBoxSizer(wxVERTICAL);
idSizer->Add(new wxStaticText(this, wxID_ANY, "ID:"), 0);
m_idCtrl = new wxSpinCtrl(this, wxID_ANY, "1", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 1000);
m_idCtrl->SetToolTip("Unique identifier for this border/brush");
idSizer->Add(m_idCtrl, 0, wxEXPAND | wxTOP, 2);
commonPropertiesHorizSizer->Add(idSizer, 0, wxEXPAND);
commonPropertiesSizer->Add(commonPropertiesHorizSizer, 0, wxEXPAND | wxALL, 5);
topSizer->Add(commonPropertiesSizer, 0, wxEXPAND | wxALL, 5);
// Create notebook with Border and Ground tabs
m_notebook = new wxNotebook(this, wxID_ANY);
// ========== BORDER TAB ==========
m_borderPanel = new wxPanel(m_notebook);
wxBoxSizer* borderSizer = new wxBoxSizer(wxVERTICAL);
// Border Properties - more compact layout
wxStaticBoxSizer* borderPropertiesSizer = new wxStaticBoxSizer(wxVERTICAL, m_borderPanel, "Border Properties");
// Two-column horizontal layout
wxBoxSizer* borderPropsHorizSizer = new wxBoxSizer(wxHORIZONTAL);
// Left column - Group and Type
wxBoxSizer* leftColSizer = new wxBoxSizer(wxVERTICAL);
// Border Group
wxBoxSizer* groupSizer = new wxBoxSizer(wxVERTICAL);
groupSizer->Add(new wxStaticText(m_borderPanel, wxID_ANY, "Group:"), 0);
m_groupCtrl = new wxSpinCtrl(m_borderPanel, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 1000);
m_groupCtrl->SetToolTip("Optional group identifier (0 = no group)");
groupSizer->Add(m_groupCtrl, 0, wxEXPAND | wxTOP, 2);
leftColSizer->Add(groupSizer, 0, wxEXPAND | wxBOTTOM, 5);
// Border Type
wxBoxSizer* typeSizer = new wxBoxSizer(wxVERTICAL);
typeSizer->Add(new wxStaticText(m_borderPanel, wxID_ANY, "Type:"), 0);
wxBoxSizer* checkboxSizer = new wxBoxSizer(wxHORIZONTAL);
m_isOptionalCheck = new wxCheckBox(m_borderPanel, wxID_ANY, "Optional");
m_isOptionalCheck->SetToolTip("Marks this border as optional");
m_isGroundCheck = new wxCheckBox(m_borderPanel, wxID_ANY, "Ground");
m_isGroundCheck->SetToolTip("Marks this border as a ground border");
checkboxSizer->Add(m_isOptionalCheck, 0, wxRIGHT, 10);
checkboxSizer->Add(m_isGroundCheck, 0);
typeSizer->Add(checkboxSizer, 0, wxEXPAND | wxTOP, 2);
leftColSizer->Add(typeSizer, 0, wxEXPAND);
borderPropsHorizSizer->Add(leftColSizer, 1, wxEXPAND | wxRIGHT, 10);
// Right column - Load Existing
wxBoxSizer* rightColSizer = new wxBoxSizer(wxVERTICAL);
rightColSizer->Add(new wxStaticText(m_borderPanel, wxID_ANY, "Load Existing:"), 0);
m_existingBordersCombo = new wxComboBox(m_borderPanel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY | wxCB_DROPDOWN);
m_existingBordersCombo->SetToolTip("Load an existing border as template");
rightColSizer->Add(m_existingBordersCombo, 0, wxEXPAND | wxTOP, 2);
borderPropsHorizSizer->Add(rightColSizer, 1, wxEXPAND);
borderPropertiesSizer->Add(borderPropsHorizSizer, 0, wxEXPAND | wxALL, 5);
borderSizer->Add(borderPropertiesSizer, 0, wxEXPAND | wxALL, 5);
// Border content area with grid and preview
wxBoxSizer* borderContentSizer = new wxBoxSizer(wxHORIZONTAL);
// Left side - Grid Editor
wxStaticBoxSizer* gridSizer = new wxStaticBoxSizer(wxVERTICAL, m_borderPanel, "Border Grid");
m_gridPanel = new BorderGridPanel(m_borderPanel);
gridSizer->Add(m_gridPanel, 1, wxEXPAND | wxALL, 5);
// Add instruction label
wxStaticText* instructions = new wxStaticText(m_borderPanel, wxID_ANY,
"Click on a grid position to place the currently selected brush.\n"
"The item ID will be extracted automatically from the brush.");
instructions->SetForegroundColour(*wxBLUE);
gridSizer->Add(instructions, 0, wxEXPAND | wxALL, 5);
// Current selected item controls
wxBoxSizer* itemSizer = new wxBoxSizer(wxHORIZONTAL);
itemSizer->Add(new wxStaticText(m_borderPanel, wxID_ANY, "Item ID:"), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
m_itemIdCtrl = new wxSpinCtrl(m_borderPanel, wxID_ANY, "0", wxDefaultPosition, wxSize(80, -1), wxSP_ARROW_KEYS, 0, 65535);
m_itemIdCtrl->SetToolTip("Enter an item ID manually if you don't want to use the current brush");
itemSizer->Add(m_itemIdCtrl, 0, wxRIGHT, 5);
wxButton* browseButton = new wxButton(m_borderPanel, wxID_FIND, "Browse...", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
browseButton->SetToolTip("Browse for an item to use instead of the current brush");
itemSizer->Add(browseButton, 0, wxRIGHT, 5);
wxButton* addButton = new wxButton(m_borderPanel, wxID_ADD, "Add Manually", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
addButton->SetToolTip("Add the item ID manually to the currently selected position");
itemSizer->Add(addButton, 0);
gridSizer->Add(itemSizer, 0, wxEXPAND | wxALL, 5);
// Add grid editor to content sizer
borderContentSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 5);
// Right side - Preview Panel
wxStaticBoxSizer* previewSizer = new wxStaticBoxSizer(wxVERTICAL, m_borderPanel, "Preview");
m_previewPanel = new BorderPreviewPanel(m_borderPanel);
previewSizer->Add(m_previewPanel, 1, wxEXPAND | wxALL, 5);
// Add preview to content sizer
borderContentSizer->Add(previewSizer, 1, wxEXPAND | wxALL, 5);
// Add content sizer to main border sizer
borderSizer->Add(borderContentSizer, 1, wxEXPAND | wxALL, 5);
// Bottom buttons for border tab
wxBoxSizer* borderButtonSizer = new wxBoxSizer(wxHORIZONTAL);
borderButtonSizer->Add(new wxButton(m_borderPanel, wxID_CLEAR, "Clear"), 0, wxRIGHT, 5);
borderButtonSizer->Add(new wxButton(m_borderPanel, wxID_SAVE, "Save Border"), 0, wxRIGHT, 5);
borderButtonSizer->AddStretchSpacer(1);
borderButtonSizer->Add(new wxButton(m_borderPanel, wxID_CLOSE, "Close"), 0);
borderSizer->Add(borderButtonSizer, 0, wxEXPAND | wxALL, 5);
m_borderPanel->SetSizer(borderSizer);
// ========== GROUND TAB ==========
m_groundPanel = new wxPanel(m_notebook);
wxBoxSizer* groundSizer = new wxBoxSizer(wxVERTICAL);
// Ground Brush Properties - more compact layout
wxStaticBoxSizer* groundPropertiesSizer = new wxStaticBoxSizer(wxVERTICAL, m_groundPanel, "Ground Brush Properties");
// Two rows of two columns each
wxBoxSizer* topRowSizer = new wxBoxSizer(wxHORIZONTAL);
// Tileset selector
wxBoxSizer* tilesetSizer = new wxBoxSizer(wxVERTICAL);
tilesetSizer->Add(new wxStaticText(m_groundPanel, wxID_ANY, "Tileset:"), 0);
m_tilesetChoice = new wxChoice(m_groundPanel, wxID_ANY);
m_tilesetChoice->SetToolTip("Select tileset to add this brush to");
tilesetSizer->Add(m_tilesetChoice, 0, wxEXPAND | wxTOP, 2);
topRowSizer->Add(tilesetSizer, 1, wxEXPAND | wxRIGHT, 10);
// Server Look ID
wxBoxSizer* serverIdSizer = new wxBoxSizer(wxVERTICAL);
serverIdSizer->Add(new wxStaticText(m_groundPanel, wxID_ANY, "Server Look ID:"), 0);
m_serverLookIdCtrl = new wxSpinCtrl(m_groundPanel, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 65535);
m_serverLookIdCtrl->SetToolTip("Server-side item ID");
serverIdSizer->Add(m_serverLookIdCtrl, 0, wxEXPAND | wxTOP, 2);
topRowSizer->Add(serverIdSizer, 1, wxEXPAND);
groundPropertiesSizer->Add(topRowSizer, 0, wxEXPAND | wxALL, 5);
// Second row
wxBoxSizer* bottomRowSizer = new wxBoxSizer(wxHORIZONTAL);
// Z-Order
wxBoxSizer* zOrderSizer = new wxBoxSizer(wxVERTICAL);
zOrderSizer->Add(new wxStaticText(m_groundPanel, wxID_ANY, "Z-Order:"), 0);
m_zOrderCtrl = new wxSpinCtrl(m_groundPanel, wxID_ANY, "0", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 10000);
m_zOrderCtrl->SetToolTip("Z-Order for display");
zOrderSizer->Add(m_zOrderCtrl, 0, wxEXPAND | wxTOP, 2);
bottomRowSizer->Add(zOrderSizer, 1, wxEXPAND | wxRIGHT, 10);
// Existing ground brushes dropdown
wxBoxSizer* existingSizer = new wxBoxSizer(wxVERTICAL);
existingSizer->Add(new wxStaticText(m_groundPanel, wxID_ANY, "Load Existing:"), 0);
m_existingGroundBrushesCombo = new wxComboBox(m_groundPanel, wxID_ANY + 100, "", wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY | wxCB_DROPDOWN);
m_existingGroundBrushesCombo->SetToolTip("Load an existing ground brush as template");
existingSizer->Add(m_existingGroundBrushesCombo, 0, wxEXPAND | wxTOP, 2);
bottomRowSizer->Add(existingSizer, 1, wxEXPAND);
groundPropertiesSizer->Add(bottomRowSizer, 0, wxEXPAND | wxALL, 5);
groundSizer->Add(groundPropertiesSizer, 0, wxEXPAND | wxALL, 5);
// Ground Items
wxStaticBoxSizer* groundItemsSizer = new wxStaticBoxSizer(wxVERTICAL, m_groundPanel, "Ground Items");
// List of ground items - set a smaller height
m_groundItemsList = new wxListBox(m_groundPanel, ID_GROUND_ITEM_LIST, wxDefaultPosition, wxSize(-1, 100), 0, nullptr, wxLB_SINGLE);
groundItemsSizer->Add(m_groundItemsList, 0, wxEXPAND | wxALL, 5);
// Controls for adding/removing ground items
wxBoxSizer* groundItemRowSizer = new wxBoxSizer(wxHORIZONTAL);
// Left side - item ID and chance
wxBoxSizer* itemDetailsSizer = new wxBoxSizer(wxHORIZONTAL);
// Item ID input
wxBoxSizer* itemIdSizer = new wxBoxSizer(wxVERTICAL);
itemIdSizer->Add(new wxStaticText(m_groundPanel, wxID_ANY, "Item ID:"), 0);
m_groundItemIdCtrl = new wxSpinCtrl(m_groundPanel, wxID_ANY, "0", wxDefaultPosition, wxSize(80, -1), wxSP_ARROW_KEYS, 0, 65535);
m_groundItemIdCtrl->SetToolTip("ID of the item to add");
itemIdSizer->Add(m_groundItemIdCtrl, 0, wxEXPAND | wxTOP, 2);
itemDetailsSizer->Add(itemIdSizer, 0, wxEXPAND | wxRIGHT, 5);
// Chance input
wxBoxSizer* chanceSizer = new wxBoxSizer(wxVERTICAL);
chanceSizer->Add(new wxStaticText(m_groundPanel, wxID_ANY, "Chance:"), 0);
m_groundItemChanceCtrl = new wxSpinCtrl(m_groundPanel, wxID_ANY, "10", wxDefaultPosition, wxSize(60, -1), wxSP_ARROW_KEYS, 1, 10000);
m_groundItemChanceCtrl->SetToolTip("Chance of this item appearing");
chanceSizer->Add(m_groundItemChanceCtrl, 0, wxEXPAND | wxTOP, 2);
itemDetailsSizer->Add(chanceSizer, 0, wxEXPAND);
groundItemRowSizer->Add(itemDetailsSizer, 1, wxEXPAND | wxRIGHT, 10);
// Right side - buttons
wxBoxSizer* itemButtonsSizer = new wxBoxSizer(wxVERTICAL);
itemButtonsSizer->AddStretchSpacer();
wxBoxSizer* buttonsSizer = new wxBoxSizer(wxHORIZONTAL);
wxButton* groundBrowseButton = new wxButton(m_groundPanel, wxID_FIND + 100, "Browse...", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
groundBrowseButton->SetToolTip("Browse for an item");
buttonsSizer->Add(groundBrowseButton, 0, wxRIGHT, 5);
wxButton* addGroundItemButton = new wxButton(m_groundPanel, wxID_ADD + 100, "Add", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
addGroundItemButton->SetToolTip("Add this item to the list");
buttonsSizer->Add(addGroundItemButton, 0, wxRIGHT, 5);
wxButton* removeGroundItemButton = new wxButton(m_groundPanel, wxID_REMOVE, "Remove", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
removeGroundItemButton->SetToolTip("Remove the selected item");
buttonsSizer->Add(removeGroundItemButton, 0);
itemButtonsSizer->Add(buttonsSizer, 0, wxEXPAND);
groundItemRowSizer->Add(itemButtonsSizer, 0, wxEXPAND);
groundItemsSizer->Add(groundItemRowSizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
groundSizer->Add(groundItemsSizer, 0, wxEXPAND | wxALL, 5); // Changed from 1 to 0 to not expand
// Grid and border selection for ground tab
wxStaticBoxSizer* groundBorderSizer = new wxStaticBoxSizer(wxVERTICAL, m_groundPanel, "Border for Ground Brush");
// First row - Border alignment and 'to none' option
wxBoxSizer* borderRow1 = new wxBoxSizer(wxHORIZONTAL);
// Border alignment
wxBoxSizer* alignSizer = new wxBoxSizer(wxVERTICAL);
alignSizer->Add(new wxStaticText(m_groundPanel, wxID_ANY, "Border Alignment:"), 0);
wxArrayString alignOptions;
alignOptions.Add("outer");
alignOptions.Add("inner");
m_borderAlignmentChoice = new wxChoice(m_groundPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, alignOptions);
m_borderAlignmentChoice->SetSelection(0); // Default to "outer"
m_borderAlignmentChoice->SetToolTip("Alignment type for the border");
alignSizer->Add(m_borderAlignmentChoice, 0, wxEXPAND | wxTOP, 2);
borderRow1->Add(alignSizer, 1, wxEXPAND | wxRIGHT, 10);
// Border options (checkboxes)
wxBoxSizer* optionsSizer = new wxBoxSizer(wxVERTICAL);
optionsSizer->Add(new wxStaticText(m_groundPanel, wxID_ANY, "Border Options:"), 0);
wxBoxSizer* checksSizer = new wxBoxSizer(wxHORIZONTAL);
m_includeToNoneCheck = new wxCheckBox(m_groundPanel, wxID_ANY, "To None");
m_includeToNoneCheck->SetValue(true); // Default to checked
m_includeToNoneCheck->SetToolTip("Adds additional border with 'to none' attribute");
m_includeInnerCheck = new wxCheckBox(m_groundPanel, wxID_ANY, "Inner Border");
m_includeInnerCheck->SetToolTip("Adds additional inner border with same ID");
checksSizer->Add(m_includeToNoneCheck, 0, wxRIGHT, 10);
checksSizer->Add(m_includeInnerCheck, 0);
optionsSizer->Add(checksSizer, 0, wxEXPAND | wxTOP, 2);
borderRow1->Add(optionsSizer, 1, wxEXPAND);
groundBorderSizer->Add(borderRow1, 0, wxEXPAND | wxALL, 5);
// Border ID notice (red text)
wxBoxSizer* borderIdSizer = new wxBoxSizer(wxHORIZONTAL);
wxStaticText* borderIdLabel = new wxStaticText(m_groundPanel, wxID_ANY, "Border ID:");
borderIdSizer->Add(borderIdLabel, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
wxStaticText* borderId = new wxStaticText(m_groundPanel, wxID_ANY, "Uses the ID specified in 'Common Properties' section");
borderId->SetForegroundColour(*wxRED);
borderIdSizer->Add(borderId, 1, wxALIGN_CENTER_VERTICAL);
groundBorderSizer->Add(borderIdSizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
// Grid use instruction - shorter text
wxStaticText* gridInstructions = new wxStaticText(m_groundPanel, wxID_ANY,
"Use the grid in the Border tab to define borders for this ground brush.");
gridInstructions->SetForegroundColour(*wxBLUE);
groundBorderSizer->Add(gridInstructions, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
groundSizer->Add(groundBorderSizer, 0, wxEXPAND | wxALL, 5);
// Bottom buttons for ground tab
wxBoxSizer* groundButtonSizer = new wxBoxSizer(wxHORIZONTAL);
groundButtonSizer->Add(new wxButton(m_groundPanel, wxID_CLEAR, "Clear"), 0, wxRIGHT, 5);
groundButtonSizer->Add(new wxButton(m_groundPanel, wxID_SAVE, "Save Ground"), 0, wxRIGHT, 5);
groundButtonSizer->AddStretchSpacer(1);
groundButtonSizer->Add(new wxButton(m_groundPanel, wxID_CLOSE, "Close"), 0);
groundSizer->Add(groundButtonSizer, 0, wxEXPAND | wxALL, 5);
m_groundPanel->SetSizer(groundSizer);
// Add tabs to notebook
m_notebook->AddPage(m_borderPanel, "Border");
m_notebook->AddPage(m_groundPanel, "Ground");
topSizer->Add(m_notebook, 1, wxEXPAND | wxALL, 5);
SetSizer(topSizer);
Layout();
}
void BorderEditorDialog::LoadExistingBorders() {
// Clear the combobox
m_existingBordersCombo->Clear();
// Add an empty entry
m_existingBordersCombo->Append("<Create New>");
m_existingBordersCombo->SetSelection(0);
// Find the borders.xml file using the same version path conversion as in map_display.cpp
wxString dataDir = g_gui.GetDataDirectory();
// Get version string and convert to proper directory format
wxString versionString = g_gui.GetCurrentVersion().getName();
std::string versionStr = std::string(versionString.mb_str());
// Convert version number to data directory format
// Remove dots first
versionStr.erase(std::remove(versionStr.begin(), versionStr.end(), '.'), versionStr.end());
// Handle special cases for 2-digit versions (add 0)
if(versionStr.length() == 2) {
versionStr += "0";
}
// Handle special case for 10.10 -> 10100
else if(versionStr == "1010") {
versionStr = "10100";
}
// Construct borders.xml path
wxString bordersFile = dataDir + wxFileName::GetPathSeparator() +
wxString(versionStr.c_str()) +
wxFileName::GetPathSeparator() + "borders.xml";
if (!wxFileExists(bordersFile)) {
wxMessageBox("Cannot find borders.xml file in the data directory.", "Error", wxICON_ERROR);
return;
}
// Load the XML file
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(nstr(bordersFile).c_str());
if (!result) {
wxMessageBox("Failed to load borders.xml: " + wxString(result.description()), "Error", wxICON_ERROR);
return;
}
pugi::xml_node materials = doc.child("materials");
if (!materials) {
wxMessageBox("Invalid borders.xml file: missing 'materials' node", "Error", wxICON_ERROR);
return;
}
int highestId = 0;
// Parse all borders
for (pugi::xml_node borderNode = materials.child("border"); borderNode; borderNode = borderNode.next_sibling("border")) {
pugi::xml_attribute idAttr = borderNode.attribute("id");
if (!idAttr) continue;
int id = idAttr.as_int();
if (id > highestId) {
highestId = id;
}
// Get the comment node before this border for its description
std::string description;
pugi::xml_node commentNode = borderNode.previous_sibling();
if (commentNode && commentNode.type() == pugi::node_comment) {
description = commentNode.value();
// Extract the actual comment text by removing XML comment markers
description = description.c_str(); // Ensure we have a clean copy
// Trim leading and trailing whitespace first
description.erase(0, description.find_first_not_of(" \t\n\r"));
description.erase(description.find_last_not_of(" \t\n\r") + 1);
// Remove leading "<!--" if present
if (description.substr(0, 4) == "<!--") {
description.erase(0, 4);
// Trim whitespace after removing the marker
description.erase(0, description.find_first_not_of(" \t\n\r"));
}
// Remove trailing "-->" if present
if (description.length() >= 3 && description.substr(description.length() - 3) == "-->") {
description.erase(description.length() - 3);
// Trim whitespace after removing the marker
description.erase(description.find_last_not_of(" \t\n\r") + 1);
}
}
// Add to combobox
wxString label = wxString::Format("Border %d", id);
if (!description.empty()) {
label += wxString::Format(" (%s)", wxstr(description));
}
m_existingBordersCombo->Append(label, new wxStringClientData(wxString::Format("%d", id)));
}
// Set the next border ID to one higher than the highest found
m_nextBorderId = highestId + 1;
m_idCtrl->SetValue(m_nextBorderId);
}
void BorderEditorDialog::OnLoadBorder(wxCommandEvent& event) {
int selection = m_existingBordersCombo->GetSelection();
if (selection <= 0) {
// Selected "Create New" or nothing
ClearItems();
return;
}
wxStringClientData* data = static_cast<wxStringClientData*>(m_existingBordersCombo->GetClientObject(selection));
if (!data) return;
int borderId = wxAtoi(data->GetData());
// Find the borders.xml file using the same version path conversion as in LoadExistingBorders
wxString dataDir = g_gui.GetDataDirectory();
// Get version string and convert to proper directory format
wxString versionString = g_gui.GetCurrentVersion().getName();
std::string versionStr = std::string(versionString.mb_str());
// Convert version number to data directory format
// Remove dots first
versionStr.erase(std::remove(versionStr.begin(), versionStr.end(), '.'), versionStr.end());
// Handle special cases for 2-digit versions (add 0)
if(versionStr.length() == 2) {
versionStr += "0";
}
// Handle special case for 10.10 -> 10100
else if(versionStr == "1010") {
versionStr = "10100";
}
wxString bordersFile = dataDir + wxFileName::GetPathSeparator() +
wxString(versionStr.c_str()) +
wxFileName::GetPathSeparator() + "borders.xml";
if (!wxFileExists(bordersFile)) {
wxMessageBox("Cannot find borders.xml file in the data directory.", "Error", wxICON_ERROR);
return;
}
// Load the XML file
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(nstr(bordersFile).c_str());
if (!result) {
wxMessageBox("Failed to load borders.xml: " + wxString(result.description()), "Error", wxICON_ERROR);
return;
}
// Clear existing items
ClearItems();
// Look for the border with the specified ID
pugi::xml_node materials = doc.child("materials");
for (pugi::xml_node borderNode = materials.child("border"); borderNode; borderNode = borderNode.next_sibling("border")) {
pugi::xml_attribute idAttr = borderNode.attribute("id");
if (!idAttr || idAttr.as_int() != borderId) continue;
// Set the ID in the control
m_idCtrl->SetValue(borderId);
// Check for border type
pugi::xml_attribute typeAttr = borderNode.attribute("type");
if (typeAttr) {
std::string type = typeAttr.as_string();
m_isOptionalCheck->SetValue(type == "optional");
} else {
m_isOptionalCheck->SetValue(false);
}
// Check for border group
pugi::xml_attribute groupAttr = borderNode.attribute("group");
if (groupAttr) {
m_groupCtrl->SetValue(groupAttr.as_int());
} else {
m_groupCtrl->SetValue(0);
}
// Get the comment node before this border for its description
pugi::xml_node commentNode = borderNode.previous_sibling();
if (commentNode && commentNode.type() == pugi::node_comment) {
std::string description = commentNode.value();
// Extract the actual comment text by removing XML comment markers
description = description.c_str(); // Ensure we have a clean copy
// Trim leading and trailing whitespace first
description.erase(0, description.find_first_not_of(" \t\n\r"));
description.erase(description.find_last_not_of(" \t\n\r") + 1);
// Remove leading "<!--" if present
if (description.substr(0, 4) == "<!--") {
description.erase(0, 4);
// Trim whitespace after removing the marker
description.erase(0, description.find_first_not_of(" \t\n\r"));
}
// Remove trailing "-->" if present
if (description.length() >= 3 && description.substr(description.length() - 3) == "-->") {
description.erase(description.length() - 3);
// Trim whitespace after removing the marker
description.erase(description.find_last_not_of(" \t\n\r") + 1);
}
m_nameCtrl->SetValue(wxstr(description));
} else {
m_nameCtrl->SetValue("");
}
// Load all border items
for (pugi::xml_node itemNode = borderNode.child("borderitem"); itemNode; itemNode = itemNode.next_sibling("borderitem")) {
pugi::xml_attribute edgeAttr = itemNode.attribute("edge");
pugi::xml_attribute itemAttr = itemNode.attribute("item");
if (!edgeAttr || !itemAttr) continue;
BorderEdgePosition pos = edgeStringToPosition(edgeAttr.as_string());
uint16_t itemId = itemAttr.as_uint();
if (pos != EDGE_NONE && itemId > 0) {
m_borderItems.push_back(BorderItem(pos, itemId));
m_gridPanel->SetItemId(pos, itemId);
}
}
break;
}
// Update the preview
UpdatePreview();
// Keep selection
m_existingBordersCombo->SetSelection(selection);
}
void BorderEditorDialog::OnItemIdChanged(wxCommandEvent& event) {
// This event handler would update the display when an item ID is entered manually
// but we're handling this directly in OnAddItem instead
}
void BorderEditorDialog::OnBrowse(wxCommandEvent& event) {
// Open the Find Item dialog instead
FindItemDialog dialog(this, "Select Border Item");
if (dialog.ShowModal() == wxID_OK) {
// Get the selected item ID
uint16_t itemId = dialog.getResultID();
// Find the item ID spin control
wxSpinCtrl* itemIdCtrl = nullptr;
wxWindowList& children = GetChildren();
for (wxWindowList::iterator it = children.begin(); it != children.end(); ++it) {
wxSpinCtrl* spinCtrl = dynamic_cast<wxSpinCtrl*>(*it);
if (spinCtrl && spinCtrl != m_idCtrl) {
itemIdCtrl = spinCtrl;
break;
}
}
if (itemIdCtrl && itemId > 0) {
itemIdCtrl->SetValue(itemId);
}
}
}
void BorderEditorDialog::OnPositionSelected(wxCommandEvent& event) {
// Get the position from the event
BorderEdgePosition pos = static_cast<BorderEdgePosition>(event.GetInt());
wxLogDebug("OnPositionSelected: Position %s selected", wxstr(edgePositionToString(pos)).c_str());
OutputDebugStringA(wxString::Format("BorderEditor: Position %s selected\n", wxstr(edgePositionToString(pos)).c_str()).mb_str());
// Get the item ID from the current brush
Brush* currentBrush = g_gui.GetCurrentBrush();
if (!currentBrush) {
wxLogDebug("OnPositionSelected: No current brush selected");
OutputDebugStringA("BorderEditor: No current brush selected\n");
wxMessageBox("Please select a brush or item first.", "No Brush Selected", wxICON_INFORMATION);
return;
}
wxLogDebug("OnPositionSelected: Using brush: %s", wxString(currentBrush->getName()).c_str());
OutputDebugStringA(wxString::Format("BorderEditor: Using brush: %s\n", wxString(currentBrush->getName()).c_str()).mb_str());
// Try to get the item ID directly - check if it's a RAW brush first
uint16_t itemId = 0;
if (currentBrush->isRaw()) {
RAWBrush* rawBrush = currentBrush->asRaw();
if (rawBrush) {
itemId = rawBrush->getItemID();
wxLogDebug("OnPositionSelected: Got item ID %d directly from RAW brush", itemId);
OutputDebugStringA(wxString::Format("BorderEditor: Got item ID %d directly from RAW brush\n", itemId).mb_str());
} else {
wxLogDebug("OnPositionSelected: Failed to cast to RAW brush");
OutputDebugStringA("BorderEditor: Failed to cast to RAW brush\n");
}
} else {
OutputDebugStringA(wxString::Format("BorderEditor: Current brush is NOT a RAW brush, is: %s\n",
currentBrush->isGround() ? "Ground" :
currentBrush->isWall() ? "Wall" :
currentBrush->isDoodad() ? "Doodad" : "Other").mb_str());
}
// If we didn't get an ID from the RAW brush method, try the generic method
if (itemId == 0) {
itemId = GetItemIDFromBrush(currentBrush);
wxLogDebug("OnPositionSelected: Got item ID %d from GetItemIDFromBrush", itemId);
OutputDebugStringA(wxString::Format("BorderEditor: Got item ID %d from GetItemIDFromBrush\n", itemId).mb_str());
}
if (itemId > 0) {
// Update the item ID control - keeps the UI in sync with our selection
if (m_itemIdCtrl) {
m_itemIdCtrl->SetValue(itemId);
wxLogDebug("OnPositionSelected: Updated item ID control to %d", itemId);
OutputDebugStringA(wxString::Format("BorderEditor: Updated item ID control to %d\n", itemId).mb_str());
}
// Add or update the border item
bool updated = false;
for (size_t i = 0; i < m_borderItems.size(); i++) {
if (m_borderItems[i].position == pos) {
m_borderItems[i].itemId = itemId;
updated = true;
wxLogDebug("OnPositionSelected: Updated existing border item at position %s", wxstr(edgePositionToString(pos)).c_str());
OutputDebugStringA(wxString::Format("BorderEditor: Updated existing border item at position %s\n", wxstr(edgePositionToString(pos)).c_str()).mb_str());
break;
}
}
if (!updated) {
m_borderItems.push_back(BorderItem(pos, itemId));
wxLogDebug("OnPositionSelected: Added new border item at position %s", wxstr(edgePositionToString(pos)).c_str());
OutputDebugStringA(wxString::Format("BorderEditor: Added new border item at position %s\n", wxstr(edgePositionToString(pos)).c_str()).mb_str());
}
// Update the grid panel
m_gridPanel->SetItemId(pos, itemId);
wxLogDebug("OnPositionSelected: Set grid panel item ID for position %s to %d", wxstr(edgePositionToString(pos)).c_str(), itemId);
OutputDebugStringA(wxString::Format("BorderEditor: Set grid panel item ID for position %s to %d\n", wxstr(edgePositionToString(pos)).c_str(), itemId).mb_str());
// Update the preview
UpdatePreview();
// Log the addition
wxLogDebug("Added border item at position %s with item ID %d",
wxstr(edgePositionToString(pos)).c_str(), itemId);
OutputDebugStringA(wxString::Format("BorderEditor: Successfully added border item at position %s with item ID %d\n",
wxstr(edgePositionToString(pos)).c_str(), itemId).mb_str());
} else {
// If we couldn't get an item ID from the brush, check if there's a value in the item ID control
itemId = m_itemIdCtrl->GetValue();
if (itemId > 0) {
// Use the value from the control to update/add the border item
bool updated = false;
for (size_t i = 0; i < m_borderItems.size(); i++) {
if (m_borderItems[i].position == pos) {
m_borderItems[i].itemId = itemId;
updated = true;
break;
}
}
if (!updated) {
m_borderItems.push_back(BorderItem(pos, itemId));
}
// Update the grid panel
m_gridPanel->SetItemId(pos, itemId);
// Update the preview
UpdatePreview();
wxLogDebug("Used item ID %d from control for position %s",
itemId, wxstr(edgePositionToString(pos)).c_str());
OutputDebugStringA(wxString::Format("BorderEditor: Used item ID %d from control for position %s\n",
itemId, wxstr(edgePositionToString(pos)).c_str()).mb_str());
} else {
wxLogDebug("No valid item ID found from current brush: %s", wxString(currentBrush->getName()).c_str());
OutputDebugStringA(wxString::Format("BorderEditor: No valid item ID found from current brush: %s\n", wxString(currentBrush->getName()).c_str()).mb_str());
wxMessageBox("Could not get a valid item ID from the current brush. Please select an item brush or use the Browse button to select an item manually.", "Invalid Brush", wxICON_INFORMATION);
}
}
}
void BorderEditorDialog::OnAddItem(wxCommandEvent& event) {
// Get the currently selected position in the grid panel
static BorderEdgePosition lastSelectedPos = EDGE_NONE;
BorderEdgePosition selectedPos = m_gridPanel->GetSelectedPosition();
// If no position is currently selected, use the last selected position
if (selectedPos == EDGE_NONE) {
selectedPos = lastSelectedPos;
}
if (selectedPos == EDGE_NONE) {
wxMessageBox("Please select a position on the grid first by clicking on it.", "Error", wxICON_ERROR);
return;
}
// Save this position for future use
lastSelectedPos = selectedPos;
// Get the item ID from the control (now using the class member)
uint16_t itemId = m_itemIdCtrl->GetValue();
if (itemId == 0) {
wxMessageBox("Please enter a valid item ID or use the Browse button.", "Error", wxICON_ERROR);
return;
}
// Add or update the border item
bool updated = false;
for (size_t i = 0; i < m_borderItems.size(); i++) {
if (m_borderItems[i].position == selectedPos) {
m_borderItems[i].itemId = itemId;
updated = true;
break;
}
}
if (!updated) {
m_borderItems.push_back(BorderItem(selectedPos, itemId));
}
// Update the grid panel
m_gridPanel->SetItemId(selectedPos, itemId);
// Update the preview
UpdatePreview();
// Log the addition for debugging
wxLogDebug("Added item ID %d at position %s via Add button",
itemId, wxstr(edgePositionToString(selectedPos)).c_str());
}
void BorderEditorDialog::OnClear(wxCommandEvent& event) {
if (m_activeTab == 0) {
// Border tab
ClearItems();
} else {
// Ground tab
ClearGroundItems();
}
}
void BorderEditorDialog::ClearItems() {
m_borderItems.clear();
m_gridPanel->Clear();
m_previewPanel->Clear();
// Reset controls to defaults
m_idCtrl->SetValue(m_nextBorderId);
m_nameCtrl->SetValue("");
m_isOptionalCheck->SetValue(false);
m_isGroundCheck->SetValue(false);
m_groupCtrl->SetValue(0);
// Set combo selection to "Create New"
m_existingBordersCombo->SetSelection(0);
}
void BorderEditorDialog::UpdatePreview() {
m_previewPanel->SetBorderItems(m_borderItems);
m_previewPanel->Refresh();
}
bool BorderEditorDialog::ValidateBorder() {
// Check for empty name