tibia-rme/source/map_tab.cpp

122 lines
3 KiB
C++
Raw Permalink Normal View History

//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
2020-07-30 11:42:28 -03:00
// 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 <thread>
#ifdef __linux__
#include <malloc.h>
#endif
#include "gui.h"
#include "editor.h"
#include "map.h"
#include "sprites.h"
#include "map_tab.h"
#include "editor_tabs.h"
#include "map_display.h"
MapTab::MapTab(MapTabbook* aui, Editor* editor) :
EditorTab(),
MapWindow(aui->notebook, *editor),
2023-10-09 19:12:16 -07:00
aui(aui) {
iref = newd InternalReference;
iref->editor = editor;
iref->owner_count = 1;
aui->AddTab(this, true);
FitToMap();
}
MapTab::MapTab(const MapTab* other) :
EditorTab(),
MapWindow(other->aui->notebook, *other->iref->editor),
aui(other->aui),
2023-10-09 19:12:16 -07:00
iref(other->iref) {
iref->owner_count++;
aui->AddTab(this, true);
FitToMap();
int x, y;
other->GetCanvas()->GetScreenCenter(&x, &y);
SetScreenCenterPosition(Position(x, y, other->GetCanvas()->GetFloor()));
}
2023-10-09 19:12:16 -07:00
MapTab::~MapTab() {
iref->owner_count--;
2023-10-09 19:12:16 -07:00
if (iref->owner_count <= 0) {
Editor* ed = iref->editor;
iref->editor = nullptr;
delete iref;
if (ed->IsLive()) {
ed->CloseLiveServer();
}
std::thread([ed]() {
delete ed;
#ifdef __linux__
malloc_trim(0);
#endif
}).detach();
}
}
2023-10-09 19:12:16 -07:00
bool MapTab::IsUniqueReference() const {
return iref->owner_count == 1;
}
2023-10-09 19:12:16 -07:00
wxWindow* MapTab::GetWindow() const {
return const_cast<MapTab*>(this);
}
2023-10-09 19:12:16 -07:00
MapCanvas* MapTab::GetCanvas() const {
return canvas;
}
2023-10-09 19:12:16 -07:00
MapWindow* MapTab::GetView() const {
return const_cast<MapWindow*>((const MapWindow*)this);
}
2023-10-09 19:12:16 -07:00
wxString MapTab::GetTitle() const {
wxString ss;
2023-10-09 19:12:16 -07:00
const Map &map = iref->editor->getMap();
feat: synchronizing commits with the official rme repository (#36) * Show indicators for pickupable and moveable items * Fix: drawing always refreshing ui * Fix crash on invalid friend for wallbrush * Option to remove empty spawns * Draws position indicator, some code cleanup * Teleport copy/paste improvements * Fix flood fill * Add function to get minimap/8bit color * Small code cleanup * Cleanup Position * Code cleanup and small optimizations * Code cleanup * Code cleanup and small optimizations (#406) * Cleanup and cast functions. * Avoid adding a new Unique ID if it already exists * Code cleanup and small optimizations * More changes and cleanup * Changes and cleanup * Some changes * Fix copy position. * Only show uid/aid alert if it really changed * Add actions history panel * Does not draw tooltips on minimap mode * Use constexpr * Replace items fix (#408) * Draw grid small optimization * Small change in selection box and Fix #409 * Fix some xpm * Ingame box improvements, add lights support. * Fix go to previous position (#410) * Fix depot crash (#411) * Fix XPMs * Export minimap as .otmm (otclient format) or .png (#413) * Fix glitch after drawing secondary map * fix * Update about_window.cpp * sonar * fix Minimap and progress bar * fix erro load items.xml * fix * fix doodad brush * fix: slightly more accurate house size estimation * feat: update items.otb and items.xml * fix: bad merge * Revert "feat: update items.otb and items.xml" This reverts commit 40f1edc70f17c423282d546a41541a8fe9b92dcc. --------- Co-authored-by: Nailson <Mignari@users.noreply.github.com> Co-authored-by: wtver <51377408+maattch@users.noreply.github.com> Co-authored-by: Majesty <32709570+majestyotbr@users.noreply.github.com> Co-authored-by: Luan Santos <github@luan.sh>
2023-10-09 23:02:37 -03:00
ss << wxstr(map.getName()) << (map.hasChanged() ? "*" : "");
return ss;
}
2023-10-09 19:12:16 -07:00
Editor* MapTab::GetEditor() const {
return &editor;
}
2023-10-09 19:12:16 -07:00
Map* MapTab::GetMap() const {
feat: synchronizing commits with the official rme repository (#36) * Show indicators for pickupable and moveable items * Fix: drawing always refreshing ui * Fix crash on invalid friend for wallbrush * Option to remove empty spawns * Draws position indicator, some code cleanup * Teleport copy/paste improvements * Fix flood fill * Add function to get minimap/8bit color * Small code cleanup * Cleanup Position * Code cleanup and small optimizations * Code cleanup * Code cleanup and small optimizations (#406) * Cleanup and cast functions. * Avoid adding a new Unique ID if it already exists * Code cleanup and small optimizations * More changes and cleanup * Changes and cleanup * Some changes * Fix copy position. * Only show uid/aid alert if it really changed * Add actions history panel * Does not draw tooltips on minimap mode * Use constexpr * Replace items fix (#408) * Draw grid small optimization * Small change in selection box and Fix #409 * Fix some xpm * Ingame box improvements, add lights support. * Fix go to previous position (#410) * Fix depot crash (#411) * Fix XPMs * Export minimap as .otmm (otclient format) or .png (#413) * Fix glitch after drawing secondary map * fix * Update about_window.cpp * sonar * fix Minimap and progress bar * fix erro load items.xml * fix * fix doodad brush * fix: slightly more accurate house size estimation * feat: update items.otb and items.xml * fix: bad merge * Revert "feat: update items.otb and items.xml" This reverts commit 40f1edc70f17c423282d546a41541a8fe9b92dcc. --------- Co-authored-by: Nailson <Mignari@users.noreply.github.com> Co-authored-by: wtver <51377408+maattch@users.noreply.github.com> Co-authored-by: Majesty <32709570+majestyotbr@users.noreply.github.com> Co-authored-by: Luan Santos <github@luan.sh>
2023-10-09 23:02:37 -03:00
return &editor.getMap();
}
2023-10-09 19:12:16 -07:00
void MapTab::VisibilityCheck() {
EditorTab* editorTab = aui->GetCurrentTab();
MapTab* mapTab = dynamic_cast<MapTab*>(editorTab);
UpdateDialogs(mapTab && HasSameReference(mapTab));
}
2023-10-09 19:12:16 -07:00
void MapTab::OnSwitchEditorMode(EditorMode mode) {
gem->SetSprite(mode == DRAWING_MODE ? EDITOR_SPRITE_DRAWING_GEM : EDITOR_SPRITE_SELECTION_GEM);
if (mode == SELECTION_MODE) {
canvas->EnterSelectionMode();
2023-10-09 19:12:16 -07:00
} else {
canvas->EnterDrawingMode();
2023-10-09 19:12:16 -07:00
}
}