2015-01-19 00:44:47 -03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
// 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
|
2015-01-19 00:44:47 -03:00
|
|
|
// 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.
|
2016-09-29 19:24:45 -03:00
|
|
|
//
|
2020-07-30 11:42:28 -03:00
|
|
|
// Remere's Map Editor is distributed in the hope that it will be useful,
|
2015-01-19 00:44:47 -03:00
|
|
|
// 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
|
2015-01-19 00:44:47 -03:00
|
|
|
// GNU General Public License for more details.
|
2016-09-29 19:24:45 -03:00
|
|
|
//
|
2015-01-19 00:44:47 -03:00
|
|
|
// 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/>.
|
2015-01-19 00:44:47 -03:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
|
|
#include "map.h"
|
2016-04-24 12:14:38 -03:00
|
|
|
#include "gui.h"
|
|
|
|
|
#include "raw_brush.h"
|
2015-01-19 00:44:47 -03:00
|
|
|
#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;
|
2016-04-24 12:14:38 -03:00
|
|
|
Item* GetSelectedItem();
|
2015-01-21 13:41:44 -03:00
|
|
|
void RemoveSelected();
|
2015-01-19 00:44:47 -03:00
|
|
|
|
|
|
|
|
protected:
|
2015-01-21 13:41:44 -03:00
|
|
|
void UpdateItems();
|
|
|
|
|
|
2015-01-19 00:44:47 -03:00
|
|
|
typedef std::map<int, Item*> ItemsMap;
|
|
|
|
|
ItemsMap items;
|
2015-01-21 13:41:44 -03:00
|
|
|
Tile* edit_tile;
|
2015-01-19 00:44:47 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BrowseTileListBox::BrowseTileListBox(wxWindow* parent, wxWindowID id, Tile* tile) :
|
2015-01-24 13:34:52 -03:00
|
|
|
wxVListBox(parent, id, wxDefaultPosition, wxSize(200, 180), wxLB_MULTIPLE), edit_tile(tile)
|
2015-01-19 00:44:47 -03:00
|
|
|
{
|
2015-01-21 13:41:44 -03:00
|
|
|
UpdateItems();
|
2015-01-19 00:44:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BrowseTileListBox::~BrowseTileListBox()
|
|
|
|
|
{
|
2015-12-06 11:42:37 -03:00
|
|
|
////
|
2015-01-19 00:44:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowseTileListBox::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const
|
|
|
|
|
{
|
|
|
|
|
ItemsMap::const_iterator item_iterator = items.find(int(n));
|
2015-01-21 13:41:44 -03:00
|
|
|
Item* item = item_iterator->second;
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2016-09-29 20:30:54 -03:00
|
|
|
Sprite* sprite = g_gui.gfx.getSprite(item->getClientID());
|
2015-12-06 11:42:37 -03:00
|
|
|
if(sprite)
|
2015-01-19 00:44:47 -03:00
|
|
|
sprite->DrawTo(&dc, SPRITE_SIZE_32x32, rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight());
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
if(IsSelected(n)) {
|
2015-01-21 13:41:44 -03:00
|
|
|
item->select();
|
2016-03-17 07:09:40 -03:00
|
|
|
if(HasFocus())
|
|
|
|
|
dc.SetTextForeground(wxColor(0xFF, 0xFF, 0xFF));
|
|
|
|
|
else
|
|
|
|
|
dc.SetTextForeground(wxColor(0x00, 0x00, 0xFF));
|
2015-12-06 11:42:37 -03:00
|
|
|
} else {
|
2015-01-21 13:41:44 -03:00
|
|
|
item->deselect();
|
2015-01-23 17:54:11 -03:00
|
|
|
dc.SetTextForeground(wxColor(0x00, 0x00, 0x00));
|
2015-01-21 13:41:44 -03:00
|
|
|
}
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2015-01-19 20:46:21 -03:00
|
|
|
wxString label;
|
2016-11-05 15:28:14 +01:00
|
|
|
label << item->getID() << " - " << item->getName();
|
2015-01-19 20:46:21 -03:00
|
|
|
dc.DrawText(label, rect.GetX() + 40, rect.GetY() + 6);
|
2015-01-19 00:44:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxCoord BrowseTileListBox::OnMeasureItem(size_t n) const
|
|
|
|
|
{
|
|
|
|
|
return 32;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-24 12:14:38 -03:00
|
|
|
Item* BrowseTileListBox::GetSelectedItem()
|
|
|
|
|
{
|
|
|
|
|
if(GetItemCount() == 0 || GetSelectedCount() == 0)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
return edit_tile->getTopSelectedItem();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 13:41:44 -03:00
|
|
|
void BrowseTileListBox::RemoveSelected()
|
|
|
|
|
{
|
2015-12-06 11:42:37 -03:00
|
|
|
if(GetItemCount() == 0 || GetSelectedCount() == 0) return;
|
2015-01-21 13:41:44 -03:00
|
|
|
|
|
|
|
|
Clear();
|
|
|
|
|
items.clear();
|
|
|
|
|
|
|
|
|
|
// Delete the items from the tile
|
2020-12-20 20:48:36 -03:00
|
|
|
ItemVector tile_selection = edit_tile->popSelectedItems(true);
|
2015-12-06 11:42:37 -03:00
|
|
|
for(ItemVector::iterator iit = tile_selection.begin(); iit != tile_selection.end(); ++iit) {
|
2015-01-21 13:41:44 -03:00
|
|
|
delete *iit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateItems();
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowseTileListBox::UpdateItems()
|
|
|
|
|
{
|
|
|
|
|
int n = 0;
|
2015-12-06 11:42:37 -03:00
|
|
|
for(ItemVector::reverse_iterator it = edit_tile->items.rbegin(); it != edit_tile->items.rend(); ++it) {
|
2015-01-21 13:41:44 -03:00
|
|
|
items[n] = (*it);
|
|
|
|
|
++n;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
if(edit_tile->ground) {
|
2015-01-21 13:41:44 -03:00
|
|
|
items[n] = edit_tile->ground;
|
|
|
|
|
++n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetItemCount(n);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 00:44:47 -03:00
|
|
|
// ============================================================================
|
|
|
|
|
//
|
|
|
|
|
|
2015-01-21 13:41:44 -03:00
|
|
|
BEGIN_EVENT_TABLE(BrowseTileWindow, wxDialog)
|
|
|
|
|
EVT_BUTTON(wxID_REMOVE, BrowseTileWindow::OnClickDelete)
|
2016-04-24 12:14:38 -03:00
|
|
|
EVT_BUTTON(wxID_FIND, BrowseTileWindow::OnClickSelectRaw)
|
2015-01-21 13:41:44 -03:00
|
|
|
EVT_BUTTON(wxID_OK, BrowseTileWindow::OnClickOK)
|
|
|
|
|
EVT_BUTTON(wxID_CANCEL, BrowseTileWindow::OnClickCancel)
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
2016-04-24 12:14:38 -03:00
|
|
|
BrowseTileWindow::BrowseTileWindow(wxWindow* parent, Tile* tile, wxPoint position /* = wxDefaultPosition */) :
|
2015-01-19 00:44:47 -03:00
|
|
|
wxDialog(parent, wxID_ANY, "Browse Field", position, wxSize(600, 400), wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER)
|
|
|
|
|
{
|
|
|
|
|
wxSizer* sizer = newd wxBoxSizer(wxVERTICAL);
|
|
|
|
|
item_list = newd BrowseTileListBox(this, wxID_ANY, tile);
|
|
|
|
|
sizer->Add(item_list, wxSizerFlags(1).Expand());
|
|
|
|
|
|
|
|
|
|
wxString pos;
|
2016-11-05 15:28:14 +01:00
|
|
|
pos << "x=" << tile->getX() << ", y=" << tile->getY() << ", z=" << tile->getZ();
|
2015-01-19 00:44:47 -03:00
|
|
|
|
|
|
|
|
wxSizer* infoSizer = newd wxBoxSizer(wxVERTICAL);
|
2016-04-24 12:14:38 -03:00
|
|
|
wxBoxSizer* buttons = newd wxBoxSizer(wxHORIZONTAL);
|
2020-12-27 11:37:35 -03:00
|
|
|
delete_button = newd wxButton(this, wxID_REMOVE, "Delete");
|
|
|
|
|
delete_button->Enable(false);
|
|
|
|
|
buttons->Add(delete_button);
|
2016-04-24 12:14:38 -03:00
|
|
|
buttons->AddSpacer(5);
|
2020-12-27 11:37:35 -03:00
|
|
|
select_raw_button = newd wxButton(this, wxID_FIND, "Select RAW");
|
|
|
|
|
select_raw_button->Enable(false);
|
|
|
|
|
buttons->Add(select_raw_button);
|
2016-04-24 12:14:38 -03:00
|
|
|
infoSizer->Add(buttons);
|
2015-01-21 13:41:44 -03:00
|
|
|
infoSizer->AddSpacer(5);
|
2016-11-05 15:28:14 +01:00
|
|
|
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "Position: " + pos), wxSizerFlags(0).Left());
|
|
|
|
|
infoSizer->Add(item_count_txt = newd wxStaticText(this, wxID_ANY, "Item count: " + i2ws(item_list->GetItemCount())), wxSizerFlags(0).Left());
|
|
|
|
|
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "Protection zone: " + b2yn(tile->isPZ())), wxSizerFlags(0).Left());
|
|
|
|
|
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "No PvP: " + b2yn(tile->getMapFlags() & TILESTATE_NOPVP)), wxSizerFlags(0).Left());
|
|
|
|
|
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "No logout: " + b2yn(tile->getMapFlags() & TILESTATE_NOLOGOUT)), wxSizerFlags(0).Left());
|
|
|
|
|
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "PvP zone: " + b2yn(tile->getMapFlags() & TILESTATE_PVPZONE)), wxSizerFlags(0).Left());
|
|
|
|
|
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "House: " + b2yn(tile->isHouseTile())), wxSizerFlags(0).Left());
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2015-01-21 13:41:44 -03:00
|
|
|
sizer->Add(infoSizer, wxSizerFlags(0).Left().DoubleBorder());
|
|
|
|
|
|
|
|
|
|
// OK/Cancel buttons
|
|
|
|
|
wxSizer* btnSizer = newd wxBoxSizer(wxHORIZONTAL);
|
2016-11-05 15:28:14 +01:00
|
|
|
btnSizer->Add(newd wxButton(this, wxID_OK, "OK"), wxSizerFlags(0).Center());
|
|
|
|
|
btnSizer->Add(newd wxButton(this, wxID_CANCEL, "Cancel"), wxSizerFlags(0).Center());
|
2015-01-21 13:41:44 -03:00
|
|
|
sizer->Add(btnSizer, wxSizerFlags(0).Center().DoubleBorder());
|
2015-01-19 00:44:47 -03:00
|
|
|
|
|
|
|
|
SetSizerAndFit(sizer);
|
2020-12-27 11:37:35 -03:00
|
|
|
|
|
|
|
|
// Connect Events
|
|
|
|
|
item_list->Connect(wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler(BrowseTileWindow::OnItemSelected), NULL, this);
|
2015-01-19 00:44:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BrowseTileWindow::~BrowseTileWindow()
|
|
|
|
|
{
|
2020-12-27 11:37:35 -03:00
|
|
|
// 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);
|
2015-01-19 00:44:47 -03:00
|
|
|
}
|
|
|
|
|
|
2015-01-21 13:41:44 -03:00
|
|
|
void BrowseTileWindow::OnClickDelete(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
item_list->RemoveSelected();
|
2020-12-27 11:37:35 -03:00
|
|
|
item_count_txt->SetLabelText("Item count: " + i2ws(item_list->GetItemCount()));
|
2015-01-21 13:41:44 -03:00
|
|
|
}
|
|
|
|
|
|
2016-04-24 12:14:38 -03:00
|
|
|
void BrowseTileWindow::OnClickSelectRaw(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
Item* item = item_list->GetSelectedItem();
|
|
|
|
|
if(item && item->getRAWBrush())
|
2016-09-29 20:30:54 -03:00
|
|
|
g_gui.SelectBrush(item->getRAWBrush(), TILESET_RAW);
|
2016-04-24 12:14:38 -03:00
|
|
|
|
|
|
|
|
EndModal(1);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 13:41:44 -03:00
|
|
|
void BrowseTileWindow::OnClickOK(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
EndModal(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowseTileWindow::OnClickCancel(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
EndModal(0);
|
|
|
|
|
}
|
|
|
|
|
|