2012-06-29 16:44:26 +02: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
|
|
|
|
|
// 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/>.
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2012-06-29 16:44:26 +02:00
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
|
|
#include "container_properties_window.h"
|
|
|
|
|
|
|
|
|
|
#include "old_properties_window.h"
|
2012-07-20 16:32:57 +02:00
|
|
|
#include "properties_window.h"
|
2017-05-19 15:19:10 -03:00
|
|
|
#include "find_item_window.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
#include "gui.h"
|
|
|
|
|
#include "complexitem.h"
|
2012-07-20 16:32:57 +02:00
|
|
|
#include "map.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Container Item Button
|
|
|
|
|
// Displayed in the container object properties menu, needs some
|
|
|
|
|
// custom event handling for the right-click menu etcetera so we
|
|
|
|
|
// need to define a custom class for it.
|
|
|
|
|
|
2014-01-23 21:06:52 -02:00
|
|
|
std::unique_ptr<ContainerItemPopupMenu> ContainerItemButton::popup_menu;
|
2012-06-29 16:44:26 +02:00
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(ContainerItemButton, ItemButton)
|
|
|
|
|
EVT_LEFT_DOWN(ContainerItemButton::OnMouseDoubleLeftClick)
|
|
|
|
|
EVT_RIGHT_UP(ContainerItemButton::OnMouseRightRelease)
|
|
|
|
|
|
|
|
|
|
EVT_MENU(CONTAINER_POPUP_MENU_ADD, ContainerItemButton::OnAddItem)
|
|
|
|
|
EVT_MENU(CONTAINER_POPUP_MENU_EDIT, ContainerItemButton::OnEditItem)
|
|
|
|
|
EVT_MENU(CONTAINER_POPUP_MENU_REMOVE, ContainerItemButton::OnRemoveItem)
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
ContainerItemButton::ContainerItemButton(wxWindow* parent, bool large, int _index, const Map* map, Item* item) :
|
|
|
|
|
ItemButton(parent, (large? RENDER_SIZE_32x32 : RENDER_SIZE_16x16), (item? item->getClientID() : 0)),
|
|
|
|
|
edit_map(map),
|
|
|
|
|
edit_item(item),
|
|
|
|
|
index(_index)
|
|
|
|
|
{
|
2015-12-06 11:42:37 -03:00
|
|
|
////
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContainerItemButton::~ContainerItemButton()
|
|
|
|
|
{
|
2015-12-06 11:42:37 -03:00
|
|
|
////
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-01 15:04:40 -05:00
|
|
|
void ContainerItemButton::OnMouseDoubleLeftClick(wxMouseEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
if(edit_item) {
|
2014-08-01 15:04:40 -05:00
|
|
|
OnEditItem(dummy);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Container* container = getParentContainer();
|
2015-12-06 11:42:37 -03:00
|
|
|
if(container->getVolume() > container->getItemCount()) {
|
2014-08-01 15:04:40 -05:00
|
|
|
OnAddItem(dummy);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
|
|
|
|
void ContainerItemButton::OnMouseRightRelease(wxMouseEvent& WXUNUSED(event))
|
|
|
|
|
{
|
2015-12-06 11:42:37 -03:00
|
|
|
if(!popup_menu) {
|
2014-03-14 22:52:39 +01:00
|
|
|
popup_menu.reset(newd ContainerItemPopupMenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
popup_menu->Update(this);
|
|
|
|
|
PopupMenu(popup_menu.get());
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerItemButton::OnAddItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
2017-05-19 15:19:10 -03:00
|
|
|
FindItemDialog dialog(GetParent(), "Choose Item to add", true);
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2018-08-12 10:20:25 +02:00
|
|
|
if(dialog.ShowModal() == wxID_OK) {
|
2017-05-19 15:19:10 -03:00
|
|
|
Container* container = getParentContainer();
|
|
|
|
|
ItemVector& itemVector = container->getVector();
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2017-05-19 15:19:10 -03:00
|
|
|
Item* item = Item::Create(dialog.getResultID());
|
|
|
|
|
if(index < itemVector.size())
|
|
|
|
|
itemVector.insert(itemVector.begin() + index, item);
|
|
|
|
|
else
|
|
|
|
|
itemVector.push_back(item);
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2017-05-19 15:19:10 -03:00
|
|
|
ObjectPropertiesWindowBase* propertyWindow = getParentContainerWindow();
|
|
|
|
|
if(propertyWindow)
|
|
|
|
|
propertyWindow->Update();
|
2014-03-14 22:52:39 +01:00
|
|
|
}
|
2017-05-19 15:19:10 -03:00
|
|
|
dialog.Destroy();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerItemButton::OnEditItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
ASSERT(edit_item);
|
2012-07-20 16:32:57 +02:00
|
|
|
|
|
|
|
|
wxPoint newDialogAt;
|
|
|
|
|
wxWindow* w = this;
|
2015-12-06 11:42:37 -03:00
|
|
|
while((w = w->GetParent())) {
|
|
|
|
|
if(ObjectPropertiesWindowBase* o = dynamic_cast<ObjectPropertiesWindowBase*>(w)) {
|
2012-07-20 16:32:57 +02:00
|
|
|
newDialogAt = o->GetPosition();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newDialogAt += wxPoint(20, 20);
|
|
|
|
|
|
|
|
|
|
wxDialog* d;
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
if(edit_map->getVersion().otbm >= MAP_OTBM_4)
|
|
|
|
|
d = newd PropertiesWindow(this, edit_map, nullptr, edit_item, newDialogAt);
|
2012-07-20 16:32:57 +02:00
|
|
|
else
|
2015-12-06 11:42:37 -03:00
|
|
|
d = newd OldPropertiesWindow(this, edit_map, nullptr, edit_item, newDialogAt);
|
|
|
|
|
|
2012-07-20 16:32:57 +02:00
|
|
|
d->ShowModal();
|
|
|
|
|
d->Destroy();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerItemButton::OnRemoveItem(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
{
|
|
|
|
|
ASSERT(edit_item);
|
2016-09-29 20:30:54 -03:00
|
|
|
int32_t ret = g_gui.PopupDialog(GetParent(),
|
2016-11-05 15:28:14 +01:00
|
|
|
"Remove Item",
|
|
|
|
|
"Are you sure you want to remove this item from the container?",
|
2014-03-10 22:46:28 +01:00
|
|
|
wxYES | wxNO
|
|
|
|
|
);
|
2012-07-20 16:32:57 +02:00
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
if(ret != wxID_YES) {
|
2014-03-10 22:46:28 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2014-03-10 22:46:28 +01:00
|
|
|
Container* container = getParentContainer();
|
|
|
|
|
ItemVector& itemVector = container->getVector();
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2014-03-10 22:46:28 +01:00
|
|
|
auto it = itemVector.begin();
|
2015-12-06 11:42:37 -03:00
|
|
|
for(; it != itemVector.end(); ++it) {
|
|
|
|
|
if(*it == edit_item) {
|
2014-03-10 22:46:28 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2014-03-10 22:46:28 +01:00
|
|
|
|
|
|
|
|
ASSERT(it != itemVector.end());
|
2014-03-14 22:52:39 +01:00
|
|
|
|
2014-03-10 22:46:28 +01:00
|
|
|
itemVector.erase(it);
|
|
|
|
|
delete edit_item;
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2014-03-14 22:52:39 +01:00
|
|
|
ObjectPropertiesWindowBase* propertyWindow = getParentContainerWindow();
|
2015-12-06 11:42:37 -03:00
|
|
|
if(propertyWindow) {
|
2014-03-14 22:52:39 +01:00
|
|
|
propertyWindow->Update();
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerItemButton::setItem(Item* item)
|
|
|
|
|
{
|
|
|
|
|
edit_item = item;
|
2015-12-06 11:42:37 -03:00
|
|
|
if(edit_item) {
|
2012-06-29 16:44:26 +02:00
|
|
|
SetSprite(edit_item->getClientID());
|
2014-03-10 22:46:28 +01:00
|
|
|
} else {
|
2012-06-29 16:44:26 +02:00
|
|
|
SetSprite(0);
|
2014-03-10 22:46:28 +01:00
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2014-03-14 22:52:39 +01:00
|
|
|
ObjectPropertiesWindowBase* ContainerItemButton::getParentContainerWindow()
|
2012-07-20 16:32:57 +02:00
|
|
|
{
|
2015-12-06 11:42:37 -03:00
|
|
|
for(wxWindow* window = GetParent(); window != nullptr; window = window->GetParent()) {
|
2014-03-10 22:46:28 +01:00
|
|
|
ObjectPropertiesWindowBase* propertyWindow = dynamic_cast<ObjectPropertiesWindowBase*>(window);
|
2015-12-06 11:42:37 -03:00
|
|
|
if(propertyWindow) {
|
2014-03-14 22:52:39 +01:00
|
|
|
return propertyWindow;
|
2014-03-10 22:46:28 +01:00
|
|
|
}
|
2012-07-20 16:32:57 +02:00
|
|
|
}
|
2014-01-22 20:16:17 +01:00
|
|
|
return nullptr;
|
2012-07-20 16:32:57 +02:00
|
|
|
}
|
|
|
|
|
|
2014-03-14 22:52:39 +01:00
|
|
|
Container* ContainerItemButton::getParentContainer()
|
2012-07-20 16:32:57 +02:00
|
|
|
{
|
2014-03-14 22:52:39 +01:00
|
|
|
ObjectPropertiesWindowBase* propertyWindow = getParentContainerWindow();
|
2015-12-06 11:42:37 -03:00
|
|
|
if(propertyWindow) {
|
2014-03-14 22:52:39 +01:00
|
|
|
return dynamic_cast<Container*>(propertyWindow->getItemBeingEdited());
|
2012-07-20 16:32:57 +02:00
|
|
|
}
|
2014-03-14 22:52:39 +01:00
|
|
|
return nullptr;
|
2012-07-20 16:32:57 +02:00
|
|
|
}
|
|
|
|
|
|
2014-03-14 22:52:39 +01:00
|
|
|
// ContainerItemPopupMenu
|
2016-11-05 15:28:14 +01:00
|
|
|
ContainerItemPopupMenu::ContainerItemPopupMenu() : wxMenu("")
|
2012-06-29 16:44:26 +02:00
|
|
|
{
|
2015-12-06 11:42:37 -03:00
|
|
|
////
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContainerItemPopupMenu::~ContainerItemPopupMenu()
|
|
|
|
|
{
|
2015-12-06 11:42:37 -03:00
|
|
|
////
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ContainerItemPopupMenu::Update(ContainerItemButton* btn)
|
|
|
|
|
{
|
|
|
|
|
// Clear the menu of all items
|
2015-12-06 11:42:37 -03:00
|
|
|
while(GetMenuItemCount() != 0) {
|
2012-06-29 16:44:26 +02:00
|
|
|
wxMenuItem* m_item = FindItemByPosition(0);
|
|
|
|
|
// If you add a submenu, this won't delete it.
|
|
|
|
|
Delete(m_item);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-22 20:16:17 +01:00
|
|
|
wxMenuItem* addItem = nullptr;
|
2015-12-06 11:42:37 -03:00
|
|
|
if(btn->edit_item) {
|
2016-11-05 15:28:14 +01:00
|
|
|
Append( CONTAINER_POPUP_MENU_EDIT, "&Edit Item", "Open the properties menu for this item");
|
|
|
|
|
addItem = Append( CONTAINER_POPUP_MENU_ADD, "&Add Item", "Add a newd item to the container");
|
|
|
|
|
Append( CONTAINER_POPUP_MENU_REMOVE, "&Remove Item", "Remove this item from the container");
|
2015-12-06 11:42:37 -03:00
|
|
|
} else {
|
2016-11-05 15:28:14 +01:00
|
|
|
addItem = Append( CONTAINER_POPUP_MENU_ADD, "&Add Item", "Add a newd item to the container");
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2012-07-20 16:32:57 +02:00
|
|
|
|
|
|
|
|
Container* parentContainer = btn->getParentContainer();
|
|
|
|
|
if(parentContainer->getVolume() <= (int)parentContainer->getVector().size())
|
2012-06-29 16:44:26 +02:00
|
|
|
addItem->Enable(false);
|
|
|
|
|
}
|