mirror of
https://github.com/opentibiabr/remeres-map-editor
synced 2026-08-15 18:26:04 -04:00
212 lines
7.2 KiB
C++
212 lines
7.2 KiB
C++
//////////////////////////////////////////////////////////////////////
|
|
// 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 "map.h"
|
|
#include "gui.h"
|
|
#include "raw_brush.h"
|
|
#include "tile.h"
|
|
#include "graphics.h"
|
|
#include "gui.h"
|
|
#include "browse_tile_window.h"
|
|
|
|
// ============================================================================
|
|
//
|
|
|
|
class BrowseTileListBox : public wxVListBox {
|
|
public:
|
|
BrowseTileListBox(wxWindow* parent, wxWindowID id, Tile* tile);
|
|
~BrowseTileListBox();
|
|
|
|
void OnDrawItem(wxDC &dc, const wxRect &rect, size_t index) const;
|
|
wxCoord OnMeasureItem(size_t index) const;
|
|
Item* GetSelectedItem();
|
|
void RemoveSelected();
|
|
|
|
protected:
|
|
void UpdateItems();
|
|
|
|
typedef std::map<int, Item*> ItemsMap;
|
|
ItemsMap items;
|
|
Tile* edit_tile;
|
|
};
|
|
|
|
BrowseTileListBox::BrowseTileListBox(wxWindow* parent, wxWindowID id, Tile* tile) :
|
|
wxVListBox(parent, id, wxDefaultPosition, wxSize(200, 180), wxLB_MULTIPLE), edit_tile(tile) {
|
|
UpdateItems();
|
|
}
|
|
|
|
BrowseTileListBox::~BrowseTileListBox() {
|
|
////
|
|
}
|
|
|
|
void BrowseTileListBox::OnDrawItem(wxDC &dc, const wxRect &rect, size_t n) const {
|
|
ItemsMap::const_iterator item_iterator = items.find(int(n));
|
|
Item* item = item_iterator->second;
|
|
|
|
Sprite* sprite = g_gui.gfx.getSprite(item->getClientID());
|
|
if (sprite) {
|
|
sprite->DrawTo(&dc, SPRITE_SIZE_32x32, rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight());
|
|
}
|
|
|
|
if (IsSelected(n)) {
|
|
item->select();
|
|
if (HasFocus()) {
|
|
dc.SetTextForeground(wxColor(0xFF, 0xFF, 0xFF));
|
|
} else {
|
|
dc.SetTextForeground(wxColor(0x00, 0x00, 0xFF));
|
|
}
|
|
} else {
|
|
item->deselect();
|
|
dc.SetTextForeground(wxColor(0x00, 0x00, 0x00));
|
|
}
|
|
|
|
wxString label;
|
|
label << item->getID() << " - " << item->getName();
|
|
dc.DrawText(label, rect.GetX() + 40, rect.GetY() + 6);
|
|
}
|
|
|
|
wxCoord BrowseTileListBox::OnMeasureItem(size_t n) const {
|
|
return 32;
|
|
}
|
|
|
|
Item* BrowseTileListBox::GetSelectedItem() {
|
|
if (GetItemCount() == 0 || GetSelectedCount() == 0) {
|
|
return nullptr;
|
|
}
|
|
|
|
return edit_tile->getTopSelectedItem();
|
|
}
|
|
|
|
void BrowseTileListBox::RemoveSelected() {
|
|
if (GetItemCount() == 0 || GetSelectedCount() == 0) {
|
|
return;
|
|
}
|
|
|
|
Clear();
|
|
items.clear();
|
|
|
|
// Delete the items from the tile
|
|
ItemVector tile_selection = edit_tile->popSelectedItems(true);
|
|
for (ItemVector::iterator iit = tile_selection.begin(); iit != tile_selection.end(); ++iit) {
|
|
delete *iit;
|
|
}
|
|
|
|
UpdateItems();
|
|
Refresh();
|
|
}
|
|
|
|
void BrowseTileListBox::UpdateItems() {
|
|
int n = 0;
|
|
for (ItemVector::reverse_iterator it = edit_tile->items.rbegin(); it != edit_tile->items.rend(); ++it) {
|
|
items[n] = (*it);
|
|
++n;
|
|
}
|
|
|
|
if (edit_tile->ground) {
|
|
items[n] = edit_tile->ground;
|
|
++n;
|
|
}
|
|
|
|
SetItemCount(n);
|
|
}
|
|
|
|
// ============================================================================
|
|
//
|
|
|
|
BEGIN_EVENT_TABLE(BrowseTileWindow, wxDialog)
|
|
EVT_BUTTON(wxID_REMOVE, BrowseTileWindow::OnClickDelete)
|
|
EVT_BUTTON(wxID_FIND, BrowseTileWindow::OnClickSelectRaw)
|
|
EVT_BUTTON(wxID_OK, BrowseTileWindow::OnClickOK)
|
|
EVT_BUTTON(wxID_CANCEL, BrowseTileWindow::OnClickCancel)
|
|
END_EVENT_TABLE()
|
|
|
|
BrowseTileWindow::BrowseTileWindow(wxWindow* parent, Tile* tile, wxPoint position /* = wxDefaultPosition */) :
|
|
wxDialog(parent, wxID_ANY, "Browse Field", position, wxSize(600, 400), wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER) {
|
|
std::shared_ptr<wxSizer> sizer = newd<wxBoxSizer>(wxVERTICAL);
|
|
item_list = newd<BrowseTileListBox>(this, wxID_ANY, tile);
|
|
sizer->Add(item_list.get(), wxSizerFlags(1).Expand());
|
|
|
|
wxString pos;
|
|
pos << "x=" << tile->getX() << ", y=" << tile->getY() << ", z=" << tile->getZ();
|
|
|
|
std::shared_ptr<wxSizer> infoSizer = newd<wxBoxSizer>(wxVERTICAL);
|
|
std::shared_ptr<wxBoxSizer> buttons = newd<wxBoxSizer>(wxHORIZONTAL);
|
|
delete_button = newd<wxButton>(this, wxID_REMOVE, "Delete");
|
|
delete_button->Enable(false);
|
|
buttons->Add(delete_button.get());
|
|
buttons->AddSpacer(5);
|
|
select_raw_button = newd<wxButton>(this, wxID_FIND, "Select RAW");
|
|
select_raw_button->Enable(false);
|
|
buttons->Add(select_raw_button.get());
|
|
infoSizer->Add(buttons.get());
|
|
infoSizer->AddSpacer(5);
|
|
infoSizer->Add(newd<wxStaticText>(this, wxID_ANY, "Position: " + pos).get(), wxSizerFlags(0).Left());
|
|
infoSizer->Add(item_count_txt = newd<wxStaticText>(this, wxID_ANY, "Item count: " + i2ws(item_list->GetItemCount())).get(), wxSizerFlags(0).Left());
|
|
infoSizer->Add(newd<wxStaticText>(this, wxID_ANY, "Protection zone: " + b2yn(tile->isPZ())).get(), wxSizerFlags(0).Left());
|
|
infoSizer->Add(newd<wxStaticText>(this, wxID_ANY, "No PvP: " + b2yn(tile->getMapFlags() & TILESTATE_NOPVP)).get(), wxSizerFlags(0).Left());
|
|
infoSizer->Add(newd<wxStaticText>(this, wxID_ANY, "No logout: " + b2yn(tile->getMapFlags() & TILESTATE_NOLOGOUT)).get(), wxSizerFlags(0).Left());
|
|
infoSizer->Add(newd<wxStaticText>(this, wxID_ANY, "PvP zone: " + b2yn(tile->getMapFlags() & TILESTATE_PVPZONE)).get(), wxSizerFlags(0).Left());
|
|
infoSizer->Add(newd<wxStaticText>(this, wxID_ANY, "House: " + b2yn(tile->isHouseTile())).get(), wxSizerFlags(0).Left());
|
|
|
|
sizer->Add(infoSizer.get(), wxSizerFlags(0).Left().DoubleBorder());
|
|
|
|
// OK/Cancel buttons
|
|
std::shared_ptr<wxSizer> btnSizer = newd<wxBoxSizer>(wxHORIZONTAL);
|
|
btnSizer->Add(newd<wxButton>(this, wxID_OK, "OK").get(), wxSizerFlags(0).Center());
|
|
btnSizer->Add(newd<wxButton>(this, wxID_CANCEL, "Cancel").get(), wxSizerFlags(0).Center());
|
|
sizer->Add(btnSizer.get(), wxSizerFlags(0).Center().DoubleBorder());
|
|
|
|
SetSizerAndFit(sizer.get());
|
|
|
|
// Connect Events
|
|
item_list->Connect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(BrowseTileWindow::OnItemSelected), NULL, this);
|
|
}
|
|
|
|
BrowseTileWindow::~BrowseTileWindow() {
|
|
// Disconnect Events
|
|
item_list->Disconnect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(BrowseTileWindow::OnItemSelected), NULL, this);
|
|
}
|
|
|
|
void BrowseTileWindow::OnItemSelected(wxCommandEvent &WXUNUSED(event)) {
|
|
const size_t count = item_list->GetSelectedCount();
|
|
delete_button->Enable(count != 0);
|
|
select_raw_button->Enable(count == 1);
|
|
}
|
|
|
|
void BrowseTileWindow::OnClickDelete(wxCommandEvent &WXUNUSED(event)) {
|
|
item_list->RemoveSelected();
|
|
item_count_txt->SetLabelText("Item count: " + i2ws(item_list->GetItemCount()));
|
|
}
|
|
|
|
void BrowseTileWindow::OnClickSelectRaw(wxCommandEvent &WXUNUSED(event)) {
|
|
Item* item = item_list->GetSelectedItem();
|
|
if (item && item->getRAWBrush()) {
|
|
g_gui.SelectBrush(item->getRAWBrush(), TILESET_RAW);
|
|
}
|
|
|
|
EndModal(1);
|
|
}
|
|
|
|
void BrowseTileWindow::OnClickOK(wxCommandEvent &WXUNUSED(event)) {
|
|
EndModal(1);
|
|
}
|
|
|
|
void BrowseTileWindow::OnClickCancel(wxCommandEvent &WXUNUSED(event)) {
|
|
EndModal(0);
|
|
}
|