tibia-rme/source/map_window.cpp

231 lines
6.4 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.
//
2020-07-30 11:42:28 -03:00
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
2020-07-30 11:42:28 -03:00
// 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
2020-07-30 11:42:28 -03:00
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#include "main.h"
#include "map_window.h"
#include "gui.h"
#include "sprites.h"
#include "editor.h"
2023-10-09 19:12:16 -07:00
MapWindow::MapWindow(wxWindow* parent, Editor &editor) :
wxPanel(parent, PANE_MAIN),
editor(editor),
2023-10-09 19:12:16 -07:00
replaceItemsDialog(nullptr) {
int GL_settings[3];
GL_settings[0] = WX_GL_RGBA;
GL_settings[1] = WX_GL_DOUBLEBUFFER;
GL_settings[2] = 0;
canvas = newd MapCanvas(this, editor, GL_settings);
vScroll = newd MapScrollBar(this, MAP_WINDOW_VSCROLL, wxVERTICAL, canvas);
hScroll = newd MapScrollBar(this, MAP_WINDOW_HSCROLL, wxHORIZONTAL, canvas);
gem = newd DCButton(this, MAP_WINDOW_GEM, wxDefaultPosition, DC_BTN_NORMAL, RENDER_SIZE_16x16, EDITOR_SPRITE_SELECTION_GEM);
2012-06-30 11:41:07 +02:00
wxFlexGridSizer* topsizer = newd wxFlexGridSizer(2, 0, 0);
topsizer->AddGrowableCol(0);
topsizer->AddGrowableRow(0);
topsizer->Add(canvas, wxSizerFlags(1).Expand());
topsizer->Add(vScroll, wxSizerFlags(1).Expand());
topsizer->Add(hScroll, wxSizerFlags(1).Expand());
topsizer->Add(gem, wxSizerFlags(1));
SetSizerAndFit(topsizer);
}
2023-10-09 19:12:16 -07:00
MapWindow::~MapWindow() {
2015-12-06 11:42:37 -03:00
////
}
2023-10-09 19:12:16 -07:00
void MapWindow::ShowReplaceItemsDialog(bool selectionOnly) {
if (replaceItemsDialog) {
return;
2023-10-09 19:12:16 -07:00
}
replaceItemsDialog = new ReplaceItemsDialog(this, selectionOnly);
2024-06-07 18:16:45 -03:00
replaceItemsDialog->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MapWindow::OnReplaceItemsDialogClose), nullptr, this);
replaceItemsDialog->Show();
}
2023-10-09 19:12:16 -07:00
void MapWindow::CloseReplaceItemsDialog() {
if (replaceItemsDialog) {
replaceItemsDialog->Close();
2023-10-09 19:12:16 -07:00
}
}
2023-10-09 19:12:16 -07:00
void MapWindow::OnReplaceItemsDialogClose(wxCloseEvent &event) {
if (replaceItemsDialog) {
2024-06-07 18:16:45 -03:00
replaceItemsDialog->Disconnect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(MapWindow::OnReplaceItemsDialogClose), nullptr, this);
replaceItemsDialog->Destroy();
replaceItemsDialog = nullptr;
}
}
2023-10-09 19:12:16 -07:00
void MapWindow::SetSize(int x, int y, bool center) {
if (x == 0 || y == 0) {
return;
}
int windowSizeX;
int windowSizeY;
canvas->GetSize(&windowSizeX, &windowSizeY);
2023-10-09 19:12:16 -07:00
hScroll->SetScrollbar(center ? (x - windowSizeX) / 2 : hScroll->GetThumbPosition(), windowSizeX / x, x, windowSizeX / x);
vScroll->SetScrollbar(center ? (y - windowSizeY) / 2 : vScroll->GetThumbPosition(), windowSizeY / y, y, windowSizeX / y);
// wxPanel::SetSize(x, y);
}
2023-10-09 19:12:16 -07:00
void MapWindow::UpdateScrollbars(int nx, int ny) {
// nx and ny are size of this window
hScroll->SetScrollbar(hScroll->GetThumbPosition(), nx / std::max(1, hScroll->GetRange()), std::max(1, hScroll->GetRange()), 96);
vScroll->SetScrollbar(vScroll->GetThumbPosition(), ny / std::max(1, vScroll->GetRange()), std::max(1, vScroll->GetRange()), 96);
}
2023-10-09 19:12:16 -07:00
void MapWindow::UpdateDialogs(bool show) {
if (replaceItemsDialog) {
replaceItemsDialog->Show(show);
2023-10-09 19:12:16 -07:00
}
}
2023-10-09 19:12:16 -07:00
void MapWindow::GetViewStart(int* x, int* y) {
*x = hScroll->GetThumbPosition();
*y = vScroll->GetThumbPosition();
}
2023-10-09 19:12:16 -07:00
void MapWindow::GetViewSize(int* x, int* y) {
canvas->GetSize(x, y);
*x *= canvas->GetContentScaleFactor();
*y *= canvas->GetContentScaleFactor();
}
2023-10-09 19:12:16 -07:00
void MapWindow::FitToMap() {
const Map &map = 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
SetSize(map.getWidth() * rme::TileSize, map.getHeight() * rme::TileSize, true);
}
2023-10-09 19:12:16 -07:00
Position MapWindow::GetScreenCenterPosition() {
int x, y;
canvas->GetScreenCenter(&x, &y);
return Position(x, y, canvas->GetFloor());
}
2023-10-09 19:12:16 -07:00
void MapWindow::SetScreenCenterPosition(const Position &position, bool showIndicator) {
if (!position.isValid()) {
return;
2023-10-09 19:12:16 -07:00
}
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
int x = position.x * rme::TileSize;
int y = position.y * rme::TileSize;
int z = position.z;
2023-10-09 19:12:16 -07:00
if (position.z < 8) {
// Compensate for floor offset above ground
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
x -= (rme::MapGroundLayer - z) * rme::TileSize;
y -= (rme::MapGroundLayer - z) * rme::TileSize;
}
2023-10-09 19:12:16 -07:00
const Position &center = GetScreenCenterPosition();
if (previous_position != center) {
previous_position.x = center.x;
previous_position.y = center.y;
previous_position.z = center.z;
}
Scroll(x, y, true);
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
canvas->ChangeFloor(z);
2023-10-09 19:12:16 -07:00
if (showIndicator) {
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
canvas->ShowPositionIndicator(position);
2023-10-09 19:12:16 -07:00
}
}
2023-10-09 19:12:16 -07:00
void MapWindow::GoToPreviousCenterPosition() {
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
SetScreenCenterPosition(previous_position, true);
}
2023-10-09 19:12:16 -07:00
void MapWindow::Scroll(int x, int y, bool center) {
if (center) {
int windowSizeX, windowSizeY;
canvas->GetSize(&windowSizeX, &windowSizeY);
x -= int((windowSizeX * g_gui.GetCurrentZoom()) / 2.0);
y -= int((windowSizeY * g_gui.GetCurrentZoom()) / 2.0);
}
hScroll->SetThumbPosition(x);
vScroll->SetThumbPosition(y);
g_gui.UpdateMinimap();
}
2023-10-09 19:12:16 -07:00
void MapWindow::ScrollRelative(int x, int y) {
hScroll->SetThumbPosition(hScroll->GetThumbPosition() + x);
vScroll->SetThumbPosition(vScroll->GetThumbPosition() + y);
g_gui.UpdateMinimap();
}
2023-10-09 19:12:16 -07:00
void MapWindow::OnGem(wxCommandEvent &WXUNUSED(event)) {
g_gui.SwitchMode();
}
2023-10-09 19:12:16 -07:00
void MapWindow::OnSize(wxSizeEvent &event) {
UpdateScrollbars(event.GetSize().GetWidth(), event.GetSize().GetHeight());
event.Skip();
}
2023-10-09 19:12:16 -07:00
void MapWindow::OnScroll(wxScrollEvent &event) {
Refresh();
}
2023-10-09 19:12:16 -07:00
void MapWindow::OnScrollLineDown(wxScrollEvent &event) {
if (event.GetOrientation() == wxHORIZONTAL) {
ScrollRelative(96, 0);
} else {
ScrollRelative(0, 96);
}
Refresh();
}
2023-10-09 19:12:16 -07:00
void MapWindow::OnScrollLineUp(wxScrollEvent &event) {
if (event.GetOrientation() == wxHORIZONTAL) {
ScrollRelative(-96, 0);
} else {
ScrollRelative(0, -96);
}
Refresh();
}
2023-10-09 19:12:16 -07:00
void MapWindow::OnScrollPageDown(wxScrollEvent &event) {
if (event.GetOrientation() == wxHORIZONTAL) {
ScrollRelative(5 * 96, 0);
} else {
ScrollRelative(0, 5 * 96);
}
Refresh();
}
2023-10-09 19:12:16 -07:00
void MapWindow::OnScrollPageUp(wxScrollEvent &event) {
if (event.GetOrientation() == wxHORIZONTAL) {
ScrollRelative(-5 * 96, 0);
} else {
ScrollRelative(0, -5 * 96);
}
Refresh();
}