-
Notifications
You must be signed in to change notification settings - Fork 224
/
map_display.cpp
2580 lines (2239 loc) · 74.7 KB
/
map_display.cpp
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 <sstream>
#include <time.h>
#include <wx/wfstream.h>
#include "gui.h"
#include "editor.h"
#include "brush.h"
#include "sprites.h"
#include "map.h"
#include "tile.h"
#include "old_properties_window.h"
#include "properties_window.h"
#include "palette_window.h"
#include "map_display.h"
#include "map_drawer.h"
#include "application.h"
#include "live_server.h"
#include "browse_tile_window.h"
#include "doodad_brush.h"
#include "house_exit_brush.h"
#include "house_brush.h"
#include "wall_brush.h"
#include "spawn_brush.h"
#include "creature_brush.h"
#include "ground_brush.h"
#include "waypoint_brush.h"
#include "raw_brush.h"
#include "carpet_brush.h"
#include "table_brush.h"
BEGIN_EVENT_TABLE(MapCanvas, wxGLCanvas)
EVT_KEY_DOWN(MapCanvas::OnKeyDown)
EVT_KEY_DOWN(MapCanvas::OnKeyUp)
// Mouse events
EVT_MOTION(MapCanvas::OnMouseMove)
EVT_LEFT_UP(MapCanvas::OnMouseLeftRelease)
EVT_LEFT_DOWN(MapCanvas::OnMouseLeftClick)
EVT_LEFT_DCLICK(MapCanvas::OnMouseLeftDoubleClick)
EVT_MIDDLE_DOWN(MapCanvas::OnMouseCenterClick)
EVT_MIDDLE_UP(MapCanvas::OnMouseCenterRelease)
EVT_RIGHT_DOWN(MapCanvas::OnMouseRightClick)
EVT_RIGHT_UP(MapCanvas::OnMouseRightRelease)
EVT_MOUSEWHEEL(MapCanvas::OnWheel)
EVT_ENTER_WINDOW(MapCanvas::OnGainMouse)
EVT_LEAVE_WINDOW(MapCanvas::OnLoseMouse)
//Drawing events
EVT_PAINT(MapCanvas::OnPaint)
EVT_ERASE_BACKGROUND(MapCanvas::OnEraseBackground)
// Menu events
EVT_MENU(MAP_POPUP_MENU_CUT, MapCanvas::OnCut)
EVT_MENU(MAP_POPUP_MENU_COPY, MapCanvas::OnCopy)
EVT_MENU(MAP_POPUP_MENU_COPY_POSITION, MapCanvas::OnCopyPosition)
EVT_MENU(MAP_POPUP_MENU_PASTE, MapCanvas::OnPaste)
EVT_MENU(MAP_POPUP_MENU_DELETE, MapCanvas::OnDelete)
//----
EVT_MENU(MAP_POPUP_MENU_COPY_SERVER_ID, MapCanvas::OnCopyServerId)
EVT_MENU(MAP_POPUP_MENU_COPY_CLIENT_ID, MapCanvas::OnCopyClientId)
EVT_MENU(MAP_POPUP_MENU_COPY_NAME, MapCanvas::OnCopyName)
// ----
EVT_MENU(MAP_POPUP_MENU_ROTATE, MapCanvas::OnRotateItem)
EVT_MENU(MAP_POPUP_MENU_GOTO, MapCanvas::OnGotoDestination)
EVT_MENU(MAP_POPUP_MENU_COPY_DESTINATION, MapCanvas::OnCopyDestination)
EVT_MENU(MAP_POPUP_MENU_SWITCH_DOOR, MapCanvas::OnSwitchDoor)
// ----
EVT_MENU(MAP_POPUP_MENU_SELECT_RAW_BRUSH, MapCanvas::OnSelectRAWBrush)
EVT_MENU(MAP_POPUP_MENU_SELECT_GROUND_BRUSH, MapCanvas::OnSelectGroundBrush)
EVT_MENU(MAP_POPUP_MENU_SELECT_DOODAD_BRUSH, MapCanvas::OnSelectDoodadBrush)
EVT_MENU(MAP_POPUP_MENU_SELECT_DOOR_BRUSH, MapCanvas::OnSelectDoorBrush)
EVT_MENU(MAP_POPUP_MENU_SELECT_WALL_BRUSH, MapCanvas::OnSelectWallBrush)
EVT_MENU(MAP_POPUP_MENU_SELECT_CARPET_BRUSH, MapCanvas::OnSelectCarpetBrush)
EVT_MENU(MAP_POPUP_MENU_SELECT_TABLE_BRUSH, MapCanvas::OnSelectTableBrush)
EVT_MENU(MAP_POPUP_MENU_SELECT_CREATURE_BRUSH, MapCanvas::OnSelectCreatureBrush)
EVT_MENU(MAP_POPUP_MENU_SELECT_SPAWN_BRUSH, MapCanvas::OnSelectSpawnBrush)
EVT_MENU(MAP_POPUP_MENU_SELECT_HOUSE_BRUSH, MapCanvas::OnSelectHouseBrush)
// ----
EVT_MENU(MAP_POPUP_MENU_PROPERTIES, MapCanvas::OnProperties)
// ----
EVT_MENU(MAP_POPUP_MENU_BROWSE_TILE, MapCanvas::OnBrowseTile)
END_EVENT_TABLE()
bool MapCanvas::processed[] = {0};
MapCanvas::MapCanvas(MapWindow* parent, Editor& editor, int* attriblist) :
wxGLCanvas(parent, wxID_ANY, nullptr, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS),
editor(editor),
floor(rme::MapGroundLayer),
zoom(1.0),
cursor_x(-1),
cursor_y(-1),
dragging(false),
boundbox_selection(false),
screendragging(false),
drawing(false),
dragging_draw(false),
replace_dragging(false),
screenshot_buffer(nullptr),
drag_start_x(-1),
drag_start_y(-1),
drag_start_z(-1),
last_cursor_map_x(-1),
last_cursor_map_y(-1),
last_cursor_map_z(-1),
last_click_map_x(-1),
last_click_map_y(-1),
last_click_map_z(-1),
last_click_abs_x(-1),
last_click_abs_y(-1),
last_click_x(-1),
last_click_y(-1),
last_mmb_click_x(-1),
last_mmb_click_y(-1)
{
popup_menu = newd MapPopupMenu(editor);
animation_timer = newd AnimationTimer(this);
drawer = new MapDrawer(this);
keyCode = WXK_NONE;
}
MapCanvas::~MapCanvas()
{
delete popup_menu;
delete animation_timer;
delete drawer;
free(screenshot_buffer);
}
void MapCanvas::Refresh()
{
if(refresh_watch.Time() > g_settings.getInteger(Config::HARD_REFRESH_RATE)) {
refresh_watch.Start();
wxGLCanvas::Update();
}
wxGLCanvas::Refresh();
}
void MapCanvas::SetZoom(double value)
{
if(value < 0.125)
value = 0.125;
if(value > 25.00)
value = 25.0;
if(zoom != value) {
int center_x, center_y;
GetScreenCenter(¢er_x, ¢er_y);
zoom = value;
GetMapWindow()->SetScreenCenterPosition(Position(center_x, center_y, floor));
UpdatePositionStatus();
UpdateZoomStatus();
Refresh();
}
}
void MapCanvas::GetViewBox(int* view_scroll_x, int* view_scroll_y, int* screensize_x, int* screensize_y) const
{
MapWindow* window = GetMapWindow();
window->GetViewSize(screensize_x, screensize_y);
window->GetViewStart(view_scroll_x, view_scroll_y);
}
void MapCanvas::OnPaint(wxPaintEvent& event)
{
SetCurrent(*g_gui.GetGLContext(this));
if(g_gui.IsRenderingEnabled()) {
DrawingOptions& options = drawer->getOptions();
if(screenshot_buffer) {
options.SetIngame();
} else {
options.transparent_floors = g_settings.getBoolean(Config::TRANSPARENT_FLOORS);
options.transparent_items = g_settings.getBoolean(Config::TRANSPARENT_ITEMS);
options.show_ingame_box = g_settings.getBoolean(Config::SHOW_INGAME_BOX);
options.show_lights = g_settings.getBoolean(Config::SHOW_LIGHTS);
options.show_grid = g_settings.getInteger(Config::SHOW_GRID);
options.ingame = !g_settings.getBoolean(Config::SHOW_EXTRA);
options.show_all_floors = g_settings.getBoolean(Config::SHOW_ALL_FLOORS);
options.show_creatures = g_settings.getBoolean(Config::SHOW_CREATURES);
options.show_spawns = g_settings.getBoolean(Config::SHOW_SPAWNS);
options.show_houses = g_settings.getBoolean(Config::SHOW_HOUSES);
options.show_shade = g_settings.getBoolean(Config::SHOW_SHADE);
options.show_special_tiles = g_settings.getBoolean(Config::SHOW_SPECIAL_TILES);
options.show_items = g_settings.getBoolean(Config::SHOW_ITEMS);
options.highlight_items = g_settings.getBoolean(Config::HIGHLIGHT_ITEMS);
options.show_blocking = g_settings.getBoolean(Config::SHOW_BLOCKING);
options.show_tooltips = g_settings.getBoolean(Config::SHOW_TOOLTIPS);
options.show_as_minimap = g_settings.getBoolean(Config::SHOW_AS_MINIMAP);
options.show_only_colors = g_settings.getBoolean(Config::SHOW_ONLY_TILEFLAGS);
options.show_only_modified = g_settings.getBoolean(Config::SHOW_ONLY_MODIFIED_TILES);
options.show_preview = g_settings.getBoolean(Config::SHOW_PREVIEW);
options.show_hooks = g_settings.getBoolean(Config::SHOW_WALL_HOOKS);
options.show_pickupables = g_settings.getBoolean(Config::SHOW_PICKUPABLES);
options.show_moveables = g_settings.getBoolean(Config::SHOW_MOVEABLES);
options.hide_items_when_zoomed = g_settings.getBoolean(Config::HIDE_ITEMS_WHEN_ZOOMED);
}
options.dragging = boundbox_selection;
if(options.show_preview || drawer->GetPositionIndicatorTime() != 0)
animation_timer->Start();
else
animation_timer->Stop();
drawer->SetupVars();
drawer->SetupGL();
drawer->Draw();
if(screenshot_buffer)
drawer->TakeScreenshot(screenshot_buffer);
drawer->Release();
}
// Clean unused textures
g_gui.gfx.garbageCollection();
// Swap buffer
SwapBuffers();
// Send newd node requests
editor.SendNodeRequests();
}
void MapCanvas::ShowPositionIndicator(const Position& position)
{
if(drawer) {
drawer->ShowPositionIndicator(position);
if(!animation_timer->IsRunning()) {
Update();
}
}
}
void MapCanvas::TakeScreenshot(wxFileName path, wxString format)
{
int screensize_x, screensize_y;
GetViewBox(&view_scroll_x, &view_scroll_y, &screensize_x, &screensize_y);
delete[] screenshot_buffer;
screenshot_buffer = newd uint8_t[3 * screensize_x * screensize_y];
// Draw the window
Refresh();
wxGLCanvas::Update(); // Forces immediate redraws the window.
// screenshot_buffer should now contain the screenbuffer
if(screenshot_buffer == nullptr) {
g_gui.PopupDialog("Capture failed", "Image capture failed. Old Video Driver?", wxOK);
} else {
// We got the shit
int screensize_x, screensize_y;
GetMapWindow()->GetViewSize(&screensize_x, &screensize_y);
wxImage screenshot(screensize_x, screensize_y, screenshot_buffer);
time_t t = time(nullptr);
struct tm* current_time = localtime(&t);
ASSERT(current_time);
wxString date;
date << "screenshot_" << (1900 + current_time->tm_year);
if(current_time->tm_mon < 9)
date << "-" << "0" << current_time->tm_mon+1;
else
date << "-" << current_time->tm_mon+1;
date << "-" << current_time->tm_mday;
date << "-" << current_time->tm_hour;
date << "-" << current_time->tm_min;
date << "-" << current_time->tm_sec;
int type = 0;
path.SetName(date);
if(format == "bmp") {
path.SetExt(format);
type = wxBITMAP_TYPE_BMP;
} else if(format == "png") {
path.SetExt(format);
type = wxBITMAP_TYPE_PNG;
} else if(format == "jpg" || format == "jpeg") {
path.SetExt(format);
type = wxBITMAP_TYPE_JPEG;
} else if(format == "tga") {
path.SetExt(format);
type = wxBITMAP_TYPE_TGA;
} else {
g_gui.SetStatusText("Unknown screenshot format \'" + format + "\", switching to default (png)");
path.SetExt("png");;
type = wxBITMAP_TYPE_PNG;
}
path.Mkdir(0755, wxPATH_MKDIR_FULL);
wxFileOutputStream of(path.GetFullPath());
if(of.IsOk()) {
if(screenshot.SaveFile(of, static_cast<wxBitmapType>(type)))
g_gui.SetStatusText("Took screenshot and saved as " + path.GetFullName());
else
g_gui.PopupDialog("File error", "Couldn't save image file correctly.", wxOK);
} else {
g_gui.PopupDialog("File error", "Couldn't open file " + path.GetFullPath() + " for writing.", wxOK);
}
}
Refresh();
screenshot_buffer = nullptr;
}
void MapCanvas::ScreenToMap(int screen_x, int screen_y, int* map_x, int* map_y)
{
int start_x, start_y;
GetMapWindow()->GetViewStart(&start_x, &start_y);
screen_x *= GetContentScaleFactor();
screen_y *= GetContentScaleFactor();
if(screen_x < 0) {
*map_x = (start_x + screen_x) / rme::TileSize;
} else {
*map_x = int(start_x + (screen_x * zoom)) / rme::TileSize;
}
if(screen_y < 0) {
*map_y = (start_y + screen_y) / rme::TileSize;
} else {
*map_y = int(start_y + (screen_y * zoom)) / rme::TileSize;
}
if(floor <= rme::MapGroundLayer) {
*map_x += rme::MapGroundLayer - floor;
*map_y += rme::MapGroundLayer - floor;
}/* else {
*map_x += rme::MapMaxLayer - floor;
*map_y += rme::MapMaxLayer - floor;
}*/
}
MapWindow* MapCanvas::GetMapWindow() const
{
wxWindow* window = GetParent();
if(window)
return static_cast<MapWindow*>(window);
return nullptr;
}
void MapCanvas::GetScreenCenter(int* map_x, int* map_y)
{
int width, height;
GetMapWindow()->GetViewSize(&width, &height);
return ScreenToMap(width/2, height/2, map_x, map_y);
}
Position MapCanvas::GetCursorPosition() const
{
return Position(last_cursor_map_x, last_cursor_map_y, floor);
}
void MapCanvas::UpdatePositionStatus(int x, int y)
{
if(x == -1) x = cursor_x;
if(y == -1) y = cursor_y;
int map_x, map_y;
ScreenToMap(x, y, &map_x, &map_y);
wxString ss;
ss << "x: " << map_x << " y:" << map_y << " z:" << floor;
g_gui.root->SetStatusText(ss,2);
ss = "";
Tile* tile = editor.getMap().getTile(map_x, map_y, floor);
if(tile) {
if(tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) {
ss << "Spawn radius: " << tile->spawn->getSize();
} else if(tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) {
ss << (tile->creature->isNpc()? "NPC" : "Monster");
ss << " \"" << wxstr(tile->creature->getName()) << "\" spawntime: " << tile->creature->getSpawnTime();
} else if(Item* item = tile->getTopItem()) {
ss << "Item \"" << wxstr(item->getName()) << "\"";
ss << " id:" << item->getID();
ss << " cid:" << item->getClientID();
if(item->getUniqueID()) ss << " uid:" << item->getUniqueID();
if(item->getActionID()) ss << " aid:" << item->getActionID();
if(item->hasWeight()) {
wxString s;
s.Printf("%.2f", item->getWeight());
ss << " weight: " << s;
}
} else {
ss << "Nothing";
}
} else {
ss << "Nothing";
}
if(editor.IsLive()) {
editor.GetLive().updateCursor(Position(map_x, map_y, floor));
}
g_gui.root->SetStatusText(ss, 1);
}
void MapCanvas::UpdateZoomStatus()
{
int percentage = (int)((1.0 / zoom) * 100);
wxString ss;
ss << "zoom: " << percentage << "%";
g_gui.root->SetStatusText(ss, 3);
}
void MapCanvas::OnMouseMove(wxMouseEvent& event)
{
if(screendragging) {
GetMapWindow()->ScrollRelative(int(g_settings.getFloat(Config::SCROLL_SPEED) * zoom*(event.GetX() - cursor_x)), int(g_settings.getFloat(Config::SCROLL_SPEED) * zoom*(event.GetY() - cursor_y)));
Refresh();
}
cursor_x = event.GetX();
cursor_y = event.GetY();
int mouse_map_x, mouse_map_y;
MouseToMap(&mouse_map_x,&mouse_map_y);
bool map_update = false;
if(last_cursor_map_x != mouse_map_x || last_cursor_map_y != mouse_map_y || last_cursor_map_z != floor) {
map_update = true;
}
last_cursor_map_x = mouse_map_x;
last_cursor_map_y = mouse_map_y;
last_cursor_map_z = floor;
if(map_update) {
UpdatePositionStatus(cursor_x, cursor_y);
UpdateZoomStatus();
}
if(g_gui.IsSelectionMode()) {
if(map_update && isPasting()) {
Refresh();
} else if(map_update && dragging) {
wxString ss;
int move_x = drag_start_x - mouse_map_x;
int move_y = drag_start_y - mouse_map_y;
int move_z = drag_start_z - floor;
ss << "Dragging " << -move_x << "," << -move_y << "," << -move_z;
g_gui.SetStatusText(ss);
Refresh();
} else if(boundbox_selection) {
if(map_update) {
wxString ss;
int move_x = std::abs(last_click_map_x - mouse_map_x);
int move_y = std::abs(last_click_map_y - mouse_map_y);
ss << "Selection " << move_x+1 << ":" << move_y+1;
g_gui.SetStatusText(ss);
}
Refresh();
}
} else { // Drawing mode
Brush* brush = g_gui.GetCurrentBrush();
if(map_update && drawing && brush) {
if(brush->isDoodad()) {
if(event.ControlDown()) {
PositionVector tilestodraw;
getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, nullptr);
editor.undraw(tilestodraw, event.ShiftDown() || event.AltDown());
} else {
editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.ShiftDown() || event.AltDown());
}
} else if(brush->isDoor()) {
if(!brush->canDraw(&editor.getMap(), Position(mouse_map_x, mouse_map_y, floor))) {
// We don't have to waste an action in this case...
} else {
PositionVector tilestodraw;
PositionVector tilestoborder;
tilestodraw.push_back(Position(mouse_map_x, mouse_map_y, floor));
tilestoborder.push_back(Position(mouse_map_x , mouse_map_y - 1, floor));
tilestoborder.push_back(Position(mouse_map_x - 1, mouse_map_y , floor));
tilestoborder.push_back(Position(mouse_map_x , mouse_map_y + 1, floor));
tilestoborder.push_back(Position(mouse_map_x + 1, mouse_map_y , floor));
if(event.ControlDown()) {
editor.undraw(tilestodraw, tilestoborder, event.AltDown());
} else {
editor.draw(tilestodraw, tilestoborder, event.AltDown());
}
}
} else if(brush->needBorders()) {
PositionVector tilestodraw, tilestoborder;
getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, &tilestoborder);
if(event.ControlDown()) {
editor.undraw(tilestodraw, tilestoborder, event.AltDown());
} else {
editor.draw(tilestodraw, tilestoborder, event.AltDown());
}
} else if(brush->oneSizeFitsAll()) {
drawing = true;
PositionVector tilestodraw;
tilestodraw.push_back(Position(mouse_map_x,mouse_map_y, floor));
if(event.ControlDown()) {
editor.undraw(tilestodraw, event.AltDown());
} else {
editor.draw(tilestodraw, event.AltDown());
}
} else { // No borders
PositionVector tilestodraw;
for(int y = -g_gui.GetBrushSize(); y <= g_gui.GetBrushSize(); y++) {
for(int x = -g_gui.GetBrushSize(); x <= g_gui.GetBrushSize(); x++) {
if(g_gui.GetBrushShape() == BRUSHSHAPE_SQUARE) {
tilestodraw.push_back(Position(mouse_map_x+x,mouse_map_y+y, floor));
} else if(g_gui.GetBrushShape() == BRUSHSHAPE_CIRCLE) {
double distance = sqrt(double(x*x) + double(y*y));
if(distance < g_gui.GetBrushSize()+0.005) {
tilestodraw.push_back(Position(mouse_map_x+x,mouse_map_y+y, floor));
}
}
}
}
if(event.ControlDown()) {
editor.undraw(tilestodraw, event.AltDown());
} else {
editor.draw(tilestodraw, event.AltDown());
}
}
// Create newd doodad layout (does nothing if a non-doodad brush is selected)
g_gui.FillDoodadPreviewBuffer();
g_gui.RefreshView();
} else if(dragging_draw) {
g_gui.RefreshView();
} else if(map_update && brush) {
Refresh();
}
}
}
void MapCanvas::OnMouseLeftRelease(wxMouseEvent& event)
{
OnMouseActionRelease(event);
}
void MapCanvas::OnMouseLeftClick(wxMouseEvent& event)
{
OnMouseActionClick(event);
}
void MapCanvas::OnMouseLeftDoubleClick(wxMouseEvent& event)
{
if(!g_settings.getInteger(Config::DOUBLECLICK_PROPERTIES)) {
return;
}
Map& map = editor.getMap();
int mouse_map_x, mouse_map_y;
ScreenToMap(event.GetX(), event.GetY(), &mouse_map_x, &mouse_map_y);
const Tile* tile = map.getTile(mouse_map_x, mouse_map_y, floor);
if(tile && tile->size() > 0) {
Tile* new_tile = tile->deepCopy(map);
wxDialog* dialog = nullptr;
if(new_tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) {
dialog = newd OldPropertiesWindow(g_gui.root, &map, new_tile, new_tile->spawn);
} else if(new_tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) {
dialog = newd OldPropertiesWindow(g_gui.root, &map, new_tile, new_tile->creature);
} else if(Item* item = new_tile->getTopItem()) {
if(map.getVersion().otbm >= MAP_OTBM_4) {
dialog = newd PropertiesWindow(g_gui.root, &map, new_tile, item);
} else {
dialog = newd OldPropertiesWindow(g_gui.root, &map, new_tile, item);
}
} else {
delete new_tile;
return;
}
int ret = dialog->ShowModal();
if(ret != 0) {
Action* action = editor.createAction(ACTION_CHANGE_PROPERTIES);
action->addChange(newd Change(new_tile));
editor.addAction(action);
} else {
// Cancel!
delete new_tile;
}
dialog->Destroy();
}
}
void MapCanvas::OnMouseCenterClick(wxMouseEvent& event)
{
if(g_settings.getInteger(Config::SWITCH_MOUSEBUTTONS)) {
OnMousePropertiesClick(event);
} else {
OnMouseCameraClick(event);
}
}
void MapCanvas::OnMouseCenterRelease(wxMouseEvent& event)
{
if(g_settings.getInteger(Config::SWITCH_MOUSEBUTTONS)) {
OnMousePropertiesRelease(event);
} else {
OnMouseCameraRelease(event);
}
}
void MapCanvas::OnMouseRightClick(wxMouseEvent& event)
{
if(g_settings.getInteger(Config::SWITCH_MOUSEBUTTONS)) {
OnMouseCameraClick(event);
} else {
OnMousePropertiesClick(event);
}
}
void MapCanvas::OnMouseRightRelease(wxMouseEvent& event)
{
if(g_settings.getInteger(Config::SWITCH_MOUSEBUTTONS)) {
OnMouseCameraRelease(event);
} else {
OnMousePropertiesRelease(event);
}
}
void MapCanvas::OnMouseActionClick(wxMouseEvent& event)
{
SetFocus();
int mouse_map_x, mouse_map_y;
ScreenToMap(event.GetX(), event.GetY(), &mouse_map_x, &mouse_map_y);
if(event.ControlDown() && event.AltDown()) {
Tile* tile = editor.getMap().getTile(mouse_map_x, mouse_map_y, floor);
if(tile && tile->size() > 0) {
Item* item = tile->getTopItem();
if(item && item->getRAWBrush())
g_gui.SelectBrush(item->getRAWBrush(), TILESET_RAW);
}
} else if(g_gui.IsSelectionMode()) {
Selection& selection = editor.getSelection();
if(isPasting()) {
// Set paste to false (no rendering etc.)
EndPasting();
// Paste to the map
editor.copybuffer.paste(editor, Position(mouse_map_x, mouse_map_y, floor));
// Start dragging
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
} else do {
boundbox_selection = false;
if(event.ShiftDown()) {
boundbox_selection = true;
if(!event.ControlDown()) {
selection.start(Selection::NONE, ACTION_UNSELECT); // Start selection session
selection.clear(); // Clear out selection
selection.finish(); // End selection session
selection.updateSelectionCount();
}
} else if(event.ControlDown()) {
Tile* tile = editor.getMap().getTile(mouse_map_x, mouse_map_y, floor);
if(tile) {
if(tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) {
selection.start(); // Start selection session
if(tile->spawn->isSelected()) {
selection.remove(tile, tile->spawn);
} else {
selection.add(tile, tile->spawn);
}
selection.finish(); // Finish selection session
selection.updateSelectionCount();
} else if(tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) {
selection.start(); // Start selection session
if(tile->creature->isSelected()) {
selection.remove(tile, tile->creature);
} else {
selection.add(tile, tile->creature);
}
selection.finish(); // Finish selection session
selection.updateSelectionCount();
} else {
Item* item = tile->getTopItem();
if(item) {
selection.start(); // Start selection session
if(item->isSelected()) {
selection.remove(tile, item);
} else {
selection.add(tile, item);
}
selection.finish(); // Finish selection session
selection.updateSelectionCount();
}
}
}
} else {
Tile* tile = editor.getMap().getTile(mouse_map_x, mouse_map_y, floor);
if(!tile) {
selection.start(Selection::NONE, ACTION_UNSELECT); // Start selection session
selection.clear(); // Clear out selection
selection.finish(); // End selection session
selection.updateSelectionCount();
} else if(tile->isSelected()) {
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
} else {
selection.start(); // Start a selection session
selection.clear();
selection.commit();
if(tile->spawn && g_settings.getInteger(Config::SHOW_SPAWNS)) {
selection.add(tile, tile->spawn);
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
} else if(tile->creature && g_settings.getInteger(Config::SHOW_CREATURES)) {
selection.add(tile, tile->creature);
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
} else {
Item* item = tile->getTopItem();
if(item) {
selection.add(tile, item);
dragging = true;
drag_start_x = mouse_map_x;
drag_start_y = mouse_map_y;
drag_start_z = floor;
}
}
selection.finish(); // Finish the selection session
selection.updateSelectionCount();
}
}
} while(false);
} else if(g_gui.GetCurrentBrush()) { // Drawing mode
Brush* brush = g_gui.GetCurrentBrush();
if(event.ShiftDown() && brush->canDrag()) {
dragging_draw = true;
} else {
if(g_gui.GetBrushSize() == 0 && !brush->oneSizeFitsAll()) {
drawing = true;
} else {
drawing = g_gui.GetCurrentBrush()->canSmear();
}
if(brush->isWall()) {
if(event.AltDown() && g_gui.GetBrushSize() == 0) {
// z0mg, just clicked a tile, shift variaton.
if(event.ControlDown()) {
editor.undraw(Position(mouse_map_x, mouse_map_y, floor), event.AltDown());
} else {
editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.AltDown());
}
} else {
PositionVector tilestodraw;
PositionVector tilestoborder;
int start_map_x = mouse_map_x - g_gui.GetBrushSize();
int start_map_y = mouse_map_y - g_gui.GetBrushSize();
int end_map_x = mouse_map_x + g_gui.GetBrushSize();
int end_map_y = mouse_map_y + g_gui.GetBrushSize();
for(int y = start_map_y -1; y <= end_map_y + 1; ++y) {
for(int x = start_map_x - 1; x <= end_map_x + 1; ++x) {
if((x <= start_map_x+1 || x >= end_map_x-1) || (y <= start_map_y+1 || y >= end_map_y-1)) {
tilestoborder.push_back(Position(x,y,floor));
}
if(((x == start_map_x || x == end_map_x) || (y == start_map_y || y == end_map_y)) &&
((x >= start_map_x && x <= end_map_x) && (y >= start_map_y && y <= end_map_y))) {
tilestodraw.push_back(Position(x,y,floor));
}
}
}
if(event.ControlDown()) {
editor.undraw(tilestodraw, tilestoborder, event.AltDown());
} else {
editor.draw(tilestodraw, tilestoborder, event.AltDown());
}
}
} else if(brush->isDoor()) {
PositionVector tilestodraw;
PositionVector tilestoborder;
tilestodraw.push_back(Position(mouse_map_x, mouse_map_y, floor));
tilestoborder.push_back(Position(mouse_map_x , mouse_map_y - 1, floor));
tilestoborder.push_back(Position(mouse_map_x - 1, mouse_map_y , floor));
tilestoborder.push_back(Position(mouse_map_x , mouse_map_y + 1, floor));
tilestoborder.push_back(Position(mouse_map_x + 1, mouse_map_y , floor));
if(event.ControlDown()) {
editor.undraw(tilestodraw, tilestoborder, event.AltDown());
} else {
editor.draw(tilestodraw, tilestoborder, event.AltDown());
}
} else if(brush->isDoodad() || brush->isSpawn() || brush->isCreature()) {
if(event.ControlDown()) {
if(brush->isDoodad()) {
PositionVector tilestodraw;
getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, nullptr);
editor.undraw(tilestodraw, event.AltDown());
} else {
editor.undraw(Position(mouse_map_x, mouse_map_y, floor), event.ShiftDown() || event.AltDown());
}
} else {
bool will_show_spawn = false;
if(brush->isSpawn() || brush->isCreature()) {
if(!g_settings.getBoolean(Config::SHOW_SPAWNS)) {
Tile* tile = editor.getMap().getTile(mouse_map_x, mouse_map_y, floor);
if(!tile || !tile->spawn) {
will_show_spawn = true;
}
}
}
editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.ShiftDown() || event.AltDown());
if(will_show_spawn) {
Tile* tile = editor.getMap().getTile(mouse_map_x, mouse_map_y, floor);
if(tile && tile->spawn) {
g_settings.setInteger(Config::SHOW_SPAWNS, true);
g_gui.UpdateMenubar();
}
}
}
} else {
if(brush->isGround() && event.AltDown()) {
replace_dragging = true;
Tile* draw_tile = editor.getMap().getTile(mouse_map_x, mouse_map_y, floor);
if(draw_tile) {
editor.replace_brush = draw_tile->getGroundBrush();
} else {
editor.replace_brush = nullptr;
}
}
if(brush->needBorders()) {
PositionVector tilestodraw;
PositionVector tilestoborder;
bool fill = keyCode == WXK_CONTROL_D && event.ControlDown() && brush->isGround();
getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, &tilestoborder, fill);
if(!fill && event.ControlDown()) {
editor.undraw(tilestodraw, tilestoborder, event.AltDown());
} else {
editor.draw(tilestodraw, tilestoborder, event.AltDown());
}
} else if(brush->oneSizeFitsAll()) {
if(brush->isHouseExit() || brush->isWaypoint()) {
editor.draw(Position(mouse_map_x, mouse_map_y, floor), event.AltDown());
} else {
PositionVector tilestodraw;
tilestodraw.push_back(Position(mouse_map_x,mouse_map_y, floor));
if(event.ControlDown()) {
editor.undraw(tilestodraw, event.AltDown());
} else {
editor.draw(tilestodraw, event.AltDown());
}
}
} else {
PositionVector tilestodraw;
getTilesToDraw(mouse_map_x, mouse_map_y, floor, &tilestodraw, nullptr);
if(event.ControlDown()) {
editor.undraw(tilestodraw, event.AltDown());
} else {
editor.draw(tilestodraw, event.AltDown());
}
}
}
// Change the doodad layout brush
g_gui.FillDoodadPreviewBuffer();
}
}
last_click_x = int(event.GetX()*zoom);
last_click_y = int(event.GetY()*zoom);
int start_x, start_y;
GetMapWindow()->GetViewStart(&start_x, &start_y);
last_click_abs_x = last_click_x + start_x;
last_click_abs_y = last_click_y + start_y;
last_click_map_x = mouse_map_x;
last_click_map_y = mouse_map_y;
last_click_map_z = floor;
g_gui.RefreshView();
g_gui.UpdateMinimap();
}
void MapCanvas::OnMouseActionRelease(wxMouseEvent& event)
{
int mouse_map_x, mouse_map_y;
ScreenToMap(event.GetX(), event.GetY(), &mouse_map_x, &mouse_map_y);
int move_x = last_click_map_x - mouse_map_x;
int move_y = last_click_map_y - mouse_map_y;
int move_z = last_click_map_z - floor;
if(g_gui.IsSelectionMode()) {
if(dragging && (move_x != 0 || move_y != 0 || move_z != 0)) {
editor.moveSelection(Position(move_x, move_y, move_z));
} else {
Selection& selection = editor.getSelection();
if(boundbox_selection) {
if(mouse_map_x == last_click_map_x && mouse_map_y == last_click_map_y && event.ControlDown()) {
// Mouse hasn't moved, do control+shift thingy!
Tile* tile = editor.getMap().getTile(mouse_map_x, mouse_map_y, floor);
if(tile) {
selection.start(); // Start a selection session
if(tile->isSelected()) {
selection.remove(tile);
} else {
selection.add(tile);
}
selection.finish(); // Finish the selection session
selection.updateSelectionCount();
}
} else {
// The cursor has moved, do some boundboxing!
if(last_click_map_x > mouse_map_x) {
int tmp = mouse_map_x;
mouse_map_x = last_click_map_x;
last_click_map_x = tmp;
}
if(last_click_map_y > mouse_map_y) {
int tmp = mouse_map_y;
mouse_map_y = last_click_map_y;
last_click_map_y = tmp;
}
int numtiles = 0;
int threadcount = std::max(g_settings.getInteger(Config::WORKER_THREADS), 1);
int start_x = 0, start_y = 0, start_z = 0;
int end_x = 0, end_y = 0, end_z = 0;
switch(g_settings.getInteger(Config::SELECTION_TYPE)) {
case SELECT_CURRENT_FLOOR: {
start_z = end_z = floor;
start_x = last_click_map_x;
start_y = last_click_map_y;
end_x = mouse_map_x;
end_y = mouse_map_y;
break;
}
case SELECT_ALL_FLOORS: {
start_x = last_click_map_x;
start_y = last_click_map_y;
start_z = rme::MapMaxLayer;
end_x = mouse_map_x;
end_y = mouse_map_y;
end_z = floor;