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 <wx/grid.h>
# include "tile.h"
# include "item.h"
# include "complexitem.h"
# include "town.h"
# include "house.h"
# include "map.h"
# include "editor.h"
2021-05-25 00:29:12 -03:00
# include "monster.h"
# include "npc.h"
2012-06-29 16:44:26 +02:00
# include "gui.h"
# include "application.h"
# include "old_properties_window.h"
# include "container_properties_window.h"
// ============================================================================
// Old Properties Window
BEGIN_EVENT_TABLE ( OldPropertiesWindow , wxDialog )
EVT_SET_FOCUS ( OldPropertiesWindow : : OnFocusChange )
EVT_BUTTON ( wxID_OK , OldPropertiesWindow : : OnClickOK )
EVT_BUTTON ( wxID_CANCEL , OldPropertiesWindow : : OnClickCancel )
END_EVENT_TABLE ( )
OldPropertiesWindow : : OldPropertiesWindow ( wxWindow * win_parent , const Map * map , const Tile * tile_parent , Item * item , wxPoint pos ) :
2016-11-05 15:28:14 +01:00
ObjectPropertiesWindowBase ( win_parent , " Item Properties " , map , tile_parent , item , pos ) ,
2014-01-22 20:16:17 +01:00
count_field ( nullptr ) ,
2014-12-08 05:03:40 +13:00
direction_field ( nullptr ) ,
2014-01-22 20:16:17 +01:00
action_id_field ( nullptr ) ,
unique_id_field ( nullptr ) ,
door_id_field ( nullptr ) ,
depot_id_field ( nullptr ) ,
splash_type_field ( nullptr ) ,
text_field ( nullptr ) ,
description_field ( nullptr )
2012-06-29 16:44:26 +02:00
{
ASSERT ( edit_item ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
wxSizer * topsizer = newd wxBoxSizer ( wxVERTICAL ) ;
if ( Container * container = dynamic_cast < Container * > ( edit_item ) ) {
// Container
2016-11-05 15:28:14 +01:00
wxSizer * boxsizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Container Properties " ) ;
2012-06-29 16:44:26 +02:00
wxFlexGridSizer * subsizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
subsizer - > AddGrowableCol ( 1 ) ;
2016-09-29 19:24:45 -03:00
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " ID " + i2ws ( item - > getID ( ) ) ) ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " \" " + wxstr ( item - > getName ( ) ) + " \" " ) ) ;
2012-06-29 16:44:26 +02:00
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Action ID " ) ) ;
2012-06-29 16:44:26 +02:00
action_id_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_item - > getActionID ( ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , 0 , 0xFFFF , edit_item - > getActionID ( ) ) ;
subsizer - > Add ( action_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Unique ID " ) ) ;
2012-06-29 16:44:26 +02:00
unique_id_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_item - > getUniqueID ( ) ) , wxDefaultPosition , wxSize ( - 1 , 20 ) , wxSP_ARROW_KEYS , 0 , 0xFFFF , edit_item - > getUniqueID ( ) ) ;
subsizer - > Add ( unique_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
boxsizer - > Add ( subsizer , wxSizerFlags ( 0 ) . Expand ( ) ) ;
// Now we add the subitems!
2016-11-05 15:28:14 +01:00
wxSizer * contents_sizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Contents " ) ;
2012-06-29 16:44:26 +02:00
2016-09-29 20:37:43 -03:00
bool use_large_sprites = g_settings . getBoolean ( Config : : USE_LARGE_CONTAINER_ICONS ) ;
2014-01-22 20:16:17 +01:00
wxSizer * horizontal_sizer = nullptr ;
2012-06-29 16:44:26 +02:00
const int additional_height_increment = ( use_large_sprites ? 40 : 24 ) ;
int additional_height = 0 ;
2014-03-10 22:46:28 +01:00
int32_t maxColumns ;
2015-12-06 11:42:37 -03:00
if ( use_large_sprites ) {
2014-03-10 22:46:28 +01:00
maxColumns = 6 ;
} else {
maxColumns = 12 ;
}
2015-12-06 11:42:37 -03:00
for ( uint32_t index = 0 ; index < container - > getVolume ( ) ; + + index ) {
if ( ! horizontal_sizer ) {
2012-06-29 16:44:26 +02:00
horizontal_sizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
}
2014-03-10 22:46:28 +01:00
Item * item = container - > getItem ( index ) ;
ContainerItemButton * containerItemButton = newd ContainerItemButton ( this , use_large_sprites , index , map , item ) ;
container_items . push_back ( containerItemButton ) ;
horizontal_sizer - > Add ( containerItemButton ) ;
2015-12-06 11:42:37 -03:00
if ( ( ( index + 1 ) % maxColumns ) = = 0 ) {
2012-06-29 16:44:26 +02:00
contents_sizer - > Add ( horizontal_sizer ) ;
2014-01-22 20:16:17 +01:00
horizontal_sizer = nullptr ;
2012-06-29 16:44:26 +02:00
additional_height + = additional_height_increment ;
}
}
2014-03-10 22:46:28 +01:00
2014-01-22 20:16:17 +01:00
if ( horizontal_sizer ! = nullptr ) {
2012-06-29 16:44:26 +02:00
contents_sizer - > Add ( horizontal_sizer ) ;
additional_height + = additional_height_increment ;
}
boxsizer - > Add ( contents_sizer , wxSizerFlags ( 2 ) . Expand ( ) ) ;
topsizer - > Add ( boxsizer , wxSizerFlags ( 0 ) . Expand ( ) . Border ( wxALL , 20 ) ) ;
//SetSize(260, 150 + additional_height);
} else if ( edit_item - > canHoldText ( ) | | edit_item - > canHoldDescription ( ) ) {
// Book
2016-11-05 15:28:14 +01:00
wxSizer * boxsizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Writeable Properties " ) ;
2012-06-29 16:44:26 +02:00
wxFlexGridSizer * subsizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
subsizer - > AddGrowableCol ( 1 ) ;
2016-09-29 19:24:45 -03:00
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " ID " + i2ws ( item - > getID ( ) ) ) ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " \" " + wxstr ( item - > getName ( ) ) + " \" " ) ) ;
2012-06-29 16:44:26 +02:00
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Action ID " ) ) ;
2012-06-29 16:44:26 +02:00
action_id_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_item - > getActionID ( ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , 0 , 0xFFFF , edit_item - > getActionID ( ) ) ;
action_id_field - > SetSelection ( - 1 , - 1 ) ;
subsizer - > Add ( action_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Unique ID " ) ) ;
2012-06-29 16:44:26 +02:00
unique_id_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_item - > getUniqueID ( ) ) , wxDefaultPosition , wxSize ( - 1 , 20 ) , wxSP_ARROW_KEYS , 0 , 0xFFFF , edit_item - > getUniqueID ( ) ) ;
subsizer - > Add ( unique_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
boxsizer - > Add ( subsizer , wxSizerFlags ( 1 ) . Expand ( ) ) ;
wxSizer * textsizer = newd wxBoxSizer ( wxVERTICAL ) ;
2016-11-05 15:28:14 +01:00
textsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Text " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
2012-06-29 16:44:26 +02:00
text_field = newd wxTextCtrl ( this , wxID_ANY , wxstr ( item - > getText ( ) ) , wxDefaultPosition , wxDefaultSize , wxTE_MULTILINE ) ;
textsizer - > Add ( text_field , wxSizerFlags ( 7 ) . Expand ( ) ) ;
boxsizer - > Add ( textsizer , wxSizerFlags ( 2 ) . Expand ( ) ) ;
topsizer - > Add ( boxsizer , wxSizerFlags ( 0 ) . Expand ( ) . Border ( wxALL , 20 ) ) ;
//SetSize(220, 310);
} else if ( edit_item - > isSplash ( ) | | edit_item - > isFluidContainer ( ) ) {
// Splash
2016-11-05 15:28:14 +01:00
wxSizer * boxsizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Splash Properties " ) ;
2012-06-29 16:44:26 +02:00
wxFlexGridSizer * subsizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
subsizer - > AddGrowableCol ( 1 ) ;
2016-09-29 19:24:45 -03:00
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " ID " + i2ws ( item - > getID ( ) ) ) ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " \" " + wxstr ( item - > getName ( ) ) + " \" " ) ) ;
2012-06-29 16:44:26 +02:00
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Type " ) ) ;
2012-06-29 16:44:26 +02:00
2014-03-14 22:52:39 +01:00
// Splash types
2012-06-29 16:44:26 +02:00
splash_type_field = newd wxChoice ( this , wxID_ANY ) ;
2015-12-06 11:42:37 -03:00
if ( edit_item - > isFluidContainer ( ) ) {
2014-03-14 22:52:39 +01:00
splash_type_field - > Append ( wxstr ( Item : : LiquidID2Name ( LIQUID_NONE ) ) , newd int32_t ( LIQUID_NONE ) ) ;
}
2015-12-06 11:42:37 -03:00
for ( SplashType splashType = LIQUID_FIRST ; splashType ! = LIQUID_LAST ; + + splashType ) {
2014-03-14 22:52:39 +01:00
splash_type_field - > Append ( wxstr ( Item : : LiquidID2Name ( splashType ) ) , newd int32_t ( splashType ) ) ;
2012-06-29 16:44:26 +02:00
}
2014-03-14 22:52:39 +01:00
2015-12-06 11:42:37 -03:00
if ( item - > getSubtype ( ) ) {
2014-03-14 22:52:39 +01:00
const std : : string & what = Item : : LiquidID2Name ( item - > getSubtype ( ) ) ;
2015-12-06 11:42:37 -03:00
if ( what = = " Unknown " ) {
2014-03-14 22:52:39 +01:00
splash_type_field - > Append ( wxstr ( Item : : LiquidID2Name ( LIQUID_NONE ) ) , newd int32_t ( LIQUID_NONE ) ) ;
2012-06-29 16:44:26 +02:00
}
splash_type_field - > SetStringSelection ( wxstr ( what ) ) ;
} else {
splash_type_field - > SetSelection ( 0 ) ;
}
2014-03-14 22:52:39 +01:00
2012-06-29 16:44:26 +02:00
subsizer - > Add ( splash_type_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Action ID " ) ) ;
2012-06-29 16:44:26 +02:00
action_id_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_item - > getActionID ( ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , 0 , 0xFFFF , edit_item - > getActionID ( ) ) ;
subsizer - > Add ( action_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Unique ID " ) ) ;
2012-06-29 16:44:26 +02:00
unique_id_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_item - > getUniqueID ( ) ) , wxDefaultPosition , wxSize ( - 1 , 20 ) , wxSP_ARROW_KEYS , 0 , 0xFFFF , edit_item - > getUniqueID ( ) ) ;
subsizer - > Add ( unique_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
boxsizer - > Add ( subsizer , wxSizerFlags ( 1 ) . Expand ( ) ) ;
topsizer - > Add ( boxsizer , wxSizerFlags ( 0 ) . Expand ( ) . Border ( wxALL , 20 ) ) ;
//SetSize(220, 190);
} else if ( Depot * depot = dynamic_cast < Depot * > ( edit_item ) ) {
// Depot
2016-11-05 15:28:14 +01:00
wxSizer * boxsizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Depot Properties " ) ;
2012-06-29 16:44:26 +02:00
wxFlexGridSizer * subsizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
subsizer - > AddGrowableCol ( 1 ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " ID " + i2ws ( item - > getID ( ) ) ) ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " \" " + wxstr ( item - > getName ( ) ) + " \" " ) ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
const Towns & towns = map - > towns ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Depot ID " ) ) ;
2012-06-29 16:44:26 +02:00
depot_id_field = newd wxChoice ( this , wxID_ANY ) ;
int to_select_index = 0 ;
if ( towns . count ( ) > 0 ) {
bool found = false ;
for ( TownMap : : const_iterator town_iter = towns . begin ( ) ;
town_iter ! = towns . end ( ) ;
+ + town_iter )
{
if ( town_iter - > second - > getID ( ) = = depot - > getDepotID ( ) ) {
found = true ;
}
depot_id_field - > Append ( wxstr ( town_iter - > second - > getName ( ) ) , newd int ( town_iter - > second - > getID ( ) ) ) ;
2015-12-06 11:42:37 -03:00
if ( ! found ) + + to_select_index ;
2012-06-29 16:44:26 +02:00
}
2015-12-06 11:42:37 -03:00
if ( ! found ) {
2012-06-29 16:44:26 +02:00
if ( depot - > getDepotID ( ) ! = 0 ) {
2016-11-05 15:28:14 +01:00
depot_id_field - > Append ( " Undefined Town (id: " + i2ws ( depot - > getDepotID ( ) ) + " ) " , newd int ( depot - > getDepotID ( ) ) ) ;
2012-06-29 16:44:26 +02:00
}
}
}
2016-11-05 15:28:14 +01:00
depot_id_field - > Append ( " No Town " , newd int ( 0 ) ) ;
2012-06-29 16:44:26 +02:00
if ( depot - > getDepotID ( ) = = 0 ) {
to_select_index = depot_id_field - > GetCount ( ) - 1 ;
}
depot_id_field - > SetSelection ( to_select_index ) ;
subsizer - > Add ( depot_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
boxsizer - > Add ( subsizer , wxSizerFlags ( 5 ) . Expand ( ) ) ;
topsizer - > Add ( boxsizer , wxSizerFlags ( 0 ) . Expand ( ) . Border ( wxALL , 20 ) ) ;
//SetSize(220, 140);
} else {
// Normal item
Door * door = dynamic_cast < Door * > ( edit_item ) ;
Teleport * teleport = dynamic_cast < Teleport * > ( edit_item ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
wxString description ;
if ( door ) {
ASSERT ( tile_parent ) ;
2016-11-05 15:28:14 +01:00
description = " Door Properties " ;
2012-06-29 16:44:26 +02:00
} else if ( teleport ) {
2016-11-05 15:28:14 +01:00
description = " Teleport Properties " ;
2012-06-29 16:44:26 +02:00
} else {
2016-11-05 15:28:14 +01:00
description = " Item Properties " ;
2012-06-29 16:44:26 +02:00
}
wxSizer * boxsizer = newd wxStaticBoxSizer ( wxVERTICAL , this , description ) ;
int num_items = 4 ;
//if(item->canHoldDescription()) num_items += 1;
if ( door ) num_items + = 1 ;
if ( teleport ) num_items + = 1 ;
wxFlexGridSizer * subsizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
subsizer - > AddGrowableCol ( 1 ) ;
2016-09-29 19:24:45 -03:00
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " ID " + i2ws ( item - > getID ( ) ) ) ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " \" " + wxstr ( item - > getName ( ) ) + " \" " ) ) ;
2012-06-29 16:44:26 +02:00
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , ( item - > isCharged ( ) ? " Charges " : " Count " ) ) ) ;
2012-06-29 16:44:26 +02:00
int max_count = 100 ;
if ( item - > isClientCharged ( ) ) max_count = 250 ;
if ( item - > isExtraCharged ( ) ) max_count = 65500 ;
count_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_item - > getCount ( ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , 1 , max_count , edit_item - > getCount ( ) ) ;
2015-12-06 11:42:37 -03:00
if ( ! item - > isStackable ( ) & & ! item - > isCharged ( ) ) {
2012-06-29 16:44:26 +02:00
count_field - > Enable ( false ) ;
}
subsizer - > Add ( count_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Action ID " ) ) ;
2012-06-29 16:44:26 +02:00
action_id_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_item - > getActionID ( ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , 0 , 0xFFFF , edit_item - > getActionID ( ) ) ;
subsizer - > Add ( action_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Unique ID " ) ) ;
2012-06-29 16:44:26 +02:00
unique_id_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_item - > getUniqueID ( ) ) , wxDefaultPosition , wxSize ( - 1 , 20 ) , wxSP_ARROW_KEYS , 0 , 0xFFFF , edit_item - > getUniqueID ( ) ) ;
subsizer - > Add ( unique_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
/*
if ( item - > canHoldDescription ( ) ) {
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Description " ) ) ;
2012-06-29 16:44:26 +02:00
description_field = newd wxTextCtrl ( this , wxID_ANY , edit_item - > getText ( ) , wxDefaultPosition , wxSize ( - 1 , 20 ) ) ;
subsizer - > Add ( description_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
}
*/
if ( door ) {
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Door ID " ) ) ;
2012-06-29 16:44:26 +02:00
door_id_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( door - > getDoorID ( ) ) , wxDefaultPosition , wxSize ( - 1 , 20 ) , wxSP_ARROW_KEYS , 0 , 0xFF , door - > getDoorID ( ) ) ;
2015-12-06 11:42:37 -03:00
if ( ! edit_tile | | ! edit_tile - > isHouseTile ( ) ) {
2012-06-29 16:44:26 +02:00
door_id_field - > Disable ( ) ;
}
subsizer - > Add ( door_id_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
}
if ( teleport ) {
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Destination " ) ) ;
2012-06-29 16:44:26 +02:00
wxSizer * possizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
x_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( teleport - > getX ( ) ) , wxDefaultPosition , wxSize ( - 1 , 20 ) , wxSP_ARROW_KEYS , 0 , map - > getWidth ( ) , teleport - > getX ( ) ) ;
possizer - > Add ( x_field , wxSizerFlags ( 3 ) . Expand ( ) ) ;
y_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( teleport - > getY ( ) ) , wxDefaultPosition , wxSize ( - 1 , 20 ) , wxSP_ARROW_KEYS , 0 , map - > getHeight ( ) , teleport - > getY ( ) ) ;
possizer - > Add ( y_field , wxSizerFlags ( 3 ) . Expand ( ) ) ;
2016-02-28 19:44:08 -03:00
z_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( teleport - > getZ ( ) ) , wxDefaultPosition , wxSize ( - 1 , 20 ) , wxSP_ARROW_KEYS , 0 , MAP_MAX_LAYER , teleport - > getZ ( ) ) ;
2012-06-29 16:44:26 +02:00
possizer - > Add ( z_field , wxSizerFlags ( 2 ) . Expand ( ) ) ;
subsizer - > Add ( possizer , wxSizerFlags ( 1 ) . Expand ( ) ) ;
}
boxsizer - > Add ( subsizer , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2021-06-16 18:41:45 -03:00
topsizer - > Add ( boxsizer , wxSizerFlags ( 0 ) . Expand ( ) . Border ( wxLEFT | wxRIGHT , 20 ) ) ;
2012-06-29 16:44:26 +02:00
}
2021-06-16 18:41:45 -03:00
// Others attributes
const ItemType & type = g_items . getItemType ( edit_item - > getID ( ) ) ;
wxStaticBoxSizer * others_sizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Others " ) ;
wxFlexGridSizer * others_subsizer = newd wxFlexGridSizer ( 2 , 5 , 10 ) ;
others_subsizer - > AddGrowableCol ( 1 ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Stackable " ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , b2yn ( type . stackable ) ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Movable " ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , b2yn ( type . moveable ) ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Pickupable " ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , b2yn ( type . pickupable ) ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Hangable " ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , b2yn ( type . isHangable ) ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Block Missiles " ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , b2yn ( type . blockMissiles ) ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Block Pathfinder " ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , b2yn ( type . blockPathfinder ) ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Has Elevation " ) ) ;
others_subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , b2yn ( type . hasElevation ) ) ) ;
others_sizer - > Add ( others_subsizer , wxSizerFlags ( 1 ) . Expand ( ) ) ;
topsizer - > Add ( others_sizer , wxSizerFlags ( 0 ) . Expand ( ) . Border ( wxLEFT | wxRIGHT | wxBOTTOM , 20 ) ) ;
2012-06-29 16:44:26 +02:00
wxSizer * subsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
subsizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
2012-06-29 16:44:26 +02:00
topsizer - > Add ( subsizer , wxSizerFlags ( 0 ) . Center ( ) . Border ( wxLEFT | wxRIGHT | wxBOTTOM , 20 ) ) ;
SetSizerAndFit ( topsizer ) ;
2016-02-29 21:47:54 -03:00
Centre ( wxBOTH ) ;
2012-06-29 16:44:26 +02:00
}
2021-05-25 00:29:12 -03:00
OldPropertiesWindow : : OldPropertiesWindow ( wxWindow * win_parent , const Map * map , const Tile * tile_parent , Monster * monster , wxPoint pos ) :
ObjectPropertiesWindowBase ( win_parent , " Monster Properties " , map , tile_parent , monster , pos ) ,
2014-01-22 20:16:17 +01:00
count_field ( nullptr ) ,
2014-12-08 02:16:13 +13:00
direction_field ( nullptr ) ,
2014-01-22 20:16:17 +01:00
action_id_field ( nullptr ) ,
unique_id_field ( nullptr ) ,
door_id_field ( nullptr ) ,
depot_id_field ( nullptr ) ,
splash_type_field ( nullptr ) ,
text_field ( nullptr ) ,
description_field ( nullptr )
2012-06-29 16:44:26 +02:00
{
2021-05-25 00:29:12 -03:00
ASSERT ( edit_monster ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
wxSizer * topsizer = newd wxBoxSizer ( wxVERTICAL ) ;
2021-05-25 00:29:12 -03:00
wxSizer * boxsizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Monster Properties " ) ;
2012-06-29 16:44:26 +02:00
2012-06-30 11:40:30 +02:00
wxFlexGridSizer * subsizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
2012-06-29 16:44:26 +02:00
subsizer - > AddGrowableCol ( 1 ) ;
2016-09-29 19:24:45 -03:00
2021-05-25 00:29:12 -03:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Monster name " ) ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " \" " + wxstr ( edit_monster - > getName ( ) ) + " \" " ) , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2012-06-29 16:44:26 +02:00
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Spawn interval " ) ) ;
2021-05-25 00:29:12 -03:00
count_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_monster - > getSpawnMonsterTime ( ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , 10 , 3600 , edit_monster - > getSpawnMonsterTime ( ) ) ;
// count_field->SetSelection(-1, -1);
subsizer - > Add ( count_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Direction " ) ) ;
direction_field = newd wxChoice ( this , wxID_ANY ) ;
for ( Direction dir = DIRECTION_FIRST ; dir < = DIRECTION_LAST ; + + dir ) {
direction_field - > Append ( wxstr ( Monster : : DirID2Name ( dir ) ) , newd int32_t ( dir ) ) ;
}
direction_field - > SetSelection ( edit_monster - > getDirection ( ) ) ;
subsizer - > Add ( direction_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
boxsizer - > Add ( subsizer , wxSizerFlags ( 1 ) . Expand ( ) ) ;
topsizer - > Add ( boxsizer , wxSizerFlags ( 3 ) . Expand ( ) . Border ( wxALL , 20 ) ) ;
//SetSize(220, 0);
wxSizer * std_sizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
std_sizer - > Add ( newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
std_sizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
topsizer - > Add ( std_sizer , wxSizerFlags ( 0 ) . Center ( ) . Border ( wxLEFT | wxRIGHT | wxBOTTOM , 20 ) ) ;
SetSizerAndFit ( topsizer ) ;
Centre ( wxBOTH ) ;
}
OldPropertiesWindow : : OldPropertiesWindow ( wxWindow * win_parent , const Map * map , const Tile * tile_parent , SpawnMonster * spawnMonster , wxPoint pos ) :
ObjectPropertiesWindowBase ( win_parent , " Spawn Monster Properties " , map , tile_parent , spawnMonster , pos ) ,
count_field ( nullptr ) ,
direction_field ( nullptr ) ,
action_id_field ( nullptr ) ,
unique_id_field ( nullptr ) ,
door_id_field ( nullptr ) ,
depot_id_field ( nullptr ) ,
splash_type_field ( nullptr ) ,
text_field ( nullptr ) ,
description_field ( nullptr )
{
ASSERT ( edit_spawn_monster ) ;
wxSizer * topsizer = newd wxBoxSizer ( wxVERTICAL ) ;
wxSizer * boxsizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Spawn Monster Properties " ) ;
//if(item->canHoldDescription()) num_items += 1;
wxFlexGridSizer * subsizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
subsizer - > AddGrowableCol ( 1 ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Spawn size " ) ) ;
count_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_spawn_monster - > getSize ( ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , 1 , g_settings . getInteger ( Config : : MAX_SPAWN_MONSTER_RADIUS ) , edit_spawn_monster - > getSize ( ) ) ;
2012-06-30 11:40:30 +02:00
// count_field->SetSelection(-1, -1);
2012-06-29 16:44:26 +02:00
subsizer - > Add ( count_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2021-05-25 00:29:12 -03:00
boxsizer - > Add ( subsizer , wxSizerFlags ( 1 ) . Expand ( ) ) ;
topsizer - > Add ( boxsizer , wxSizerFlags ( 3 ) . Expand ( ) . Border ( wxALL , 20 ) ) ;
wxSizer * std_sizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
std_sizer - > Add ( newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
std_sizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
topsizer - > Add ( std_sizer , wxSizerFlags ( 0 ) . Center ( ) . Border ( wxLEFT | wxRIGHT | wxBOTTOM , 20 ) ) ;
SetSizerAndFit ( topsizer ) ;
Centre ( wxBOTH ) ;
}
OldPropertiesWindow : : OldPropertiesWindow ( wxWindow * win_parent , const Map * map , const Tile * tile_parent , Npc * npc , wxPoint pos ) :
ObjectPropertiesWindowBase ( win_parent , " Npc Properties " , map , tile_parent , npc , pos ) ,
count_field ( nullptr ) ,
direction_field ( nullptr ) ,
action_id_field ( nullptr ) ,
unique_id_field ( nullptr ) ,
door_id_field ( nullptr ) ,
depot_id_field ( nullptr ) ,
splash_type_field ( nullptr ) ,
text_field ( nullptr ) ,
description_field ( nullptr )
{
ASSERT ( edit_npc ) ;
wxSizer * topsizer = newd wxBoxSizer ( wxVERTICAL ) ;
wxSizer * boxsizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Npc Properties " ) ;
wxFlexGridSizer * subsizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
subsizer - > AddGrowableCol ( 1 ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Npc name " ) ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " \" " + wxstr ( edit_npc - > getName ( ) ) + " \" " ) , wxSizerFlags ( 1 ) . Expand ( ) ) ;
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Spawn interval " ) ) ;
count_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_npc - > getSpawnNpcTime ( ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , 10 , 3600 , edit_npc - > getSpawnNpcTime ( ) ) ;
// count_field->SetSelection(-1, -1);
subsizer - > Add ( count_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Direction " ) ) ;
2014-12-08 04:56:42 +13:00
direction_field = newd wxChoice ( this , wxID_ANY ) ;
2015-12-06 11:42:37 -03:00
for ( Direction dir = DIRECTION_FIRST ; dir < = DIRECTION_LAST ; + + dir ) {
2021-05-25 00:29:12 -03:00
direction_field - > Append ( wxstr ( Npc : : DirID2Name ( dir ) ) , newd int32_t ( dir ) ) ;
2014-12-08 04:56:42 +13:00
}
2021-05-25 00:29:12 -03:00
direction_field - > SetSelection ( edit_npc - > getDirection ( ) ) ;
2014-12-08 02:16:13 +13:00
subsizer - > Add ( direction_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
2012-06-29 16:44:26 +02:00
boxsizer - > Add ( subsizer , wxSizerFlags ( 1 ) . Expand ( ) ) ;
topsizer - > Add ( boxsizer , wxSizerFlags ( 3 ) . Expand ( ) . Border ( wxALL , 20 ) ) ;
2015-06-20 18:09:18 -04:00
//SetSize(220, 0);
2012-06-29 16:44:26 +02:00
wxSizer * std_sizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
2016-11-05 15:28:14 +01:00
std_sizer - > Add ( newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
std_sizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
2012-06-29 16:44:26 +02:00
topsizer - > Add ( std_sizer , wxSizerFlags ( 0 ) . Center ( ) . Border ( wxLEFT | wxRIGHT | wxBOTTOM , 20 ) ) ;
SetSizerAndFit ( topsizer ) ;
2016-02-29 21:47:54 -03:00
Centre ( wxBOTH ) ;
2012-06-29 16:44:26 +02:00
}
2021-05-25 00:29:12 -03:00
OldPropertiesWindow : : OldPropertiesWindow ( wxWindow * win_parent , const Map * map , const Tile * tile_parent , SpawnNpc * spawnNpc , wxPoint pos ) :
ObjectPropertiesWindowBase ( win_parent , " Spawn Npc Properties " , map , tile_parent , spawnNpc , pos ) ,
2014-01-22 20:16:17 +01:00
count_field ( nullptr ) ,
2014-12-08 05:03:40 +13:00
direction_field ( nullptr ) ,
2014-01-22 20:16:17 +01:00
action_id_field ( nullptr ) ,
unique_id_field ( nullptr ) ,
door_id_field ( nullptr ) ,
depot_id_field ( nullptr ) ,
splash_type_field ( nullptr ) ,
text_field ( nullptr ) ,
description_field ( nullptr )
2012-06-29 16:44:26 +02:00
{
2021-05-25 00:29:12 -03:00
ASSERT ( edit_spawn_npc ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
wxSizer * topsizer = newd wxBoxSizer ( wxVERTICAL ) ;
2021-05-25 00:29:12 -03:00
wxSizer * boxsizer = newd wxStaticBoxSizer ( wxVERTICAL , this , " Npc Spawn Properties " ) ;
2012-06-29 16:44:26 +02:00
//if(item->canHoldDescription()) num_items += 1;
2012-06-30 11:40:30 +02:00
wxFlexGridSizer * subsizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
2012-06-29 16:44:26 +02:00
subsizer - > AddGrowableCol ( 1 ) ;
2016-11-05 15:28:14 +01:00
subsizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Spawn size " ) ) ;
2021-05-25 00:29:12 -03:00
count_field = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( edit_spawn_npc - > getSize ( ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , 1 , g_settings . getInteger ( Config : : MAX_SPAWN_NPC_RADIUS ) , edit_spawn_npc - > getSize ( ) ) ;
2012-06-30 11:40:30 +02:00
// count_field->SetSelection(-1, -1);
2012-06-29 16:44:26 +02:00
subsizer - > Add ( count_field , wxSizerFlags ( 1 ) . Expand ( ) ) ;
boxsizer - > Add ( subsizer , wxSizerFlags ( 1 ) . Expand ( ) ) ;
topsizer - > Add ( boxsizer , wxSizerFlags ( 3 ) . Expand ( ) . Border ( wxALL , 20 ) ) ;
wxSizer * std_sizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
2016-11-05 15:28:14 +01:00
std_sizer - > Add ( newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
std_sizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
2012-06-29 16:44:26 +02:00
topsizer - > Add ( std_sizer , wxSizerFlags ( 0 ) . Center ( ) . Border ( wxLEFT | wxRIGHT | wxBOTTOM , 20 ) ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
SetSizerAndFit ( topsizer ) ;
2016-02-29 21:47:54 -03:00
Centre ( wxBOTH ) ;
2012-06-29 16:44:26 +02:00
}
OldPropertiesWindow : : ~ OldPropertiesWindow ( )
{
// Warning: edit_item may no longer be valid, DONT USE IT!
2015-12-06 11:42:37 -03:00
if ( splash_type_field ) {
for ( uint32_t i = 0 ; i < splash_type_field - > GetCount ( ) ; + + i ) {
2012-06-29 16:44:26 +02:00
delete reinterpret_cast < int * > ( splash_type_field - > GetClientData ( i ) ) ;
}
}
2015-12-06 11:42:37 -03:00
if ( direction_field ) {
for ( uint32_t i = 0 ; i < direction_field - > GetCount ( ) ; + + i ) {
2014-12-08 04:56:42 +13:00
delete reinterpret_cast < int * > ( direction_field - > GetClientData ( i ) ) ;
}
}
2015-12-06 11:42:37 -03:00
if ( depot_id_field ) {
for ( uint32_t i = 0 ; i < depot_id_field - > GetCount ( ) ; + + i ) {
2012-06-29 16:44:26 +02:00
delete reinterpret_cast < int * > ( depot_id_field - > GetClientData ( i ) ) ;
}
}
}
void OldPropertiesWindow : : OnFocusChange ( wxFocusEvent & event )
{
wxWindow * win = event . GetWindow ( ) ;
2015-12-06 11:42:37 -03:00
if ( wxSpinCtrl * spin = dynamic_cast < wxSpinCtrl * > ( win ) )
2012-06-29 16:44:26 +02:00
spin - > SetSelection ( - 1 , - 1 ) ;
2015-12-06 11:42:37 -03:00
else if ( wxTextCtrl * text = dynamic_cast < wxTextCtrl * > ( win ) )
2012-06-29 16:44:26 +02:00
text - > SetSelection ( - 1 , - 1 ) ;
}
void OldPropertiesWindow : : OnClickOK ( wxCommandEvent & WXUNUSED ( event ) )
{
if ( edit_item ) {
if ( dynamic_cast < Container * > ( edit_item ) ) {
// Container
int new_uid = unique_id_field - > GetValue ( ) ;
int new_aid = action_id_field - > GetValue ( ) ;
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
if ( ( new_uid < 1000 | | new_uid > 0xFFFF ) & & new_uid ! = 0 ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Unique ID must be between 1000 and 65535. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( /* there is no item with the same UID */ false ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Unique ID must be unique, this UID is already taken. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( ( new_aid < 100 | | new_aid > 0xFFFF ) & & new_aid ! = 0 ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Action ID must be between 100 and 65535. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
edit_item - > setUniqueID ( new_uid ) ;
edit_item - > setActionID ( new_aid ) ;
} else if ( edit_item - > canHoldText ( ) | | edit_item - > canHoldDescription ( ) ) {
// Book
int new_uid = unique_id_field - > GetValue ( ) ;
int new_aid = action_id_field - > GetValue ( ) ;
std : : string text = nstr ( text_field - > GetValue ( ) ) ;
if ( ( new_uid < 1000 | | new_uid > 0xFFFF ) & & new_uid ! = 0 ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Unique ID must be between 1000 and 65535. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( /* there is no item with the same UID */ false ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Unique ID must be unique, this UID is already taken. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( ( new_aid < 100 | | new_aid > 0xFFFF ) & & new_aid ! = 0 ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Action ID must be between 100 and 65535. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( text . length ( ) > = 0xFFFF ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Text is longer than 65535 characters, this is not supported by OpenTibia. Reduce the length of the text. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( edit_item - > canHoldText ( ) & & text . length ( ) > edit_item - > getMaxWriteLength ( ) ) {
2016-11-05 15:28:14 +01:00
int ret = g_gui . PopupDialog ( this , " Error " , " Text is longer than the maximum supported length of this book type, do you still want to change it? " , wxYES | wxNO ) ;
2012-06-29 16:44:26 +02:00
if ( ret ! = wxID_YES ) {
return ;
}
}
edit_item - > setUniqueID ( new_uid ) ;
edit_item - > setActionID ( new_aid ) ;
edit_item - > setText ( text ) ;
} else if ( edit_item - > isSplash ( ) | | edit_item - > isFluidContainer ( ) ) {
// Splash
int new_uid = unique_id_field - > GetValue ( ) ;
int new_aid = action_id_field - > GetValue ( ) ;
int * new_type = reinterpret_cast < int * > ( splash_type_field - > GetClientData ( splash_type_field - > GetSelection ( ) ) ) ;
if ( ( new_uid < 1000 | | new_uid > 0xFFFF ) & & new_uid ! = 0 ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Unique ID must be between 1000 and 65535. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( /* there is no item with the same UID */ false ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Unique ID must be unique, this UID is already taken. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( ( new_aid < 100 | | new_aid > 0xFFFF ) & & new_aid ! = 0 ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Action ID must be between 100 and 65535. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( new_type ) {
edit_item - > setSubtype ( * new_type ) ;
}
edit_item - > setUniqueID ( new_uid ) ;
edit_item - > setActionID ( new_aid ) ;
// Clean up client data
} else if ( Depot * depot = dynamic_cast < Depot * > ( edit_item ) ) {
// Depot
int * new_depotid = reinterpret_cast < int * > ( depot_id_field - > GetClientData ( depot_id_field - > GetSelection ( ) ) ) ;
depot - > setDepotID ( * new_depotid ) ;
} else {
// Normal item
Door * door = dynamic_cast < Door * > ( edit_item ) ;
Teleport * teleport = dynamic_cast < Teleport * > ( edit_item ) ;
int new_uid = unique_id_field - > GetValue ( ) ;
int new_aid = action_id_field - > GetValue ( ) ;
int new_count = count_field ? count_field - > GetValue ( ) : 1 ;
std : : string new_desc ;
if ( edit_item - > canHoldDescription ( ) & & description_field ) {
description_field - > GetValue ( ) ;
}
Position new_dest ;
if ( teleport ) {
new_dest = Position ( x_field - > GetValue ( ) , y_field - > GetValue ( ) , z_field - > GetValue ( ) ) ;
}
uint8_t new_door_id = 0 ;
if ( door ) {
new_door_id = door_id_field - > GetValue ( ) ;
}
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
if ( ( new_uid < 1000 | | new_uid > 0xFFFF ) & & new_uid ! = 0 ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Unique ID must be between 1000 and 65535. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( /* there is no item with the same UID */ false ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Unique ID must be unique, this UID is already taken. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
if ( ( new_aid < 100 | | new_aid > 0xFFFF ) & & new_aid ! = 0 ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " Action ID must be between 100 and 65535. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
/*
if ( edit_item - > canHoldDescription ( ) ) {
if ( new_desc . length ( ) > 127 ) {
2016-09-29 20:30:54 -03:00
g_gui . PopupDialog ( " Error " , " Description must be shorter than 127 characters. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
}
*/
2016-09-29 20:37:43 -03:00
if ( door & & g_settings . getInteger ( Config : : WARN_FOR_DUPLICATE_ID ) ) {
2012-06-29 16:44:26 +02:00
if ( edit_tile & & edit_tile - > isHouseTile ( ) ) {
const House * house = edit_map - > houses . getHouse ( edit_tile - > getHouseID ( ) ) ;
if ( house ) {
Position pos = house - > getDoorPositionByID ( new_door_id ) ;
if ( pos = = Position ( ) ) {
// Do nothing
} else if ( pos ! = edit_tile - > getPosition ( ) ) {
2016-11-05 15:28:14 +01:00
int ret = g_gui . PopupDialog ( this , " Warning " , " This doorid conflicts with another one in this house, are you sure you want to continue? " , wxYES | wxNO ) ;
2012-06-29 16:44:26 +02:00
if ( ret = = wxID_NO ) {
return ;
}
}
}
}
}
if ( teleport ) {
2014-01-22 20:16:17 +01:00
if ( edit_map - > getTile ( new_dest ) = = nullptr | | edit_map - > getTile ( new_dest ) - > isBlocking ( ) ) {
2016-11-05 15:28:14 +01:00
int ret = g_gui . PopupDialog ( this , " Warning " , " This teleport leads nowhere, or to an invalid location. Do you want to change the destination? " , wxYES | wxNO ) ;
2012-06-29 16:44:26 +02:00
if ( ret = = wxID_YES ) {
return ;
}
}
}
2016-09-29 19:24:45 -03:00
2012-06-29 16:44:26 +02:00
// Done validating, set the values.
if ( edit_item - > canHoldDescription ( ) ) {
edit_item - > setText ( new_desc ) ;
}
if ( edit_item - > isStackable ( ) | | edit_item - > isCharged ( ) ) {
edit_item - > setSubtype ( new_count ) ;
}
if ( door ) {
door - > setDoorID ( new_door_id ) ;
}
if ( teleport ) {
teleport - > setDestination ( new_dest ) ;
}
edit_item - > setUniqueID ( new_uid ) ;
edit_item - > setActionID ( new_aid ) ;
}
2021-05-25 00:29:12 -03:00
} else if ( edit_monster ) {
int new_spawn_monster_time = count_field - > GetValue ( ) ;
edit_monster - > setSpawnMonsterTime ( new_spawn_monster_time ) ;
2014-12-08 02:16:13 +13:00
2014-12-08 04:56:42 +13:00
int * new_dir = reinterpret_cast < int * > ( direction_field - > GetClientData (
direction_field - > GetSelection ( ) ) ) ;
2015-12-06 11:42:37 -03:00
if ( new_dir ) {
2021-05-25 00:29:12 -03:00
edit_monster - > setDirection ( ( Direction ) * new_dir ) ;
2014-12-08 04:56:42 +13:00
}
2021-05-25 00:29:12 -03:00
} else if ( edit_npc ) {
int new_spawn_npc_time = count_field - > GetValue ( ) ;
edit_npc - > setSpawnNpcTime ( new_spawn_npc_time ) ;
int * new_dir = reinterpret_cast < int * > ( direction_field - > GetClientData (
direction_field - > GetSelection ( ) ) ) ;
if ( new_dir ) {
edit_npc - > setDirection ( ( Direction ) * new_dir ) ;
}
} else if ( edit_spawn_monster ) {
int new_spawn_monster_size = count_field - > GetValue ( ) ;
edit_spawn_monster - > setSize ( new_spawn_monster_size ) ;
} else if ( edit_spawn_npc ) {
int new_spawn_npc_size = count_field - > GetValue ( ) ;
edit_spawn_npc - > setSize ( new_spawn_npc_size ) ;
}
2012-06-29 16:44:26 +02:00
EndModal ( 1 ) ;
}
void OldPropertiesWindow : : OnClickCancel ( wxCommandEvent & WXUNUSED ( event ) )
{
// Just close this window
EndModal ( 0 ) ;
}
2014-03-10 22:46:28 +01:00
void OldPropertiesWindow : : Update ( )
{
Container * container = dynamic_cast < Container * > ( edit_item ) ;
2015-12-06 11:42:37 -03:00
if ( container ) {
for ( uint32_t i = 0 ; i < container - > getVolume ( ) ; + + i ) {
2014-03-10 22:46:28 +01:00
container_items [ i ] - > setItem ( container - > getItem ( i ) ) ;
}
}
wxDialog : : Update ( ) ;
}