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 "materials.h"
# include "brush.h"
# include "editor.h"
# include "items.h"
# include "map.h"
# include "item.h"
# include "complexitem.h"
# include "raw_brush.h"
# include "palette_window.h"
# include "gui.h"
# include "application.h"
# include "common_windows.h"
2015-07-11 21:20:07 -03:00
# include "positionctrl.h"
2012-06-29 16:44:26 +02:00
2023-10-09 23:02:37 -03:00
# include "iominimap.h"
2014-08-02 18:29:37 -05:00
# ifdef _MSC_VER
2023-10-09 19:12:16 -07:00
# pragma warning(disable : 4018) // signed/unsigned mismatch
2014-08-02 13:09:03 -05:00
# endif
2012-06-29 16:44:26 +02:00
// ============================================================================
// Map Properties Window
BEGIN_EVENT_TABLE ( MapPropertiesWindow , wxDialog )
2023-10-09 19:12:16 -07:00
EVT_CHOICE ( MAP_PROPERTIES_VERSION , MapPropertiesWindow : : OnChangeVersion )
EVT_BUTTON ( wxID_OK , MapPropertiesWindow : : OnClickOK )
EVT_BUTTON ( wxID_CANCEL , MapPropertiesWindow : : OnClickCancel )
2012-06-29 16:44:26 +02:00
END_EVENT_TABLE ( )
2023-10-09 19:12:16 -07:00
MapPropertiesWindow : : MapPropertiesWindow ( wxWindow * parent , MapTab * view , Editor & editor ) :
2016-11-05 15:28:14 +01:00
wxDialog ( parent , wxID_ANY , " Map Properties " , wxDefaultPosition , wxSize ( 300 , 200 ) , wxRESIZE_BORDER | wxCAPTION ) ,
2012-06-29 16:44:26 +02:00
view ( view ) ,
2023-10-09 19:12:16 -07:00
editor ( editor ) {
2012-06-29 16:44:26 +02:00
// Setup data variabels
2023-10-09 19:12:16 -07:00
const Map & map = editor . getMap ( ) ;
2012-06-29 16:44:26 +02:00
wxSizer * topsizer = newd wxBoxSizer ( wxVERTICAL ) ;
2012-06-30 11:41:07 +02:00
wxFlexGridSizer * grid_sizer = newd wxFlexGridSizer ( 2 , 10 , 10 ) ;
2012-06-29 16:44:26 +02:00
grid_sizer - > AddGrowableCol ( 1 ) ;
// Description
2016-11-05 15:28:14 +01:00
grid_sizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Map Description " ) ) ;
2012-06-29 16:44:26 +02:00
description_ctrl = newd wxTextCtrl ( this , wxID_ANY , wxstr ( map . getMapDescription ( ) ) , wxDefaultPosition , wxDefaultSize , wxTE_MULTILINE ) ;
grid_sizer - > Add ( description_ctrl , wxSizerFlags ( 1 ) . Expand ( ) ) ;
// Map version
2016-11-05 15:28:14 +01:00
grid_sizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Map Version " ) ) ;
2012-06-29 16:44:26 +02:00
version_choice = newd wxChoice ( this , MAP_PROPERTIES_VERSION ) ;
2016-11-05 15:28:14 +01:00
version_choice - > Append ( " OTServ 0.5.0 " ) ;
version_choice - > Append ( " OTServ 0.6.0 " ) ;
version_choice - > Append ( " OTServ 0.6.1 " ) ;
version_choice - > Append ( " OTServ 0.7.0 (revscriptsys) " ) ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
switch ( map . getVersion ( ) . otbm ) {
2012-06-29 16:44:26 +02:00
case MAP_OTBM_1 :
version_choice - > SetSelection ( 0 ) ;
break ;
case MAP_OTBM_2 :
version_choice - > SetSelection ( 1 ) ;
break ;
case MAP_OTBM_3 :
version_choice - > SetSelection ( 2 ) ;
break ;
case MAP_OTBM_4 :
version_choice - > SetSelection ( 3 ) ;
break ;
default :
version_choice - > SetSelection ( 0 ) ;
}
2016-09-29 18:36:27 -03:00
2012-06-29 16:44:26 +02:00
grid_sizer - > Add ( version_choice , wxSizerFlags ( 1 ) . Expand ( ) ) ;
// Version
2016-11-05 15:28:14 +01:00
grid_sizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Client Version " ) ) ;
2012-06-29 16:44:26 +02:00
protocol_choice = newd wxChoice ( this , wxID_ANY ) ;
2016-09-29 18:36:27 -03:00
2016-09-29 20:30:54 -03:00
protocol_choice - > SetStringSelection ( wxstr ( g_gui . GetCurrentVersion ( ) . getName ( ) ) ) ;
2012-06-29 16:44:26 +02:00
grid_sizer - > Add ( protocol_choice , wxSizerFlags ( 1 ) . Expand ( ) ) ;
// Dimensions
2016-11-05 15:28:14 +01:00
grid_sizer - > Add ( newd wxStaticText ( this , wxID_ANY , " Map Dimensions " ) ) ;
2012-06-29 16:44:26 +02:00
{
wxSizer * subsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
subsizer - > Add (
2023-10-09 19:12:16 -07:00
width_spin = newd wxSpinCtrl ( this , wxID_ANY , wxstr ( i2s ( map . getWidth ( ) ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , rme : : MapMinWidth , rme : : MapMaxWidth ) , wxSizerFlags ( 1 ) . Expand ( )
) ;
2012-06-29 16:44:26 +02:00
subsizer - > Add (
2023-10-09 19:12:16 -07:00
height_spin = newd wxSpinCtrl ( this , wxID_ANY , wxstr ( i2s ( map . getHeight ( ) ) ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , rme : : MapMinHeight , rme : : MapMaxHeight ) , wxSizerFlags ( 1 ) . Expand ( )
) ;
2012-06-29 16:44:26 +02:00
grid_sizer - > Add ( subsizer , 1 , wxEXPAND ) ;
}
// External files
grid_sizer - > Add (
2021-05-25 00:29:12 -03:00
newd wxStaticText ( this , wxID_ANY , " External house file " )
2023-10-09 19:12:16 -07:00
) ;
2012-06-29 16:44:26 +02:00
grid_sizer - > Add (
2023-10-09 19:12:16 -07:00
house_filename_ctrl = newd wxTextCtrl ( this , wxID_ANY , wxstr ( map . getHouseFilename ( ) ) ) , 1 , wxEXPAND
) ;
2012-06-29 16:44:26 +02:00
2023-11-08 17:04:13 -08:00
grid_sizer - > Add (
newd wxStaticText ( this , wxID_ANY , " External zone file " )
) ;
grid_sizer - > Add (
zone_filename_ctrl = newd wxTextCtrl ( this , wxID_ANY , wxstr ( map . getZoneFilename ( ) ) ) , 1 , wxEXPAND
) ;
2012-06-29 16:44:26 +02:00
grid_sizer - > Add (
2021-05-25 00:29:12 -03:00
newd wxStaticText ( this , wxID_ANY , " External monster file " )
2023-10-09 19:12:16 -07:00
) ;
2012-06-29 16:44:26 +02:00
grid_sizer - > Add (
2023-10-09 19:12:16 -07:00
spawn_filename_ctrl = newd wxTextCtrl ( this , wxID_ANY , wxstr ( map . getSpawnFilename ( ) ) ) , 1 , wxEXPAND
) ;
2023-09-08 19:41:54 -03:00
2021-05-25 00:29:12 -03:00
grid_sizer - > Add (
newd wxStaticText ( this , wxID_ANY , " External npc file " )
2023-10-09 19:12:16 -07:00
) ;
2021-05-25 00:29:12 -03:00
grid_sizer - > Add (
2023-10-09 19:12:16 -07:00
spawn_npc_filename_ctrl = newd wxTextCtrl ( this , wxID_ANY , wxstr ( map . getSpawnNpcFilename ( ) ) ) , 1 , wxEXPAND
) ;
2012-06-29 16:44:26 +02:00
topsizer - > Add ( grid_sizer , wxSizerFlags ( 1 ) . Expand ( ) . Border ( wxALL , 20 ) ) ;
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
UpdateProtocolList ( ) ;
2012-07-01 17:52:20 +02:00
ClientVersion * current_version = ClientVersion : : get ( map . getVersion ( ) . client ) ;
protocol_choice - > SetStringSelection ( wxstr ( current_version - > getName ( ) ) ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void MapPropertiesWindow : : UpdateProtocolList ( ) {
2012-06-29 16:44:26 +02:00
wxString ver = version_choice - > GetStringSelection ( ) ;
wxString client = protocol_choice - > GetStringSelection ( ) ;
protocol_choice - > Clear ( ) ;
2016-09-29 18:36:27 -03:00
2012-07-01 13:41:59 +02:00
ClientVersionList versions ;
2023-10-09 19:12:16 -07:00
if ( g_settings . getInteger ( Config : : USE_OTBM_4_FOR_ALL_MAPS ) ) {
2012-07-01 13:41:59 +02:00
versions = ClientVersion : : getAllVisible ( ) ;
2015-12-06 11:42:37 -03:00
} else {
2012-07-01 13:41:59 +02:00
MapVersionID map_version = MAP_OTBM_1 ;
2023-10-09 19:12:16 -07:00
if ( ver . Contains ( " 0.5.0 " ) ) {
2012-07-01 13:41:59 +02:00
map_version = MAP_OTBM_1 ;
2023-10-09 19:12:16 -07:00
} else if ( ver . Contains ( " 0.6.0 " ) ) {
2012-07-01 13:41:59 +02:00
map_version = MAP_OTBM_2 ;
2023-10-09 19:12:16 -07:00
} else if ( ver . Contains ( " 0.6.1 " ) ) {
2012-07-01 13:41:59 +02:00
map_version = MAP_OTBM_3 ;
2023-10-09 19:12:16 -07:00
} else if ( ver . Contains ( " 0.7.0 " ) ) {
2012-07-01 13:41:59 +02:00
map_version = MAP_OTBM_4 ;
2023-10-09 19:12:16 -07:00
}
2012-07-01 17:52:20 +02:00
ClientVersionList protocols = ClientVersion : : getAllForOTBMVersion ( map_version ) ;
2023-10-09 19:12:16 -07:00
for ( ClientVersionList : : const_iterator p = protocols . begin ( ) ; p ! = protocols . end ( ) ; + + p ) {
2012-07-01 17:52:20 +02:00
protocol_choice - > Append ( wxstr ( ( * p ) - > getName ( ) ) ) ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
}
protocol_choice - > SetSelection ( 0 ) ;
protocol_choice - > SetStringSelection ( client ) ;
}
2023-10-09 19:12:16 -07:00
void MapPropertiesWindow : : OnChangeVersion ( wxCommandEvent & ) {
2012-06-29 16:44:26 +02:00
UpdateProtocolList ( ) ;
}
2023-10-09 19:12:16 -07:00
struct MapConversionContext {
struct MonsterInfo {
2012-07-05 17:32:36 +02:00
std : : string name ;
Outfit outfit ;
} ;
2021-05-25 00:29:12 -03:00
typedef std : : map < std : : string , MonsterInfo > MonsterMap ;
MonsterMap monsterType ;
2023-10-09 19:12:16 -07:00
struct NpcInfo {
2021-05-25 00:29:12 -03:00
std : : string name ;
Outfit outfit ;
} ;
typedef std : : map < std : : string , NpcInfo > NpcMap ;
NpcMap npcType ;
2012-07-05 17:32:36 +02:00
2023-10-09 19:12:16 -07:00
void operator ( ) ( Map & map , Tile * tile , long long done ) {
if ( tile - > monster ) {
2021-05-25 00:29:12 -03:00
MonsterMap : : iterator f = monsterType . find ( tile - > monster - > getName ( ) ) ;
2023-10-09 19:12:16 -07:00
if ( f = = monsterType . end ( ) ) {
2021-05-25 00:29:12 -03:00
MonsterInfo info = {
tile - > monster - > getName ( ) ,
tile - > monster - > getLookType ( )
} ;
monsterType [ tile - > monster - > getName ( ) ] = info ;
}
}
2023-10-09 19:12:16 -07:00
if ( tile - > npc ) {
2021-05-25 00:29:12 -03:00
NpcMap : : iterator f = npcType . find ( tile - > npc - > getName ( ) ) ;
2023-10-09 19:12:16 -07:00
if ( f = = npcType . end ( ) ) {
2021-05-25 00:29:12 -03:00
NpcInfo info = {
tile - > npc - > getName ( ) ,
tile - > npc - > getLookType ( )
2012-07-05 17:32:36 +02:00
} ;
2021-05-25 00:29:12 -03:00
npcType [ tile - > npc - > getName ( ) ] = info ;
2012-07-05 17:32:36 +02:00
}
}
}
} ;
2023-10-09 19:12:16 -07:00
void MapPropertiesWindow : : OnClickOK ( wxCommandEvent & WXUNUSED ( event ) ) {
Map & map = editor . getMap ( ) ;
2012-06-29 16:44:26 +02:00
MapVersion old_ver = map . getVersion ( ) ;
MapVersion new_ver ;
2016-09-29 18:36:27 -03:00
2012-06-29 16:44:26 +02:00
wxString ver = version_choice - > GetStringSelection ( ) ;
new_ver . client = ClientVersion : : get ( nstr ( protocol_choice - > GetStringSelection ( ) ) ) - > getID ( ) ;
2023-10-09 19:12:16 -07:00
if ( ver . Contains ( " 0.5.0 " ) ) {
2012-06-29 16:44:26 +02:00
new_ver . otbm = MAP_OTBM_1 ;
2023-10-09 19:12:16 -07:00
} else if ( ver . Contains ( " 0.6.0 " ) ) {
2012-06-29 16:44:26 +02:00
new_ver . otbm = MAP_OTBM_2 ;
2023-10-09 19:12:16 -07:00
} else if ( ver . Contains ( " 0.6.1 " ) ) {
2012-06-29 16:44:26 +02:00
new_ver . otbm = MAP_OTBM_3 ;
2023-10-09 19:12:16 -07:00
} else if ( ver . Contains ( " 0.7.0 " ) ) {
2012-06-29 16:44:26 +02:00
new_ver . otbm = MAP_OTBM_4 ;
}
2023-10-09 19:12:16 -07:00
if ( new_ver . client ! = old_ver . client ) {
if ( g_gui . GetOpenMapCount ( ) > 1 ) {
g_gui . PopupDialog ( this , " Error " , " You can not change editor version with multiple maps open " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
wxString error ;
wxArrayString warnings ;
// Switch version
2023-10-09 23:02:37 -03:00
g_gui . GetCurrentEditor ( ) - > getSelection ( ) . clear ( ) ;
g_gui . GetCurrentEditor ( ) - > clearActions ( ) ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
if ( new_ver . client < old_ver . client ) {
int ret = g_gui . PopupDialog ( this , " Notice " , " Converting to a previous version may have serious side-effects, are you sure you want to do this? " , wxYES | wxNO ) ;
if ( ret ! = wxID_YES ) {
2012-06-29 16:44:26 +02:00
return ;
}
2012-07-05 17:32:36 +02:00
UnnamedRenderingLock ( ) ;
2021-05-25 00:29:12 -03:00
// Remember all monsters types on the map
2012-07-05 17:32:36 +02:00
MapConversionContext conversion_context ;
foreach_TileOnMap ( map , conversion_context ) ;
2012-06-29 16:44:26 +02:00
2016-09-29 18:36:27 -03:00
// Perform the conversion
2012-06-29 16:44:26 +02:00
map . convert ( new_ver , true ) ;
2012-07-05 17:32:36 +02:00
// Load the new version
2023-10-09 19:12:16 -07:00
if ( ! g_gui . LoadVersion ( new_ver . client , error , warnings ) ) {
2016-11-05 15:28:14 +01:00
g_gui . ListDialog ( this , " Warnings " , warnings ) ;
g_gui . PopupDialog ( this , " Map Loader Error " , error , wxOK ) ;
g_gui . PopupDialog ( this , " Conversion Error " , " Could not convert map. The map will now be closed. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
EndModal ( 0 ) ;
return ;
}
2021-05-25 00:29:12 -03:00
// Monsters
// Remove all monsters that were present are present in the new version
2023-10-09 19:12:16 -07:00
for ( MapConversionContext : : MonsterMap : : iterator cs = conversion_context . monsterType . begin ( ) ; cs ! = conversion_context . monsterType . end ( ) ; ) {
if ( g_monsters [ cs - > first ] ) {
2021-05-25 00:29:12 -03:00
cs = conversion_context . monsterType . erase ( cs ) ;
2023-10-09 19:12:16 -07:00
} else {
2021-05-25 00:29:12 -03:00
+ + cs ;
2023-10-09 19:12:16 -07:00
}
2021-05-25 00:29:12 -03:00
}
2023-10-09 19:12:16 -07:00
if ( conversion_context . monsterType . size ( ) > 0 ) {
2021-05-25 00:29:12 -03:00
int add = g_gui . PopupDialog ( this , " Unrecognized monsters " , " There were monsters on the old version that are not present in this and were on the map, do you want to add them to this version as well? " , wxYES | wxNO ) ;
2023-10-09 19:12:16 -07:00
if ( add = = wxID_YES ) {
for ( MapConversionContext : : MonsterMap : : iterator cs = conversion_context . monsterType . begin ( ) ; cs ! = conversion_context . monsterType . end ( ) ; + + cs ) {
2021-05-25 00:29:12 -03:00
MapConversionContext : : MonsterInfo info = cs - > second ;
g_monsters . addMonsterType ( info . name , info . outfit ) ;
}
}
}
// Npcs
// Remove all npcs that were present are present in the new version
2023-10-09 19:12:16 -07:00
for ( MapConversionContext : : NpcMap : : iterator cs = conversion_context . npcType . begin ( ) ; cs ! = conversion_context . npcType . end ( ) ; ) {
if ( g_npcs [ cs - > first ] ) {
2021-05-25 00:29:12 -03:00
cs = conversion_context . npcType . erase ( cs ) ;
2023-10-09 19:12:16 -07:00
} else {
2012-07-05 17:32:36 +02:00
+ + cs ;
2023-10-09 19:12:16 -07:00
}
2012-07-05 17:32:36 +02:00
}
2023-10-09 19:12:16 -07:00
if ( conversion_context . npcType . size ( ) > 0 ) {
2021-05-25 00:29:12 -03:00
int add = g_gui . PopupDialog ( this , " Unrecognized npcs " , " There were npcs on the old version that are not present in this and were on the map, do you want to add them to this version as well? " , wxYES | wxNO ) ;
2023-10-09 19:12:16 -07:00
if ( add = = wxID_YES ) {
for ( MapConversionContext : : NpcMap : : iterator cs = conversion_context . npcType . begin ( ) ; cs ! = conversion_context . npcType . end ( ) ; + + cs ) {
2021-05-25 00:29:12 -03:00
MapConversionContext : : NpcInfo info = cs - > second ;
g_npcs . addNpcType ( info . name , info . outfit ) ;
2012-07-05 17:32:36 +02:00
}
}
}
2012-06-29 16:44:26 +02:00
map . cleanInvalidTiles ( true ) ;
2023-10-09 19:12:16 -07:00
} else {
2012-06-29 16:44:26 +02:00
UnnamedRenderingLock ( ) ;
2023-10-09 19:12:16 -07:00
if ( ! g_gui . LoadVersion ( new_ver . client , error , warnings ) ) {
2016-11-05 15:28:14 +01:00
g_gui . ListDialog ( this , " Warnings " , warnings ) ;
g_gui . PopupDialog ( this , " Map Loader Error " , error , wxOK ) ;
g_gui . PopupDialog ( this , " Conversion Error " , " Could not convert map. The map will now be closed. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
EndModal ( 0 ) ;
return ;
}
map . convert ( new_ver , true ) ;
}
2015-12-06 11:42:37 -03:00
} else {
2012-06-29 16:44:26 +02:00
map . convert ( new_ver , true ) ;
}
map . setMapDescription ( nstr ( description_ctrl - > GetValue ( ) ) ) ;
map . setHouseFilename ( nstr ( house_filename_ctrl - > GetValue ( ) ) ) ;
2021-05-25 00:29:12 -03:00
map . setSpawnMonsterFilename ( nstr ( spawn_filename_ctrl - > GetValue ( ) ) ) ;
map . setSpawnNpcFilename ( nstr ( spawn_npc_filename_ctrl - > GetValue ( ) ) ) ;
2023-11-08 17:04:13 -08:00
map . setZoneFilename ( nstr ( zone_filename_ctrl - > GetValue ( ) ) ) ;
2012-06-29 16:44:26 +02:00
// Only resize if we have to
int new_map_width = width_spin - > GetValue ( ) ;
int new_map_height = height_spin - > GetValue ( ) ;
2023-10-09 19:12:16 -07:00
if ( new_map_width ! = map . getWidth ( ) | | new_map_height ! = map . getHeight ( ) ) {
2012-06-29 16:44:26 +02:00
map . setWidth ( new_map_width ) ;
map . setHeight ( new_map_height ) ;
2016-09-29 20:30:54 -03:00
g_gui . FitViewToMap ( view ) ;
2012-06-29 16:44:26 +02:00
}
2016-09-29 20:30:54 -03:00
g_gui . RefreshPalettes ( ) ;
2012-06-29 16:44:26 +02:00
EndModal ( 1 ) ;
}
2023-10-09 19:12:16 -07:00
void MapPropertiesWindow : : OnClickCancel ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
// Just close this window
EndModal ( 1 ) ;
}
2019-06-25 18:07:36 +02:00
MapPropertiesWindow : : ~ MapPropertiesWindow ( ) = default ;
2012-06-29 16:44:26 +02:00
// ============================================================================
// Map Import Window
BEGIN_EVENT_TABLE ( ImportMapWindow , wxDialog )
2023-10-09 19:12:16 -07:00
EVT_BUTTON ( MAP_WINDOW_FILE_BUTTON , ImportMapWindow : : OnClickBrowse )
EVT_BUTTON ( wxID_OK , ImportMapWindow : : OnClickOK )
EVT_BUTTON ( wxID_CANCEL , ImportMapWindow : : OnClickCancel )
2012-06-29 16:44:26 +02:00
END_EVENT_TABLE ( )
2023-10-09 19:12:16 -07:00
ImportMapWindow : : ImportMapWindow ( wxWindow * parent , Editor & editor ) :
2022-09-30 18:57:21 -03:00
wxDialog ( parent , wxID_ANY , " Import Map " , wxDefaultPosition , wxSize ( 420 , 350 ) ) ,
2023-10-09 19:12:16 -07:00
editor ( editor ) {
2016-02-27 20:19:33 -03:00
wxBoxSizer * sizer = newd wxBoxSizer ( wxVERTICAL ) ;
wxStaticBoxSizer * tmpsizer ;
2012-06-29 16:44:26 +02:00
// File
2016-11-05 15:28:14 +01:00
tmpsizer = newd wxStaticBoxSizer ( new wxStaticBox ( this , wxID_ANY , " Map File " ) , wxHORIZONTAL ) ;
2022-04-03 03:10:34 +02:00
file_text_field = newd wxTextCtrl ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , " " , wxDefaultPosition , wxSize ( 300 , 23 ) ) ;
2016-02-27 20:19:33 -03:00
tmpsizer - > Add ( file_text_field , 0 , wxALL , 5 ) ;
2016-11-05 15:28:14 +01:00
wxButton * browse_button = newd wxButton ( tmpsizer - > GetStaticBox ( ) , MAP_WINDOW_FILE_BUTTON , " Browse... " , wxDefaultPosition , wxSize ( 80 , 23 ) ) ;
2016-02-27 20:19:33 -03:00
tmpsizer - > Add ( browse_button , 0 , wxALL , 5 ) ;
sizer - > Add ( tmpsizer , 1 , wxEXPAND | wxLEFT | wxRIGHT | wxTOP , 5 ) ;
2012-06-29 16:44:26 +02:00
// Import offset
2016-11-05 15:28:14 +01:00
tmpsizer = newd wxStaticBoxSizer ( new wxStaticBox ( this , wxID_ANY , " Import Offset " ) , wxHORIZONTAL ) ;
tmpsizer - > Add ( newd wxStaticText ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , " Offset X: " ) , 0 , wxALL | wxEXPAND , 5 ) ;
2023-10-09 23:02:37 -03:00
x_offset_ctrl = newd wxSpinCtrl ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( 60 , 23 ) , wxSP_ARROW_KEYS , - rme : : MapMaxHeight , rme : : MapMaxHeight ) ;
2016-02-27 20:19:33 -03:00
tmpsizer - > Add ( x_offset_ctrl , 0 , wxALL , 5 ) ;
2016-11-05 15:28:14 +01:00
tmpsizer - > Add ( newd wxStaticText ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , " Offset Y: " ) , 0 , wxALL , 5 ) ;
2023-10-09 23:02:37 -03:00
y_offset_ctrl = newd wxSpinCtrl ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( 60 , 23 ) , wxSP_ARROW_KEYS , - rme : : MapMaxHeight , rme : : MapMaxHeight ) ;
2016-02-27 20:19:33 -03:00
tmpsizer - > Add ( y_offset_ctrl , 0 , wxALL , 5 ) ;
2022-04-03 03:10:34 +02:00
tmpsizer - > Add ( newd wxStaticText ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , " Offset Z: " ) , 0 , wxALL , 5 ) ;
2023-10-09 23:02:37 -03:00
z_offset_ctrl = newd wxSpinCtrl ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , wxEmptyString , wxDefaultPosition , wxSize ( 60 , 23 ) , wxSP_ARROW_KEYS , - rme : : MapMaxLayer , rme : : MapMaxLayer ) ;
2022-04-03 03:10:34 +02:00
tmpsizer - > Add ( z_offset_ctrl , 0 , wxALL , 5 ) ;
2016-02-27 20:19:33 -03:00
sizer - > Add ( tmpsizer , 1 , wxEXPAND | wxLEFT | wxRIGHT , 5 ) ;
2012-06-29 16:44:26 +02:00
// Import options
wxArrayString house_choices ;
2016-11-05 15:28:14 +01:00
house_choices . Add ( " Smart Merge " ) ;
house_choices . Add ( " Insert " ) ;
house_choices . Add ( " Merge " ) ;
house_choices . Add ( " Don't Import " ) ;
2012-06-29 16:44:26 +02:00
// House options
2016-11-05 15:28:14 +01:00
tmpsizer = newd wxStaticBoxSizer ( new wxStaticBox ( this , wxID_ANY , " House Import Behaviour " ) , wxVERTICAL ) ;
2016-02-27 20:19:33 -03:00
house_options = newd wxChoice ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , wxDefaultPosition , wxDefaultSize , house_choices ) ;
2012-06-29 16:44:26 +02:00
house_options - > SetSelection ( 0 ) ;
2016-02-27 20:19:33 -03:00
tmpsizer - > Add ( house_options , 0 , wxALL | wxEXPAND , 5 ) ;
sizer - > Add ( tmpsizer , 1 , wxEXPAND | wxLEFT | wxRIGHT , 5 ) ;
2012-06-29 16:44:26 +02:00
// Import options
wxArrayString spawn_choices ;
2016-11-05 15:28:14 +01:00
spawn_choices . Add ( " Merge " ) ;
spawn_choices . Add ( " Don't Import " ) ;
2012-06-29 16:44:26 +02:00
2021-05-25 00:29:12 -03:00
// Monster spawn options
tmpsizer = newd wxStaticBoxSizer ( new wxStaticBox ( this , wxID_ANY , " Monster Spawn Import Behaviour " ) , wxVERTICAL ) ;
spawn_monster_options = newd wxChoice ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , wxDefaultPosition , wxDefaultSize , spawn_choices ) ;
spawn_monster_options - > SetSelection ( 0 ) ;
tmpsizer - > Add ( spawn_monster_options , 0 , wxALL | wxEXPAND , 5 ) ;
sizer - > Add ( tmpsizer , 1 , wxEXPAND | wxLEFT | wxRIGHT , 5 ) ;
// Npc spawn options
tmpsizer = newd wxStaticBoxSizer ( new wxStaticBox ( this , wxID_ANY , " Npc Spawn Import Behaviour " ) , wxVERTICAL ) ;
spawn_npc_options = newd wxChoice ( tmpsizer - > GetStaticBox ( ) , wxID_ANY , wxDefaultPosition , wxDefaultSize , spawn_choices ) ;
spawn_npc_options - > SetSelection ( 0 ) ;
tmpsizer - > Add ( spawn_npc_options , 0 , wxALL | wxEXPAND , 5 ) ;
2016-02-27 20:19:33 -03:00
sizer - > Add ( tmpsizer , 1 , wxEXPAND | wxLEFT | wxRIGHT , 5 ) ;
2012-06-29 16:44:26 +02:00
// OK/Cancel buttons
2016-02-27 20:19:33 -03:00
wxBoxSizer * buttons = newd wxBoxSizer ( wxHORIZONTAL ) ;
2016-11-05 15:28:14 +01:00
buttons - > Add ( newd wxButton ( this , wxID_OK , " Ok " ) , 0 , wxALL , 5 ) ;
buttons - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , 0 , wxALL , 5 ) ;
2016-02-27 20:19:33 -03:00
sizer - > Add ( buttons , wxSizerFlags ( 1 ) . Center ( ) ) ;
SetSizer ( sizer ) ;
Layout ( ) ;
Centre ( wxBOTH ) ;
2012-06-29 16:44:26 +02:00
}
2019-06-25 18:07:36 +02:00
ImportMapWindow : : ~ ImportMapWindow ( ) = default ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
void ImportMapWindow : : OnClickBrowse ( wxCommandEvent & WXUNUSED ( event ) ) {
2016-11-05 15:28:14 +01:00
wxFileDialog dialog ( this , " Import... " , " " , " " , " *.otbm " , wxFD_OPEN | wxFD_FILE_MUST_EXIST ) ;
2016-02-27 20:19:33 -03:00
int ok = dialog . ShowModal ( ) ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
if ( ok = = wxID_OK ) {
2016-02-27 20:19:33 -03:00
file_text_field - > ChangeValue ( dialog . GetPath ( ) ) ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void ImportMapWindow : : OnClickOK ( wxCommandEvent & WXUNUSED ( event ) ) {
if ( Validate ( ) & & TransferDataFromWindow ( ) ) {
2016-02-27 20:19:33 -03:00
wxFileName fn = file_text_field - > GetValue ( ) ;
2023-10-09 19:12:16 -07:00
if ( ! fn . FileExists ( ) ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " The specified map file doesn't exist " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
ImportType spawn_import_type = IMPORT_DONT ;
2021-05-25 00:29:12 -03:00
ImportType spawn_npc_import_type = IMPORT_DONT ;
2012-06-29 16:44:26 +02:00
ImportType house_import_type = IMPORT_DONT ;
2023-10-09 19:12:16 -07:00
switch ( spawn_monster_options - > GetSelection ( ) ) {
case 0 :
spawn_import_type = IMPORT_MERGE ;
break ;
case 1 :
spawn_import_type = IMPORT_DONT ;
break ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
switch ( spawn_npc_options - > GetSelection ( ) ) {
case 0 :
spawn_npc_import_type = IMPORT_MERGE ;
break ;
case 1 :
spawn_npc_import_type = IMPORT_DONT ;
break ;
2021-05-25 00:29:12 -03:00
}
2023-10-09 19:12:16 -07:00
switch ( house_options - > GetSelection ( ) ) {
case 0 :
house_import_type = IMPORT_SMART_MERGE ;
break ;
case 1 :
house_import_type = IMPORT_MERGE ;
break ;
case 2 :
house_import_type = IMPORT_INSERT ;
break ;
case 3 :
house_import_type = IMPORT_DONT ;
break ;
2012-06-29 16:44:26 +02:00
}
EndModal ( 1 ) ;
2022-08-19 02:50:53 -03:00
editor . importMap ( fn , x_offset_ctrl - > GetValue ( ) , y_offset_ctrl - > GetValue ( ) , z_offset_ctrl - > GetValue ( ) , house_import_type , spawn_import_type , spawn_npc_import_type ) ;
2012-06-29 16:44:26 +02:00
}
}
2023-10-09 19:12:16 -07:00
void ImportMapWindow : : OnClickCancel ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
// Just close this window
EndModal ( 0 ) ;
}
// ============================================================================
// Export Minimap window
BEGIN_EVENT_TABLE ( ExportMiniMapWindow , wxDialog )
2023-10-09 19:12:16 -07:00
EVT_BUTTON ( MAP_WINDOW_FILE_BUTTON , ExportMiniMapWindow : : OnClickBrowse )
EVT_BUTTON ( wxID_OK , ExportMiniMapWindow : : OnClickOK )
EVT_BUTTON ( wxID_CANCEL , ExportMiniMapWindow : : OnClickCancel )
EVT_CHOICE ( wxID_ANY , ExportMiniMapWindow : : OnExportTypeChange )
2012-06-29 16:44:26 +02:00
END_EVENT_TABLE ( )
2023-10-09 19:12:16 -07:00
ExportMiniMapWindow : : ExportMiniMapWindow ( wxWindow * parent , Editor & editor ) :
2016-11-05 15:28:14 +01:00
wxDialog ( parent , wxID_ANY , " Export Minimap " , wxDefaultPosition , wxSize ( 400 , 300 ) ) ,
2023-10-09 19:12:16 -07:00
editor ( editor ) {
2012-06-29 16:44:26 +02:00
wxSizer * sizer = newd wxBoxSizer ( wxVERTICAL ) ;
wxSizer * tmpsizer ;
2016-10-18 13:54:41 -03:00
// Error field
2016-11-05 15:28:14 +01:00
error_field = newd wxStaticText ( this , wxID_VIEW_DETAILS , " " , wxDefaultPosition , wxDefaultSize ) ;
2016-10-18 13:54:41 -03:00
error_field - > SetForegroundColour ( * wxRED ) ;
tmpsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
tmpsizer - > Add ( error_field , 0 , wxALL , 5 ) ;
sizer - > Add ( tmpsizer , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
// Output folder
2016-11-05 15:28:14 +01:00
directory_text_field = newd wxTextCtrl ( this , wxID_ANY , " " , wxDefaultPosition , wxDefaultSize ) ;
2016-10-18 13:54:41 -03:00
directory_text_field - > Bind ( wxEVT_KEY_UP , & ExportMiniMapWindow : : OnDirectoryChanged , this ) ;
2020-05-18 21:20:44 -03:00
directory_text_field - > SetValue ( wxString ( g_settings . getString ( Config : : MINIMAP_EXPORT_DIR ) ) ) ;
2016-11-05 15:28:14 +01:00
tmpsizer = newd wxStaticBoxSizer ( wxHORIZONTAL , this , " Output Folder " ) ;
2016-10-18 13:54:41 -03:00
tmpsizer - > Add ( directory_text_field , 1 , wxALL , 5 ) ;
2016-11-05 15:28:14 +01:00
tmpsizer - > Add ( newd wxButton ( this , MAP_WINDOW_FILE_BUTTON , " Browse " ) , 0 , wxALL , 5 ) ;
2016-10-18 13:54:41 -03:00
sizer - > Add ( tmpsizer , 0 , wxALL | wxEXPAND , 5 ) ;
// File name
2023-10-09 23:02:37 -03:00
wxString mapName ( editor . getMap ( ) . getName ( ) . c_str ( ) , wxConvUTF8 ) ;
2016-10-18 13:54:41 -03:00
file_name_text_field = newd wxTextCtrl ( this , wxID_ANY , mapName . BeforeLast ( ' . ' ) , wxDefaultPosition , wxDefaultSize ) ;
file_name_text_field - > Bind ( wxEVT_KEY_UP , & ExportMiniMapWindow : : OnFileNameChanged , this ) ;
2016-11-05 15:28:14 +01:00
tmpsizer = newd wxStaticBoxSizer ( wxHORIZONTAL , this , " File Name " ) ;
2016-10-18 13:54:41 -03:00
tmpsizer - > Add ( file_name_text_field , 1 , wxALL , 5 ) ;
sizer - > Add ( tmpsizer , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
2023-10-09 23:02:37 -03:00
// Format options
wxArrayString format_choices ;
format_choices . Add ( " .otmm (Client Minimap) " ) ;
format_choices . Add ( " .png (PNG Image) " ) ;
format_choices . Add ( " .bmp (Bitmap Image) " ) ;
format_options = new wxChoice ( this , wxID_ANY , wxDefaultPosition , wxDefaultSize , format_choices ) ;
format_options - > SetSelection ( 0 ) ;
tmpsizer - > Add ( format_options , 1 , wxALL , 5 ) ;
2016-10-18 13:54:41 -03:00
// Export options
2012-06-29 16:44:26 +02:00
wxArrayString choices ;
2016-11-05 15:28:14 +01:00
choices . Add ( " All Floors " ) ;
choices . Add ( " Ground Floor " ) ;
choices . Add ( " Specific Floor " ) ;
2016-10-25 09:47:00 -03:00
2023-10-09 19:12:16 -07:00
if ( editor . hasSelection ( ) ) {
2016-11-05 15:28:14 +01:00
choices . Add ( " Selected Area " ) ;
2023-10-09 19:12:16 -07:00
}
2016-10-18 13:54:41 -03:00
// Area options
2016-11-05 15:28:14 +01:00
tmpsizer = newd wxStaticBoxSizer ( wxHORIZONTAL , this , " Area Options " ) ;
2012-06-29 16:44:26 +02:00
floor_options = newd wxChoice ( this , wxID_ANY , wxDefaultPosition , wxDefaultSize , choices ) ;
2023-10-09 23:02:37 -03:00
floor_number = newd wxSpinCtrl ( this , wxID_ANY , i2ws ( rme : : MapGroundLayer ) , wxDefaultPosition , wxDefaultSize , wxSP_ARROW_KEYS , rme : : MapMinLayer , rme : : MapMaxLayer , rme : : MapGroundLayer ) ;
2012-06-29 16:44:26 +02:00
floor_number - > Enable ( false ) ;
floor_options - > SetSelection ( 0 ) ;
2016-10-18 13:54:41 -03:00
tmpsizer - > Add ( floor_options , 1 , wxALL , 5 ) ;
tmpsizer - > Add ( floor_number , 0 , wxALL , 5 ) ;
sizer - > Add ( tmpsizer , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
2012-06-29 16:44:26 +02:00
// OK/Cancel buttons
tmpsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
2016-11-05 15:28:14 +01:00
tmpsizer - > Add ( ok_button = newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
tmpsizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
2016-10-18 13:54:41 -03:00
sizer - > Add ( tmpsizer , 0 , wxCENTER , 10 ) ;
2012-06-29 16:44:26 +02:00
2016-10-18 13:54:41 -03:00
SetSizer ( sizer ) ;
Layout ( ) ;
2016-02-29 21:47:54 -03:00
Centre ( wxBOTH ) ;
2016-10-18 13:54:41 -03:00
CheckValues ( ) ;
2012-06-29 16:44:26 +02:00
}
2019-06-25 18:07:36 +02:00
ExportMiniMapWindow : : ~ ExportMiniMapWindow ( ) = default ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
void ExportMiniMapWindow : : OnExportTypeChange ( wxCommandEvent & event ) {
2016-10-18 13:54:41 -03:00
floor_number - > Enable ( event . GetSelection ( ) = = 2 ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void ExportMiniMapWindow : : OnClickBrowse ( wxCommandEvent & WXUNUSED ( event ) ) {
2016-10-18 13:54:41 -03:00
wxDirDialog dialog ( NULL , " Select the output folder " , " " , wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST ) ;
2023-10-09 19:12:16 -07:00
if ( dialog . ShowModal ( ) = = wxID_OK ) {
const wxString & directory = dialog . GetPath ( ) ;
2016-10-18 13:54:41 -03:00
directory_text_field - > ChangeValue ( directory ) ;
2012-06-29 16:44:26 +02:00
}
2016-10-18 13:54:41 -03:00
CheckValues ( ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void ExportMiniMapWindow : : OnDirectoryChanged ( wxKeyEvent & event ) {
2016-10-18 13:54:41 -03:00
CheckValues ( ) ;
event . Skip ( ) ;
}
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
void ExportMiniMapWindow : : OnFileNameChanged ( wxKeyEvent & event ) {
2016-10-18 13:54:41 -03:00
CheckValues ( ) ;
event . Skip ( ) ;
}
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
void ExportMiniMapWindow : : OnClickOK ( wxCommandEvent & WXUNUSED ( event ) ) {
2023-10-09 23:02:37 -03:00
g_gui . CreateLoadBar ( " Exporting minimap... " ) ;
2016-10-18 13:54:41 -03:00
2023-10-09 23:02:37 -03:00
auto format = static_cast < MinimapExportFormat > ( format_options - > GetSelection ( ) ) ;
auto mode = static_cast < MinimapExportMode > ( floor_options - > GetSelection ( ) ) ;
std : : string directory = directory_text_field - > GetValue ( ) . ToStdString ( ) ;
std : : string file_name = file_name_text_field - > GetValue ( ) . ToStdString ( ) ;
int floor = floor_number - > GetValue ( ) ;
2016-10-18 13:54:41 -03:00
2023-10-09 23:02:37 -03:00
g_settings . setString ( Config : : MINIMAP_EXPORT_DIR , directory ) ;
2016-10-18 13:54:41 -03:00
2023-10-09 23:02:37 -03:00
IOMinimap io ( & editor , format , mode , true ) ;
if ( ! io . saveMinimap ( directory , file_name , floor ) ) {
g_gui . PopupDialog ( " Error " , io . getError ( ) , wxOK ) ;
2012-06-29 16:44:26 +02:00
}
2016-10-18 13:54:41 -03:00
2016-09-29 20:30:54 -03:00
g_gui . DestroyLoadBar ( ) ;
2023-10-09 23:02:37 -03:00
EndModal ( wxID_OK ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void ExportMiniMapWindow : : OnClickCancel ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
// Just close this window
2023-10-09 23:02:37 -03:00
EndModal ( wxID_CANCEL ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void ExportMiniMapWindow : : CheckValues ( ) {
if ( directory_text_field - > IsEmpty ( ) ) {
2016-11-05 15:28:14 +01:00
error_field - > SetLabel ( " Type or select an output folder. " ) ;
2016-10-18 13:54:41 -03:00
ok_button - > Enable ( false ) ;
return ;
}
if ( file_name_text_field - > IsEmpty ( ) ) {
2016-11-05 15:28:14 +01:00
error_field - > SetLabel ( " Type a name for the file. " ) ;
2016-10-18 13:54:41 -03:00
ok_button - > Enable ( false ) ;
return ;
}
FileName directory ( directory_text_field - > GetValue ( ) ) ;
if ( ! directory . Exists ( ) ) {
2016-11-05 15:28:14 +01:00
error_field - > SetLabel ( " Output folder not found. " ) ;
2016-10-18 13:54:41 -03:00
ok_button - > Enable ( false ) ;
return ;
}
if ( ! directory . IsDirWritable ( ) ) {
2016-11-05 15:28:14 +01:00
error_field - > SetLabel ( " Output folder is not writable. " ) ;
2016-10-18 13:54:41 -03:00
ok_button - > Enable ( false ) ;
return ;
}
error_field - > SetLabel ( wxEmptyString ) ;
ok_button - > Enable ( true ) ;
}
2024-06-07 15:03:37 -03:00
// ============================================================================
// Export Tilesets window
BEGIN_EVENT_TABLE ( ExportTilesetsWindow , wxDialog )
EVT_BUTTON ( TILESET_FILE_BUTTON , ExportTilesetsWindow : : OnClickBrowse )
EVT_BUTTON ( wxID_OK , ExportTilesetsWindow : : OnClickOK )
EVT_BUTTON ( wxID_CANCEL , ExportTilesetsWindow : : OnClickCancel )
END_EVENT_TABLE ( )
ExportTilesetsWindow : : ExportTilesetsWindow ( wxWindow * parent , Editor & editor ) :
wxDialog ( parent , wxID_ANY , " Export Tilesets " , wxDefaultPosition , wxSize ( 400 , 230 ) ) ,
editor ( editor ) {
wxSizer * sizer = newd wxBoxSizer ( wxVERTICAL ) ;
wxSizer * tmpsizer ;
// Error field
error_field = newd wxStaticText ( this , wxID_VIEW_DETAILS , " " , wxDefaultPosition , wxDefaultSize ) ;
error_field - > SetForegroundColour ( * wxRED ) ;
tmpsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
tmpsizer - > Add ( error_field , 0 , wxALL , 5 ) ;
sizer - > Add ( tmpsizer , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
// Output folder
directory_text_field = newd wxTextCtrl ( this , wxID_ANY , " " , wxDefaultPosition , wxDefaultSize ) ;
directory_text_field - > Bind ( wxEVT_KEY_UP , & ExportTilesetsWindow : : OnDirectoryChanged , this ) ;
directory_text_field - > SetValue ( wxString ( g_settings . getString ( Config : : TILESET_EXPORT_DIR ) ) ) ;
tmpsizer = newd wxStaticBoxSizer ( wxHORIZONTAL , this , " Output Folder " ) ;
tmpsizer - > Add ( directory_text_field , 1 , wxALL , 5 ) ;
tmpsizer - > Add ( newd wxButton ( this , TILESET_FILE_BUTTON , " Browse " ) , 0 , wxALL , 5 ) ;
sizer - > Add ( tmpsizer , 0 , wxALL | wxEXPAND , 5 ) ;
// File name
file_name_text_field = newd wxTextCtrl ( this , wxID_ANY , " tilesets " , wxDefaultPosition , wxDefaultSize ) ;
file_name_text_field - > Bind ( wxEVT_KEY_UP , & ExportTilesetsWindow : : OnFileNameChanged , this ) ;
tmpsizer = newd wxStaticBoxSizer ( wxHORIZONTAL , this , " File Name " ) ;
tmpsizer - > Add ( file_name_text_field , 1 , wxALL , 5 ) ;
sizer - > Add ( tmpsizer , 0 , wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND , 5 ) ;
// OK/Cancel buttons
tmpsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
tmpsizer - > Add ( ok_button = newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
tmpsizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
sizer - > Add ( tmpsizer , 0 , wxCENTER , 10 ) ;
SetSizer ( sizer ) ;
Layout ( ) ;
Centre ( wxBOTH ) ;
CheckValues ( ) ;
}
ExportTilesetsWindow : : ~ ExportTilesetsWindow ( ) = default ;
void ExportTilesetsWindow : : OnClickBrowse ( wxCommandEvent & WXUNUSED ( event ) ) {
wxDirDialog dialog ( NULL , " Select the output folder " , " " , wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST ) ;
if ( dialog . ShowModal ( ) = = wxID_OK ) {
const wxString & directory = dialog . GetPath ( ) ;
directory_text_field - > ChangeValue ( directory ) ;
}
CheckValues ( ) ;
}
void ExportTilesetsWindow : : OnDirectoryChanged ( wxKeyEvent & event ) {
CheckValues ( ) ;
event . Skip ( ) ;
}
void ExportTilesetsWindow : : OnFileNameChanged ( wxKeyEvent & event ) {
CheckValues ( ) ;
event . Skip ( ) ;
}
void ExportTilesetsWindow : : OnClickOK ( wxCommandEvent & WXUNUSED ( event ) ) {
g_gui . CreateLoadBar ( " Exporting Tilesets " ) ;
try {
FileName directory ( directory_text_field - > GetValue ( ) ) ;
g_settings . setString ( Config : : TILESET_EXPORT_DIR , directory_text_field - > GetValue ( ) . ToStdString ( ) ) ;
FileName file ( file_name_text_field - > GetValue ( ) + " .xml " ) ;
file . Normalize ( wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_CASE | wxPATH_NORM_ABSOLUTE , directory . GetFullPath ( ) ) ;
pugi : : xml_document doc ;
pugi : : xml_node node = doc . append_child ( " materials " ) ;
std : : map < std : : string , TilesetCategoryType > palettes {
{ " Terrain " , TILESET_TERRAIN } ,
{ " Doodad " , TILESET_DOODAD } ,
{ " Items " , TILESET_ITEM } ,
{ " Raw " , TILESET_RAW }
} ;
for ( TilesetContainer : : iterator iter = g_materials . tilesets . begin ( ) ; iter ! = g_materials . tilesets . end ( ) ; + + iter ) {
std : : string _data = iter - > second - > name ;
std : : transform ( _data . begin ( ) , _data . end ( ) , _data . begin ( ) , [ ] ( unsigned char c ) { return std : : tolower ( c ) ; } ) ;
if ( _data = = " others " ) {
bool blocked = 1 ;
for ( const auto & kv : palettes ) {
TilesetCategory * tilesetCategory = iter - > second - > getCategory ( kv . second ) ;
if ( kv . second ! = TILESET_RAW & & tilesetCategory - > brushlist . size ( ) > 0 ) {
blocked = 0 ;
}
}
if ( blocked ) {
continue ;
}
}
pugi : : xml_node tileset = node . append_child ( " tileset " ) ;
tileset . append_attribute ( " name " ) = iter - > second - > name . c_str ( ) ;
for ( const auto & kv : palettes ) {
TilesetCategory * tilesetCategory = iter - > second - > getCategory ( kv . second ) ;
if ( tilesetCategory - > brushlist . size ( ) > 0 ) {
std : : string data = kv . first ;
std : : transform ( data . begin ( ) , data . end ( ) , data . begin ( ) , [ ] ( unsigned char c ) { return std : : tolower ( c ) ; } ) ;
pugi : : xml_node palette = tileset . append_child ( data . c_str ( ) ) ;
for ( BrushVector : : const_iterator _iter = tilesetCategory - > brushlist . begin ( ) ; _iter ! = tilesetCategory - > brushlist . end ( ) ; + + _iter ) {
if ( ! ( * _iter ) - > isRaw ( ) ) {
pugi : : xml_node brush = palette . append_child ( " brush " ) ;
brush . append_attribute ( " name " ) = ( * _iter ) - > getName ( ) . c_str ( ) ;
} else {
ItemType & it = g_items [ ( * _iter ) - > asRaw ( ) - > getItemID ( ) ] ;
if ( it . id ! = 0 ) {
pugi : : xml_node item = palette . append_child ( " item " ) ;
item . append_attribute ( " id " ) = it . id ;
}
}
}
}
}
size_t n = std : : distance ( tileset . begin ( ) , tileset . end ( ) ) ;
if ( n < = 0 ) {
node . remove_child ( tileset ) ;
}
}
doc . save_file ( file . GetFullPath ( ) . mb_str ( ) ) ;
g_gui . PopupDialog ( " Successfully saved Tilesets " , " Saved tilesets to ' " + std : : string ( file . GetFullPath ( ) . mb_str ( ) ) + " ' " , wxOK ) ;
g_materials . modify ( false ) ;
} catch ( std : : bad_alloc & ) {
g_gui . PopupDialog ( " Error " , " There is not enough memory available to complete the operation. " , wxOK ) ;
}
g_gui . DestroyLoadBar ( ) ;
EndModal ( 1 ) ;
}
void ExportTilesetsWindow : : OnClickCancel ( wxCommandEvent & WXUNUSED ( event ) ) {
// Just close this window
EndModal ( 0 ) ;
}
void ExportTilesetsWindow : : CheckValues ( ) {
if ( directory_text_field - > IsEmpty ( ) ) {
error_field - > SetLabel ( " Type or select an output folder. " ) ;
ok_button - > Enable ( false ) ;
return ;
}
if ( file_name_text_field - > IsEmpty ( ) ) {
error_field - > SetLabel ( " Type a name for the file. " ) ;
ok_button - > Enable ( false ) ;
return ;
}
FileName directory ( directory_text_field - > GetValue ( ) ) ;
if ( ! directory . Exists ( ) ) {
error_field - > SetLabel ( " Output folder not found. " ) ;
ok_button - > Enable ( false ) ;
return ;
}
if ( ! directory . IsDirWritable ( ) ) {
error_field - > SetLabel ( " Output folder is not writable. " ) ;
ok_button - > Enable ( false ) ;
return ;
}
error_field - > SetLabel ( wxEmptyString ) ;
ok_button - > Enable ( true ) ;
}
2012-06-30 18:27:02 +02:00
// ============================================================================
// Numkey forwarding text control
BEGIN_EVENT_TABLE ( KeyForwardingTextCtrl , wxTextCtrl )
2023-10-09 19:12:16 -07:00
EVT_KEY_DOWN ( KeyForwardingTextCtrl : : OnKeyDown )
2012-06-30 18:27:02 +02:00
END_EVENT_TABLE ( )
2023-10-09 19:12:16 -07:00
void KeyForwardingTextCtrl : : OnKeyDown ( wxKeyEvent & event ) {
if ( event . GetKeyCode ( ) = = WXK_UP | | event . GetKeyCode ( ) = = WXK_DOWN | | event . GetKeyCode ( ) = = WXK_PAGEDOWN | | event . GetKeyCode ( ) = = WXK_PAGEUP ) {
2012-06-30 18:27:02 +02:00
GetParent ( ) - > GetEventHandler ( ) - > AddPendingEvent ( event ) ;
2015-12-06 11:42:37 -03:00
} else {
2012-06-30 18:27:02 +02:00
event . Skip ( ) ;
}
}
2012-06-29 16:44:26 +02:00
// ============================================================================
// Find Item Dialog (Jump to item)
BEGIN_EVENT_TABLE ( FindDialog , wxDialog )
2023-10-09 19:12:16 -07:00
EVT_TIMER ( wxID_ANY , FindDialog : : OnTextIdle )
EVT_TEXT ( JUMP_DIALOG_TEXT , FindDialog : : OnTextChange )
EVT_KEY_DOWN ( FindDialog : : OnKeyDown )
EVT_TEXT_ENTER ( JUMP_DIALOG_TEXT , FindDialog : : OnClickOK )
EVT_LISTBOX_DCLICK ( JUMP_DIALOG_LIST , FindDialog : : OnClickList )
EVT_BUTTON ( wxID_OK , FindDialog : : OnClickOK )
EVT_BUTTON ( wxID_CANCEL , FindDialog : : OnClickCancel )
2012-06-29 16:44:26 +02:00
END_EVENT_TABLE ( )
FindDialog : : FindDialog ( wxWindow * parent , wxString title ) :
2016-09-29 20:30:54 -03:00
wxDialog ( g_gui . root , wxID_ANY , title , wxDefaultPosition , wxDefaultSize , wxRESIZE_BORDER | wxCAPTION | wxCLOSE_BOX ) ,
2012-06-29 16:44:26 +02:00
idle_input_timer ( this ) ,
2014-01-22 20:16:17 +01:00
result_brush ( nullptr ) ,
2023-10-09 19:12:16 -07:00
result_id ( 0 ) {
2012-06-29 16:44:26 +02:00
wxSizer * sizer = newd wxBoxSizer ( wxVERTICAL ) ;
2016-11-05 15:28:14 +01:00
search_field = newd KeyForwardingTextCtrl ( this , JUMP_DIALOG_TEXT , " " , wxDefaultPosition , wxDefaultSize , wxTE_PROCESS_ENTER ) ;
2012-06-29 16:44:26 +02:00
search_field - > SetFocus ( ) ;
sizer - > Add ( search_field , 0 , wxEXPAND ) ;
item_list = newd FindDialogListBox ( this , JUMP_DIALOG_LIST ) ;
item_list - > SetMinSize ( wxSize ( 470 , 400 ) ) ;
2012-06-30 18:27:02 +02:00
sizer - > Add ( item_list , wxSizerFlags ( 1 ) . Expand ( ) . Border ( ) ) ;
2012-06-29 16:44:26 +02:00
wxSizer * stdsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
2016-11-05 15:28:14 +01:00
stdsizer - > Add ( newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
stdsizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
2012-06-30 18:27:02 +02:00
sizer - > Add ( stdsizer , wxSizerFlags ( 0 ) . Center ( ) . Border ( ) ) ;
2012-06-29 16:44:26 +02:00
SetSizerAndFit ( sizer ) ;
2016-02-29 21:47:54 -03:00
Centre ( wxBOTH ) ;
2012-06-29 16:44:26 +02:00
// We can't call it here since it calls an abstract function, call in child constructors instead.
// RefreshContents();
}
2019-06-25 18:07:36 +02:00
FindDialog : : ~ FindDialog ( ) = default ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
void FindDialog : : OnKeyDown ( wxKeyEvent & event ) {
2012-06-29 16:44:26 +02:00
int w , h ;
item_list - > GetSize ( & w , & h ) ;
2016-09-29 18:36:27 -03:00
size_t amount = 1 ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
switch ( event . GetKeyCode ( ) ) {
2012-06-29 16:44:26 +02:00
case WXK_PAGEUP :
amount = h / 32 + 1 ;
2020-03-25 14:07:43 -07:00
[[fallthrough]] ;
2015-12-06 11:42:37 -03:00
case WXK_UP : {
2023-10-09 19:12:16 -07:00
if ( item_list - > GetItemCount ( ) > 0 ) {
2014-08-01 15:04:40 -05:00
ssize_t n = item_list - > GetSelection ( ) ;
2023-10-09 19:12:16 -07:00
if ( n = = wxNOT_FOUND ) {
2012-06-29 16:44:26 +02:00
n = 0 ;
2023-10-09 19:12:16 -07:00
} else if ( n ! = amount & & n - amount < n ) { // latter is needed for unsigned overflow
2012-06-29 16:44:26 +02:00
n - = amount ;
2023-10-09 19:12:16 -07:00
} else {
2012-06-29 16:44:26 +02:00
n = 0 ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
item_list - > SetSelection ( n ) ;
}
2015-12-06 11:42:37 -03:00
break ;
2012-06-29 16:44:26 +02:00
}
2015-12-06 11:42:37 -03:00
2012-06-29 16:44:26 +02:00
case WXK_PAGEDOWN :
amount = h / 32 + 1 ;
2020-03-25 14:07:43 -07:00
[[fallthrough]] ;
2015-12-06 11:42:37 -03:00
case WXK_DOWN : {
2023-10-09 19:12:16 -07:00
if ( item_list - > GetItemCount ( ) > 0 ) {
2014-08-01 15:04:40 -05:00
ssize_t n = item_list - > GetSelection ( ) ;
2012-06-29 16:44:26 +02:00
size_t itemcount = item_list - > GetItemCount ( ) ;
2023-10-09 19:12:16 -07:00
if ( n = = wxNOT_FOUND ) {
2012-06-29 16:44:26 +02:00
n = 0 ;
2023-10-09 19:12:16 -07:00
} else if ( static_cast < uint32_t > ( n ) < itemcount - amount & & itemcount - amount < itemcount ) {
2012-06-29 16:44:26 +02:00
n + = amount ;
2023-10-09 19:12:16 -07:00
} else {
2012-06-29 16:44:26 +02:00
n = item_list - > GetItemCount ( ) - 1 ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
item_list - > SetSelection ( n ) ;
}
2015-12-06 11:42:37 -03:00
break ;
2012-06-29 16:44:26 +02:00
}
2015-12-06 11:42:37 -03:00
default :
event . Skip ( ) ;
break ;
2012-06-29 16:44:26 +02:00
}
}
2023-10-09 19:12:16 -07:00
void FindDialog : : OnTextIdle ( wxTimerEvent & WXUNUSED ( event ) ) {
2012-06-30 18:27:02 +02:00
RefreshContents ( ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void FindDialog : : OnTextChange ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
idle_input_timer . Start ( 800 , true ) ;
}
2023-10-09 19:12:16 -07:00
void FindDialog : : OnClickList ( wxCommandEvent & event ) {
2012-06-29 16:44:26 +02:00
OnClickListInternal ( event ) ;
}
2023-10-09 19:12:16 -07:00
void FindDialog : : OnClickOK ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
// This is to get virtual callback
OnClickOKInternal ( ) ;
}
2023-10-09 19:12:16 -07:00
void FindDialog : : OnClickCancel ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
EndModal ( 0 ) ;
}
2023-10-09 19:12:16 -07:00
void FindDialog : : RefreshContents ( ) {
2012-06-29 16:44:26 +02:00
// This is to get virtual callback
RefreshContentsInternal ( ) ;
}
// ============================================================================
// Find Brush Dialog (Jump to brush)
2023-10-09 19:12:16 -07:00
FindBrushDialog : : FindBrushDialog ( wxWindow * parent , wxString title ) :
FindDialog ( parent , title ) {
2012-06-29 16:44:26 +02:00
RefreshContents ( ) ;
}
2019-06-25 18:07:36 +02:00
FindBrushDialog : : ~ FindBrushDialog ( ) = default ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
void FindBrushDialog : : OnClickListInternal ( wxCommandEvent & event ) {
2012-06-29 16:44:26 +02:00
Brush * brush = item_list - > GetSelectedBrush ( ) ;
2023-10-09 19:12:16 -07:00
if ( brush ) {
2012-06-29 16:44:26 +02:00
result_brush = brush ;
EndModal ( 1 ) ;
}
}
2023-10-09 19:12:16 -07:00
void FindBrushDialog : : OnClickOKInternal ( ) {
2012-06-29 16:44:26 +02:00
// This is kind of stupid as it would fail unless the "Please enter a search string" wasn't there
2023-10-09 19:12:16 -07:00
if ( item_list - > GetItemCount ( ) > 0 ) {
if ( item_list - > GetSelection ( ) = = wxNOT_FOUND ) {
2012-06-29 16:44:26 +02:00
item_list - > SetSelection ( 0 ) ;
}
Brush * brush = item_list - > GetSelectedBrush ( ) ;
2023-10-09 19:12:16 -07:00
if ( ! brush ) {
2012-06-29 16:44:26 +02:00
// It's either "Please enter a search string" or "No matches"
// Perhaps we can refresh now?
std : : string search_string = as_lower_str ( nstr ( search_field - > GetValue ( ) ) ) ;
bool do_search = ( search_string . size ( ) > = 2 ) ;
2023-10-09 19:12:16 -07:00
if ( do_search ) {
const BrushMap & map = g_brushes . getMap ( ) ;
for ( BrushMap : : const_iterator iter = map . begin ( ) ; iter ! = map . end ( ) ; + + iter ) {
2012-06-29 16:44:26 +02:00
const Brush * brush = iter - > second ;
2023-10-09 19:12:16 -07:00
if ( as_lower_str ( brush - > getName ( ) ) . find ( search_string ) = = std : : string : : npos ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
// Don't match RAWs now.
2023-10-09 19:12:16 -07:00
if ( brush - > isRaw ( ) ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
// Found one!
result_brush = brush ;
break ;
}
// Did we not find a matching brush?
2023-10-09 19:12:16 -07:00
if ( ! result_brush ) {
2012-06-29 16:44:26 +02:00
// Then let's search the RAWs
2023-10-09 19:12:16 -07:00
for ( int id = 0 ; id < = g_items . getMaxID ( ) ; + + id ) {
const ItemType & type = g_items . getItemType ( id ) ;
if ( type . id = = 0 ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
2023-10-09 23:02:37 -03:00
RAWBrush * raw_brush = type . raw_brush ;
2023-10-09 19:12:16 -07:00
if ( ! raw_brush ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
if ( as_lower_str ( raw_brush - > getName ( ) ) . find ( search_string ) = = std : : string : : npos ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
// Found one!
2016-11-12 10:30:06 -03:00
result_brush = raw_brush ;
2012-06-29 16:44:26 +02:00
break ;
}
}
// Done!
}
2015-12-06 11:42:37 -03:00
} else {
2012-06-29 16:44:26 +02:00
result_brush = brush ;
}
}
EndModal ( 1 ) ;
}
2023-10-09 19:12:16 -07:00
void FindBrushDialog : : RefreshContentsInternal ( ) {
2012-06-29 16:44:26 +02:00
item_list - > Clear ( ) ;
std : : string search_string = as_lower_str ( nstr ( search_field - > GetValue ( ) ) ) ;
bool do_search = ( search_string . size ( ) > = 2 ) ;
2023-10-09 19:12:16 -07:00
if ( do_search ) {
2016-11-06 18:57:58 +01:00
bool found_search_results = false ;
2023-10-09 19:12:16 -07:00
const BrushMap & brushes_map = g_brushes . getMap ( ) ;
2016-09-29 18:36:27 -03:00
2012-06-29 16:44:26 +02:00
// We store the raws so they display last of all results
std : : deque < const RAWBrush * > raws ;
2023-10-09 19:12:16 -07:00
for ( BrushMap : : const_iterator iter = brushes_map . begin ( ) ; iter ! = brushes_map . end ( ) ; + + iter ) {
2012-06-29 16:44:26 +02:00
const Brush * brush = iter - > second ;
2023-10-09 19:12:16 -07:00
if ( as_lower_str ( brush - > getName ( ) ) . find ( search_string ) = = std : : string : : npos ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
if ( brush - > isRaw ( ) ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
2016-11-06 18:57:58 +01:00
found_search_results = true ;
2012-06-29 16:44:26 +02:00
item_list - > AddBrush ( const_cast < Brush * > ( brush ) ) ;
}
2023-10-09 19:12:16 -07:00
for ( int id = 0 ; id < = g_items . getMaxID ( ) ; + + id ) {
const ItemType & type = g_items . getItemType ( id ) ;
if ( type . id = = 0 ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
2023-10-09 23:02:37 -03:00
RAWBrush * raw_brush = type . raw_brush ;
2023-10-09 19:12:16 -07:00
if ( ! raw_brush ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
if ( as_lower_str ( raw_brush - > getName ( ) ) . find ( search_string ) = = std : : string : : npos ) {
2012-06-29 16:44:26 +02:00
continue ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
2016-11-06 18:57:58 +01:00
found_search_results = true ;
2016-11-12 10:30:06 -03:00
item_list - > AddBrush ( raw_brush ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
while ( raws . size ( ) > 0 ) {
2012-06-29 16:44:26 +02:00
item_list - > AddBrush ( const_cast < RAWBrush * > ( raws . front ( ) ) ) ;
raws . pop_front ( ) ;
}
2023-10-09 19:12:16 -07:00
if ( found_search_results ) {
2012-06-29 16:44:26 +02:00
item_list - > SetSelection ( 0 ) ;
2015-12-06 11:42:37 -03:00
} else {
2012-06-29 16:44:26 +02:00
item_list - > SetNoMatches ( ) ;
}
}
2016-11-06 18:57:58 +01:00
item_list - > Refresh ( ) ;
2012-06-29 16:44:26 +02:00
}
2012-06-30 18:27:02 +02:00
// ============================================================================
// Listbox in find item / brush stuff
2012-06-29 16:44:26 +02:00
FindDialogListBox : : FindDialogListBox ( wxWindow * parent , wxWindowID id ) :
wxVListBox ( parent , id , wxDefaultPosition , wxDefaultSize , wxLB_SINGLE ) ,
cleared ( false ) ,
2023-10-09 19:12:16 -07:00
no_matches ( false ) {
2012-06-29 16:44:26 +02:00
Clear ( ) ;
}
2023-10-09 19:12:16 -07:00
FindDialogListBox : : ~ FindDialogListBox ( ) {
2015-12-06 11:42:37 -03:00
////
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void FindDialogListBox : : Clear ( ) {
2012-06-29 16:44:26 +02:00
cleared = true ;
no_matches = false ;
brushlist . clear ( ) ;
SetItemCount ( 1 ) ;
}
2023-10-09 19:12:16 -07:00
void FindDialogListBox : : SetNoMatches ( ) {
2012-06-29 16:44:26 +02:00
cleared = false ;
no_matches = true ;
brushlist . clear ( ) ;
SetItemCount ( 1 ) ;
}
2023-10-09 19:12:16 -07:00
void FindDialogListBox : : AddBrush ( Brush * brush ) {
if ( cleared | | no_matches ) {
2012-06-29 16:44:26 +02:00
SetItemCount ( 0 ) ;
2023-10-09 19:12:16 -07:00
}
2016-09-29 18:36:27 -03:00
2012-06-29 16:44:26 +02:00
cleared = false ;
no_matches = false ;
SetItemCount ( GetItemCount ( ) + 1 ) ;
brushlist . push_back ( brush ) ;
}
2023-10-09 19:12:16 -07:00
Brush * FindDialogListBox : : GetSelectedBrush ( ) {
2014-08-01 15:04:40 -05:00
ssize_t n = GetSelection ( ) ;
2023-10-09 19:12:16 -07:00
if ( n = = wxNOT_FOUND | | no_matches | | cleared ) {
2014-01-22 20:16:17 +01:00
return nullptr ;
2023-10-09 19:12:16 -07:00
}
2012-06-29 16:44:26 +02:00
return brushlist [ n ] ;
}
2023-10-09 19:12:16 -07:00
void FindDialogListBox : : OnDrawItem ( wxDC & dc , const wxRect & rect , size_t n ) const {
if ( no_matches ) {
2016-11-05 15:28:14 +01:00
dc . DrawText ( " No matches for your search. " , rect . GetX ( ) + 40 , rect . GetY ( ) + 6 ) ;
2023-10-09 19:12:16 -07:00
} else if ( cleared ) {
2016-11-05 15:28:14 +01:00
dc . DrawText ( " Please enter your search string. " , rect . GetX ( ) + 40 , rect . GetY ( ) + 6 ) ;
2015-12-06 11:42:37 -03:00
} else {
2012-06-29 16:44:26 +02:00
ASSERT ( n < brushlist . size ( ) ) ;
2016-09-29 20:30:54 -03:00
Sprite * spr = g_gui . gfx . getSprite ( brushlist [ n ] - > getLookID ( ) ) ;
2023-10-09 19:12:16 -07:00
if ( spr ) {
2012-06-29 16:44:26 +02:00
spr - > DrawTo ( & dc , SPRITE_SIZE_32x32 , rect . GetX ( ) , rect . GetY ( ) , rect . GetWidth ( ) , rect . GetHeight ( ) ) ;
}
2023-10-09 19:12:16 -07:00
if ( IsSelected ( n ) ) {
if ( HasFocus ( ) ) {
2016-03-17 07:09:40 -03:00
dc . SetTextForeground ( wxColor ( 0xFF , 0xFF , 0xFF ) ) ;
2023-10-09 19:12:16 -07:00
} else {
2016-03-17 07:09:40 -03:00
dc . SetTextForeground ( wxColor ( 0x00 , 0x00 , 0xFF ) ) ;
2023-10-09 19:12:16 -07:00
}
2015-12-06 11:42:37 -03:00
} else {
2012-06-29 16:44:26 +02:00
dc . SetTextForeground ( wxColor ( 0x00 , 0x00 , 0x00 ) ) ;
}
dc . DrawText ( wxstr ( brushlist [ n ] - > getName ( ) ) , rect . GetX ( ) + 40 , rect . GetY ( ) + 6 ) ;
}
}
2023-10-09 19:12:16 -07:00
wxCoord FindDialogListBox : : OnMeasureItem ( size_t n ) const {
2012-06-29 16:44:26 +02:00
return 32 ;
}
2016-11-08 23:29:05 +01:00
// ============================================================================
// wxListBox that can be sorted
2023-10-09 19:12:16 -07:00
SortableListBox : : SortableListBox ( wxWindow * parent , wxWindowID id , const wxPoint & pos , const wxSize & size ) :
2023-11-08 17:04:13 -08:00
wxCheckListBox ( parent , id , pos , size , 0 , nullptr , wxLB_SINGLE | wxLB_NEEDED_SB ) { }
2016-11-08 23:29:05 +01:00
2023-10-09 19:12:16 -07:00
SortableListBox : : ~ SortableListBox ( ) { }
2016-11-08 23:29:05 +01:00
void SortableListBox : : Sort ( ) {
2023-10-09 19:12:16 -07:00
if ( GetCount ( ) = = 0 ) {
2016-11-11 23:32:10 +01:00
return ;
2023-10-09 19:12:16 -07:00
}
2016-11-11 23:32:10 +01:00
wxASSERT_MSG ( GetClientDataType ( ) ! = wxClientData_Object , " Sorting a list with data of type wxClientData_Object is currently not implemented " ) ;
DoSort ( ) ;
}
void SortableListBox : : DoSort ( ) {
size_t count = GetCount ( ) ;
int selection = GetSelection ( ) ;
wxClientDataType dataType = GetClientDataType ( ) ;
wxArrayString stringList ;
wxArrayPtrVoid dataList ;
for ( size_t i = 0 ; i < count ; + + i ) {
stringList . Add ( GetString ( i ) ) ;
2023-10-09 19:12:16 -07:00
if ( dataType = = wxClientData_Void ) {
2016-11-11 23:32:10 +01:00
dataList . Add ( GetClientData ( i ) ) ;
2023-10-09 19:12:16 -07:00
}
2016-11-11 23:32:10 +01:00
}
2023-10-09 19:12:16 -07:00
// Insertion sort
2016-11-11 23:32:10 +01:00
for ( size_t i = 0 ; i < count ; + + i ) {
size_t j = i ;
while ( j > 0 & & stringList [ j ] . CmpNoCase ( stringList [ j - 1 ] ) < 0 ) {
wxString tmpString = stringList [ j ] ;
stringList [ j ] = stringList [ j - 1 ] ;
stringList [ j - 1 ] = tmpString ;
if ( dataType = = wxClientData_Void ) {
void * tmpData = dataList [ j ] ;
dataList [ j ] = dataList [ j - 1 ] ;
dataList [ j - 1 ] = tmpData ;
}
2023-10-09 19:12:16 -07:00
if ( selection = = j - 1 ) {
2016-11-11 23:32:10 +01:00
selection + + ;
2023-10-09 19:12:16 -07:00
} else if ( selection = = j ) {
2016-11-11 23:32:10 +01:00
selection - - ;
}
2016-11-09 14:52:04 +01:00
j - - ;
}
}
2016-11-08 23:29:05 +01:00
2016-11-11 23:32:10 +01:00
Freeze ( ) ;
Clear ( ) ;
for ( size_t i = 0 ; i < count ; + + i ) {
2023-10-09 19:12:16 -07:00
if ( dataType = = wxClientData_Void ) {
2016-11-11 23:32:10 +01:00
Append ( stringList [ i ] , dataList [ i ] ) ;
2023-10-09 19:12:16 -07:00
} else {
2016-11-11 23:32:10 +01:00
Append ( stringList [ i ] ) ;
2023-10-09 19:12:16 -07:00
}
2016-11-09 14:52:04 +01:00
}
2016-11-11 23:32:10 +01:00
Thaw ( ) ;
2016-11-09 14:52:04 +01:00
2016-11-11 23:32:10 +01:00
SetSelection ( selection ) ;
2016-11-08 23:29:05 +01:00
}
2012-07-20 16:32:57 +02:00
// ============================================================================
// Object properties base
ObjectPropertiesWindowBase : : ObjectPropertiesWindowBase ( wxWindow * parent , wxString title , const Map * map , const Tile * tile , Item * item , wxPoint position /* = wxDefaultPosition */ ) :
2023-10-09 19:12:16 -07:00
wxDialog ( parent , wxID_ANY , title , position , wxSize ( 600 , 400 ) , wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER ) ,
2012-07-20 16:32:57 +02:00
edit_map ( map ) ,
edit_tile ( tile ) ,
edit_item ( item ) ,
2021-05-25 00:29:12 -03:00
edit_monster ( nullptr ) ,
edit_spawn_monster ( nullptr ) ,
edit_npc ( nullptr ) ,
2023-10-09 19:12:16 -07:00
edit_spawn_npc ( nullptr ) {
2021-05-25 00:29:12 -03:00
////
}
ObjectPropertiesWindowBase : : ObjectPropertiesWindowBase ( wxWindow * parent , wxString title , const Map * map , const Tile * tile , Monster * monster , wxPoint position /* = wxDefaultPosition */ ) :
2023-10-09 19:12:16 -07:00
wxDialog ( parent , wxID_ANY , title , position , wxSize ( 600 , 400 ) , wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER ) ,
2021-05-25 00:29:12 -03:00
edit_map ( map ) ,
edit_tile ( tile ) ,
edit_item ( nullptr ) ,
edit_monster ( monster ) ,
edit_spawn_monster ( nullptr ) ,
edit_npc ( nullptr ) ,
2023-10-09 19:12:16 -07:00
edit_spawn_npc ( nullptr ) {
2021-05-25 00:29:12 -03:00
////
}
ObjectPropertiesWindowBase : : ObjectPropertiesWindowBase ( wxWindow * parent , wxString title , const Map * map , const Tile * tile , SpawnMonster * spawnMonster , wxPoint position /* = wxDefaultPosition */ ) :
2023-10-09 19:12:16 -07:00
wxDialog ( parent , wxID_ANY , title , position , wxSize ( 600 , 400 ) , wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER ) ,
2021-05-25 00:29:12 -03:00
edit_map ( map ) ,
edit_tile ( tile ) ,
edit_item ( nullptr ) ,
edit_monster ( nullptr ) ,
edit_spawn_monster ( spawnMonster ) ,
edit_npc ( nullptr ) ,
2023-10-09 19:12:16 -07:00
edit_spawn_npc ( nullptr ) {
2015-12-06 11:42:37 -03:00
////
2012-07-20 16:32:57 +02:00
}
2021-05-25 00:29:12 -03:00
ObjectPropertiesWindowBase : : ObjectPropertiesWindowBase ( wxWindow * parent , wxString title , const Map * map , const Tile * tile , Npc * npc , wxPoint position /* = wxDefaultPosition */ ) :
2023-10-09 19:12:16 -07:00
wxDialog ( parent , wxID_ANY , title , position , wxSize ( 600 , 400 ) , wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER ) ,
2012-07-20 16:32:57 +02:00
edit_map ( map ) ,
edit_tile ( tile ) ,
2014-01-22 20:16:17 +01:00
edit_item ( nullptr ) ,
2021-05-25 00:29:12 -03:00
edit_monster ( nullptr ) ,
edit_spawn_monster ( nullptr ) ,
edit_npc ( npc ) ,
2023-10-09 19:12:16 -07:00
edit_spawn_npc ( nullptr ) {
2015-12-06 11:42:37 -03:00
////
2012-07-20 16:32:57 +02:00
}
2021-05-25 00:29:12 -03:00
ObjectPropertiesWindowBase : : ObjectPropertiesWindowBase ( wxWindow * parent , wxString title , const Map * map , const Tile * tile , SpawnNpc * spawnNpc , wxPoint position /* = wxDefaultPosition */ ) :
2023-10-09 19:12:16 -07:00
wxDialog ( parent , wxID_ANY , title , position , wxSize ( 600 , 400 ) , wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER ) ,
2012-07-20 16:32:57 +02:00
edit_map ( map ) ,
edit_tile ( tile ) ,
2014-01-22 20:16:17 +01:00
edit_item ( nullptr ) ,
2021-05-25 00:29:12 -03:00
edit_monster ( nullptr ) ,
edit_spawn_monster ( nullptr ) ,
edit_npc ( nullptr ) ,
2023-10-09 19:12:16 -07:00
edit_spawn_npc ( spawnNpc ) {
2015-12-06 11:42:37 -03:00
////
2012-07-20 16:32:57 +02:00
}
2024-06-07 15:03:37 -03:00
ObjectPropertiesWindowBase : : ObjectPropertiesWindowBase ( wxWindow * parent , wxString title , wxPoint position /* = wxDefaultPosition */ ) :
wxDialog ( parent , wxID_ANY , title , position , wxSize ( 600 , 400 ) , wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER ) {
////
}
2023-10-09 19:12:16 -07:00
Item * ObjectPropertiesWindowBase : : getItemBeingEdited ( ) {
2012-07-20 16:32:57 +02:00
return edit_item ;
}
2012-06-29 16:44:26 +02:00
// ============================================================================
// Edit Towns Dialog
BEGIN_EVENT_TABLE ( EditTownsDialog , wxDialog )
2023-10-09 19:12:16 -07:00
EVT_LISTBOX ( EDIT_TOWNS_LISTBOX , EditTownsDialog : : OnListBoxChange )
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
EVT_BUTTON ( EDIT_TOWNS_SELECT_TEMPLE , EditTownsDialog : : OnClickSelectTemplePosition )
EVT_BUTTON ( EDIT_TOWNS_ADD , EditTownsDialog : : OnClickAdd )
EVT_BUTTON ( EDIT_TOWNS_REMOVE , EditTownsDialog : : OnClickRemove )
EVT_BUTTON ( wxID_OK , EditTownsDialog : : OnClickOK )
EVT_BUTTON ( wxID_CANCEL , EditTownsDialog : : OnClickCancel )
2012-06-29 16:44:26 +02:00
END_EVENT_TABLE ( )
2023-10-09 19:12:16 -07:00
EditTownsDialog : : EditTownsDialog ( wxWindow * parent , Editor & editor ) :
wxDialog ( parent , wxID_ANY , " Towns " , wxDefaultPosition , wxSize ( 280 , 330 ) ) ,
editor ( editor ) {
const Map & map = editor . getMap ( ) ;
2012-06-29 16:44:26 +02:00
// Create topsizer
wxSizer * sizer = newd wxBoxSizer ( wxVERTICAL ) ;
wxSizer * tmpsizer ;
2023-10-09 19:12:16 -07:00
for ( TownMap : : const_iterator town_iter = map . towns . begin ( ) ; town_iter ! = map . towns . end ( ) ; + + town_iter ) {
2012-06-29 16:44:26 +02:00
Town * town = town_iter - > second ;
town_list . push_back ( newd Town ( * town ) ) ;
2023-10-09 19:12:16 -07:00
if ( max_town_id < town - > getID ( ) ) {
2012-06-29 16:44:26 +02:00
max_town_id = town - > getID ( ) ;
}
}
// Town list
2015-01-23 18:30:56 -03:00
town_listbox = newd wxListBox ( this , EDIT_TOWNS_LISTBOX , wxDefaultPosition , wxSize ( 240 , 100 ) ) ;
sizer - > Add ( town_listbox , 1 , wxEXPAND | wxTOP | wxLEFT | wxRIGHT , 10 ) ;
2012-06-29 16:44:26 +02:00
tmpsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
2016-11-05 15:28:14 +01:00
tmpsizer - > Add ( newd wxButton ( this , EDIT_TOWNS_ADD , " Add " ) , 0 , wxTOP , 5 ) ;
tmpsizer - > Add ( remove_button = newd wxButton ( this , EDIT_TOWNS_REMOVE , " Remove " ) , 0 , wxRIGHT | wxTOP , 5 ) ;
2015-01-23 18:30:56 -03:00
sizer - > Add ( tmpsizer , 0 , wxEXPAND | wxLEFT | wxRIGHT , 10 ) ;
2012-06-29 16:44:26 +02:00
// House options
2016-11-05 15:28:14 +01:00
tmpsizer = newd wxStaticBoxSizer ( wxHORIZONTAL , this , " Name / ID " ) ;
2023-10-09 19:12:16 -07:00
name_field = newd wxTextCtrl ( this , wxID_ANY , " " , wxDefaultPosition , wxSize ( 190 , 20 ) , 0 , wxTextValidator ( wxFILTER_ASCII , & town_name ) ) ;
2015-01-23 18:30:56 -03:00
tmpsizer - > Add ( name_field , 2 , wxEXPAND | wxLEFT | wxBOTTOM , 5 ) ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
id_field = newd wxTextCtrl ( this , wxID_ANY , " " , wxDefaultPosition , wxSize ( 40 , 20 ) , 0 , wxTextValidator ( wxFILTER_NUMERIC , & town_id ) ) ;
2012-06-29 16:44:26 +02:00
id_field - > Enable ( false ) ;
2015-01-23 18:30:56 -03:00
tmpsizer - > Add ( id_field , 1 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 5 ) ;
sizer - > Add ( tmpsizer , 0 , wxEXPAND | wxALL , 10 ) ;
2012-06-29 16:44:26 +02:00
// Temple position
2016-11-05 15:28:14 +01:00
temple_position = newd PositionCtrl ( this , " Temple Position " , 0 , 0 , 0 , map . getWidth ( ) , map . getHeight ( ) ) ;
select_position_button = newd wxButton ( this , EDIT_TOWNS_SELECT_TEMPLE , " Go To " ) ;
2015-07-11 21:20:07 -03:00
temple_position - > Add ( select_position_button , 0 , wxLEFT | wxRIGHT | wxBOTTOM , 5 ) ;
sizer - > Add ( temple_position , 0 , wxEXPAND | wxLEFT | wxRIGHT , 10 ) ;
2012-06-29 16:44:26 +02:00
// OK/Cancel buttons
tmpsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
2016-11-05 15:28:14 +01:00
tmpsizer - > Add ( newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
tmpsizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
2015-01-23 18:30:56 -03:00
sizer - > Add ( tmpsizer , 0 , wxCENTER | wxALL , 10 ) ;
2012-06-29 16:44:26 +02:00
SetSizerAndFit ( sizer ) ;
2016-02-29 21:47:54 -03:00
Centre ( wxBOTH ) ;
2012-06-29 16:44:26 +02:00
BuildListBox ( true ) ;
}
2023-10-09 19:12:16 -07:00
EditTownsDialog : : ~ EditTownsDialog ( ) {
for ( std : : vector < Town * > : : iterator town_iter = town_list . begin ( ) ; town_iter ! = town_list . end ( ) ; + + town_iter ) {
2012-06-29 16:44:26 +02:00
delete * town_iter ;
}
}
2023-10-09 19:12:16 -07:00
void EditTownsDialog : : BuildListBox ( bool doselect ) {
2012-06-29 16:44:26 +02:00
long tmplong = 0 ;
max_town_id = 0 ;
wxArrayString town_name_list ;
uint32_t selection_before = 0 ;
2023-10-09 19:12:16 -07:00
if ( doselect & & id_field - > GetValue ( ) . ToLong ( & tmplong ) ) {
2012-06-29 16:44:26 +02:00
uint32_t old_town_id = tmplong ;
2023-10-09 19:12:16 -07:00
for ( std : : vector < Town * > : : iterator town_iter = town_list . begin ( ) ; town_iter ! = town_list . end ( ) ; + + town_iter ) {
if ( old_town_id = = ( * town_iter ) - > getID ( ) ) {
2012-06-29 16:44:26 +02:00
selection_before = ( * town_iter ) - > getID ( ) ;
break ;
}
}
}
2023-10-09 19:12:16 -07:00
for ( std : : vector < Town * > : : iterator town_iter = town_list . begin ( ) ; town_iter ! = town_list . end ( ) ; + + town_iter ) {
2012-06-29 16:44:26 +02:00
Town * town = * town_iter ;
town_name_list . Add ( wxstr ( town - > getName ( ) ) ) ;
2023-10-09 19:12:16 -07:00
if ( max_town_id < town - > getID ( ) ) {
2012-06-29 16:44:26 +02:00
max_town_id = town - > getID ( ) ;
}
}
town_listbox - > Set ( town_name_list ) ;
remove_button - > Enable ( town_listbox - > GetCount ( ) ! = 0 ) ;
select_position_button - > Enable ( false ) ;
2023-10-09 19:12:16 -07:00
if ( doselect ) {
if ( selection_before ) {
2012-06-29 16:44:26 +02:00
int i = 0 ;
2023-10-09 19:12:16 -07:00
for ( std : : vector < Town * > : : iterator town_iter = town_list . begin ( ) ; town_iter ! = town_list . end ( ) ; + + town_iter ) {
if ( selection_before = = ( * town_iter ) - > getID ( ) ) {
2012-06-29 16:44:26 +02:00
town_listbox - > SetSelection ( i ) ;
return ;
}
+ + i ;
}
}
UpdateSelection ( 0 ) ;
}
}
2023-10-09 19:12:16 -07:00
void EditTownsDialog : : UpdateSelection ( int new_selection ) {
2012-06-29 16:44:26 +02:00
long tmplong ;
// Save old values
2023-10-09 19:12:16 -07:00
if ( town_list . size ( ) > 0 ) {
if ( id_field - > GetValue ( ) . ToLong ( & tmplong ) ) {
2012-06-29 16:44:26 +02:00
uint32_t old_town_id = tmplong ;
2014-01-22 20:16:17 +01:00
Town * old_town = nullptr ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
for ( std : : vector < Town * > : : iterator town_iter = town_list . begin ( ) ; town_iter ! = town_list . end ( ) ; + + town_iter ) {
if ( old_town_id = = ( * town_iter ) - > getID ( ) ) {
2012-06-29 16:44:26 +02:00
old_town = * town_iter ;
break ;
}
}
2023-10-09 19:12:16 -07:00
if ( old_town ) {
2015-07-11 21:20:07 -03:00
Position templepos = temple_position - > GetPosition ( ) ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
// printf("Changed town %d:%s\n", old_town_id, old_town->getName().c_str());
// printf("New values %d:%s:%d:%d:%d\n", town_id, town_name.c_str(), templepos.x, templepos.y, templepos.z);
2012-06-29 16:44:26 +02:00
old_town - > setTemplePosition ( templepos ) ;
wxString new_name = name_field - > GetValue ( ) ;
wxString old_name = wxstr ( old_town - > getName ( ) ) ;
old_town - > setName ( nstr ( new_name ) ) ;
2023-10-09 19:12:16 -07:00
if ( new_name ! = old_name ) {
2012-06-29 16:44:26 +02:00
// Name has changed, update list
BuildListBox ( false ) ;
}
}
}
}
// Clear fields
town_name . Clear ( ) ;
town_id . Clear ( ) ;
2023-10-09 19:12:16 -07:00
if ( town_list . size ( ) > size_t ( new_selection ) ) {
2012-06-29 16:44:26 +02:00
name_field - > Enable ( true ) ;
2015-07-11 21:20:07 -03:00
temple_position - > Enable ( true ) ;
2015-01-20 16:43:23 -03:00
select_position_button - > Enable ( true ) ;
2012-06-29 16:44:26 +02:00
// Change the values to reflect the newd selection
Town * town = town_list [ new_selection ] ;
ASSERT ( town ) ;
2023-10-09 19:12:16 -07:00
// printf("Selected %d:%s\n", new_selection, town->getName().c_str());
2012-06-29 16:44:26 +02:00
town_name < < wxstr ( town - > getName ( ) ) ;
name_field - > SetValue ( town_name ) ;
town_id < < long ( town - > getID ( ) ) ;
id_field - > SetValue ( town_id ) ;
2015-07-11 21:20:07 -03:00
temple_position - > SetPosition ( town - > getTemplePosition ( ) ) ;
2012-06-29 16:44:26 +02:00
town_listbox - > SetSelection ( new_selection ) ;
2015-12-06 11:42:37 -03:00
} else {
2012-06-29 16:44:26 +02:00
name_field - > Enable ( false ) ;
2015-07-11 21:20:07 -03:00
temple_position - > Enable ( false ) ;
2012-06-29 16:44:26 +02:00
select_position_button - > Enable ( false ) ;
}
Refresh ( ) ;
}
2023-10-09 19:12:16 -07:00
void EditTownsDialog : : OnListBoxChange ( wxCommandEvent & event ) {
2012-06-29 16:44:26 +02:00
UpdateSelection ( event . GetSelection ( ) ) ;
}
2023-10-09 19:12:16 -07:00
void EditTownsDialog : : OnClickSelectTemplePosition ( wxCommandEvent & WXUNUSED ( event ) ) {
2015-07-11 21:20:07 -03:00
Position templepos = temple_position - > GetPosition ( ) ;
2016-09-29 20:30:54 -03:00
g_gui . SetScreenCenterPosition ( templepos ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void EditTownsDialog : : OnClickAdd ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
Town * new_town = newd Town ( + + max_town_id ) ;
new_town - > setName ( " Unnamed Town " ) ;
2023-10-09 19:12:16 -07:00
new_town - > setTemplePosition ( Position ( 0 , 0 , 0 ) ) ;
2012-06-29 16:44:26 +02:00
town_list . push_back ( new_town ) ;
BuildListBox ( false ) ;
2023-10-09 19:12:16 -07:00
UpdateSelection ( town_list . size ( ) - 1 ) ;
town_listbox - > SetSelection ( town_list . size ( ) - 1 ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void EditTownsDialog : : OnClickRemove ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
long tmplong ;
2023-10-09 19:12:16 -07:00
if ( id_field - > GetValue ( ) . ToLong ( & tmplong ) ) {
2012-06-29 16:44:26 +02:00
uint32_t old_town_id = tmplong ;
2014-01-22 20:16:17 +01:00
Town * town = nullptr ;
2012-06-29 16:44:26 +02:00
std : : vector < Town * > : : iterator town_iter = town_list . begin ( ) ;
int selection_index = 0 ;
2023-10-09 19:12:16 -07:00
while ( town_iter ! = town_list . end ( ) ) {
if ( old_town_id = = ( * town_iter ) - > getID ( ) ) {
2012-06-29 16:44:26 +02:00
town = * town_iter ;
break ;
}
+ + selection_index ;
+ + town_iter ;
}
2023-10-09 19:12:16 -07:00
if ( ! town ) {
return ;
}
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
const Map & map = editor . getMap ( ) ;
for ( const auto & pair : map . houses ) {
if ( pair . second - > townid = = town - > getID ( ) ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " You cannot delete a town which still has houses associated with it. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
}
delete town ;
town_list . erase ( town_iter ) ;
BuildListBox ( false ) ;
2023-10-09 19:12:16 -07:00
UpdateSelection ( selection_index - 1 ) ;
2012-06-29 16:44:26 +02:00
}
}
2023-10-09 19:12:16 -07:00
void EditTownsDialog : : OnClickOK ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
long tmplong = 0 ;
2023-10-09 19:12:16 -07:00
if ( Validate ( ) & & TransferDataFromWindow ( ) ) {
2012-06-29 16:44:26 +02:00
// Save old values
2023-10-09 19:12:16 -07:00
if ( town_list . size ( ) > 0 & & id_field - > GetValue ( ) . ToLong ( & tmplong ) ) {
2012-06-29 16:44:26 +02:00
uint32_t old_town_id = tmplong ;
2014-01-22 20:16:17 +01:00
Town * old_town = nullptr ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
for ( std : : vector < Town * > : : iterator town_iter = town_list . begin ( ) ; town_iter ! = town_list . end ( ) ; + + town_iter ) {
if ( old_town_id = = ( * town_iter ) - > getID ( ) ) {
2012-06-29 16:44:26 +02:00
old_town = * town_iter ;
break ;
}
}
2023-10-09 19:12:16 -07:00
if ( old_town ) {
2015-07-11 21:20:07 -03:00
Position templepos = temple_position - > GetPosition ( ) ;
2012-06-29 16:44:26 +02:00
2023-10-09 19:12:16 -07:00
// printf("Changed town %d:%s\n", old_town_id, old_town->getName().c_str());
// printf("New values %d:%s:%d:%d:%d\n", town_id, town_name.c_str(), templepos.x, templepos.y, templepos.z);
2012-06-29 16:44:26 +02:00
old_town - > setTemplePosition ( templepos ) ;
wxString new_name = name_field - > GetValue ( ) ;
wxString old_name = wxstr ( old_town - > getName ( ) ) ;
old_town - > setName ( nstr ( new_name ) ) ;
2023-10-09 19:12:16 -07:00
if ( new_name ! = old_name ) {
2012-06-29 16:44:26 +02:00
// Name has changed, update list
BuildListBox ( true ) ;
}
}
}
2023-10-09 19:12:16 -07:00
Towns & towns = editor . getMap ( ) . towns ;
2012-06-29 16:44:26 +02:00
// Verify the newd information
2023-10-09 19:12:16 -07:00
for ( std : : vector < Town * > : : iterator town_iter = town_list . begin ( ) ; town_iter ! = town_list . end ( ) ; + + town_iter ) {
2012-06-29 16:44:26 +02:00
Town * town = * town_iter ;
2023-10-09 19:12:16 -07:00
if ( town - > getName ( ) = = " " ) {
2016-11-05 15:28:14 +01:00
g_gui . PopupDialog ( this , " Error " , " You can't have a town with an empty name. " , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
2023-10-09 19:12:16 -07:00
if ( ! town - > getTemplePosition ( ) . isValid ( ) | | town - > getTemplePosition ( ) . x > editor . getMap ( ) . getWidth ( ) | | town - > getTemplePosition ( ) . y > editor . getMap ( ) . getHeight ( ) ) {
2012-06-29 16:44:26 +02:00
wxString msg ;
2016-11-05 15:28:14 +01:00
msg < < " The town " < < wxstr ( town - > getName ( ) ) < < " has an invalid temple position. " ;
g_gui . PopupDialog ( this , " Error " , msg , wxOK ) ;
2012-06-29 16:44:26 +02:00
return ;
}
}
// Clear old towns
towns . clear ( ) ;
// Build the newd town map
2023-10-09 19:12:16 -07:00
for ( std : : vector < Town * > : : iterator town_iter = town_list . begin ( ) ; town_iter ! = town_list . end ( ) ; + + town_iter ) {
2012-06-29 16:44:26 +02:00
towns . addTown ( * town_iter ) ;
}
town_list . clear ( ) ;
2023-10-09 23:02:37 -03:00
editor . getMap ( ) . doChange ( ) ;
2012-06-29 16:44:26 +02:00
EndModal ( 1 ) ;
2016-09-29 20:30:54 -03:00
g_gui . RefreshPalettes ( ) ;
2012-06-29 16:44:26 +02:00
}
}
2023-10-09 19:12:16 -07:00
void EditTownsDialog : : OnClickCancel ( wxCommandEvent & WXUNUSED ( event ) ) {
2012-06-29 16:44:26 +02:00
// Just close this window
EndModal ( 0 ) ;
}
// ============================================================================
2015-05-08 12:50:15 -03:00
// Go To Position Dialog
2012-06-29 16:44:26 +02:00
// Jump to a position on the map by entering XYZ coordinates
BEGIN_EVENT_TABLE ( GotoPositionDialog , wxDialog )
2023-10-09 19:12:16 -07:00
EVT_BUTTON ( wxID_OK , GotoPositionDialog : : OnClickOK )
EVT_BUTTON ( wxID_CANCEL , GotoPositionDialog : : OnClickCancel )
2012-06-29 16:44:26 +02:00
END_EVENT_TABLE ( )
2023-10-09 19:12:16 -07:00
GotoPositionDialog : : GotoPositionDialog ( wxWindow * parent , Editor & editor ) :
2016-11-05 15:28:14 +01:00
wxDialog ( parent , wxID_ANY , " Go To Position " , wxDefaultPosition , wxDefaultSize ) ,
2023-10-09 19:12:16 -07:00
editor ( editor ) {
const Map & map = editor . getMap ( ) ;
2012-06-29 16:44:26 +02:00
2015-07-11 21:20:07 -03:00
// create topsizer
2012-06-29 16:44:26 +02:00
wxSizer * sizer = newd wxBoxSizer ( wxVERTICAL ) ;
2023-10-09 23:02:37 -03:00
posctrl = newd PositionCtrl ( this , " Destination " , map . getWidth ( ) / 2 , map . getHeight ( ) / 2 , rme : : MapGroundLayer , map . getWidth ( ) , map . getHeight ( ) ) ;
2015-07-11 21:20:07 -03:00
sizer - > Add ( posctrl , 0 , wxTOP | wxLEFT | wxRIGHT , 20 ) ;
2012-06-29 16:44:26 +02:00
// OK/Cancel buttons
2015-07-11 21:20:07 -03:00
wxSizer * tmpsizer = newd wxBoxSizer ( wxHORIZONTAL ) ;
2016-11-05 15:28:14 +01:00
tmpsizer - > Add ( newd wxButton ( this , wxID_OK , " OK " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
tmpsizer - > Add ( newd wxButton ( this , wxID_CANCEL , " Cancel " ) , wxSizerFlags ( 1 ) . Center ( ) ) ;
2012-06-29 16:44:26 +02:00
sizer - > Add ( tmpsizer , 0 , wxALL | wxCENTER , 20 ) ; // Border to top too
SetSizerAndFit ( sizer ) ;
2016-02-29 21:47:54 -03:00
Centre ( wxBOTH ) ;
2012-06-29 16:44:26 +02:00
}
2023-10-09 19:12:16 -07:00
void GotoPositionDialog : : OnClickCancel ( wxCommandEvent & ) {
2012-06-29 16:44:26 +02:00
EndModal ( 0 ) ;
}
2023-10-09 19:12:16 -07:00
void GotoPositionDialog : : OnClickOK ( wxCommandEvent & ) {
2016-09-29 20:30:54 -03:00
g_gui . SetScreenCenterPosition ( posctrl - > GetPosition ( ) ) ;
2012-06-29 16:44:26 +02:00
EndModal ( 1 ) ;
}