2010-05-04 00:22:11 +00:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
2011-12-14 07:40:48 +00:00
// Copyright (C) 2001-2008 Martiño Figueroa
2010-05-04 00:22:11 +00:00
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
# include "main.h"
# include <ctime>
# include "conversion.h"
# include "icons.h"
2010-05-04 08:15:16 +00:00
# include "platform_common.h"
2011-04-05 04:49:48 +00:00
# include "config.h"
2010-05-04 08:15:16 +00:00
# include <iostream>
2011-05-23 19:23:00 +00:00
# include"platform_util.h"
2011-04-05 04:49:48 +00:00
# include <wx/stdpaths.h>
2011-05-23 19:50:17 +00:00
# ifndef WIN32
# include <errno.h>
# endif
2011-12-25 03:09:39 +00:00
# include <memory>
2010-05-04 00:22:11 +00:00
using namespace Shared : : Util ;
2010-05-04 08:15:16 +00:00
using namespace Shared : : PlatformCommon ;
2011-04-05 04:49:48 +00:00
using namespace Glest : : Game ;
2010-05-04 00:22:11 +00:00
using namespace std ;
2011-04-05 04:49:48 +00:00
namespace Glest { namespace Game {
string getGameReadWritePath ( string lookupKey ) {
string path = " " ;
if ( path = = " " & & getenv ( " GLESTHOME " ) ! = NULL ) {
path = getenv ( " GLESTHOME " ) ;
if ( path ! = " " & & EndsWith ( path , " / " ) = = false & & EndsWith ( path , " \\ " ) = = false ) {
path + = " / " ;
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path to be used for read/write files [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
}
2010-05-04 00:22:11 +00:00
2011-04-05 04:49:48 +00:00
return path ;
}
} }
2010-12-03 05:07:42 +00:00
2011-04-05 04:49:48 +00:00
namespace MapEditor {
2010-12-03 05:07:42 +00:00
2013-06-21 18:21:07 +00:00
const string mapeditorVersionString = " v1.6.1 " ;
2010-12-13 00:32:59 +00:00
const string MainWindow : : winHeader = " MegaGlest Map Editor " + mapeditorVersionString ;
2010-05-04 00:22:11 +00:00
// ===============================================
// class Global functions
// ===============================================
wxString ToUnicode ( const char * str ) {
return wxString ( str , wxConvUTF8 ) ;
}
wxString ToUnicode ( const string & str ) {
return wxString ( str . c_str ( ) , wxConvUTF8 ) ;
}
// ===============================================
// class MainWindow
// ===============================================
2011-04-05 04:49:48 +00:00
MainWindow : : MainWindow ( string appPath )
2010-09-12 05:20:56 +00:00
: wxFrame ( NULL , - 1 , ToUnicode ( winHeader ) , wxPoint ( 0 , 0 ) , wxSize ( 1024 , 768 ) )
2010-05-04 00:22:11 +00:00
, lastX ( 0 ) , lastY ( 0 )
, currentBrush ( btHeight )
, height ( 0 )
, surface ( 1 )
, radius ( 1 )
, object ( 0 )
, resource ( 0 )
, startLocation ( 1 )
, enabledGroup ( ctHeight )
2010-06-23 22:21:08 +00:00
, fileModified ( false )
, menuBar ( NULL )
2010-07-18 05:09:30 +00:00
, panel ( NULL )
, glCanvas ( NULL )
2012-07-21 20:21:27 +00:00
, fileDialog ( NULL )
2011-03-20 06:05:09 +00:00
, program ( NULL ) , boxsizer ( NULL ) , startupSettingsInited ( false ) {
2010-05-04 00:22:11 +00:00
2011-09-01 18:08:56 +00:00
menuFile = NULL ;
menuEdit = NULL ;
menuEditMirror = NULL ;
menuView = NULL ;
menuBrush = NULL ;
menuBrushHeight = NULL ;
menuBrushGradient = NULL ;
menuBrushSurface = NULL ;
menuBrushObject = NULL ;
menuBrushResource = NULL ;
menuBrushStartLocation = NULL ;
menuRadius = NULL ;
fileDialog = NULL ;
resourceUnderMouse = 0 ;
objectUnderMouse = 0 ;
2011-04-05 04:49:48 +00:00
this - > appPath = appPath ;
2011-05-03 11:15:15 +00:00
Properties : : setApplicationPath ( executable_path ( appPath ) ) ;
2011-04-05 04:49:48 +00:00
2010-05-04 00:22:11 +00:00
this - > panel = new wxPanel ( this , wxID_ANY ) ;
//gl canvas
2011-01-29 22:06:05 +00:00
int args [ ] = { WX_GL_RGBA , WX_GL_DOUBLEBUFFER , WX_GL_MIN_ALPHA , 8 } ;
2010-05-04 00:22:11 +00:00
glCanvas = new GlCanvas ( this , this - > panel , args ) ;
2011-02-01 20:10:18 +00:00
glCanvas - > SetFocus ( ) ;
}
void MainWindow : : onToolPlayer ( wxCommandEvent & event ) {
PopupMenu ( menuBrushStartLocation ) ;
}
2013-06-04 07:21:01 +00:00
void MainToolBar : : onMouseMove ( wxMouseEvent & event ) {
# ifdef WIN32
if ( this - > GetParent ( ) ! = NULL & & this - > GetParent ( ) - > GetParent ( ) ! = NULL ) {
MainWindow * mainWindow = dynamic_cast < MainWindow * > ( this - > GetParent ( ) - > GetParent ( ) ) ;
if ( mainWindow ! = NULL ) {
mainWindow - > refreshMapRender ( ) ;
}
}
# endif
event . Skip ( ) ;
}
BEGIN_EVENT_TABLE ( MainToolBar , wxToolBar )
EVT_MOTION ( MainToolBar : : onMouseMove )
END_EVENT_TABLE ( )
2011-02-01 20:10:18 +00:00
void MainWindow : : init ( string fname ) {
2013-06-04 07:21:01 +00:00
# if wxCHECK_VERSION(2, 9, 3)
glCanvas - > setCurrentGLContext ( ) ;
//printf("setcurrent #1\n");
# elif wxCHECK_VERSION(2, 9, 1)
2011-03-20 06:05:09 +00:00
2011-03-20 00:59:17 +00:00
# else
2011-02-01 20:10:18 +00:00
glCanvas - > SetCurrent ( ) ;
2013-06-04 07:21:01 +00:00
//printf("setcurrent #2\n");
2011-03-20 00:59:17 +00:00
# endif
2010-05-04 00:22:11 +00:00
//menus
menuBar = new wxMenuBar ( ) ;
//file
menuFile = new wxMenu ( ) ;
2010-12-03 05:07:42 +00:00
menuFile - > Append ( wxID_NEW ) ;
2010-05-04 00:22:11 +00:00
menuFile - > Append ( wxID_OPEN ) ;
menuFile - > AppendSeparator ( ) ;
menuFile - > Append ( wxID_SAVE ) ;
menuFile - > Append ( wxID_SAVEAS ) ;
menuFile - > AppendSeparator ( ) ;
menuFile - > Append ( wxID_EXIT ) ;
menuBar - > Append ( menuFile , wxT ( " &File " ) ) ;
//edit
menuEdit = new wxMenu ( ) ;
menuEdit - > Append ( miEditUndo , wxT ( " &Undo \t CTRL+Z " ) ) ;
menuEdit - > Append ( miEditRedo , wxT ( " &Redo \t CTRL+Y " ) ) ;
2010-12-03 05:07:42 +00:00
menuEdit - > AppendSeparator ( ) ;
// menuEdit->Append(miEditReset, wxT("Rese&t..."));
menuEdit - > Append ( miEditResetPlayers , wxT ( " Reset &Players... " ) ) ;
menuEdit - > Append ( miEditResize , wxT ( " Re&size... " ) ) ;
2011-05-24 00:58:21 +00:00
menuEdit - > Append ( miEditFlipDiagonal , wxT ( " Flip &Diagonal " ) ) ;
2010-05-04 00:22:11 +00:00
menuEdit - > Append ( miEditFlipX , wxT ( " Flip &X " ) ) ;
menuEdit - > Append ( miEditFlipY , wxT ( " Flip &Y " ) ) ;
2010-12-03 05:07:42 +00:00
// Mirror submenu-------------------------------------------
menuEditMirror = new wxMenu ( ) ;
menuEditMirror - > Append ( miEditMirrorX , wxT ( " Copy &Left to Right " ) ) ;
menuEditMirror - > Append ( miEditMirrorY , wxT ( " Copy &Top to Bottom " ) ) ;
menuEditMirror - > Append ( miEditMirrorXY , wxT ( " Copy &BottomLeft to TopRight " ) ) ;
menuEditMirror - > AppendSeparator ( ) ;
menuEditMirror - > Append ( miEditRotatecopyX , wxT ( " &Rotate Left to Right " ) ) ;
menuEditMirror - > Append ( miEditRotatecopyY , wxT ( " Rotate T&op to Bottom " ) ) ;
menuEditMirror - > Append ( miEditRotatecopyXY , wxT ( " Rotate Botto&mLeft to TopRight " ) ) ;
menuEditMirror - > Append ( miEditRotatecopyCorner , wxT ( " Rotate TopLeft &corner to TopRight " ) ) ;
menuEdit - > Append ( miEditMirror , wxT ( " &Mirror " ) , menuEditMirror ) ;
// ---------------------------------------------------------
2010-05-04 00:22:11 +00:00
menuEdit - > Append ( miEditRandomizeHeights , wxT ( " Randomize &Heights " ) ) ;
2010-12-03 05:07:42 +00:00
menuEdit - > Append ( miEditRandomize , wxT ( " Randomi&ze Heights/Players " ) ) ;
menuEdit - > Append ( miEditSwitchSurfaces , wxT ( " Switch Sur&faces... " ) ) ;
menuEdit - > Append ( miEditInfo , wxT ( " &Info... " ) ) ;
menuEdit - > Append ( miEditAdvanced , wxT ( " &Advanced... " ) ) ;
2010-05-04 00:22:11 +00:00
menuBar - > Append ( menuEdit , wxT ( " &Edit " ) ) ;
2010-12-03 05:07:42 +00:00
//view
menuView = new wxMenu ( ) ;
menuView - > Append ( miViewResetZoomAndPos , wxT ( " &Reset zoom and pos " ) ) ;
2010-12-05 01:33:28 +00:00
menuView - > AppendCheckItem ( miViewGrid , wxT ( " &Grid " ) ) ;
2013-06-21 18:21:07 +00:00
menuView - > AppendCheckItem ( miViewHeightMap , wxT ( " H&eightMap " ) ) ;
menuView - > AppendCheckItem ( miHideWater , wxT ( " Hide&Water " ) ) ;
2010-12-03 05:07:42 +00:00
menuView - > AppendSeparator ( ) ;
menuView - > Append ( miViewHelp , wxT ( " &Help... " ) ) ;
menuView - > Append ( miViewAbout , wxT ( " &About... " ) ) ;
menuBar - > Append ( menuView , wxT ( " &View " ) ) ;
2010-05-04 00:22:11 +00:00
//brush
2010-12-03 05:07:42 +00:00
// menuBrush = new wxMenu();
2010-05-04 00:22:11 +00:00
2010-12-03 05:07:42 +00:00
//surface
menuBrushSurface = new wxMenu ( ) ;
menuBrushSurface - > AppendCheckItem ( miBrushSurface + 1 , wxT ( " &Grass " ) ) ;
menuBrushSurface - > AppendCheckItem ( miBrushSurface + 2 , wxT ( " S&econdary grass " ) ) ;
menuBrushSurface - > AppendCheckItem ( miBrushSurface + 3 , wxT ( " &Road " ) ) ;
menuBrushSurface - > AppendCheckItem ( miBrushSurface + 4 , wxT ( " &Stone " ) ) ;
menuBrushSurface - > AppendCheckItem ( miBrushSurface + 5 , wxT ( " Gr&ound " ) ) ;
menuBar - > Append ( menuBrushSurface , wxT ( " &Surface " ) ) ;
2010-05-04 00:22:11 +00:00
2010-12-03 05:07:42 +00:00
//resources
menuBrushResource = new wxMenu ( ) ;
//menuBrushResource->AppendCheckItem(miBrushResource + 1, wxT("&0 - None"));
menuBrushResource - > AppendCheckItem ( miBrushResource + 2 , wxT ( " &Gold (unwalkable) " ) ) ;
menuBrushResource - > AppendCheckItem ( miBrushResource + 3 , wxT ( " &Stone (unwalkable) " ) ) ;
menuBrushResource - > AppendCheckItem ( miBrushResource + 4 , wxT ( " &3 - custom " ) ) ;
menuBrushResource - > AppendCheckItem ( miBrushResource + 5 , wxT ( " &4 - custom " ) ) ;
menuBrushResource - > AppendCheckItem ( miBrushResource + 6 , wxT ( " &5 - custom " ) ) ;
menuBar - > Append ( menuBrushResource , wxT ( " &Resource " ) ) ;
//objects
menuBrushObject = new wxMenu ( ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 1 , wxT ( " &None (erase) \t ALT+0 " ) ) ;
menuBrushObject - > AppendSeparator ( ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 2 , wxT ( " &Tree (harvestable) " ) ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 3 , wxT ( " &Dead tree/Cactuses/Thornbush " ) ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 4 , wxT ( " &Stone " ) ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 5 , wxT ( " &Bush/Grass/Fern (walkable) " ) ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 6 , wxT ( " &Water object/Reed/Papyrus (walkable) " ) ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 7 , wxT ( " Big tree/&Old palm " ) ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 8 , wxT ( " &Hanged/Impaled " ) ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 9 , wxT ( " St&atues " ) ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 10 , wxT ( " &Mountain " ) ) ;
menuBrushObject - > AppendCheckItem ( miBrushObject + 11 , wxT ( " &Invisible blocking object " ) ) ;
menuBar - > Append ( menuBrushObject , wxT ( " &Object " ) ) ;
2010-05-04 00:22:11 +00:00
// ZombiePirate height brush
menuBrushGradient = new wxMenu ( ) ;
for ( int i = 0 ; i < heightCount ; + + i ) {
2010-12-03 05:07:42 +00:00
menuBrushGradient - > AppendCheckItem ( miBrushGradient + i + 1 , ToUnicode ( ( i > 4 ? " & " : " " ) + intToStr ( i - heightCount / 2 ) ) ) ;
2010-05-04 00:22:11 +00:00
}
2010-12-03 05:07:42 +00:00
menuBar - > Append ( menuBrushGradient , wxT ( " &Gradient " ) ) ;
2010-05-04 00:22:11 +00:00
2010-12-03 05:07:42 +00:00
// Glest height brush
menuBrushHeight = new wxMenu ( ) ;
for ( int i = 0 ; i < heightCount ; + + i ) {
menuBrushHeight - > AppendCheckItem ( miBrushHeight + i + 1 , ToUnicode ( ( i > 4 ? " & " : " " ) + intToStr ( i - heightCount / 2 ) ) ) ;
}
menuBrushHeight - > Check ( miBrushHeight + ( heightCount + 1 ) / 2 , true ) ;
menuBar - > Append ( menuBrushHeight , wxT ( " &Height " ) ) ;
2010-05-04 00:22:11 +00:00
2010-12-03 05:07:42 +00:00
enabledGroup = ctHeight ;
2010-05-04 00:22:11 +00:00
2010-12-03 05:07:42 +00:00
//radius
menuRadius = new wxMenu ( ) ;
for ( int i = 1 ; i < = radiusCount ; + + i ) {
menuRadius - > AppendCheckItem ( miRadius + i , ToUnicode ( " & " + intToStr ( i ) + " (diameter " + intToStr ( i * 2 - 1 ) + " ) " + " \t ALT+ " + intToStr ( i ) ) ) ;
}
menuRadius - > Check ( miRadius + 1 , true ) ;
menuBar - > Append ( menuRadius , wxT ( " R&adius " ) ) ;
2010-05-04 00:22:11 +00:00
//players
menuBrushStartLocation = new wxMenu ( ) ;
2010-12-03 05:07:42 +00:00
wxMenuItem * pmi1 = new wxMenuItem ( menuBrushStartLocation , miBrushStartLocation + 1 , wxT ( " Player &1 Red " ) ) ;
2010-05-04 00:22:11 +00:00
pmi1 - > SetBitmap ( wxBitmap ( brush_players_red ) ) ;
menuBrushStartLocation - > Append ( pmi1 ) ;
2010-12-03 05:07:42 +00:00
wxMenuItem * pmi2 = new wxMenuItem ( menuBrushStartLocation , miBrushStartLocation + 2 , wxT ( " Player &2 Blue " ) ) ;
2010-05-04 00:22:11 +00:00
pmi2 - > SetBitmap ( wxBitmap ( brush_players_blue ) ) ;
menuBrushStartLocation - > Append ( pmi2 ) ;
2010-12-03 05:07:42 +00:00
wxMenuItem * pmi3 = new wxMenuItem ( menuBrushStartLocation , miBrushStartLocation + 3 , wxT ( " Player &3 Green " ) ) ;
2010-05-04 00:22:11 +00:00
pmi3 - > SetBitmap ( wxBitmap ( brush_players_green ) ) ;
menuBrushStartLocation - > Append ( pmi3 ) ;
2010-12-03 05:07:42 +00:00
wxMenuItem * pmi4 = new wxMenuItem ( menuBrushStartLocation , miBrushStartLocation + 4 , wxT ( " Player &4 Yellow " ) ) ;
2010-05-04 00:22:11 +00:00
pmi4 - > SetBitmap ( wxBitmap ( brush_players_yellow ) ) ;
menuBrushStartLocation - > Append ( pmi4 ) ;
2010-12-03 05:07:42 +00:00
wxMenuItem * pmi5 = new wxMenuItem ( menuBrushStartLocation , miBrushStartLocation + 5 , wxT ( " Player &5 White " ) ) ;
2010-05-04 00:22:11 +00:00
pmi5 - > SetBitmap ( wxBitmap ( brush_players_white ) ) ;
menuBrushStartLocation - > Append ( pmi5 ) ;
2010-12-03 05:07:42 +00:00
wxMenuItem * pmi6 = new wxMenuItem ( menuBrushStartLocation , miBrushStartLocation + 6 , wxT ( " Player &6 Cyan " ) ) ;
2010-05-04 00:22:11 +00:00
pmi6 - > SetBitmap ( wxBitmap ( brush_players_cyan ) ) ;
menuBrushStartLocation - > Append ( pmi6 ) ;
2010-12-03 05:07:42 +00:00
wxMenuItem * pmi7 = new wxMenuItem ( menuBrushStartLocation , miBrushStartLocation + 7 , wxT ( " Player &7 Orange " ) ) ;
2010-05-04 00:22:11 +00:00
pmi7 - > SetBitmap ( wxBitmap ( brush_players_orange ) ) ;
menuBrushStartLocation - > Append ( pmi7 ) ;
2010-12-03 05:07:42 +00:00
wxMenuItem * pmi8 = new wxMenuItem ( menuBrushStartLocation , miBrushStartLocation + 8 , wxT ( " Player &8 Pink " ) ) ; // = Light Magenta :-)
2010-05-04 00:22:11 +00:00
pmi8 - > SetBitmap ( wxBitmap ( brush_players_pink ) ) ;
menuBrushStartLocation - > Append ( pmi8 ) ;
2010-12-03 05:07:42 +00:00
menuBar - > Append ( menuBrushStartLocation , wxT ( " &Player " ) ) ;
//menuBar->Append(menuBrush, wxT("&Brush"));
2010-05-04 00:22:11 +00:00
SetMenuBar ( menuBar ) ;
fileName = " New (unsaved) map " ;
int status_widths [ siCOUNT ] = {
10 , // empty
2013-10-02 22:26:06 +00:00
- 25 , // File name
- 6 , // File type
- 20 , // Current Object
- 14 , // Brush Type
- 20 , // Brush 'Value'
- 10 , // Brush Radius
- 25 , // Position
2010-05-04 00:22:11 +00:00
} ;
CreateStatusBar ( siCOUNT ) ;
GetStatusBar ( ) - > SetStatusWidths ( siCOUNT , status_widths ) ;
SetStatusText ( wxT ( " File: " ) + ToUnicode ( fileName ) , siFILE_NAME ) ;
SetStatusText ( wxT ( " .gbm " ) , siFILE_TYPE ) ;
SetStatusText ( wxT ( " Object: None (Erase) " ) , siCURR_OBJECT ) ;
SetStatusText ( wxT ( " Brush: Height " ) , siBRUSH_TYPE ) ;
SetStatusText ( wxT ( " Value: 0 " ) , siBRUSH_VALUE ) ;
SetStatusText ( wxT ( " Radius: 1 " ) , siBRUSH_RADIUS ) ;
2013-10-02 22:26:06 +00:00
SetStatusText ( wxT ( " Pos (Ingame): 0 " ) , siPOS_VALUE ) ;
2010-05-04 00:22:11 +00:00
2013-06-04 07:21:01 +00:00
wxToolBar * toolbar = new MainToolBar ( this - > panel , wxID_ANY ) ;
2010-05-04 00:22:11 +00:00
toolbar - > AddTool ( miEditUndo , _ ( " undo " ) , wxBitmap ( edit_undo ) , _ ( " Undo " ) ) ;
toolbar - > AddTool ( miEditRedo , _ ( " redo " ) , wxBitmap ( edit_redo ) , _ ( " Redo " ) ) ;
toolbar - > AddTool ( miEditRandomizeHeights , _ ( " randomizeHeights " ) , wxBitmap ( edit_randomize_heights ) , _ ( " Randomize Heights " ) ) ;
2010-12-03 05:07:42 +00:00
// toolbar->AddTool(miEditRandomize, _("randomize"), wxBitmap(edit_randomize), _("Randomize"));
2010-05-04 00:22:11 +00:00
toolbar - > AddTool ( miEditSwitchSurfaces , _ ( " switch " ) , wxBitmap ( edit_switch_surfaces ) , _ ( " Switch Surfaces " ) ) ;
toolbar - > AddSeparator ( ) ;
toolbar - > AddTool ( miBrushSurface + 1 , _ ( " brush_grass1 " ) , wxBitmap ( brush_surface_grass1 ) , _ ( " Grass " ) ) ;
2010-12-03 05:07:42 +00:00
toolbar - > AddTool ( miBrushSurface + 2 , _ ( " brush_grass2 " ) , wxBitmap ( brush_surface_grass2 ) , _ ( " Secondary grass " ) ) ;
2010-05-04 00:22:11 +00:00
toolbar - > AddTool ( miBrushSurface + 3 , _ ( " brush_road " ) , wxBitmap ( brush_surface_road ) , _ ( " Road " ) ) ;
toolbar - > AddTool ( miBrushSurface + 4 , _ ( " brush_stone " ) , wxBitmap ( brush_surface_stone ) , _ ( " Stone " ) ) ;
toolbar - > AddTool ( miBrushSurface + 5 , _ ( " brush_custom " ) , wxBitmap ( brush_surface_custom ) , _ ( " Ground " ) ) ;
toolbar - > AddSeparator ( ) ;
toolbar - > AddTool ( miBrushResource + 2 , _ ( " resource1 " ) , wxBitmap ( brush_resource_1_gold ) , _ ( " gold (unwalkable) " ) ) ;
toolbar - > AddTool ( miBrushResource + 3 , _ ( " resource2 " ) , wxBitmap ( brush_resource_2_stone ) , _ ( " stone (unwalkable) " ) ) ;
2010-12-03 05:07:42 +00:00
toolbar - > AddTool ( miBrushResource + 4 , _ ( " resource3 " ) , wxBitmap ( brush_resource_3 ) , _ ( " custom3 " ) ) ;
toolbar - > AddTool ( miBrushResource + 5 , _ ( " resource4 " ) , wxBitmap ( brush_resource_4 ) , _ ( " custom4 " ) ) ;
toolbar - > AddTool ( miBrushResource + 6 , _ ( " resource5 " ) , wxBitmap ( brush_resource_5 ) , _ ( " custom5 " ) ) ;
2010-05-04 00:22:11 +00:00
toolbar - > AddSeparator ( ) ;
toolbar - > AddTool ( miBrushObject + 1 , _ ( " brush_none " ) , wxBitmap ( brush_none ) , _ ( " None (erase) " ) ) ;
toolbar - > AddTool ( miBrushObject + 2 , _ ( " brush_tree " ) , wxBitmap ( brush_object_tree ) , _ ( " Tree (unwalkable/harvestable) " ) ) ;
2010-12-03 05:07:42 +00:00
toolbar - > AddTool ( miBrushObject + 3 , _ ( " brush_dead_tree " ) , wxBitmap ( brush_object_dead_tree ) , _ ( " Dead tree/Cactuses/Thornbush (unwalkable) " ) ) ;
toolbar - > AddTool ( miBrushObject + 4 , _ ( " brush_stone " ) , wxBitmap ( brush_object_stone ) , _ ( " Stone (unwalkable/not harvestable) " ) ) ;
2010-05-04 00:22:11 +00:00
toolbar - > AddTool ( miBrushObject + 5 , _ ( " brush_bush " ) , wxBitmap ( brush_object_bush ) , _ ( " Bush/Grass/Fern (walkable) " ) ) ;
2010-12-03 05:07:42 +00:00
toolbar - > AddTool ( miBrushObject + 6 , _ ( " brush_water " ) , wxBitmap ( brush_object_water_object ) , _ ( " Water object/Reed/Papyrus (walkable) " ) ) ;
toolbar - > AddTool ( miBrushObject + 7 , _ ( " brush_c1_bigtree " ) , wxBitmap ( brush_object_c1_bigtree ) , _ ( " Big tree/Old palm (unwalkable/not harvestable) " ) ) ;
toolbar - > AddTool ( miBrushObject + 8 , _ ( " brush_c2_hanged " ) , wxBitmap ( brush_object_c2_hanged ) , _ ( " Hanged/Impaled (unwalkable) " ) ) ;
toolbar - > AddTool ( miBrushObject + 9 , _ ( " brush_c3_statue " ) , wxBitmap ( brush_object_c3_statue ) , _ ( " Statues (unwalkable) " ) ) ;
toolbar - > AddTool ( miBrushObject + 10 , _ ( " brush_c4_bigrock " ) , wxBitmap ( brush_object_c4_bigrock ) , _ ( " Mountain (unwalkable) " ) ) ;
toolbar - > AddTool ( miBrushObject + 11 , _ ( " brush_c5_blocking " ) , wxBitmap ( brush_object_c5_blocking ) , _ ( " Invisible blocking object (unwalkable) " ) ) ;
2010-05-04 00:22:11 +00:00
toolbar - > AddSeparator ( ) ;
2010-12-03 05:07:42 +00:00
toolbar - > AddTool ( toolPlayer , _ ( " brush_player " ) , wxBitmap ( brush_players_player ) , _ ( " Player start position " ) ) ;
2010-05-04 00:22:11 +00:00
toolbar - > Realize ( ) ;
2013-06-04 07:21:01 +00:00
wxToolBar * toolbar2 = new MainToolBar ( this - > panel , wxID_ANY ) ;
2010-05-04 00:22:11 +00:00
toolbar2 - > AddTool ( miBrushGradient + 1 , _ ( " brush_gradient_n5 " ) , wxBitmap ( brush_gradient_n5 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 2 , _ ( " brush_gradient_n4 " ) , wxBitmap ( brush_gradient_n4 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 3 , _ ( " brush_gradient_n3 " ) , wxBitmap ( brush_gradient_n3 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 4 , _ ( " brush_gradient_n2 " ) , wxBitmap ( brush_gradient_n2 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 5 , _ ( " brush_gradient_n1 " ) , wxBitmap ( brush_gradient_n1 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 6 , _ ( " brush_gradient_0 " ) , wxBitmap ( brush_gradient_0 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 7 , _ ( " brush_gradient_p1 " ) , wxBitmap ( brush_gradient_p1 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 8 , _ ( " brush_gradient_p2 " ) , wxBitmap ( brush_gradient_p2 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 9 , _ ( " brush_gradient_p3 " ) , wxBitmap ( brush_gradient_p3 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 10 , _ ( " brush_gradient_p4 " ) , wxBitmap ( brush_gradient_p4 ) ) ;
toolbar2 - > AddTool ( miBrushGradient + 11 , _ ( " brush_gradient_p5 " ) , wxBitmap ( brush_gradient_p5 ) ) ;
toolbar2 - > AddSeparator ( ) ;
toolbar2 - > AddTool ( miBrushHeight + 1 , _ ( " brush_height_n5 " ) , wxBitmap ( brush_height_n5 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 2 , _ ( " brush_height_n4 " ) , wxBitmap ( brush_height_n4 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 3 , _ ( " brush_height_n3 " ) , wxBitmap ( brush_height_n3 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 4 , _ ( " brush_height_n2 " ) , wxBitmap ( brush_height_n2 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 5 , _ ( " brush_height_n1 " ) , wxBitmap ( brush_height_n1 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 6 , _ ( " brush_height_0 " ) , wxBitmap ( brush_height_0 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 7 , _ ( " brush_height_p1 " ) , wxBitmap ( brush_height_p1 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 8 , _ ( " brush_height_p2 " ) , wxBitmap ( brush_height_p2 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 9 , _ ( " brush_height_p3 " ) , wxBitmap ( brush_height_p3 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 10 , _ ( " brush_height_p4 " ) , wxBitmap ( brush_height_p4 ) ) ;
toolbar2 - > AddTool ( miBrushHeight + 11 , _ ( " brush_height_p5 " ) , wxBitmap ( brush_height_p5 ) ) ;
toolbar2 - > AddSeparator ( ) ;
2010-12-05 01:33:28 +00:00
toolbar2 - > AddTool ( miRadius + 1 , _ ( " radius1 " ) , wxBitmap ( radius_1 ) , _ ( " 1 (1x1) " ) ) ;
toolbar2 - > AddTool ( miRadius + 2 , _ ( " radius2 " ) , wxBitmap ( radius_2 ) , _ ( " 2 (3x3) " ) ) ;
toolbar2 - > AddTool ( miRadius + 3 , _ ( " radius3 " ) , wxBitmap ( radius_3 ) , _ ( " 3 (5x5) " ) ) ;
toolbar2 - > AddTool ( miRadius + 4 , _ ( " radius4 " ) , wxBitmap ( radius_4 ) , _ ( " 4 (7x7) " ) ) ;
toolbar2 - > AddTool ( miRadius + 5 , _ ( " radius5 " ) , wxBitmap ( radius_5 ) , _ ( " 5 (9x9) " ) ) ;
toolbar2 - > AddTool ( miRadius + 6 , _ ( " radius6 " ) , wxBitmap ( radius_6 ) , _ ( " 6 (11x11) " ) ) ;
toolbar2 - > AddTool ( miRadius + 7 , _ ( " radius7 " ) , wxBitmap ( radius_7 ) , _ ( " 7 (13x13) " ) ) ;
toolbar2 - > AddTool ( miRadius + 8 , _ ( " radius8 " ) , wxBitmap ( radius_8 ) , _ ( " 8 (15x15) " ) ) ;
toolbar2 - > AddTool ( miRadius + 9 , _ ( " radius9 " ) , wxBitmap ( radius_9 ) , _ ( " 9 (17x17) " ) ) ;
2010-05-04 00:22:11 +00:00
toolbar2 - > Realize ( ) ;
2010-12-03 05:07:42 +00:00
2011-05-03 23:34:25 +00:00
Config & config = Config : : getInstance ( ) ;
2013-05-26 06:03:32 +00:00
2011-05-03 23:34:25 +00:00
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
2010-06-25 22:54:00 +00:00
//std::cout << "A" << std::endl;
wxInitAllImageHandlers ( ) ;
2010-06-25 22:04:40 +00:00
# ifdef WIN32
2010-06-25 22:54:00 +00:00
//std::cout << "B" << std::endl;
2011-05-23 19:23:00 +00:00
// #if defined(__MINGW32__)
2011-05-03 23:34:25 +00:00
wxIcon icon ( ToUnicode ( " IDI_ICON1 " ) ) ;
2011-05-23 19:23:00 +00:00
// #else
// wxIcon icon("IDI_ICON1");
// #endif
2010-12-08 16:31:08 +00:00
2010-06-25 22:54:00 +00:00
# else
//std::cout << "B" << std::endl;
wxIcon icon ;
2013-05-26 06:03:32 +00:00
string iniFilePath = extractDirectoryPathFromFile ( config . getFileName ( false ) ) ;
2011-05-03 23:34:25 +00:00
string icon_file = iniFilePath + " editor.ico " ;
std : : ifstream testFile ( icon_file . c_str ( ) ) ;
2010-10-07 18:13:17 +00:00
if ( testFile . good ( ) ) {
testFile . close ( ) ;
2011-05-03 23:34:25 +00:00
icon . LoadFile ( ToUnicode ( icon_file . c_str ( ) ) , wxBITMAP_TYPE_ICO ) ;
2010-10-07 18:13:17 +00:00
}
2010-06-25 22:04:40 +00:00
# endif
2010-06-25 22:54:00 +00:00
//std::cout << "C" << std::endl;
SetIcon ( icon ) ;
2011-01-20 00:47:32 +00:00
fileDialog = new wxFileDialog ( this ) ;
2011-04-05 04:49:48 +00:00
string defaultPath = userData + " maps/ " ;
2011-04-05 07:08:29 +00:00
fileDialog - > SetDirectory ( ToUnicode ( defaultPath ) ) ;
2011-04-05 04:49:48 +00:00
//printf("Default Path [%s]\n",defaultPath.c_str());
2010-07-01 16:31:06 +00:00
lastPaintEvent . start ( ) ;
2011-02-01 20:10:18 +00:00
boxsizer = new wxBoxSizer ( wxVERTICAL ) ;
boxsizer - > Add ( toolbar , 0 , wxEXPAND ) ;
boxsizer - > Add ( toolbar2 , 0 , wxEXPAND ) ;
boxsizer - > Add ( glCanvas , 1 , wxEXPAND ) ;
2010-05-04 00:22:11 +00:00
2011-02-01 20:10:18 +00:00
this - > panel - > SetSizer ( boxsizer ) ;
this - > Layout ( ) ;
2010-05-04 08:15:16 +00:00
2011-03-20 06:05:09 +00:00
//program = new Program(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y);
2010-05-04 00:22:11 +00:00
fileName = " New (unsaved) Map " ;
2011-05-24 01:44:48 +00:00
//printf("Does file exist, fname [%s]\n",fname.c_str());
if ( fname . empty ( ) = = false & & fileExists ( fname ) ) {
//printf("YES file exist, fname [%s]\n",fname.c_str());
2011-03-20 06:05:09 +00:00
//program->loadMap(fname);
2010-05-04 00:22:11 +00:00
currentFile = fname ;
2010-05-04 08:15:16 +00:00
fileName = cutLastExt ( extractFileFromDirectoryPath ( fname . c_str ( ) ) ) ;
2011-01-20 00:47:32 +00:00
fileDialog - > SetPath ( ToUnicode ( fname ) ) ;
2010-05-04 00:22:11 +00:00
}
2010-12-03 05:07:42 +00:00
SetTitle ( ToUnicode ( currentFile + " - " + winHeader ) ) ;
2011-03-20 06:05:09 +00:00
//setDirty(false);
//setExtension();
2011-05-24 01:44:48 +00:00
if ( startupSettingsInited = = false ) {
startupSettingsInited = true ;
setupStartupSettings ( ) ;
}
2010-05-04 00:22:11 +00:00
}
void MainWindow : : onClose ( wxCloseEvent & event ) {
2012-08-10 17:59:04 +00:00
if ( program ! = NULL & & program - > getMap ( ) - > getHasChanged ( ) = = true ) {
if ( wxMessageDialog ( NULL , ToUnicode ( " Do you want to save the current map? " ) ,
ToUnicode ( " Question " ) , wxYES_NO | wxYES_DEFAULT ) . ShowModal ( ) = = wxID_YES ) {
wxCommandEvent ev ;
MainWindow : : onMenuFileSave ( ev ) ;
}
2011-01-23 04:49:49 +00:00
}
2012-04-20 01:04:05 +00:00
delete program ;
program = NULL ;
//delete glCanvas;
if ( glCanvas ) glCanvas - > Destroy ( ) ;
glCanvas = NULL ;
this - > Destroy ( ) ;
2010-05-04 00:22:11 +00:00
}
2011-03-20 06:05:09 +00:00
void MainWindow : : setupStartupSettings ( ) {
program = new Program ( glCanvas - > GetClientSize ( ) . x , glCanvas - > GetClientSize ( ) . y ) ;
fileName = " New (unsaved) Map " ;
2011-05-24 01:44:48 +00:00
//printf("#0 file load [%s]\n",currentFile.c_str());
2011-03-20 06:05:09 +00:00
if ( ! currentFile . empty ( ) & & fileExists ( currentFile ) ) {
2011-05-24 01:44:48 +00:00
//printf("#0 exists file load [%s]\n",currentFile.c_str());
2011-03-20 06:05:09 +00:00
program - > loadMap ( currentFile ) ;
//currentFile = fname;
fileName = cutLastExt ( extractFileFromDirectoryPath ( currentFile . c_str ( ) ) ) ;
fileDialog - > SetPath ( ToUnicode ( currentFile ) ) ;
}
SetTitle ( ToUnicode ( currentFile + " - " + winHeader ) ) ;
setDirty ( false ) ;
setExtension ( ) ;
}
2010-05-04 00:22:11 +00:00
MainWindow : : ~ MainWindow ( ) {
2012-07-21 20:21:27 +00:00
delete fileDialog ;
fileDialog = NULL ;
2010-07-01 16:31:06 +00:00
delete program ;
2010-07-18 05:09:30 +00:00
program = NULL ;
delete glCanvas ;
glCanvas = NULL ;
2010-05-04 00:22:11 +00:00
}
void MainWindow : : setDirty ( bool val ) {
2010-07-18 05:09:30 +00:00
wxPaintEvent ev ;
onPaint ( ev ) ;
2010-05-04 00:22:11 +00:00
if ( fileModified & & val ) {
return ;
}
fileModified = val ;
if ( fileModified ) {
SetStatusText ( wxT ( " File: " ) + ToUnicode ( fileName ) + wxT ( " * " ) , siFILE_NAME ) ;
} else {
SetStatusText ( wxT ( " File: " ) + ToUnicode ( fileName ) , siFILE_NAME ) ;
}
}
void MainWindow : : setExtension ( ) {
2011-03-20 06:05:09 +00:00
if ( currentFile . empty ( ) | | program = = NULL ) {
2010-05-04 00:22:11 +00:00
return ;
}
2011-05-24 01:44:48 +00:00
2010-05-04 00:22:11 +00:00
string extnsn = ext ( currentFile ) ;
2011-05-24 01:44:48 +00:00
//printf("#A currentFile [%s] extnsn [%s]\n",currentFile.c_str(),extnsn.c_str());
2010-05-04 00:22:11 +00:00
if ( extnsn = = " gbm " | | extnsn = = " mgm " ) {
currentFile = cutLastExt ( currentFile ) ;
}
2013-06-21 18:21:07 +00:00
if ( Program : : getMap ( ) - > getMaxFactions ( ) < = 4 | | Program : : getMap ( ) - > getCliffLevel ( ) = = 0 ) {
2010-05-04 00:22:11 +00:00
SetStatusText ( wxT ( " .gbm " ) , siFILE_TYPE ) ;
currentFile + = " .gbm " ;
2011-05-24 01:44:48 +00:00
}
else {
2010-05-04 00:22:11 +00:00
SetStatusText ( wxT ( " .mgm " ) , siFILE_TYPE ) ;
currentFile + = " .mgm " ;
}
}
void MainWindow : : onMouseDown ( wxMouseEvent & event , int x , int y ) {
2011-03-20 06:05:09 +00:00
if ( event . LeftIsDown ( ) & & program ! = NULL ) {
2010-05-04 00:22:11 +00:00
program - > setUndoPoint ( enabledGroup ) ;
program - > setRefAlt ( x , y ) ;
change ( x , y ) ;
if ( ! isDirty ( ) ) {
setDirty ( true ) ;
}
wxPaintEvent ev ;
onPaint ( ev ) ;
}
event . Skip ( ) ;
}
2010-12-03 05:07:42 +00:00
// for the mousewheel
void MainWindow : : onMouseWheelDown ( wxMouseEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-12-03 05:07:42 +00:00
wxPaintEvent ev ;
program - > incCellSize ( 1 ) ;
onPaint ( ev ) ;
}
void MainWindow : : onMouseWheelUp ( wxMouseEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-12-03 05:07:42 +00:00
wxPaintEvent ev ;
program - > incCellSize ( - 1 ) ;
onPaint ( ev ) ;
}
2010-05-04 00:22:11 +00:00
void MainWindow : : onMouseMove ( wxMouseEvent & event , int x , int y ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-07-18 05:09:30 +00:00
bool repaint = false ;
2010-05-04 00:22:11 +00:00
if ( event . LeftIsDown ( ) ) {
change ( x , y ) ;
2010-07-18 05:09:30 +00:00
repaint = true ;
2010-05-04 00:22:11 +00:00
} else if ( event . MiddleIsDown ( ) ) {
2011-09-01 18:08:56 +00:00
int dif = ( y - lastY ) ;
2010-05-04 00:22:11 +00:00
if ( dif ! = 0 ) {
program - > incCellSize ( dif / abs ( dif ) ) ;
2010-07-18 05:09:30 +00:00
repaint = true ;
2010-05-04 00:22:11 +00:00
}
} else if ( event . RightIsDown ( ) ) {
program - > setOfset ( x - lastX , y - lastY ) ;
2010-07-18 05:09:30 +00:00
repaint = true ;
2010-05-04 00:22:11 +00:00
} else {
int currResource = program - > getResource ( x , y ) ;
if ( currResource > 0 ) {
SetStatusText ( wxT ( " Resource: " ) + ToUnicode ( resource_descs [ currResource ] ) , siCURR_OBJECT ) ;
resourceUnderMouse = currResource ;
objectUnderMouse = 0 ;
} else {
int currObject = program - > getObject ( x , y ) ;
SetStatusText ( wxT ( " Object: " ) + ToUnicode ( object_descs [ currObject ] ) , siCURR_OBJECT ) ;
resourceUnderMouse = 0 ;
2010-12-03 05:07:42 +00:00
objectUnderMouse = currObject ;
2010-05-04 00:22:11 +00:00
}
2013-06-04 07:21:01 +00:00
2013-10-02 22:26:06 +00:00
SetStatusText ( wxT ( " Pos (Ingame): " )
+ ToUnicode ( intToStr ( program - > getCellX ( x ) )
+ " , "
+ intToStr ( program - > getCellY ( y ) )
+ " ( "
+ intToStr ( 2 * ( program - > getCellX ( x ) ) )
+ " , "
2013-10-02 23:48:16 +00:00
+ intToStr ( 2 * ( program - > getCellY ( y ) ) )
2013-10-02 22:26:06 +00:00
+ " ) " ) , siPOS_VALUE ) ;
2013-06-04 07:21:01 +00:00
//#ifdef WIN32
//repaint = true;
//#endif
2010-05-04 00:22:11 +00:00
}
lastX = x ;
lastY = y ;
2010-07-18 05:09:30 +00:00
if ( repaint ) {
wxPaintEvent ev ;
onPaint ( ev ) ;
}
2010-05-04 00:22:11 +00:00
event . Skip ( ) ;
}
void MainWindow : : onPaint ( wxPaintEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( ! IsShown ( ) ) {
event . Skip ( ) ;
return ;
}
2013-11-17 22:42:51 +00:00
# if wxCHECK_VERSION(2, 9, 3)
# elif wxCHECK_VERSION(2, 9, 1)
2011-03-20 06:05:09 +00:00
glCanvas - > setCurrentGLContext ( ) ;
# endif
2011-02-01 20:10:18 +00:00
if ( lastPaintEvent . getMillis ( ) < 30 ) {
2010-07-03 05:20:03 +00:00
sleep ( 1 ) ;
2010-07-01 16:31:06 +00:00
return ;
}
2010-12-03 05:07:42 +00:00
wxPaintDC dc ( this ) ; // "In a paint event handler must always create a wxPaintDC object even if you do not use it. (?)
// Otherwise, under MS Windows, refreshing for this and other windows will go wrong"
// http://docs.wxwidgets.org/2.6/wx_wxpaintevent.html
2010-07-01 16:31:06 +00:00
lastPaintEvent . start ( ) ;
2013-06-04 07:21:01 +00:00
if ( panel ) panel - > Refresh ( false ) ;
if ( menuBar ) menuBar - > Refresh ( false ) ;
refreshMapRender ( ) ;
event . Skip ( ) ;
}
2010-06-23 22:21:08 +00:00
2013-06-04 07:21:01 +00:00
void MainWindow : : refreshMapRender ( ) {
2011-01-29 21:44:09 +00:00
if ( program & & glCanvas ) {
program - > renderMap ( glCanvas - > GetClientSize ( ) . x , glCanvas - > GetClientSize ( ) . y ) ;
glCanvas - > SwapBuffers ( ) ;
}
2010-05-04 00:22:11 +00:00
}
void MainWindow : : onMenuFileLoad ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2011-05-23 19:23:00 +00:00
try {
fileDialog - > SetMessage ( wxT ( " Select Glestmap to load " ) ) ;
fileDialog - > SetWildcard ( wxT ( " Glest&Mega Map (*.gbm *.mgm)|*.gbm;*.mgm|Glest Map (*.gbm)|*.gbm|Mega Map (*.mgm)|*.mgm " ) ) ;
if ( fileDialog - > ShowModal ( ) = = wxID_OK ) {
2011-05-23 19:50:17 +00:00
# ifdef WIN32
2011-05-23 19:23:00 +00:00
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( wxFNCONV ( fileDialog - > GetPath ( ) ) ) ;
currentFile = tmp_buf ;
2011-05-23 19:50:17 +00:00
2011-05-23 19:23:00 +00:00
std : : auto_ptr < wchar_t > wstr ( Ansi2WideString ( currentFile . c_str ( ) ) ) ;
currentFile = utf8_encode ( wstr . get ( ) ) ;
2011-05-23 19:50:17 +00:00
# else
2011-05-24 01:44:48 +00:00
//currentFile = fileDialog->GetPath().ToAscii();
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( fileDialog - > GetPath ( ) ) ;
currentFile = tmp_buf ;
2011-05-23 19:23:00 +00:00
# endif
2011-05-24 01:44:48 +00:00
//printf("#1 file load [%s]\n",currentFile.c_str());
2011-05-23 19:23:00 +00:00
program - > loadMap ( currentFile ) ;
fileName = cutLastExt ( extractFileFromDirectoryPath ( currentFile . c_str ( ) ) ) ;
setDirty ( false ) ;
setExtension ( ) ;
SetTitle ( ToUnicode ( winHeader + " ; " + currentFile ) ) ;
}
}
catch ( const string & e ) {
MsgDialog ( this , ToUnicode ( e ) , wxT ( " Exception " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
}
catch ( const exception & e ) {
MsgDialog ( this , ToUnicode ( e . what ( ) ) , wxT ( " Exception " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-05-04 00:22:11 +00:00
}
2011-05-23 19:23:00 +00:00
2010-05-04 00:22:11 +00:00
}
void MainWindow : : onMenuFileSave ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
if ( currentFile . empty ( ) ) {
wxCommandEvent ev ;
onMenuFileSaveAs ( ev ) ;
2011-05-24 01:44:48 +00:00
}
else {
2010-05-04 00:22:11 +00:00
setExtension ( ) ;
2011-05-23 19:23:00 +00:00
2011-05-24 01:44:48 +00:00
//printf("#1 save load [%s]\n",currentFile.c_str());
2010-05-04 00:22:11 +00:00
program - > saveMap ( currentFile ) ;
setDirty ( false ) ;
}
}
void MainWindow : : onMenuFileSaveAs ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2011-03-20 00:59:17 +00:00
# if wxCHECK_VERSION(2, 9, 1)
wxFileDialog fd ( this , wxT ( " Select file " ) , wxT ( " " ) , wxT ( " " ) , wxT ( " *.gbm|*.mgm " ) , wxFD_SAVE ) ;
# else
2011-01-20 00:47:32 +00:00
wxFileDialog fd ( this , wxT ( " Select file " ) , wxT ( " " ) , wxT ( " " ) , wxT ( " *.gbm|*.mgm " ) , wxSAVE ) ;
2011-03-20 00:59:17 +00:00
# endif
2011-01-20 00:47:32 +00:00
2011-04-05 07:08:29 +00:00
if ( fileDialog - > GetPath ( ) ! = ToUnicode ( " " ) ) {
2011-04-05 04:49:48 +00:00
fd . SetPath ( fileDialog - > GetPath ( ) ) ;
}
else {
Config & config = Config : : getInstance ( ) ;
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
string defaultPath = userData + " maps/ " ;
2011-04-05 07:08:29 +00:00
fd . SetDirectory ( ToUnicode ( defaultPath ) ) ;
2011-04-05 04:49:48 +00:00
}
2011-01-20 00:47:32 +00:00
fd . SetWildcard ( wxT ( " Glest Map (*.gbm)|*.gbm|MegaGlest Map (*.mgm)|*.mgm " ) ) ;
if ( fd . ShowModal ( ) = = wxID_OK ) {
2011-05-23 19:50:17 +00:00
# ifdef WIN32
2011-05-23 19:23:00 +00:00
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( wxFNCONV ( fd . GetPath ( ) ) ) ;
currentFile = tmp_buf ;
2011-05-23 19:50:17 +00:00
std : : auto_ptr < wchar_t > wstr ( Ansi2WideString ( currentFile . c_str ( ) ) ) ;
currentFile = utf8_encode ( wstr . get ( ) ) ;
# else
2011-05-24 01:44:48 +00:00
//currentFile = fd.GetPath().ToAscii();
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( fd . GetPath ( ) ) ;
currentFile = tmp_buf ;
2011-05-23 19:23:00 +00:00
# endif
2011-01-20 00:47:32 +00:00
fileDialog - > SetPath ( fd . GetPath ( ) ) ;
2010-05-04 00:22:11 +00:00
setExtension ( ) ;
2011-05-24 01:44:48 +00:00
//printf("#2 file save [%s]\n",currentFile.c_str());
2010-05-04 00:22:11 +00:00
program - > saveMap ( currentFile ) ;
2010-05-04 08:15:16 +00:00
fileName = cutLastExt ( extractFileFromDirectoryPath ( currentFile . c_str ( ) ) ) ;
2010-05-04 00:22:11 +00:00
setDirty ( false ) ;
}
SetTitle ( ToUnicode ( winHeader + " ; " + currentFile ) ) ;
}
void MainWindow : : onMenuFileExit ( wxCommandEvent & event ) {
Close ( ) ;
}
void MainWindow : : onMenuEditUndo ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-12-03 05:07:42 +00:00
// std::cout << "Undo Pressed" << std::endl;
2010-05-04 00:22:11 +00:00
if ( program - > undo ( ) ) {
wxPaintEvent e ;
onPaint ( e ) ;
setDirty ( ) ;
}
}
void MainWindow : : onMenuEditRedo ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
if ( program - > redo ( ) ) {
wxPaintEvent e ;
onPaint ( e ) ;
setDirty ( ) ;
}
}
void MainWindow : : onMenuEditReset ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
program - > setUndoPoint ( ctAll ) ;
SimpleDialog simpleDialog ;
2010-12-03 05:07:42 +00:00
simpleDialog . addValue ( " Width " , " 128 " , " (must be 16,32,64,128,256,512...) " ) ; // must be an exponent of two
simpleDialog . addValue ( " Height " , " 128 " , " (must be 16,32,64,128,256,512...) " ) ;
simpleDialog . addValue ( " Surface " , " 1 " , " (Default surface material) " ) ;
simpleDialog . addValue ( " Altitude " , " 10 " , " (Default surface height) " ) ;
simpleDialog . addValue ( " Number of players " , " 8 " ) ;
if ( ! simpleDialog . show ( ) ) return ;
2010-05-04 00:22:11 +00:00
try {
program - > reset (
strToInt ( simpleDialog . getValue ( " Width " ) ) ,
strToInt ( simpleDialog . getValue ( " Height " ) ) ,
strToInt ( simpleDialog . getValue ( " Altitude " ) ) ,
strToInt ( simpleDialog . getValue ( " Surface " ) ) ) ;
2010-12-03 05:07:42 +00:00
program - > resetFactions ( strToInt ( simpleDialog . getValue ( " Number of players " ) ) ) ;
}
2010-06-23 22:21:08 +00:00
catch ( const exception & e ) {
MsgDialog ( this , ToUnicode ( e . what ( ) ) , wxT ( " Exception " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-05-04 00:22:11 +00:00
}
currentFile = " " ;
fileName = " New (unsaved) map " ;
}
void MainWindow : : onMenuEditResetPlayers ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
SimpleDialog simpleDialog ;
2010-12-03 05:07:42 +00:00
simpleDialog . addValue ( " Number of players " , intToStr ( program - > getMap ( ) - > getMaxFactions ( ) ) ) ;
if ( ! simpleDialog . show ( " Reset players " ) ) return ;
2010-05-04 00:22:11 +00:00
try {
2010-12-03 05:07:42 +00:00
program - > resetFactions ( strToInt ( simpleDialog . getValue ( " Number of players " ) ) ) ;
}
2010-06-23 22:21:08 +00:00
catch ( const exception & e ) {
MsgDialog ( this , ToUnicode ( e . what ( ) ) , wxT ( " Exception " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-05-04 00:22:11 +00:00
}
setDirty ( ) ;
setExtension ( ) ;
}
2011-05-24 00:58:21 +00:00
void MainWindow : : onMenuEditFlipDiagonal ( wxCommandEvent & event ) {
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
program - > flipDiagonal ( ) ;
setDirty ( ) ;
}
2010-05-04 00:22:11 +00:00
void MainWindow : : onMenuEditResize ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
SimpleDialog simpleDialog ;
2010-12-03 05:07:42 +00:00
simpleDialog . addValue ( " Width " , intToStr ( program - > getMap ( ) - > getW ( ) ) , " (must be 16,32,64,128,256,512...) " ) ;
simpleDialog . addValue ( " Height " , intToStr ( program - > getMap ( ) - > getH ( ) ) , " (must be 16,32,64,128,256,512...) " ) ;
simpleDialog . addValue ( " Surface " , " 1 " , " (surface material for new area around map) " ) ;
simpleDialog . addValue ( " Altitude " , " 10 " , " (surface height for new area around map) " ) ;
2010-12-24 03:36:34 +00:00
if ( ! simpleDialog . show ( " Resize - expand around, shrink to topleft " ) ) return ;
2010-05-04 00:22:11 +00:00
try {
program - > resize (
strToInt ( simpleDialog . getValue ( " Width " ) ) ,
2010-12-03 05:07:42 +00:00
strToInt ( simpleDialog . getValue ( " Height " ) ) ,
2010-05-04 00:22:11 +00:00
strToInt ( simpleDialog . getValue ( " Altitude " ) ) ,
strToInt ( simpleDialog . getValue ( " Surface " ) ) ) ;
2010-12-03 05:07:42 +00:00
}
2010-06-23 22:21:08 +00:00
catch ( const exception & e ) {
MsgDialog ( this , ToUnicode ( e . what ( ) ) , wxT ( " Exception " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-05-04 00:22:11 +00:00
}
setDirty ( ) ;
}
void MainWindow : : onMenuEditFlipX ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-05-04 00:22:11 +00:00
program - > flipX ( ) ;
setDirty ( ) ;
}
void MainWindow : : onMenuEditFlipY ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-05-04 00:22:11 +00:00
program - > flipY ( ) ;
setDirty ( ) ;
}
2010-12-03 05:07:42 +00:00
void MainWindow : : onMenuEditMirrorX ( wxCommandEvent & event ) { // copy left to right
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-12-03 05:07:42 +00:00
program - > mirrorX ( ) ;
setDirty ( ) ;
}
void MainWindow : : onMenuEditMirrorY ( wxCommandEvent & event ) { // copy top to bottom
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-12-03 05:07:42 +00:00
program - > mirrorY ( ) ;
setDirty ( ) ;
}
void MainWindow : : onMenuEditMirrorXY ( wxCommandEvent & event ) { // copy bottomleft tp topright
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-12-03 05:07:42 +00:00
program - > mirrorXY ( ) ;
setDirty ( ) ;
}
void MainWindow : : onMenuEditRotatecopyX ( wxCommandEvent & event ) { // copy left to right, rotated
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-12-03 05:07:42 +00:00
program - > rotatecopyX ( ) ;
setDirty ( ) ;
}
void MainWindow : : onMenuEditRotatecopyY ( wxCommandEvent & event ) { // copy top to bottom, rotated
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-12-03 05:07:42 +00:00
program - > rotatecopyY ( ) ;
setDirty ( ) ;
}
void MainWindow : : onMenuEditRotatecopyXY ( wxCommandEvent & event ) { // copy bottomleft to topright, rotated
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-12-03 05:07:42 +00:00
program - > rotatecopyXY ( ) ;
setDirty ( ) ;
}
void MainWindow : : onMenuEditRotatecopyCorner ( wxCommandEvent & event ) { // copy top left 1/4 to top right 1/4, rotated
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-12-03 05:07:42 +00:00
program - > rotatecopyCorner ( ) ;
setDirty ( ) ;
}
2010-05-04 00:22:11 +00:00
void MainWindow : : onMenuEditRandomizeHeights ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-05-04 00:22:11 +00:00
program - > randomizeMapHeights ( ) ;
setDirty ( ) ;
}
void MainWindow : : onMenuEditRandomize ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
program - > setUndoPoint ( ctAll ) ;
2010-05-04 00:22:11 +00:00
program - > randomizeMap ( ) ;
setDirty ( ) ;
}
void MainWindow : : onMenuEditSwitchSurfaces ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
SimpleDialog simpleDialog ;
2010-12-03 05:07:42 +00:00
simpleDialog . addValue ( " Surface1 " , " 1 " , " replace this surface with... " ) ;
simpleDialog . addValue ( " Surface2 " , " 2 " , " ...this and vice versa " ) ;
if ( ! simpleDialog . show ( " Switch surfaces " ) ) return ;
2010-05-04 00:22:11 +00:00
try {
2010-12-03 05:07:42 +00:00
program - > setUndoPoint ( ctSurface ) ;
2010-05-04 00:22:11 +00:00
program - > switchMapSurfaces (
strToInt ( simpleDialog . getValue ( " Surface1 " ) ) ,
strToInt ( simpleDialog . getValue ( " Surface2 " ) ) ) ;
2010-12-03 05:07:42 +00:00
}
2010-06-23 22:21:08 +00:00
catch ( const exception & e ) {
MsgDialog ( this , ToUnicode ( e . what ( ) ) , wxT ( " Exception " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-05-04 00:22:11 +00:00
}
setDirty ( ) ;
}
void MainWindow : : onMenuEditInfo ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
SimpleDialog simpleDialog ;
simpleDialog . addValue ( " Title " , program - > getMap ( ) - > getTitle ( ) ) ;
2010-12-03 05:07:42 +00:00
simpleDialog . addValue ( " Description " , program - > getMap ( ) - > getDesc ( ) ) ;
2010-05-04 00:22:11 +00:00
simpleDialog . addValue ( " Author " , program - > getMap ( ) - > getAuthor ( ) ) ;
2010-12-03 05:07:42 +00:00
if ( ! simpleDialog . show ( " Info " , true ) ) return ;
2010-05-04 00:22:11 +00:00
2012-11-05 05:40:47 +00:00
bool ischanged = program - > setMapTitle ( simpleDialog . getValue ( " Title " ) ) ;
2010-12-03 05:07:42 +00:00
ischanged = ( program - > setMapDesc ( simpleDialog . getValue ( " Description " ) ) | | ischanged ) ;
ischanged = ( program - > setMapAuthor ( simpleDialog . getValue ( " Author " ) ) | | ischanged ) ;
if ( ischanged )
2010-05-04 00:22:11 +00:00
if ( ! isDirty ( ) ) {
setDirty ( true ) ;
}
2010-12-03 05:07:42 +00:00
2010-05-04 00:22:11 +00:00
}
void MainWindow : : onMenuEditAdvanced ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
SimpleDialog simpleDialog ;
2012-03-29 20:18:20 +00:00
simpleDialog . addValue ( " Height Factor " , intToStr ( program - > getMap ( ) - > getHeightFactor ( ) ) , " lower means more hill effect. Numbers above 100 are handled like this: \n x=x/100 ,so a 150 will mean 1.5 in the game. " ) ;
simpleDialog . addValue ( " Water Level " , intToStr ( program - > getMap ( ) - > getWaterLevel ( ) ) , " water is visible below this, and walkable until 1.5 less " ) ;
simpleDialog . addValue ( " Cliff Level " , intToStr ( program - > getMap ( ) - > getCliffLevel ( ) ) , " neighboring fields with at least this heights difference are cliffs " ) ;
simpleDialog . addValue ( " Camera Height " , intToStr ( program - > getMap ( ) - > getCameraHeight ( ) ) , " you can give a camera heigth here default is 0 ;ignored if <20 " ) ;
2010-12-03 05:07:42 +00:00
if ( ! simpleDialog . show ( " Advanced " ) ) return ;
2010-05-04 00:22:11 +00:00
try {
program - > setMapAdvanced (
strToInt ( simpleDialog . getValue ( " Height Factor " ) ) ,
2011-02-08 03:50:59 +00:00
strToInt ( simpleDialog . getValue ( " Water Level " ) ) ,
2011-02-25 00:31:42 +00:00
strToInt ( simpleDialog . getValue ( " Cliff Level " ) ) ,
strToInt ( simpleDialog . getValue ( " Camera Height " ) ) ) ;
2010-12-03 05:07:42 +00:00
}
2010-06-23 22:21:08 +00:00
catch ( const exception & e ) {
MsgDialog ( this , ToUnicode ( e . what ( ) ) , wxT ( " Exception " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
2010-05-04 00:22:11 +00:00
}
setDirty ( ) ;
}
2010-12-03 05:07:42 +00:00
void MainWindow : : onMenuViewResetZoomAndPos ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
program - > resetOfset ( ) ;
2010-12-03 05:07:42 +00:00
wxPaintEvent e ;
onPaint ( e ) ;
2010-05-04 00:22:11 +00:00
}
2010-12-05 01:33:28 +00:00
void MainWindow : : onMenuViewGrid ( wxCommandEvent & event ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-12-05 01:33:28 +00:00
menuView - > Check ( miViewGrid , program - > setGridOnOff ( ) ) ; // miViewGrid event.GetId()
wxPaintEvent e ;
onPaint ( e ) ;
}
2013-06-21 18:21:07 +00:00
void MainWindow : : onMenuViewHeightMap ( wxCommandEvent & event ) {
if ( program = = NULL ) {
return ;
}
menuView - > Check ( miViewHeightMap , program - > setHeightMapOnOff ( ) ) ; // miViewGrid event.GetId()
wxPaintEvent e ;
onPaint ( e ) ;
}
void MainWindow : : onMenuHideWater ( wxCommandEvent & event ) {
if ( program = = NULL ) {
return ;
}
menuView - > Check ( miHideWater , program - > setHideWaterOnOff ( ) ) ; // miViewGrid event.GetId()
wxPaintEvent e ;
onPaint ( e ) ;
}
2010-12-03 05:07:42 +00:00
void MainWindow : : onMenuViewAbout ( wxCommandEvent & event ) {
2010-06-23 22:21:08 +00:00
MsgDialog (
this ,
2010-05-04 00:22:11 +00:00
wxT ( " Glest Map Editor - Copyright 2004 The Glest Team \n (with improvements by others, 2010). " ) ,
wxT ( " About " ) ) . ShowModal ( ) ;
}
2010-12-03 05:07:42 +00:00
void MainWindow : : onMenuViewHelp ( wxCommandEvent & event ) {
MsgDialog ( this ,
2010-12-24 03:36:34 +00:00
wxT ( " Draw with left mouse \n Move viewport with right mouse drag \n Zoom with center mouse drag, or mousewheel \n \n \
2010-12-03 05:07:42 +00:00
You can change brush in the same category with key 1 - 9 \ n \
2010-12-24 03:36:34 +00:00
and change category with their first letter ( keys S , R , O , G , H ) \ n \
Press Space to set brush to the resource or object under the mouse cursor \ n \
2010-12-06 20:13:27 +00:00
To center things in the map shift it with Shift - Up / Down / Left / Right keys \ n \
2010-12-05 01:33:28 +00:00
Height tool ( blue ) builds with integer height steps 0 - 20 , \ nwhile Gradient tool ( red ) uses any real number \ n \
2010-12-24 03:36:34 +00:00
Units can go over water as long as it is less than 1.5 deep \ n \ n \
2010-12-03 05:07:42 +00:00
A good idea is to put some stone , gold and tree near starting position \ n \
2010-12-05 01:33:28 +00:00
Starting position needs an open area for the tower and the starting units \ n " ),
2010-05-04 00:22:11 +00:00
wxT ( " Help " ) ) . ShowModal ( ) ;
2010-12-03 05:07:42 +00:00
/* 5 away and 10x10 empty area? */
2010-05-04 00:22:11 +00:00
}
void MainWindow : : onMenuBrushHeight ( wxCommandEvent & e ) {
uncheckBrush ( ) ;
menuBrushHeight - > Check ( e . GetId ( ) , true ) ;
height = e . GetId ( ) - miBrushHeight - heightCount / 2 - 1 ;
enabledGroup = ctHeight ;
currentBrush = btHeight ;
SetStatusText ( wxT ( " Brush: Height " ) , siBRUSH_TYPE ) ;
SetStatusText ( wxT ( " Value: " ) + ToUnicode ( intToStr ( height ) ) , siBRUSH_VALUE ) ;
}
void MainWindow : : onMenuBrushGradient ( wxCommandEvent & e ) {
uncheckBrush ( ) ;
menuBrushGradient - > Check ( e . GetId ( ) , true ) ;
height = e . GetId ( ) - miBrushGradient - heightCount / 2 - 1 ;
enabledGroup = ctGradient ;
currentBrush = btGradient ;
SetStatusText ( wxT ( " Brush: Gradient " ) , siBRUSH_TYPE ) ;
SetStatusText ( wxT ( " Value: " ) + ToUnicode ( intToStr ( height ) ) , siBRUSH_VALUE ) ;
}
void MainWindow : : onMenuBrushSurface ( wxCommandEvent & e ) {
uncheckBrush ( ) ;
menuBrushSurface - > Check ( e . GetId ( ) , true ) ;
surface = e . GetId ( ) - miBrushSurface ;
enabledGroup = ctSurface ;
currentBrush = btSurface ;
SetStatusText ( wxT ( " Brush: Surface " ) , siBRUSH_TYPE ) ;
SetStatusText (
wxT ( " Value: " ) + ToUnicode ( intToStr ( surface ) ) + wxT ( " " )
+ ToUnicode ( surface_descs [ surface - 1 ] ) , siBRUSH_VALUE ) ;
}
void MainWindow : : onMenuBrushObject ( wxCommandEvent & e ) {
uncheckBrush ( ) ;
menuBrushObject - > Check ( e . GetId ( ) , true ) ;
object = e . GetId ( ) - miBrushObject - 1 ;
enabledGroup = ctObject ;
currentBrush = btObject ;
SetStatusText ( wxT ( " Brush: Object " ) , siBRUSH_TYPE ) ;
SetStatusText (
wxT ( " Value: " ) + ToUnicode ( intToStr ( object ) ) + wxT ( " " )
+ ToUnicode ( object_descs [ object ] ) , siBRUSH_VALUE ) ;
}
void MainWindow : : onMenuBrushResource ( wxCommandEvent & e ) {
uncheckBrush ( ) ;
menuBrushResource - > Check ( e . GetId ( ) , true ) ;
resource = e . GetId ( ) - miBrushResource - 1 ;
enabledGroup = ctResource ;
currentBrush = btResource ;
SetStatusText ( wxT ( " Brush: Resource " ) , siBRUSH_TYPE ) ;
SetStatusText (
wxT ( " Value: " ) + ToUnicode ( intToStr ( resource ) ) + wxT ( " " )
+ ToUnicode ( resource_descs [ resource ] ) , siBRUSH_VALUE ) ;
}
void MainWindow : : onMenuBrushStartLocation ( wxCommandEvent & e ) {
uncheckBrush ( ) ;
menuBrushStartLocation - > Check ( e . GetId ( ) , true ) ;
startLocation = e . GetId ( ) - miBrushStartLocation ;
enabledGroup = ctLocation ;
currentBrush = btStartLocation ;
SetStatusText ( wxT ( " Brush: Start Locations " ) , siBRUSH_TYPE ) ;
SetStatusText ( wxT ( " Value: " ) + ToUnicode ( intToStr ( startLocation ) ) , siBRUSH_VALUE ) ;
}
void MainWindow : : onMenuRadius ( wxCommandEvent & e ) {
uncheckRadius ( ) ;
menuRadius - > Check ( e . GetId ( ) , true ) ;
radius = e . GetId ( ) - miRadius ;
SetStatusText ( wxT ( " Radius: " ) + ToUnicode ( intToStr ( radius ) ) , siBRUSH_RADIUS ) ;
}
void MainWindow : : change ( int x , int y ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
switch ( enabledGroup ) {
case ctHeight :
program - > glestChangeMapHeight ( x , y , height , radius ) ;
break ;
case ctSurface :
program - > changeMapSurface ( x , y , surface , radius ) ;
break ;
case ctObject :
program - > changeMapObject ( x , y , object , radius ) ;
break ;
case ctResource :
program - > changeMapResource ( x , y , resource , radius ) ;
break ;
case ctLocation :
program - > changeStartLocation ( x , y , startLocation - 1 ) ;
break ;
case ctGradient :
program - > pirateChangeMapHeight ( x , y , height , radius ) ;
break ;
}
}
void MainWindow : : uncheckBrush ( ) {
for ( int i = 0 ; i < heightCount ; + + i ) {
menuBrushHeight - > Check ( miBrushHeight + i + 1 , false ) ;
}
for ( int i = 0 ; i < heightCount ; + + i ) {
menuBrushGradient - > Check ( miBrushGradient + i + 1 , false ) ;
}
for ( int i = 0 ; i < surfaceCount ; + + i ) {
menuBrushSurface - > Check ( miBrushSurface + i + 1 , false ) ;
}
for ( int i = 0 ; i < objectCount ; + + i ) {
menuBrushObject - > Check ( miBrushObject + i + 1 , false ) ;
}
for ( int i = 0 ; i < resourceCount ; + + i ) {
menuBrushResource - > Check ( miBrushResource + i + 1 , false ) ;
}
for ( int i = 0 ; i < startLocationCount ; + + i ) {
menuBrushStartLocation - > Check ( miBrushStartLocation + i + 1 , false ) ;
}
}
void MainWindow : : uncheckRadius ( ) {
for ( int i = 1 ; i < = radiusCount ; + + i ) {
menuRadius - > Check ( miRadius + i , false ) ;
}
}
void MainWindow : : onKeyDown ( wxKeyEvent & e ) {
2011-03-20 06:05:09 +00:00
if ( program = = NULL ) {
return ;
}
2010-05-04 00:22:11 +00:00
if ( currentBrush = = btHeight | | currentBrush = = btGradient ) { // 'height' brush
if ( e . GetKeyCode ( ) > = ' 0 ' & & e . GetKeyCode ( ) < = ' 5 ' ) {
height = e . GetKeyCode ( ) - 48 ; // '0'-'5' == 0-5
if ( e . GetModifiers ( ) = = wxMOD_CONTROL ) { // Ctrl means negative
height = - height ;
}
int id_offset = heightCount / 2 + height + 1 ;
if ( currentBrush = = btHeight ) {
wxCommandEvent evt ( wxEVT_NULL , miBrushHeight + id_offset ) ;
onMenuBrushHeight ( evt ) ;
} else {
wxCommandEvent evt ( wxEVT_NULL , miBrushGradient + id_offset ) ;
onMenuBrushGradient ( evt ) ;
}
return ;
}
}
if ( currentBrush = = btSurface ) { // surface texture
if ( e . GetKeyCode ( ) > = ' 1 ' & & e . GetKeyCode ( ) < = ' 5 ' ) {
surface = e . GetKeyCode ( ) - 48 ; // '1'-'5' == 1-5
wxCommandEvent evt ( wxEVT_NULL , miBrushSurface + surface ) ;
onMenuBrushSurface ( evt ) ;
return ;
}
}
if ( currentBrush = = btObject ) {
bool valid = true ;
if ( e . GetKeyCode ( ) > = ' 1 ' & & e . GetKeyCode ( ) < = ' 9 ' ) {
object = e . GetKeyCode ( ) - 48 ; // '1'-'9' == 1-9
} else if ( e . GetKeyCode ( ) = = ' 0 ' ) { // '0' == 10
object = 10 ;
} else if ( e . GetKeyCode ( ) = = ' - ' ) { // '-' == 0
object = 0 ;
} else {
valid = false ;
}
if ( valid ) {
wxCommandEvent evt ( wxEVT_NULL , miBrushObject + object + 1 ) ;
onMenuBrushObject ( evt ) ;
return ;
}
}
if ( currentBrush = = btResource ) {
if ( e . GetKeyCode ( ) > = ' 0 ' & & e . GetKeyCode ( ) < = ' 5 ' ) {
resource = e . GetKeyCode ( ) - 48 ; // '0'-'5' == 0-5
wxCommandEvent evt ( wxEVT_NULL , miBrushResource + resource + 1 ) ;
onMenuBrushResource ( evt ) ;
return ;
}
}
if ( currentBrush = = btStartLocation ) {
if ( e . GetKeyCode ( ) > = ' 1 ' & & e . GetKeyCode ( ) < = ' 8 ' ) {
startLocation = e . GetKeyCode ( ) - 48 ; // '1'-'8' == 0-7
wxCommandEvent evt ( wxEVT_NULL , miBrushStartLocation + startLocation ) ;
onMenuBrushStartLocation ( evt ) ;
return ;
}
}
if ( e . GetKeyCode ( ) = = ' H ' ) {
wxCommandEvent evt ( wxEVT_NULL , miBrushHeight + height + heightCount / 2 + 1 ) ;
onMenuBrushHeight ( evt ) ;
2010-12-03 05:07:42 +00:00
} else if ( e . GetKeyCode ( ) = = ' ' ) {
2010-05-04 00:22:11 +00:00
if ( resourceUnderMouse ! = 0 ) {
wxCommandEvent evt ( wxEVT_NULL , miBrushResource + resourceUnderMouse + 1 ) ;
onMenuBrushResource ( evt ) ;
} else {
wxCommandEvent evt ( wxEVT_NULL , miBrushObject + objectUnderMouse + 1 ) ;
onMenuBrushObject ( evt ) ;
}
} else if ( e . GetKeyCode ( ) = = ' G ' ) {
wxCommandEvent evt ( wxEVT_NULL , miBrushGradient + height + heightCount / 2 + 1 ) ;
onMenuBrushGradient ( evt ) ;
} else if ( e . GetKeyCode ( ) = = ' S ' ) {
wxCommandEvent evt ( wxEVT_NULL , miBrushSurface + surface ) ;
onMenuBrushSurface ( evt ) ;
} else if ( e . GetKeyCode ( ) = = ' O ' ) {
wxCommandEvent evt ( wxEVT_NULL , miBrushObject + object + 1 ) ;
onMenuBrushObject ( evt ) ;
} else if ( e . GetKeyCode ( ) = = ' R ' ) {
wxCommandEvent evt ( wxEVT_NULL , miBrushResource + resource + 1 ) ;
onMenuBrushResource ( evt ) ;
} else if ( e . GetKeyCode ( ) = = ' L ' ) {
wxCommandEvent evt ( wxEVT_NULL , miBrushStartLocation + startLocation + 1 ) ;
onMenuBrushStartLocation ( evt ) ;
2010-12-06 20:13:27 +00:00
} else if ( e . GetKeyCode ( ) = = WXK_LEFT & & e . GetModifiers ( ) = = wxMOD_SHIFT ) { // shift-left/right/up/down to shift the map one square
program - > setUndoPoint ( ctAll ) ;
program - > shiftLeft ( ) ;
setDirty ( ) ;
} else if ( e . GetKeyCode ( ) = = WXK_RIGHT & & e . GetModifiers ( ) = = wxMOD_SHIFT ) {
program - > setUndoPoint ( ctAll ) ;
program - > shiftRight ( ) ;
setDirty ( ) ;
} else if ( e . GetKeyCode ( ) = = WXK_UP & & e . GetModifiers ( ) = = wxMOD_SHIFT ) {
program - > setUndoPoint ( ctAll ) ;
program - > shiftUp ( ) ;
setDirty ( ) ;
} else if ( e . GetKeyCode ( ) = = WXK_DOWN & & e . GetModifiers ( ) = = wxMOD_SHIFT ) {
program - > setUndoPoint ( ctAll ) ;
program - > shiftDown ( ) ;
setDirty ( ) ;
} else if ( e . GetKeyCode ( ) = = WXK_BACK & & e . GetModifiers ( ) = = wxMOD_ALT ) { // undo
wxCommandEvent evt ( wxEVT_NULL , 0 ) ;
onMenuEditUndo ( evt ) ;
2010-05-04 00:22:11 +00:00
} else {
e . Skip ( ) ;
}
}
BEGIN_EVENT_TABLE ( MainWindow , wxFrame )
EVT_CLOSE ( MainWindow : : onClose )
2010-12-03 05:07:42 +00:00
// these are 'handled' by GlCanvas and funneled to these handlers. See BEGIN_EVENT_TABLE(GlCanvas, wxGLCanvas) below.
2010-05-04 00:22:11 +00:00
//EVT_LEFT_DOWN(MainWindow::onMouseDown)
//EVT_MOTION(MainWindow::onMouseMove)
//EVT_KEY_DOWN(MainWindow::onKeyDown)
2010-12-03 05:07:42 +00:00
EVT_MENU ( wxID_NEW , MainWindow : : onMenuEditReset )
2010-05-04 00:22:11 +00:00
EVT_MENU ( wxID_OPEN , MainWindow : : onMenuFileLoad )
EVT_MENU ( wxID_SAVE , MainWindow : : onMenuFileSave )
EVT_MENU ( wxID_SAVEAS , MainWindow : : onMenuFileSaveAs )
EVT_MENU ( wxID_EXIT , MainWindow : : onMenuFileExit )
EVT_MENU ( miEditUndo , MainWindow : : onMenuEditUndo )
EVT_MENU ( miEditRedo , MainWindow : : onMenuEditRedo )
EVT_MENU ( miEditResetPlayers , MainWindow : : onMenuEditResetPlayers )
EVT_MENU ( miEditResize , MainWindow : : onMenuEditResize )
2011-05-24 00:58:21 +00:00
EVT_MENU ( miEditFlipDiagonal , MainWindow : : onMenuEditFlipDiagonal )
2010-05-04 00:22:11 +00:00
EVT_MENU ( miEditFlipX , MainWindow : : onMenuEditFlipX )
EVT_MENU ( miEditFlipY , MainWindow : : onMenuEditFlipY )
2010-12-03 05:07:42 +00:00
EVT_MENU ( miEditMirrorX , MainWindow : : onMenuEditMirrorX )
EVT_MENU ( miEditMirrorY , MainWindow : : onMenuEditMirrorY )
EVT_MENU ( miEditMirrorXY , MainWindow : : onMenuEditMirrorXY )
EVT_MENU ( miEditRotatecopyX , MainWindow : : onMenuEditRotatecopyX )
EVT_MENU ( miEditRotatecopyY , MainWindow : : onMenuEditRotatecopyY )
EVT_MENU ( miEditRotatecopyXY , MainWindow : : onMenuEditRotatecopyXY )
EVT_MENU ( miEditRotatecopyCorner , MainWindow : : onMenuEditRotatecopyCorner )
2010-05-04 00:22:11 +00:00
EVT_MENU ( miEditRandomizeHeights , MainWindow : : onMenuEditRandomizeHeights )
EVT_MENU ( miEditRandomize , MainWindow : : onMenuEditRandomize )
EVT_MENU ( miEditSwitchSurfaces , MainWindow : : onMenuEditSwitchSurfaces )
EVT_MENU ( miEditInfo , MainWindow : : onMenuEditInfo )
EVT_MENU ( miEditAdvanced , MainWindow : : onMenuEditAdvanced )
2010-12-03 05:07:42 +00:00
EVT_MENU ( miViewResetZoomAndPos , MainWindow : : onMenuViewResetZoomAndPos )
2010-12-05 01:33:28 +00:00
EVT_MENU ( miViewGrid , MainWindow : : onMenuViewGrid )
2013-06-21 18:21:07 +00:00
EVT_MENU ( miViewHeightMap , MainWindow : : onMenuViewHeightMap )
EVT_MENU ( miHideWater , MainWindow : : onMenuHideWater )
2010-12-03 05:07:42 +00:00
EVT_MENU ( miViewAbout , MainWindow : : onMenuViewAbout )
EVT_MENU ( miViewHelp , MainWindow : : onMenuViewHelp )
2010-05-04 00:22:11 +00:00
EVT_MENU_RANGE ( miBrushHeight + 1 , miBrushHeight + heightCount , MainWindow : : onMenuBrushHeight )
EVT_MENU_RANGE ( miBrushGradient + 1 , miBrushGradient + heightCount , MainWindow : : onMenuBrushGradient )
EVT_MENU_RANGE ( miBrushSurface + 1 , miBrushSurface + surfaceCount , MainWindow : : onMenuBrushSurface )
EVT_MENU_RANGE ( miBrushObject + 1 , miBrushObject + objectCount , MainWindow : : onMenuBrushObject )
EVT_MENU_RANGE ( miBrushResource + 1 , miBrushResource + resourceCount , MainWindow : : onMenuBrushResource )
EVT_MENU_RANGE ( miBrushStartLocation + 1 , miBrushStartLocation + startLocationCount , MainWindow : : onMenuBrushStartLocation )
EVT_MENU_RANGE ( miRadius , miRadius + radiusCount , MainWindow : : onMenuRadius )
2010-12-03 05:07:42 +00:00
2010-05-04 00:22:11 +00:00
EVT_PAINT ( MainWindow : : onPaint )
2010-12-03 05:07:42 +00:00
2010-05-04 00:22:11 +00:00
EVT_TOOL ( toolPlayer , MainWindow : : onToolPlayer )
END_EVENT_TABLE ( )
// =====================================================
// class GlCanvas
// =====================================================
GlCanvas : : GlCanvas ( MainWindow * mainWindow , wxWindow * parent , int * args )
2011-03-20 06:05:09 +00:00
# if wxCHECK_VERSION(2, 9, 1)
: wxGLCanvas ( parent , - 1 , args , wxDefaultPosition , wxDefaultSize , 0 , wxT ( " GLCanvas " ) ) {
this - > context = new wxGLContext ( this ) ;
# else
2010-05-04 00:22:11 +00:00
: wxGLCanvas ( parent , - 1 , wxDefaultPosition , wxDefaultSize , 0 , wxT ( " GLCanvas " ) , args ) {
2011-03-20 06:05:09 +00:00
this - > context = NULL ;
# endif
2010-05-04 00:22:11 +00:00
this - > mainWindow = mainWindow ;
}
2011-03-20 06:05:09 +00:00
GlCanvas : : ~ GlCanvas ( ) {
delete this - > context ;
this - > context = NULL ;
}
void GlCanvas : : setCurrentGLContext ( ) {
2011-10-18 01:13:38 +00:00
# ifndef __APPLE__
2013-11-17 22:42:51 +00:00
# if wxCHECK_VERSION(2, 9, 1)
if ( this - > context = = NULL ) {
this - > context = new wxGLContext ( this ) ;
}
# endif
2011-10-18 01:13:38 +00:00
if ( this - > context ) {
2011-03-20 06:05:09 +00:00
this - > SetCurrent ( * this - > context ) ;
}
2011-10-18 01:13:38 +00:00
# else
this - > SetCurrent ( ) ;
# endif
2011-03-20 06:05:09 +00:00
}
2010-05-04 00:22:11 +00:00
void translateCoords ( wxWindow * wnd , int & x , int & y ) {
2010-07-01 15:53:07 +00:00
/*
2010-05-04 00:22:11 +00:00
# ifdef WIN32
int cx , cy ;
wnd - > GetPosition ( & cx , & cy ) ;
x + = cx ;
y + = cy ;
# endif
2010-07-01 15:53:07 +00:00
*/
2010-05-04 00:22:11 +00:00
}
2010-12-03 05:07:42 +00:00
// for the mousewheel
void GlCanvas : : onMouseWheel ( wxMouseEvent & event ) {
if ( event . GetWheelRotation ( ) > 0 ) mainWindow - > onMouseWheelDown ( event ) ;
else mainWindow - > onMouseWheelUp ( event ) ;
}
2010-05-04 00:22:11 +00:00
void GlCanvas : : onMouseDown ( wxMouseEvent & event ) {
int x , y ;
event . GetPosition ( & x , & y ) ;
translateCoords ( this , x , y ) ;
mainWindow - > onMouseDown ( event , x , y ) ;
}
void GlCanvas : : onMouseMove ( wxMouseEvent & event ) {
int x , y ;
event . GetPosition ( & x , & y ) ;
translateCoords ( this , x , y ) ;
mainWindow - > onMouseMove ( event , x , y ) ;
}
void GlCanvas : : onKeyDown ( wxKeyEvent & event ) {
int x , y ;
event . GetPosition ( & x , & y ) ;
translateCoords ( this , x , y ) ;
mainWindow - > onKeyDown ( event ) ;
}
2010-12-03 05:07:42 +00:00
void GlCanvas : : onPaint ( wxPaintEvent & event ) {
// wxPaintDC dc(this); //N "In a paint event handler must always create a wxPaintDC object even if you do not use it. (?)
// mainWindow->program->renderMap(GetClientSize().x, GetClientSize().y);
// SwapBuffers();
// event.Skip();
mainWindow - > onPaint ( event ) ;
}
2010-05-04 08:15:16 +00:00
2010-05-04 00:22:11 +00:00
BEGIN_EVENT_TABLE ( GlCanvas , wxGLCanvas )
EVT_KEY_DOWN ( GlCanvas : : onKeyDown )
2010-12-03 05:07:42 +00:00
EVT_MOUSEWHEEL ( GlCanvas : : onMouseWheel )
2010-05-04 00:22:11 +00:00
EVT_LEFT_DOWN ( GlCanvas : : onMouseDown )
EVT_MOTION ( GlCanvas : : onMouseMove )
2010-12-03 05:07:42 +00:00
EVT_PAINT ( GlCanvas : : onPaint ) // Because the drawing area needs to be repainted too.
2010-05-04 00:22:11 +00:00
END_EVENT_TABLE ( )
// ===============================================
// class SimpleDialog
// ===============================================
2010-12-03 05:07:42 +00:00
void SimpleDialog : : addValue ( const string & key , const string & value , const string & help ) {
values . push_back ( pair < string , string > ( key , value + " | " + help ) ) ; // I guess I need map<,> instead but I don't know how to do it
2010-05-04 00:22:11 +00:00
}
string SimpleDialog : : getValue ( const string & key ) {
2010-05-04 08:15:16 +00:00
for ( unsigned int i = 0 ; i < values . size ( ) ; + + i ) {
2010-05-04 00:22:11 +00:00
if ( values [ i ] . first = = key ) {
return values [ i ] . second ;
}
}
return " " ;
}
2010-12-03 05:07:42 +00:00
bool SimpleDialog : : show ( const string & title , bool wide ) {
Create ( NULL , - 1 , ToUnicode ( title ) ) ;
wxSizer * sizer2 = new wxBoxSizer ( wxVERTICAL ) ;
wxSizer * sizer = new wxFlexGridSizer ( 3 ) ;
2010-05-04 00:22:11 +00:00
vector < wxTextCtrl * > texts ;
for ( Values : : iterator it = values . begin ( ) ; it ! = values . end ( ) ; + + it ) {
2012-04-04 15:36:09 +00:00
size_t helptextpos = it - > second . find_first_of ( ' | ' ) ;
2010-05-04 00:22:11 +00:00
sizer - > Add ( new wxStaticText ( this , - 1 , ToUnicode ( it - > first ) ) , 0 , wxALL , 5 ) ;
2010-12-03 05:07:42 +00:00
wxTextCtrl * text = new wxTextCtrl ( this , - 1 , ToUnicode ( it - > second . substr ( 0 , helptextpos ) ) ) ;
if ( wide ) text - > SetMinSize ( wxSize ( ( text - > GetSize ( ) . GetWidth ( ) ) * 4 , text - > GetSize ( ) . GetHeight ( ) ) ) ; // 4 time as wide as default
2010-05-04 00:22:11 +00:00
sizer - > Add ( text , 0 , wxALL , 5 ) ;
texts . push_back ( text ) ;
2010-12-03 05:07:42 +00:00
sizer - > Add ( new wxStaticText ( this , - 1 , ToUnicode ( it - > second . substr ( helptextpos + 1 ) ) ) , 0 , wxALL , 5 ) ;
2010-05-04 00:22:11 +00:00
}
2010-12-03 05:07:42 +00:00
sizer2 - > Add ( sizer ) ;
sizer2 - > Add ( CreateButtonSizer ( wxOK | wxCANCEL ) , 0 , wxALIGN_RIGHT ) ; // enable Cancel button
SetSizerAndFit ( sizer2 ) ;
2010-05-04 00:22:11 +00:00
ShowModal ( ) ;
2010-12-03 05:07:42 +00:00
if ( m_returnCode = = wxID_CANCEL ) return false ; // don't change values if canceled
2010-05-04 00:22:11 +00:00
2010-05-04 08:15:16 +00:00
for ( unsigned int i = 0 ; i < texts . size ( ) ; + + i ) {
2011-05-23 19:50:17 +00:00
# ifdef WIN32
2011-05-23 19:23:00 +00:00
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( wxFNCONV ( texts [ i ] - > GetValue ( ) ) ) ;
values [ i ] . second = tmp_buf ;
2011-05-23 19:50:17 +00:00
# else
values [ i ] . second = texts [ i ] - > GetValue ( ) . ToAscii ( ) ;
# endif
2010-05-04 00:22:11 +00:00
}
2010-12-03 05:07:42 +00:00
return true ;
2010-05-04 00:22:11 +00:00
}
2010-06-23 22:21:08 +00:00
2010-05-04 00:22:11 +00:00
// ===============================================
// class App
// ===============================================
bool App : : OnInit ( ) {
2011-12-03 08:54:18 +00:00
SystemFlags : : VERBOSE_MODE_ENABLED = false ;
2011-05-24 01:44:48 +00:00
SystemFlags : : ENABLE_THREADED_LOGGING = false ;
2011-05-03 23:34:25 +00:00
2010-05-04 00:22:11 +00:00
string fileparam ;
if ( argc = = 2 ) {
2010-12-03 05:07:42 +00:00
if ( argv [ 1 ] [ 0 ] = = ' - ' ) { // any flag gives help and exits program.
2011-01-29 21:20:33 +00:00
std : : cout < < " MegaGlest map editor " < < mapeditorVersionString < < " [Using " < < ( const char * ) wxConvCurrent - > cWX2MB ( wxVERSION_STRING ) < < " ] " < < std : : endl < < std : : endl ;
2010-12-03 05:07:42 +00:00
std : : cout < < " glest_map_editor [GBM OR MGM FILE] " < < std : : endl < < std : : endl ;
std : : cout < < " Creates or edits glest/megaglest maps. " < < std : : endl ;
std : : cout < < " Draw with left mouse button (select what and how large area in menu or toolbar) " < < std : : endl ;
std : : cout < < " Pan trough the map with right mouse button " < < std : : endl ;
std : : cout < < " Zoom with middle mouse button or mousewheel " < < std : : endl ;
2011-01-29 21:20:33 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << " ~ more helps should be written here ~" << std::endl;
std : : cout < < std : : endl ;
exit ( 0 ) ;
}
2010-12-08 16:31:08 +00:00
2011-05-23 19:23:00 +00:00
//#if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( argv [ 1 ] ) ;
2010-12-08 16:31:08 +00:00
fileparam = tmp_buf ;
2011-05-23 19:23:00 +00:00
# ifdef WIN32
std : : auto_ptr < wchar_t > wstr ( Ansi2WideString ( fileparam . c_str ( ) ) ) ;
fileparam = utf8_encode ( wstr . get ( ) ) ;
2010-12-08 16:31:08 +00:00
# endif
2011-05-23 19:23:00 +00:00
//#else
// fileparam = wxFNCONV(argv[1]);
//#endif
2010-05-04 00:22:11 +00:00
}
2011-04-05 04:49:48 +00:00
wxString exe_path = wxStandardPaths : : Get ( ) . GetExecutablePath ( ) ;
//wxString path_separator = wxFileName::GetPathSeparator();
//exe_path = exe_path.BeforeLast(path_separator[0]);
//exe_path += path_separator;
2013-05-26 06:03:32 +00:00
string appPath ;
2011-05-23 19:23:00 +00:00
//#if defined(__MINGW32__)
# ifdef WIN32
2011-05-23 19:50:17 +00:00
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( wxFNCONV ( exe_path ) ) ;
appPath = tmp_buf ;
std : : auto_ptr < wchar_t > wstr ( Ansi2WideString ( appPath . c_str ( ) ) ) ;
appPath = utf8_encode ( wstr . get ( ) ) ;
# else
appPath = wxFNCONV ( exe_path ) ;
2011-04-05 04:49:48 +00:00
# endif
2011-05-23 19:23:00 +00:00
//#else
// const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path));
// appPath = tmp_buf;
//#endif
2011-04-05 04:49:48 +00:00
mainWindow = new MainWindow ( appPath ) ;
2010-05-04 00:22:11 +00:00
mainWindow - > Show ( ) ;
mainWindow - > init ( fileparam ) ;
2010-05-04 08:15:16 +00:00
mainWindow - > Update ( ) ;
2010-12-03 05:07:42 +00:00
2010-05-04 08:15:16 +00:00
# ifdef WIN32
wxPoint pos = mainWindow - > GetScreenPosition ( ) ;
wxSize size = mainWindow - > GetSize ( ) ;
2013-06-04 07:21:01 +00:00
mainWindow - > SetSize ( pos . x , pos . y , 1 , 1 , wxSIZE_FORCE ) ;
//mainWindow->Update();
2010-05-04 08:15:16 +00:00
mainWindow - > SetSize ( pos . x , pos . y , size . x - 1 , size . y , wxSIZE_FORCE ) ;
mainWindow - > Update ( ) ;
# endif
2010-05-04 00:22:11 +00:00
return true ;
}
int App : : MainLoop ( ) {
try {
2012-04-14 21:21:09 +00:00
//throw megaglest_runtime_error("test");
2010-05-04 00:22:11 +00:00
return wxApp : : MainLoop ( ) ;
2010-12-03 05:07:42 +00:00
}
2010-06-23 22:21:08 +00:00
catch ( const exception & e ) {
MsgDialog ( NULL , ToUnicode ( e . what ( ) ) , wxT ( " Exception " ) ) . ShowModal ( ) ;
2010-05-04 00:22:11 +00:00
}
return 0 ;
}
int App : : OnExit ( ) {
2011-05-24 01:44:48 +00:00
SystemFlags : : Close ( ) ;
SystemFlags : : SHUTDOWN_PROGRAM_MODE = true ;
2010-05-04 00:22:11 +00:00
return 0 ;
}
2010-07-18 05:09:30 +00:00
MsgDialog : : MsgDialog ( wxWindow * parent ,
const wxString & message ,
const wxString & caption ,
long style ,
2010-06-23 22:21:08 +00:00
const wxPoint & pos ) {
2010-12-03 05:07:42 +00:00
2010-07-18 05:09:30 +00:00
m_sizerText = NULL ;
if ( ! wxDialog : : Create ( parent , wxID_ANY , caption ,
2010-12-03 05:07:42 +00:00
pos , wxDefaultSize ,
2010-07-18 05:09:30 +00:00
style ) ) {
return ;
}
m_sizerText = new wxBoxSizer ( wxVERTICAL ) ;
wxStaticText * label = new wxStaticText ( this , wxID_ANY , message ) ;
wxFont font ( * wxNORMAL_FONT ) ;
font . SetPointSize ( font . GetPointSize ( ) ) ;
font . SetWeight ( wxFONTWEIGHT_NORMAL ) ;
label - > SetFont ( font ) ;
m_sizerText - > Add ( label , wxSizerFlags ( ) . Centre ( ) . Border ( ) ) ;
wxSizer * sizerIconAndText = new wxBoxSizer ( wxHORIZONTAL ) ;
sizerIconAndText - > Add ( m_sizerText , wxSizerFlags ( 1 ) . Expand ( ) ) ;
wxSizer * sizerTop = new wxBoxSizer ( wxVERTICAL ) ;
sizerTop - > Add ( sizerIconAndText , wxSizerFlags ( 1 ) . Expand ( ) . Border ( ) ) ;
wxSizer * sizerBtns = CreateButtonSizer ( wxOK ) ;
if ( sizerBtns )
{
sizerTop - > Add ( sizerBtns , wxSizerFlags ( ) . Expand ( ) . Border ( ) ) ;
}
SetSizerAndFit ( sizerTop ) ;
CentreOnScreen ( ) ;
2010-06-23 22:21:08 +00:00
}
MsgDialog : : ~ MsgDialog ( ) {
}
2010-05-04 00:22:11 +00:00
} // end namespace
IMPLEMENT_APP ( MapEditor : : App )