2010-03-12 08:42:55 +01:00
// ==============================================================
// ==============================================================
// This file is part of Glest (www.glest.org)
//
2011-12-14 08:40:48 +01:00
// Copyright (C) 2001-2008 Martiño Figueroa
2010-03-12 08:42:55 +01: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 "gui.h"
# include <cassert>
# include <algorithm>
# include "world.h"
# include "renderer.h"
# include "game.h"
# include "upgrade.h"
# include "unit.h"
# include "metrics.h"
# include "display.h"
# include "platform_util.h"
# include "sound_renderer.h"
# include "util.h"
# include "faction.h"
# include "leak_dumper.h"
2010-03-18 22:26:40 +01:00
# include "network_types.h"
# include "network_manager.h"
2010-03-12 08:42:55 +01:00
using namespace Shared : : Graphics ;
using namespace Shared : : Util ;
namespace Glest { namespace Game {
// =====================================================
// class Mouse3d
// =====================================================
const float Mouse3d : : fadeSpeed = 1.f / 50.f ;
2010-04-18 21:28:52 +02:00
static const int queueCommandKey = vkShift ;
2010-03-12 08:42:55 +01:00
Mouse3d : : Mouse3d ( ) {
enabled = false ;
rot = 0 ;
fade = 0.f ;
}
void Mouse3d : : enable ( ) {
enabled = true ;
fade = 0.f ;
}
void Mouse3d : : update ( ) {
if ( enabled ) {
rot = ( rot + 3 ) % 360 ;
fade + = fadeSpeed ;
if ( fade > 1.f ) fade = 1.f ;
}
}
// ===============================
// class SelectionQuad
// ===============================
SelectionQuad : : SelectionQuad ( ) {
enabled = false ;
posDown = Vec2i ( 0 ) ;
posUp = Vec2i ( 0 ) ;
}
void SelectionQuad : : setPosDown ( const Vec2i & posDown ) {
enabled = true ;
this - > posDown = posDown ;
this - > posUp = posDown ;
}
void SelectionQuad : : setPosUp ( const Vec2i & posUp ) {
this - > posUp = posUp ;
}
void SelectionQuad : : disable ( ) {
enabled = false ;
}
// =====================================================
// class Gui
// =====================================================
//constructor
Gui : : Gui ( ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] START \n " , __FILE__ , __FUNCTION__ ) ;
2010-03-12 08:42:55 +01:00
2011-06-10 18:59:19 +02:00
lastGroupRecall = - 1 ;
2010-03-12 08:42:55 +01:00
posObjWorld = Vec2i ( 54 , 14 ) ;
validPosObjWorld = false ;
activeCommandType = NULL ;
activeCommandClass = ccStop ;
selectingBuilding = false ;
2010-03-25 13:15:10 +01:00
selectedBuildingFacing = CardinalDir : : NORTH ;
2010-03-12 08:42:55 +01:00
selectingPos = false ;
selectingMeetingPoint = false ;
activePos = invalidPos ;
2011-05-01 22:19:41 +02:00
lastPosDisplay = invalidPos ;
2010-09-10 14:15:21 +02:00
lastQuadCalcFrame = 0 ;
selectionCalculationFrameSkip = 10 ;
minQuadSize = 20 ;
2012-04-04 02:30:16 +02:00
selectedResourceObjectPos = Vec2i ( - 1 , - 1 ) ;
highlightedResourceObjectPos = Vec2i ( - 1 , - 1 ) ;
2012-04-05 00:57:32 +02:00
highlightedUnitId = - 1 ;
2011-06-09 02:59:03 +02:00
hudTexture = NULL ;
2011-09-01 01:10:43 +02:00
commander = NULL ;
world = NULL ;
game = NULL ;
gameCamera = NULL ;
console = NULL ;
choosenBuildingType = NULL ;
2010-03-12 08:42:55 +01:00
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] END \n " , __FILE__ , __FUNCTION__ ) ;
2010-03-12 08:42:55 +01:00
}
2014-01-27 23:15:05 +01:00
void Gui : : init ( Game * game ) {
this - > commander = game - > getCommander ( ) ;
this - > gameCamera = game - > getGameCameraPtr ( ) ;
this - > console = game - > getConsole ( ) ;
this - > world = game - > getWorld ( ) ;
this - > game = game ;
selection . init ( this ,
world - > getThisFactionIndex ( ) ,
world - > getThisTeamIndex ( ) ,
2014-01-28 03:55:08 +01:00
game - > isFlagType1BitEnabled ( ft1_allow_shared_team_units ) ) ;
2010-03-12 08:42:55 +01:00
}
void Gui : : end ( ) {
selection . clear ( ) ;
2011-06-09 02:59:03 +02:00
if ( hudTexture ! = NULL ) {
Renderer : : getInstance ( ) . endTexture ( rsGlobal , hudTexture , false ) ;
}
hudTexture = NULL ;
2010-03-12 08:42:55 +01:00
}
// ==================== get ====================
const UnitType * Gui : : getBuilding ( ) const {
assert ( selectingBuilding ) ;
return choosenBuildingType ;
}
2012-04-04 02:30:16 +02:00
const Object * Gui : : getSelectedResourceObject ( ) const {
if ( selectedResourceObjectPos . x = = - 1 ) {
return NULL ;
}
else {
return world - > getMap ( ) - > getSurfaceCell ( selectedResourceObjectPos ) - > getObject ( ) ;
}
}
Object * Gui : : getHighlightedResourceObject ( ) const {
if ( highlightedResourceObjectPos . x = = - 1 ) {
return NULL ;
}
else {
return world - > getMap ( ) - > getSurfaceCell ( highlightedResourceObjectPos ) - > getObject ( ) ;
}
}
2010-03-12 08:42:55 +01:00
2012-04-05 00:57:32 +02:00
Unit * Gui : : getHighlightedUnit ( ) const {
if ( highlightedUnitId = = - 1 ) {
return NULL ;
}
else {
return world - > findUnitById ( highlightedUnitId ) ;
}
}
2010-03-12 08:42:55 +01:00
// ==================== is ====================
bool Gui : : isPlacingBuilding ( ) const {
return isSelectingPos ( ) & & activeCommandType ! = NULL & & activeCommandType - > getClass ( ) = = ccBuild ;
}
// ==================== set ====================
void Gui : : invalidatePosObjWorld ( ) {
validPosObjWorld = false ;
}
// ==================== reset state ====================
void Gui : : resetState ( ) {
selectingBuilding = false ;
2010-03-25 13:15:10 +01:00
selectedBuildingFacing = CardinalDir : : NORTH ;
2010-03-12 08:42:55 +01:00
selectingPos = false ;
selectingMeetingPoint = false ;
activePos = invalidPos ;
activeCommandClass = ccStop ;
activeCommandType = NULL ;
}
// ==================== events ====================
void Gui : : update ( ) {
2011-01-08 22:53:05 +01:00
2010-09-10 14:15:21 +02:00
if ( selectionQuad . isEnabled ( ) & & selectionQuad . getPosUp ( ) . dist ( selectionQuad . getPosDown ( ) ) > minQuadSize ) {
computeSelected ( false , false ) ;
}
2010-03-12 08:42:55 +01:00
mouse3d . update ( ) ;
}
void Gui : : tick ( ) {
computeDisplay ( ) ;
}
//in display coords
2011-03-28 05:54:23 +02:00
bool Gui : : mouseValid ( int x , int y ) {
2010-03-12 08:42:55 +01:00
return computePosDisplay ( x , y ) ! = invalidPos ;
}
2011-03-28 05:54:23 +02:00
void Gui : : mouseDownLeftDisplay ( int x , int y ) {
2014-01-27 23:15:05 +01:00
if ( selectingPos = = false & &
selectingMeetingPoint = = false ) {
int posDisplay = computePosDisplay ( x , y ) ;
if ( posDisplay ! = invalidPos ) {
2011-03-28 05:54:23 +02:00
if ( selection . isCommandable ( ) ) {
2014-01-27 23:15:05 +01:00
2011-03-28 05:54:23 +02:00
if ( selectingBuilding ) {
2010-03-12 08:42:55 +01:00
mouseDownDisplayUnitBuild ( posDisplay ) ;
}
2011-03-28 05:54:23 +02:00
else {
2010-03-12 08:42:55 +01:00
mouseDownDisplayUnitSkills ( posDisplay ) ;
}
}
2011-03-28 05:54:23 +02:00
else {
2010-03-12 08:42:55 +01:00
resetState ( ) ;
}
}
computeDisplay ( ) ;
}
}
2011-03-28 05:54:23 +02:00
void Gui : : mouseMoveDisplay ( int x , int y ) {
2010-03-12 08:42:55 +01:00
computeInfoString ( computePosDisplay ( x , y ) ) ;
}
2011-05-01 22:19:41 +02:00
void Gui : : mouseMoveOutsideDisplay ( ) {
computeInfoString ( invalidPos ) ;
}
2011-03-28 05:54:23 +02:00
void Gui : : mouseDownLeftGraphics ( int x , int y , bool prepared ) {
if ( selectingPos ) {
2010-03-12 08:42:55 +01:00
//give standard orders
2015-01-04 14:38:32 +01:00
Vec2i targetPos = game - > getMouseCellPos ( ) ;
2015-01-29 21:59:05 +01:00
if ( prepared | | ( game - > isValidMouseCellPos ( ) & &
world - > getMap ( ) - > isInsideSurface ( world - > getMap ( ) - > toSurfCoords ( targetPos ) ) = = true ) ) {
2011-04-28 00:35:45 +02:00
giveTwoClickOrders ( x , y , prepared ) ;
}
2010-03-12 08:42:55 +01:00
resetState ( ) ;
}
//set meeting point
2011-03-28 05:54:23 +02:00
else if ( selectingMeetingPoint ) {
if ( selection . isCommandable ( ) ) {
2015-01-04 14:38:32 +01:00
Vec2i targetPos = game - > getMouseCellPos ( ) ;
2015-01-29 21:59:05 +01:00
if ( prepared | | ( game - > isValidMouseCellPos ( ) & &
world - > getMap ( ) - > isInsideSurface ( world - > getMap ( ) - > toSurfCoords ( targetPos ) ) = = true ) ) {
2010-03-12 08:42:55 +01:00
commander - > trySetMeetingPoint ( selection . getFrontUnit ( ) , targetPos ) ;
}
}
resetState ( ) ;
}
2011-03-28 05:54:23 +02:00
else {
2010-03-12 08:42:55 +01:00
selectionQuad . setPosDown ( Vec2i ( x , y ) ) ;
2010-09-10 14:15:21 +02:00
computeSelected ( false , false ) ;
2010-03-12 08:42:55 +01:00
}
computeDisplay ( ) ;
}
2011-03-28 05:54:23 +02:00
void Gui : : mouseDownRightGraphics ( int x , int y , bool prepared ) {
if ( selectingPos | | selectingMeetingPoint ) {
2010-03-12 08:42:55 +01:00
resetState ( ) ;
}
2011-03-28 05:54:23 +02:00
else if ( selection . isCommandable ( ) ) {
if ( prepared ) {
2015-01-04 14:38:32 +01:00
Vec2i targetPos = game - > getMouseCellPos ( ) ;
2015-01-29 21:59:05 +01:00
if ( prepared | | ( game - > isValidMouseCellPos ( ) & &
world - > getMap ( ) - > isInsideSurface ( world - > getMap ( ) - > toSurfCoords ( targetPos ) ) = = true ) ) {
2011-04-28 00:35:45 +02:00
givePreparedDefaultOrders ( x , y ) ;
}
2010-12-18 18:18:36 +01:00
}
2011-03-28 05:54:23 +02:00
else {
2015-01-04 14:38:32 +01:00
Vec2i targetPos = game - > getMouseCellPos ( ) ;
2015-01-29 21:59:05 +01:00
if ( prepared | | ( game - > isValidMouseCellPos ( ) & &
world - > getMap ( ) - > isInsideSurface ( world - > getMap ( ) - > toSurfCoords ( targetPos ) ) = = true ) ) {
2011-04-28 00:35:45 +02:00
giveDefaultOrders ( x , y ) ;
}
2010-12-18 18:18:36 +01:00
}
2010-03-12 08:42:55 +01:00
}
computeDisplay ( ) ;
}
2011-03-28 05:54:23 +02:00
void Gui : : mouseUpLeftGraphics ( int x , int y ) {
if ( ! selectingPos & & ! selectingMeetingPoint ) {
2010-03-12 08:42:55 +01:00
if ( selectionQuad . isEnabled ( ) ) {
selectionQuad . setPosUp ( Vec2i ( x , y ) ) ;
2011-04-28 00:35:45 +02:00
if ( selectionQuad . getPosUp ( ) . dist ( selectionQuad . getPosDown ( ) ) > minQuadSize ) {
2010-09-10 14:15:21 +02:00
computeSelected ( false , true ) ;
}
2011-01-09 21:52:00 +01:00
if ( selection . isCommandable ( ) & & random . randRange ( 0 , 1 ) = = 0 ) {
2010-03-12 08:42:55 +01:00
SoundRenderer : : getInstance ( ) . playFx (
selection . getFrontUnit ( ) - > getType ( ) - > getSelectionSound ( ) ,
2014-11-25 23:40:47 +01:00
selection . getFrontUnit ( ) - > getCurrMidHeightVector ( ) ,
2010-03-12 08:42:55 +01:00
gameCamera - > getPos ( ) ) ;
}
selectionQuad . disable ( ) ;
}
}
}
2011-03-28 05:54:23 +02:00
void Gui : : mouseMoveGraphics ( int x , int y ) {
2010-03-12 08:42:55 +01:00
//compute selection
if ( selectionQuad . isEnabled ( ) ) {
selectionQuad . setPosUp ( Vec2i ( x , y ) ) ;
2010-09-10 14:15:21 +02:00
computeSelected ( false , false ) ;
2010-03-12 08:42:55 +01:00
}
//compute position for building
if ( isPlacingBuilding ( ) ) {
2015-01-04 14:38:32 +01:00
posObjWorld = game - > getMouseCellPos ( ) ;
validPosObjWorld = game - > isValidMouseCellPos ( ) ;
2010-03-12 08:42:55 +01:00
}
display . setInfoText ( " " ) ;
}
void Gui : : mouseDoubleClickLeftGraphics ( int x , int y ) {
if ( ! selectingPos & & ! selectingMeetingPoint ) {
selectionQuad . setPosDown ( Vec2i ( x , y ) ) ;
2010-09-10 14:15:21 +02:00
computeSelected ( true , true ) ;
2010-03-12 08:42:55 +01:00
computeDisplay ( ) ;
}
}
2011-03-28 05:54:23 +02:00
void Gui : : groupKey ( int groupIndex ) {
2010-03-12 08:42:55 +01:00
if ( isKeyDown ( vkControl ) ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] groupIndex = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , groupIndex ) ;
2015-11-03 01:58:19 +01:00
bool allAssigned = true ;
bool clearGroup = ! isKeyDown ( vkShift ) ;
// if(!clearGroup){
// Unit* unit=selection.getFrontUnit();
// if(unit!=null && unit->getType()->getMultiSelect()==false){
// return;
// }
// }
allAssigned = selection . assignGroup ( groupIndex , clearGroup ) ;
if ( ! allAssigned ) {
console - > addStdMessage ( " GroupAssignFailed " ) ;
}
2010-03-12 08:42:55 +01:00
}
else {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] groupIndex = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , groupIndex ) ;
2010-04-06 16:25:00 +02:00
2013-12-25 07:27:44 +01:00
int recallGroupCenterCameraTimeout = Config : : getInstance ( ) . getInt ( " RecallGroupCenterCameraTimeoutMilliseconds " , " 1500 " ) ;
2011-06-10 18:59:19 +02:00
if ( lastGroupRecall = = groupIndex & &
lastGroupRecallTime . getMillis ( ) > 0 & &
lastGroupRecallTime . getMillis ( ) < = recallGroupCenterCameraTimeout ) {
2013-12-25 07:27:44 +01:00
2015-06-10 00:42:03 +02:00
selection . recallGroup ( groupIndex , ! isKeyDown ( vkShift ) ) ;
2011-06-10 00:37:37 +02:00
centerCameraOnSelection ( ) ;
}
else {
2015-06-10 00:42:03 +02:00
selection . recallGroup ( groupIndex , ! isKeyDown ( vkShift ) ) ;
2011-06-10 00:37:37 +02:00
}
2013-12-25 07:27:44 +01:00
2011-06-10 00:37:37 +02:00
lastGroupRecallTime . start ( ) ;
2011-06-10 18:59:19 +02:00
lastGroupRecall = groupIndex ;
2010-03-12 08:42:55 +01:00
}
}
2011-06-26 03:55:08 +02:00
void Gui : : hotKey ( SDL_KeyboardEvent key ) {
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] key = [%c][%d] \n " , __FILE__ , __FUNCTION__ , key , key ) ;
2010-03-12 08:42:55 +01:00
2010-06-12 20:27:39 +02:00
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2011-06-26 03:55:08 +02:00
//if(key == configKeys.getCharKey("HotKeyCenterCameraOnSelection")) {
if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeyCenterCameraOnSelection " ) , key ) = = true ) {
2010-03-12 08:42:55 +01:00
centerCameraOnSelection ( ) ;
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("HotKeySelectIdleHarvesterUnit")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeySelectIdleHarvesterUnit " ) , key ) = = true ) {
2010-03-12 08:42:55 +01:00
selectInterestingUnit ( iutIdleHarvester ) ;
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("HotKeySelectBuiltBuilding")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeySelectBuiltBuilding " ) , key ) = = true ) {
2010-03-12 08:42:55 +01:00
selectInterestingUnit ( iutBuiltBuilding ) ;
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("HotKeyDumpWorldToLog")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeyDumpWorldToLog " ) , key ) = = true ) {
2010-05-18 05:53:57 +02:00
std : : string worldLog = world - > DumpWorldToLog ( ) ;
2011-03-28 05:54:23 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] worldLog dumped to [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , worldLog . c_str ( ) ) ;
2010-05-18 05:53:57 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("HotKeyRotateUnitDuringPlacement")){
else if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeyRotateUnitDuringPlacement " ) , key ) = = true ) {
2010-03-18 22:26:40 +01:00
// Here the user triggers a unit rotation while placing a unit
2010-06-17 02:08:27 +02:00
if ( isPlacingBuilding ( ) ) {
2010-03-27 04:09:11 +01:00
if ( getBuilding ( ) - > getRotationAllowed ( ) ) {
+ + selectedBuildingFacing ;
}
2010-03-12 08:42:55 +01:00
}
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("HotKeySelectDamagedUnit")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeySelectDamagedUnit " ) , key ) = = true ) {
2010-03-12 08:42:55 +01:00
selectInterestingUnit ( iutDamaged ) ;
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("HotKeySelectStoreUnit")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeySelectStoreUnit " ) , key ) = = true ) {
2010-03-12 08:42:55 +01:00
selectInterestingUnit ( iutStore ) ;
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("HotKeySelectedUnitsAttack")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeySelectedUnitsAttack " ) , key ) = = true ) {
2010-03-12 08:42:55 +01:00
clickCommonCommand ( ccAttack ) ;
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("HotKeySelectedUnitsStop")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeySelectedUnitsStop " ) , key ) = = true ) {
2010-03-12 08:42:55 +01:00
clickCommonCommand ( ccStop ) ;
}
}
2010-04-08 22:19:25 +02:00
void Gui : : switchToNextDisplayColor ( ) {
display . switchColor ( ) ;
}
2010-03-12 08:42:55 +01:00
void Gui : : onSelectionChanged ( ) {
resetState ( ) ;
computeDisplay ( ) ;
}
// ================= PRIVATE =================
void Gui : : giveOneClickOrders ( ) {
2011-07-05 06:37:35 +02:00
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2012-11-10 20:39:55 +01:00
std : : pair < CommandResult , string > result ( crFailUndefined , " " ) ;
2010-04-18 21:28:52 +02:00
bool queueKeyDown = isKeyDown ( queueCommandKey ) ;
2010-03-12 08:42:55 +01:00
if ( selection . isUniform ( ) ) {
2010-04-18 21:28:52 +02:00
result = commander - > tryGiveCommand ( & selection , activeCommandType , Vec2i ( 0 ) , ( Unit * ) NULL , queueKeyDown ) ;
2010-03-12 08:42:55 +01:00
}
else {
2010-04-18 21:28:52 +02:00
result = commander - > tryGiveCommand ( & selection , activeCommandClass , Vec2i ( 0 ) , ( Unit * ) NULL , queueKeyDown ) ;
2010-03-12 08:42:55 +01:00
}
addOrdersResultToConsole ( activeCommandClass , result ) ;
activeCommandType = NULL ;
activeCommandClass = ccStop ;
}
2011-01-08 22:53:05 +01:00
void Gui : : giveDefaultOrders ( int x , int y ) {
2010-03-12 08:42:55 +01:00
//compute target
2013-01-23 22:03:00 +01:00
//printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-03-12 08:42:55 +01:00
const Unit * targetUnit = NULL ;
Vec2i targetPos ;
2011-01-08 22:53:05 +01:00
if ( computeTarget ( Vec2i ( x , y ) , targetPos , targetUnit ) = = false ) {
2010-03-12 08:42:55 +01:00
console - > addStdMessage ( " InvalidPosition " ) ;
return ;
}
2013-02-15 19:25:10 +01:00
//printf("In [%s::%s Line: %d] targetUnit = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,targetUnit);
2010-12-20 04:12:00 +01:00
giveDefaultOrders ( targetPos . x , targetPos . y , targetUnit , true ) ;
2013-01-23 22:03:00 +01:00
//printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2010-12-18 18:18:36 +01:00
}
void Gui : : givePreparedDefaultOrders ( int x , int y ) {
2011-07-05 06:37:35 +02:00
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-12-20 04:12:00 +01:00
giveDefaultOrders ( x , y , NULL , false ) ;
2010-12-18 18:18:36 +01:00
}
2010-03-12 08:42:55 +01:00
2011-01-08 22:53:05 +01:00
void Gui : : giveDefaultOrders ( int x , int y , const Unit * targetUnit , bool paintMouse3d ) {
2011-07-05 06:37:35 +02:00
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-04-18 21:28:52 +02:00
bool queueKeyDown = isKeyDown ( queueCommandKey ) ;
2010-12-18 18:18:36 +01:00
Vec2i targetPos = Vec2i ( x , y ) ;
2013-01-23 22:03:00 +01:00
2010-03-12 08:42:55 +01:00
//give order
2013-01-23 22:03:00 +01:00
//printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
2012-11-10 20:39:55 +01:00
std : : pair < CommandResult , string > result = commander - > tryGiveCommand ( & selection , targetPos , targetUnit , queueKeyDown ) ;
2010-03-12 08:42:55 +01:00
2013-02-15 19:25:10 +01:00
//printf("In [%s::%s Line: %d] selected units = %d result.first = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,selection.getCount(),result.first);
2010-03-12 08:42:55 +01:00
//graphical result
addOrdersResultToConsole ( activeCommandClass , result ) ;
2012-11-10 20:39:55 +01:00
if ( result . first = = crSuccess | | result . first = = crSomeFailed ) {
2010-12-20 04:12:00 +01:00
if ( paintMouse3d )
mouse3d . enable ( ) ;
2010-03-12 08:42:55 +01:00
if ( random . randRange ( 0 , 1 ) = = 0 ) {
SoundRenderer : : getInstance ( ) . playFx (
selection . getFrontUnit ( ) - > getType ( ) - > getCommandSound ( ) ,
2014-11-25 23:40:47 +01:00
selection . getFrontUnit ( ) - > getCurrMidHeightVector ( ) ,
2010-03-12 08:42:55 +01:00
gameCamera - > getPos ( ) ) ;
}
}
//reset
resetState ( ) ;
}
2011-01-08 22:53:05 +01:00
void Gui : : giveTwoClickOrders ( int x , int y , bool prepared ) {
2011-07-05 06:37:35 +02:00
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2012-11-10 20:39:55 +01:00
std : : pair < CommandResult , string > result ( crFailUndefined , " " ) ;
2010-03-12 08:42:55 +01:00
//compute target
const Unit * targetUnit = NULL ;
Vec2i targetPos ;
2010-12-18 18:18:36 +01:00
if ( prepared ) {
targetPos = Vec2i ( x , y ) ;
}
2011-01-08 22:53:05 +01:00
else {
if ( computeTarget ( Vec2i ( x , y ) , targetPos , targetUnit ) = = false ) {
2010-12-18 18:18:36 +01:00
console - > addStdMessage ( " InvalidPosition " ) ;
return ;
}
2010-03-12 08:42:55 +01:00
}
2010-04-18 21:28:52 +02:00
bool queueKeyDown = isKeyDown ( queueCommandKey ) ;
2010-03-12 08:42:55 +01:00
//give orders to the units of this faction
2011-01-08 22:53:05 +01:00
if ( selectingBuilding = = false ) {
if ( selection . isUniform ( ) ) {
2010-08-28 03:46:26 +02:00
result = commander - > tryGiveCommand ( & selection , activeCommandType ,
targetPos , targetUnit , queueKeyDown ) ;
2010-03-12 08:42:55 +01:00
}
2011-01-08 22:53:05 +01:00
else {
2010-08-28 03:46:26 +02:00
result = commander - > tryGiveCommand ( & selection , activeCommandClass ,
targetPos , targetUnit , queueKeyDown ) ;
2010-04-18 09:35:48 +02:00
}
2010-03-12 08:42:55 +01:00
}
2011-01-08 22:53:05 +01:00
else {
2010-03-12 08:42:55 +01:00
//selecting building
2010-08-28 03:46:26 +02:00
result = commander - > tryGiveCommand ( & selection ,
activeCommandType , posObjWorld , choosenBuildingType ,
selectedBuildingFacing , queueKeyDown ) ;
2010-03-12 08:42:55 +01:00
}
//graphical result
addOrdersResultToConsole ( activeCommandClass , result ) ;
2012-11-10 20:39:55 +01:00
if ( result . first = = crSuccess | | result . first = = crSomeFailed ) {
2011-01-08 22:53:05 +01:00
if ( prepared = = false ) {
2010-12-20 04:12:00 +01:00
mouse3d . enable ( ) ;
}
2010-03-12 08:42:55 +01:00
2011-01-08 22:53:05 +01:00
if ( random . randRange ( 0 , 1 ) = = 0 ) {
2010-03-12 08:42:55 +01:00
SoundRenderer : : getInstance ( ) . playFx (
selection . getFrontUnit ( ) - > getType ( ) - > getCommandSound ( ) ,
2014-11-25 23:40:47 +01:00
selection . getFrontUnit ( ) - > getCurrMidHeightVector ( ) ,
2010-03-12 08:42:55 +01:00
gameCamera - > getPos ( ) ) ;
}
}
}
2011-01-08 22:53:05 +01:00
void Gui : : centerCameraOnSelection ( ) {
if ( selection . isEmpty ( ) = = false ) {
2013-10-02 22:22:10 +02:00
Vec3f refPos = selection . getRefPos ( ) ;
2010-03-12 08:42:55 +01:00
gameCamera - > centerXZ ( refPos . x , refPos . z ) ;
}
}
2011-01-08 22:53:05 +01:00
void Gui : : selectInterestingUnit ( InterestingUnitType iut ) {
2014-01-27 23:15:05 +01:00
const Faction * thisFaction = world - > getThisFaction ( ) ;
const Unit * previousUnit = NULL ;
bool previousFound = true ;
2010-03-12 08:42:55 +01:00
//start at the next harvester
2014-01-27 23:15:05 +01:00
if ( selection . getCount ( ) = = 1 ) {
2010-03-12 08:42:55 +01:00
const Unit * refUnit = selection . getFrontUnit ( ) ;
2014-01-27 23:15:05 +01:00
if ( refUnit - > isInteresting ( iut ) ) {
2010-03-12 08:42:55 +01:00
previousUnit = refUnit ;
previousFound = false ;
}
}
//clear selection
selection . clear ( ) ;
//search
2014-01-27 23:15:05 +01:00
for ( int index = 0 ; index < thisFaction - > getUnitCount ( ) ; + + index ) {
Unit * unit = thisFaction - > getUnit ( index ) ;
2010-03-12 08:42:55 +01:00
2014-01-27 23:15:05 +01:00
if ( previousFound = = true ) {
if ( unit - > isInteresting ( iut ) ) {
2010-03-12 08:42:55 +01:00
selection . select ( unit ) ;
break ;
}
}
else {
2014-01-27 23:15:05 +01:00
if ( unit = = previousUnit ) {
previousFound = true ;
2010-03-12 08:42:55 +01:00
}
}
}
//search again if we have a previous
2014-01-27 23:15:05 +01:00
if ( selection . isEmpty ( ) & & previousUnit ! = NULL & & previousFound = = true ) {
for ( int index = 0 ; index < thisFaction - > getUnitCount ( ) ; + + index ) {
Unit * unit = thisFaction - > getUnit ( index ) ;
2010-03-12 08:42:55 +01:00
2014-01-27 23:15:05 +01:00
if ( unit - > isInteresting ( iut ) ) {
2010-03-12 08:42:55 +01:00
selection . select ( unit ) ;
break ;
}
}
}
}
2014-01-27 23:15:05 +01:00
void Gui : : clickCommonCommand ( CommandClass commandClass ) {
for ( int index = 0 ; index < Display : : downCellCount ; + + index ) {
const CommandType * ct = display . getCommandType ( index ) ;
if ( ( ct ! = NULL & & ct - > getClass ( ) = = commandClass ) | |
display . getCommandClass ( index ) = = commandClass ) {
mouseDownDisplayUnitSkills ( index ) ;
2010-03-12 08:42:55 +01:00
break ;
}
}
2012-04-03 01:37:03 +02:00
computeDisplay ( ) ;
2010-03-12 08:42:55 +01:00
}
2011-01-10 07:43:47 +01:00
void Gui : : mouseDownDisplayUnitSkills ( int posDisplay ) {
2014-01-27 23:15:05 +01:00
if ( selection . isEmpty ( ) = = false ) {
2011-01-10 07:43:47 +01:00
if ( posDisplay ! = cancelPos ) {
2014-01-27 23:15:05 +01:00
if ( posDisplay ! = meetingPointPos ) {
2010-03-12 08:42:55 +01:00
const Unit * unit = selection . getFrontUnit ( ) ;
//uniform selection
2011-01-10 07:43:47 +01:00
if ( selection . isUniform ( ) ) {
const CommandType * ct = display . getCommandType ( posDisplay ) ;
2014-01-27 23:15:05 +01:00
// try to switch to next attack type
2015-09-05 22:46:15 +02:00
if ( activeCommandClass = = ccAttack & & activeCommandType ! = NULL ) {
2014-01-27 23:15:05 +01:00
int maxI = unit - > getType ( ) - > getCommandTypeCount ( ) ;
int cmdTypeId = activeCommandType - > getId ( ) ;
int cmdTypeIdNext = cmdTypeId + 1 ;
while ( cmdTypeIdNext ! = cmdTypeId ) {
if ( cmdTypeIdNext > = maxI ) {
cmdTypeIdNext = 0 ;
2013-02-23 00:31:55 +01:00
}
2014-01-27 23:15:05 +01:00
const CommandType * ctype = display . getCommandType ( cmdTypeIdNext ) ;
if ( ctype ! = NULL & & ctype - > getClass ( ) = = ccAttack ) {
2013-02-25 00:56:49 +01:00
if ( ctype ! = NULL & & unit - > getFaction ( ) - > reqsOk ( ctype ) ) {
2014-01-27 23:15:05 +01:00
posDisplay = cmdTypeIdNext ;
2013-02-25 00:56:49 +01:00
break ;
}
2013-02-23 00:31:55 +01:00
}
2014-01-27 23:15:05 +01:00
cmdTypeIdNext + + ;
2013-02-23 00:31:55 +01:00
}
}
2011-01-10 07:43:47 +01:00
if ( ct ! = NULL & & unit - > getFaction ( ) - > reqsOk ( ct ) ) {
2015-09-05 22:46:15 +02:00
activeCommandType = ct ;
2010-03-12 08:42:55 +01:00
activeCommandClass = activeCommandType - > getClass ( ) ;
}
2011-01-10 07:43:47 +01:00
else {
2010-03-12 08:42:55 +01:00
posDisplay = invalidPos ;
activeCommandType = NULL ;
activeCommandClass = ccStop ;
return ;
}
}
//non uniform selection
2011-01-10 07:43:47 +01:00
else {
2010-03-12 08:42:55 +01:00
activeCommandType = NULL ;
activeCommandClass = display . getCommandClass ( posDisplay ) ;
}
//give orders depending on command type
if ( ! selection . isEmpty ( ) ) {
const CommandType * ct = selection . getUnit ( 0 ) - > getType ( ) - > getFirstCtOfClass ( activeCommandClass ) ;
if ( activeCommandType ! = NULL & & activeCommandType - > getClass ( ) = = ccBuild ) {
assert ( selection . isUniform ( ) ) ;
selectingBuilding = true ;
}
else if ( ct - > getClicks ( ) = = cOne ) {
invalidatePosObjWorld ( ) ;
giveOneClickOrders ( ) ;
}
else {
selectingPos = true ;
activePos = posDisplay ;
}
}
}
else {
activePos = posDisplay ;
selectingMeetingPoint = true ;
}
}
else {
commander - > tryCancelCommand ( & selection ) ;
}
}
}
2014-01-27 23:15:05 +01:00
void Gui : : mouseDownDisplayUnitBuild ( int posDisplay ) {
//int factionIndex = world->getThisFactionIndex();
2010-03-12 08:42:55 +01:00
2014-01-27 23:15:05 +01:00
if ( posDisplay = = cancelPos ) {
2010-03-12 08:42:55 +01:00
resetState ( ) ;
}
2014-01-27 23:15:05 +01:00
else {
if ( activeCommandType ! = NULL & &
activeCommandType - > getClass ( ) = = ccBuild ) {
const BuildCommandType * bct = dynamic_cast < const BuildCommandType * > ( activeCommandType ) ;
if ( bct ! = NULL ) {
const UnitType * ut = bct - > getBuilding ( posDisplay ) ;
const Unit * unit = selection . getFrontUnit ( ) ;
if ( unit ! = NULL & & unit - > getFaction ( ) ! = NULL ) {
if ( selection . canSelectUnitFactionCheck ( unit ) = = true & &
unit - > getFaction ( ) - > reqsOk ( ut ) ) {
choosenBuildingType = ut ;
selectingPos = true ;
selectedBuildingFacing = CardinalDir : : NORTH ;
activePos = posDisplay ;
}
}
2010-03-12 08:42:55 +01:00
}
}
}
}
2011-05-01 22:19:41 +02:00
2011-05-06 10:44:50 +02:00
string Gui : : computeDefaultInfoString ( ) {
2011-05-01 22:19:41 +02:00
string result = " " ;
2011-05-06 10:44:50 +02:00
if ( selection . isUniform ( ) ) {
if ( selection . isObserver ( ) | | selection . isCommandable ( ) ) {
// default is the description extension
2013-06-13 10:55:48 +02:00
result = selection . getFrontUnit ( ) - > getDescExtension ( game - > showTranslatedTechTree ( ) ) ;
2011-05-06 10:44:50 +02:00
}
2011-05-01 22:19:41 +02:00
}
return result ;
}
2010-03-12 08:42:55 +01:00
void Gui : : computeInfoString ( int posDisplay ) {
Lang & lang = Lang : : getInstance ( ) ;
2011-05-01 22:19:41 +02:00
lastPosDisplay = posDisplay ;
display . setInfoText ( computeDefaultInfoString ( ) ) ;
2011-05-02 01:48:08 +02:00
if ( posDisplay ! = invalidPos & & selection . isCommandable ( ) ) {
2010-03-12 08:42:55 +01:00
if ( ! selectingBuilding ) {
if ( posDisplay = = cancelPos ) {
2013-10-29 07:13:38 +01:00
display . setInfoText ( lang . getString ( " Cancel " ) ) ;
2010-03-12 08:42:55 +01:00
}
else if ( posDisplay = = meetingPointPos ) {
2013-10-29 07:13:38 +01:00
display . setInfoText ( lang . getString ( " MeetingPoint " ) ) ;
2010-03-12 08:42:55 +01:00
}
else {
//uniform selection
if ( selection . isUniform ( ) ) {
const Unit * unit = selection . getFrontUnit ( ) ;
const CommandType * ct = display . getCommandType ( posDisplay ) ;
2011-05-01 22:19:41 +02:00
2010-03-12 08:42:55 +01:00
if ( ct ! = NULL ) {
if ( unit - > getFaction ( ) - > reqsOk ( ct ) ) {
2013-06-13 10:55:48 +02:00
display . setInfoText ( ct - > getDesc ( unit - > getTotalUpgrade ( ) , game - > showTranslatedTechTree ( ) ) ) ;
2010-03-12 08:42:55 +01:00
}
else {
2014-11-12 21:31:01 +01:00
display . setInfoText ( ct - > getReqDesc ( game - > showTranslatedTechTree ( ) ) ) ;
2010-03-12 08:42:55 +01:00
if ( ct - > getClass ( ) = = ccUpgrade ) {
2011-01-24 00:57:46 +01:00
string text = " " ;
2010-03-12 08:42:55 +01:00
const UpgradeCommandType * uct = static_cast < const UpgradeCommandType * > ( ct ) ;
if ( unit - > getFaction ( ) - > getUpgradeManager ( ) - > isUpgrading ( uct - > getProducedUpgrade ( ) ) ) {
2013-10-29 07:13:38 +01:00
text = lang . getString ( " Upgrading " ) + " \n \n " ;
2010-03-12 08:42:55 +01:00
}
else if ( unit - > getFaction ( ) - > getUpgradeManager ( ) - > isUpgraded ( uct - > getProducedUpgrade ( ) ) ) {
2013-10-29 07:13:38 +01:00
text = lang . getString ( " AlreadyUpgraded " ) + " \n \n " ;
2010-03-12 08:42:55 +01:00
}
2013-06-13 10:55:48 +02:00
display . setInfoText ( text + ct - > getReqDesc ( game - > showTranslatedTechTree ( ) ) ) ;
2010-03-12 08:42:55 +01:00
}
2014-11-12 21:31:01 +01:00
//locked by scenario
else if ( ct - > getClass ( ) = = ccProduce ) {
string text = " " ;
const ProduceCommandType * pct = static_cast < const ProduceCommandType * > ( ct ) ;
if ( unit - > getFaction ( ) - > isUnitLocked ( pct - > getProducedUnit ( ) ) ) {
display . setInfoText ( lang . getString ( " LockedByScenario " ) + " \n \n " + ct - > getReqDesc ( game - > showTranslatedTechTree ( ) ) ) ;
}
}
else if ( ct - > getClass ( ) = = ccMorph ) {
const MorphCommandType * mct = static_cast < const MorphCommandType * > ( ct ) ;
if ( unit - > getFaction ( ) - > isUnitLocked ( mct - > getMorphUnit ( ) ) ) {
display . setInfoText ( lang . getString ( " LockedByScenario " ) + " \n \n " + ct - > getReqDesc ( game - > showTranslatedTechTree ( ) ) ) ;
}
2010-03-12 08:42:55 +01:00
}
}
}
}
//non uniform selection
else {
const UnitType * ut = selection . getFrontUnit ( ) - > getType ( ) ;
CommandClass cc = display . getCommandClass ( posDisplay ) ;
if ( cc ! = ccNull ) {
2013-10-29 07:13:38 +01:00
display . setInfoText ( lang . getString ( " CommonCommand " ) + " : " + ut - > getFirstCtOfClass ( cc ) - > toString ( true ) ) ;
2010-03-12 08:42:55 +01:00
}
}
}
}
else {
if ( posDisplay = = cancelPos ) {
2013-10-29 07:13:38 +01:00
display . setInfoText ( lang . getString ( " Return " ) ) ;
2010-03-12 08:42:55 +01:00
}
else {
if ( activeCommandType ! = NULL & & activeCommandType - > getClass ( ) = = ccBuild ) {
2014-11-12 21:31:01 +01:00
//locked by scenario
2010-03-12 08:42:55 +01:00
const BuildCommandType * bct = static_cast < const BuildCommandType * > ( activeCommandType ) ;
2014-11-12 21:31:01 +01:00
const Unit * unit = selection . getFrontUnit ( ) ;
if ( unit - > getFaction ( ) - > isUnitLocked ( bct - > getBuilding ( posDisplay ) ) ) {
display . setInfoText ( lang . getString ( " LockedByScenario " ) + " \n \n " + bct - > getBuilding ( posDisplay ) - > getReqDesc ( game - > showTranslatedTechTree ( ) ) ) ;
} else {
display . setInfoText ( bct - > getBuilding ( posDisplay ) - > getReqDesc ( game - > showTranslatedTechTree ( ) ) ) ;
}
2010-03-12 08:42:55 +01:00
}
}
}
}
}
2011-02-13 22:04:30 +01:00
void Gui : : computeDisplay ( ) {
2010-10-28 20:31:12 +02:00
//printf("Start ===> computeDisplay()\n");
2011-02-13 22:04:30 +01:00
Lang & lang = Lang : : getInstance ( ) ;
2010-03-12 08:42:55 +01:00
//init
display . clear ( ) ;
2011-02-13 22:04:30 +01:00
// ================ PART 1 ================
2012-04-04 02:30:16 +02:00
const Object * selectedResourceObject = getSelectedResourceObject ( ) ;
2012-11-15 00:24:25 +01:00
if ( selection . isEmpty ( ) & & selectedResourceObject ! = NULL & & selectedResourceObject - > getResource ( ) ! = NULL ) {
2011-02-13 22:04:30 +01:00
Resource * r = selectedResourceObject - > getResource ( ) ;
2013-06-13 10:55:48 +02:00
display . setTitle ( r - > getType ( ) - > getName ( game - > showTranslatedTechTree ( ) ) ) ;
2013-10-29 07:13:38 +01:00
display . setText ( lang . getString ( " Amount " ) + " : " + intToStr ( r - > getAmount ( ) ) + " / " + intToStr ( r - > getType ( ) - > getDefResPerPatch ( ) ) ) ;
2011-02-13 22:04:30 +01:00
//display.setProgressBar(r->);
display . setUpImage ( 0 , r - > getType ( ) - > getImage ( ) ) ;
2010-03-12 08:42:55 +01:00
}
2011-10-21 18:04:21 +02:00
else {
2011-02-13 22:04:30 +01:00
//title, text and progress bar
if ( selection . getCount ( ) = = 1 ) {
2013-06-13 10:55:48 +02:00
display . setTitle ( selection . getFrontUnit ( ) - > getFullName ( game - > showTranslatedTechTree ( ) ) ) ;
display . setText ( selection . getFrontUnit ( ) - > getDesc ( game - > showTranslatedTechTree ( ) ) ) ;
2011-02-13 22:04:30 +01:00
display . setProgressBar ( selection . getFrontUnit ( ) - > getProductionPercent ( ) ) ;
}
2010-03-12 08:42:55 +01:00
2011-02-13 22:04:30 +01:00
//portraits
2015-10-25 17:14:28 +01:00
int unitIndex = 0 ;
for ( unitIndex = 0 ; unitIndex < selection . getCount ( ) ; + + unitIndex ) {
try {
const Unit * unit = selection . getUnit ( unitIndex ) ;
if ( unit = = NULL ) {
throw megaglest_runtime_error ( " unit == NULL " ) ;
}
if ( unit - > getType ( ) = = NULL ) {
throw megaglest_runtime_error ( " unit->getType() = = NULL " ) ;
}
if ( unit - > getType ( ) - > getImage ( ) = = NULL ) {
throw megaglest_runtime_error ( " unit->getType() - > getImage ( ) " ) ;
}
display . setUpImage ( unitIndex , unit - > getType ( ) - > getImage ( ) ) ;
}
catch ( exception & ex ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Error in unit selection for index: %d error [%s] " , unitIndex , ex . what ( ) ) ;
throw megaglest_runtime_error ( szBuf , true ) ;
}
2011-02-13 22:04:30 +01:00
}
2010-03-12 08:42:55 +01:00
2011-02-13 22:04:30 +01:00
// ================ PART 2 ================
2010-03-12 08:42:55 +01:00
2011-02-13 22:04:30 +01:00
if ( selectingPos | | selectingMeetingPoint ) {
//printf("selectingPos || selectingMeetingPoint\n");
display . setDownSelectedPos ( activePos ) ;
}
2010-10-28 20:31:12 +02:00
2011-10-21 18:04:21 +02:00
//printf("computeDisplay selection.isCommandable() = %d\n",selection.isCommandable());
if ( selection . isCommandable ( ) ) {
2011-02-13 22:04:30 +01:00
//printf("selection.isComandable()\n");
2010-03-12 08:42:55 +01:00
2011-02-13 22:04:30 +01:00
if ( selectingBuilding = = false ) {
2010-10-28 20:31:12 +02:00
2011-02-13 22:04:30 +01:00
//cancel button
const Unit * u = selection . getFrontUnit ( ) ;
const UnitType * ut = u - > getType ( ) ;
2011-10-21 18:04:21 +02:00
if ( selection . isCancelable ( ) ) {
2011-02-13 22:04:30 +01:00
//printf("selection.isCancelable() commandcount = %d\n",selection.getUnit(0)->getCommandSize());
if ( selection . getUnit ( 0 ) - > getCommandSize ( ) > 0 ) {
//printf("Current Command [%s]\n",selection.getUnit(0)->getCurrCommand()->toString().c_str());
}
2010-03-12 08:42:55 +01:00
2011-02-13 22:04:30 +01:00
display . setDownImage ( cancelPos , ut - > getCancelImage ( ) ) ;
display . setDownLighted ( cancelPos , true ) ;
}
2010-10-28 20:31:12 +02:00
2011-02-13 22:04:30 +01:00
//meeting point
if ( selection . isMeetable ( ) ) {
//printf("selection.isMeetable()\n");
2010-03-12 08:42:55 +01:00
2011-02-13 22:04:30 +01:00
display . setDownImage ( meetingPointPos , ut - > getMeetingPointImage ( ) ) ;
display . setDownLighted ( meetingPointPos , true ) ;
}
2010-10-28 20:31:12 +02:00
2011-10-21 18:04:21 +02:00
//printf("computeDisplay selection.isUniform() = %d\n",selection.isUniform());
if ( selection . isUniform ( ) ) {
2011-02-13 22:04:30 +01:00
//printf("selection.isUniform()\n");
//uniform selection
if ( u - > isBuilt ( ) ) {
//printf("u->isBuilt()\n");
int morphPos = 8 ;
for ( int i = 0 ; i < ut - > getCommandTypeCount ( ) ; + + i ) {
int displayPos = i ;
const CommandType * ct = ut - > getCommandType ( i ) ;
2011-10-21 18:04:21 +02:00
if ( ct - > getClass ( ) = = ccMorph ) {
2011-02-13 22:04:30 +01:00
displayPos = morphPos + + ;
}
2011-10-21 18:04:21 +02:00
//printf("computeDisplay i = %d displayPos = %d morphPos = %d ct->getClass() = %d [%s]\n",i,displayPos,morphPos,ct->getClass(),ct->getName().c_str());
2011-02-13 22:04:30 +01:00
display . setDownImage ( displayPos , ct - > getImage ( ) ) ;
display . setCommandType ( displayPos , ct ) ;
2011-10-21 18:04:21 +02:00
display . setCommandClass ( displayPos , ct - > getClass ( ) ) ;
2011-02-13 22:04:30 +01:00
display . setDownLighted ( displayPos , u - > getFaction ( ) - > reqsOk ( ct ) ) ;
2010-03-12 08:42:55 +01:00
}
}
}
2011-02-13 22:04:30 +01:00
else {
//printf("selection.isUniform() == FALSE\n");
//non uniform selection
int lastCommand = 0 ;
for ( int i = 0 ; i < ccCount ; + + i ) {
CommandClass cc = static_cast < CommandClass > ( i ) ;
2011-10-21 18:04:21 +02:00
//printf("computeDisplay i = %d cc = %d isshared = %d lastCommand = %d\n",i,cc,isSharedCommandClass(cc),lastCommand);
2011-02-13 22:04:30 +01:00
if ( isSharedCommandClass ( cc ) & & cc ! = ccBuild ) {
display . setDownLighted ( lastCommand , true ) ;
display . setDownImage ( lastCommand , ut - > getFirstCtOfClass ( cc ) - > getImage ( ) ) ;
display . setCommandClass ( lastCommand , cc ) ;
lastCommand + + ;
}
2010-03-12 08:42:55 +01:00
}
}
}
2011-02-13 22:04:30 +01:00
else {
2010-03-12 08:42:55 +01:00
2011-02-13 22:04:30 +01:00
//selecting building
const Unit * unit = selection . getFrontUnit ( ) ;
if ( activeCommandType ! = NULL & & activeCommandType - > getClass ( ) = = ccBuild ) {
const BuildCommandType * bct = static_cast < const BuildCommandType * > ( activeCommandType ) ;
for ( int i = 0 ; i < bct - > getBuildingCount ( ) ; + + i ) {
display . setDownImage ( i , bct - > getBuilding ( i ) - > getImage ( ) ) ;
display . setDownLighted ( i , unit - > getFaction ( ) - > reqsOk ( bct - > getBuilding ( i ) ) ) ;
}
display . setDownImage ( cancelPos , selection . getFrontUnit ( ) - > getType ( ) - > getCancelImage ( ) ) ;
display . setDownLighted ( cancelPos , true ) ;
2010-03-12 08:42:55 +01:00
}
}
}
2011-02-13 22:04:30 +01:00
}
2011-05-01 22:19:41 +02:00
// refresh other things
2011-05-02 02:34:04 +02:00
if ( ! isSelecting ( ) & & ! isSelectingPos ( ) ) {
2011-05-02 03:22:33 +02:00
if ( ! isSelectingPos ( ) & & lastPosDisplay = = invalidPos ) {
2011-05-02 02:34:04 +02:00
computeInfoString ( lastPosDisplay ) ;
}
2011-05-02 01:48:08 +02:00
}
2011-05-01 22:19:41 +02:00
2010-03-12 08:42:55 +01:00
}
int Gui : : computePosDisplay ( int x , int y ) {
int posDisplay = display . computeDownIndex ( x , y ) ;
2011-10-21 18:04:21 +02:00
//printf("computePosDisplay x = %d y = %d posDisplay = %d Display::downCellCount = %d cc = %d ct = %p\n",x,y,posDisplay,Display::downCellCount,display.getCommandClass(posDisplay),display.getCommandType(posDisplay));
if ( posDisplay < 0 | | posDisplay > = Display : : downCellCount ) {
2010-03-12 08:42:55 +01:00
posDisplay = invalidPos ;
2011-10-21 18:04:21 +02:00
//printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
2010-03-12 08:42:55 +01:00
}
2011-10-21 18:04:21 +02:00
else if ( selection . isCommandable ( ) ) {
if ( posDisplay ! = cancelPos ) {
if ( posDisplay ! = meetingPointPos ) {
if ( selectingBuilding = = false ) {
2010-03-12 08:42:55 +01:00
//standard selection
2011-10-21 18:04:21 +02:00
if ( display . getCommandClass ( posDisplay ) = = ccNull & & display . getCommandType ( posDisplay ) = = NULL ) {
2010-03-12 08:42:55 +01:00
posDisplay = invalidPos ;
2011-10-21 18:04:21 +02:00
//printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
2010-03-12 08:42:55 +01:00
}
}
2011-10-21 18:04:21 +02:00
else {
2010-03-12 08:42:55 +01:00
//building selection
2011-10-21 18:04:21 +02:00
if ( activeCommandType ! = NULL & & activeCommandType - > getClass ( ) = = ccBuild ) {
2010-03-12 08:42:55 +01:00
const BuildCommandType * bct = static_cast < const BuildCommandType * > ( activeCommandType ) ;
2011-10-21 18:04:21 +02:00
if ( posDisplay > = bct - > getBuildingCount ( ) ) {
2010-03-12 08:42:55 +01:00
posDisplay = invalidPos ;
2011-10-21 18:04:21 +02:00
//printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
2010-03-12 08:42:55 +01:00
}
}
}
}
else {
//check meeting point
2011-10-21 18:04:21 +02:00
if ( ! selection . isMeetable ( ) ) {
2010-03-12 08:42:55 +01:00
posDisplay = invalidPos ;
2011-10-21 18:04:21 +02:00
//printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
2010-03-12 08:42:55 +01:00
}
}
}
2011-10-21 18:04:21 +02:00
else {
2010-03-12 08:42:55 +01:00
//check cancel button
2011-10-21 18:04:21 +02:00
if ( selection . isCancelable ( ) = = false ) {
2010-03-12 08:42:55 +01:00
posDisplay = invalidPos ;
2011-10-21 18:04:21 +02:00
//printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
2010-03-12 08:42:55 +01:00
}
}
}
2011-10-21 18:04:21 +02:00
else {
2010-03-12 08:42:55 +01:00
posDisplay = invalidPos ;
2011-10-21 18:04:21 +02:00
//printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
2010-03-12 08:42:55 +01:00
}
2011-10-21 18:04:21 +02:00
//printf("computePosDisplay returning = %d\n",posDisplay);
2010-03-12 08:42:55 +01:00
return posDisplay ;
}
2012-11-10 20:39:55 +01:00
void Gui : : addOrdersResultToConsole ( CommandClass cc , std : : pair < CommandResult , string > result ) {
2010-03-12 08:42:55 +01:00
2012-11-10 20:39:55 +01:00
switch ( result . first ) {
2010-03-12 08:42:55 +01:00
case crSuccess :
break ;
case crFailReqs :
switch ( cc ) {
case ccBuild :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " BuildingNoReqs " , result . second ) ;
2010-03-12 08:42:55 +01:00
break ;
case ccProduce :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " UnitNoReqs " , result . second ) ;
2010-03-12 08:42:55 +01:00
break ;
2011-04-05 23:46:02 +02:00
case ccMorph :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " MorphNoReqs " , result . second ) ;
2011-04-05 23:46:02 +02:00
break ;
2010-03-12 08:42:55 +01:00
case ccUpgrade :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " UpgradeNoReqs " , result . second ) ;
2010-03-12 08:42:55 +01:00
break ;
default :
break ;
}
break ;
case crFailRes :
switch ( cc ) {
case ccBuild :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " BuildingNoRes " , result . second ) ;
2010-03-12 08:42:55 +01:00
break ;
case ccProduce :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " UnitNoRes " , result . second ) ;
2010-03-12 08:42:55 +01:00
break ;
2011-04-05 23:46:02 +02:00
case ccMorph :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " MorphNoRes " , result . second ) ;
2011-04-05 23:46:02 +02:00
break ;
2010-03-12 08:42:55 +01:00
case ccUpgrade :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " UpgradeNoRes " , result . second ) ;
2010-03-12 08:42:55 +01:00
break ;
default :
break ;
}
break ;
case crFailUndefined :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " InvalidOrder " , result . second ) ;
2010-03-12 08:42:55 +01:00
break ;
case crSomeFailed :
2012-11-10 20:39:55 +01:00
console - > addStdMessage ( " SomeOrdersFailed " , result . second ) ;
2010-03-12 08:42:55 +01:00
break ;
}
}
bool Gui : : isSharedCommandClass ( CommandClass commandClass ) {
for ( int i = 0 ; i < selection . getCount ( ) ; + + i ) {
const Unit * unit = selection . getUnit ( i ) ;
const CommandType * ct = unit - > getType ( ) - > getFirstCtOfClass ( commandClass ) ;
if ( ct = = NULL | | ! unit - > getFaction ( ) - > reqsOk ( ct ) )
return false ;
}
return true ;
}
2010-09-10 14:15:21 +02:00
void Gui : : computeSelected ( bool doubleClick , bool force ) {
2010-03-12 08:42:55 +01:00
Selection : : UnitContainer units ;
2010-09-10 14:15:21 +02:00
if ( force | | ( lastQuadCalcFrame + selectionCalculationFrameSkip < game - > getTotalRenderFps ( ) ) ) {
lastQuadCalcFrame = game - > getTotalRenderFps ( ) ;
2012-04-04 02:30:16 +02:00
const Object * selectedResourceObject = NULL ;
selectedResourceObjectPos = Vec2i ( - 1 , - 1 ) ;
2010-09-10 14:15:21 +02:00
if ( selectionQuad . isEnabled ( ) & & selectionQuad . getPosUp ( ) . dist ( selectionQuad . getPosDown ( ) ) < minQuadSize ) {
2013-01-22 05:30:06 +01:00
//Renderer::getInstance().computeSelected(units, selectedResourceObject, true, selectionQuad.getPosDown(), selectionQuad.getPosDown());
2011-02-13 22:04:30 +01:00
Renderer : : getInstance ( ) . computeSelected ( units , selectedResourceObject , true , selectionQuad . getPosDown ( ) , selectionQuad . getPosDown ( ) ) ;
2012-04-04 02:30:16 +02:00
if ( selectedResourceObject ! = NULL ) {
selectedResourceObjectPos = Map : : toSurfCoords ( selectedResourceObject - > getMapPos ( ) ) ;
}
2010-09-10 14:15:21 +02:00
}
else {
2011-02-15 01:24:31 +01:00
Renderer : : getInstance ( ) . computeSelected ( units , selectedResourceObject , false , selectionQuad . getPosDown ( ) , selectionQuad . getPosUp ( ) ) ;
2010-09-10 14:15:21 +02:00
}
selectingBuilding = false ;
activeCommandType = NULL ;
2011-01-08 22:53:05 +01:00
2010-09-10 14:15:21 +02:00
//select all units of the same type if double click
2011-09-01 01:10:43 +02:00
if ( doubleClick & & units . empty ( ) = = false ) {
2011-03-08 21:19:19 +01:00
const Unit * refUnit = getRelevantObjectFromSelection ( & units ) ;
2010-09-10 14:15:21 +02:00
int factionIndex = refUnit - > getFactionIndex ( ) ;
for ( int i = 0 ; i < world - > getFaction ( factionIndex ) - > getUnitCount ( ) ; + + i ) {
Unit * unit = world - > getFaction ( factionIndex ) - > getUnit ( i ) ;
2013-02-04 09:30:43 +01:00
if ( unit - > getPos ( ) . dist ( refUnit - > getPosNotThreadSafe ( ) ) < doubleClickSelectionRadius & &
2010-09-10 14:15:21 +02:00
unit - > getType ( ) = = refUnit - > getType ( ) )
{
units . push_back ( unit ) ;
}
2010-03-12 08:42:55 +01:00
}
}
2011-01-08 22:53:05 +01:00
2010-09-10 14:15:21 +02:00
bool shiftDown = isKeyDown ( vkShift ) ;
bool controlDown = isKeyDown ( vkControl ) ;
2011-01-08 22:53:05 +01:00
2010-09-10 14:15:21 +02:00
if ( ! shiftDown & & ! controlDown ) {
2011-04-11 02:11:52 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.clear()\n",__FILE__,__FUNCTION__,__LINE__);
2010-09-10 14:15:21 +02:00
selection . clear ( ) ;
}
2011-01-08 22:53:05 +01:00
2010-09-10 14:15:21 +02:00
if ( ! controlDown ) {
2011-04-11 02:11:52 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.select(units)\n",__FILE__,__FUNCTION__,__LINE__);
2010-09-10 14:15:21 +02:00
selection . select ( units ) ;
2011-02-13 22:04:30 +01:00
if ( ! selection . isEmpty ( ) ) {
selectedResourceObject = NULL ;
}
2010-09-10 14:15:21 +02:00
}
else {
2011-04-11 02:11:52 +02:00
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] selection.unSelect(units)\n",__FILE__,__FUNCTION__,__LINE__);
2010-09-10 14:15:21 +02:00
selection . unSelect ( units ) ;
}
2010-03-12 08:42:55 +01:00
}
}
2011-03-29 23:44:36 +02:00
bool Gui : : computeTarget ( const Vec2i & screenPos , Vec2i & targetPos , const Unit * & targetUnit ) {
2010-03-12 08:42:55 +01:00
Selection : : UnitContainer uc ;
Renderer & renderer = Renderer : : getInstance ( ) ;
2011-03-29 23:44:36 +02:00
const Object * obj = NULL ;
2011-02-13 15:35:17 +01:00
renderer . computeSelected ( uc , obj , true , screenPos , screenPos ) ;
2010-03-12 08:42:55 +01:00
validPosObjWorld = false ;
2011-03-29 23:44:36 +02:00
if ( uc . empty ( ) = = false ) {
targetUnit = getRelevantObjectFromSelection ( & uc ) ;
2013-02-04 09:30:43 +01:00
targetPos = targetUnit - > getPosNotThreadSafe ( ) ;
2012-04-05 00:57:32 +02:00
highlightedUnitId = targetUnit - > getId ( ) ;
getHighlightedUnit ( ) - > resetHighlight ( ) ;
2010-03-12 08:42:55 +01:00
return true ;
}
2011-03-29 23:44:36 +02:00
else if ( obj ! = NULL ) {
2011-02-13 15:35:17 +01:00
targetUnit = NULL ;
2012-04-04 02:30:16 +02:00
highlightedResourceObjectPos = Map : : toSurfCoords ( obj - > getMapPos ( ) ) ;
2011-03-29 23:44:36 +02:00
2013-01-25 00:10:25 +01:00
Object * selObj = getHighlightedResourceObject ( ) ;
if ( selObj ! = NULL ) {
selObj - > resetHighlight ( ) ;
// get real click pos
2015-01-04 14:38:32 +01:00
targetPos = game - > getMouseCellPos ( ) ;
2013-01-25 00:10:25 +01:00
//validPosObjWorld= true;
//posObjWorld = targetPos;
2011-03-29 23:44:36 +02:00
2013-01-25 00:10:25 +01:00
int tx = targetPos . x ;
int ty = targetPos . y ;
2011-03-29 23:44:36 +02:00
2013-01-25 00:10:25 +01:00
int ox = obj - > getMapPos ( ) . x ;
int oy = obj - > getMapPos ( ) . y ;
2011-03-29 23:44:36 +02:00
2013-01-25 00:10:25 +01:00
Resource * clickedRecource = world - > getMap ( ) - > getSurfaceCell ( Map : : toSurfCoords ( obj - > getMapPos ( ) ) ) - > getResource ( ) ;
2011-03-29 23:44:36 +02:00
2013-01-25 00:10:25 +01:00
// lets see if the click had the same Resource
if ( clickedRecource = = world - > getMap ( ) - > getSurfaceCell ( Map : : toSurfCoords ( targetPos ) ) - > getResource ( ) ) {
// same ressource is meant, so use the user selected position
2011-03-29 23:44:36 +02:00
return true ;
}
2013-01-25 00:10:25 +01:00
else { // calculate a valid resource position which is as near as possible to the selected position
Vec2i testIt = Vec2i ( obj - > getMapPos ( ) ) ;
///////////////
// test both //
///////////////
if ( ty < oy ) {
testIt . y - - ;
}
else if ( ty > oy ) {
testIt . y + + ;
}
if ( tx < ox ) {
testIt . x - - ;
}
else if ( tx > ox ) {
testIt . x + + ;
}
2011-03-29 23:44:36 +02:00
2013-01-25 00:10:25 +01:00
if ( clickedRecource = = world - > getMap ( ) - > getSurfaceCell ( Map : : toSurfCoords ( testIt ) ) - > getResource ( ) ) {
// same ressource is meant, so use this position
targetPos = testIt ;
//posObjWorld= targetPos;
return true ;
}
else {
testIt = Vec2i ( obj - > getMapPos ( ) ) ;
}
2011-03-29 23:44:36 +02:00
2013-01-25 00:10:25 +01:00
/////////////////
// test y-only //
/////////////////
if ( ty < oy ) {
testIt . y - - ;
}
else if ( ty > oy ) {
testIt . y + + ;
}
if ( clickedRecource = = world - > getMap ( ) - > getSurfaceCell ( Map : : toSurfCoords ( testIt ) ) - > getResource ( ) ) {
// same ressource is meant, so use this position
targetPos = testIt ;
//posObjWorld= targetPos;
return true ;
}
else {
testIt = Vec2i ( obj - > getMapPos ( ) ) ;
}
/////////////////
// test x-only //
/////////////////
if ( tx < ox ) {
testIt . x - - ;
}
else if ( tx > ox ) {
testIt . x + + ;
}
if ( clickedRecource = = world - > getMap ( ) - > getSurfaceCell ( Map : : toSurfCoords ( testIt ) ) - > getResource ( ) ) {
// same ressource is meant, so use this position
targetPos = testIt ;
//posObjWorld= targetPos;
return true ;
}
2011-03-29 23:44:36 +02:00
}
2013-01-25 00:10:25 +01:00
// give up and use the object position;
targetPos = obj - > getMapPos ( ) ;
posObjWorld = targetPos ;
return true ;
}
else {
return false ;
2011-03-29 23:44:36 +02:00
}
2011-02-13 15:35:17 +01:00
}
2011-03-29 23:44:36 +02:00
else {
2010-03-12 08:42:55 +01:00
targetUnit = NULL ;
2015-01-04 14:38:32 +01:00
targetPos = game - > getMouseCellPos ( ) ;
if ( game - > isValidMouseCellPos ( ) ) {
2010-03-12 08:42:55 +01:00
validPosObjWorld = true ;
posObjWorld = targetPos ;
2012-04-04 02:30:16 +02:00
2013-01-25 00:10:25 +01:00
if ( world - > getMap ( ) - > getSurfaceCell ( Map : : toSurfCoords ( targetPos ) ) - > getResource ( ) ! = NULL ) {
2012-04-04 02:30:16 +02:00
highlightedResourceObjectPos = Map : : toSurfCoords ( targetPos ) ;
2013-01-25 00:10:25 +01:00
Object * selObj = getHighlightedResourceObject ( ) ;
if ( selObj ! = NULL ) {
selObj - > resetHighlight ( ) ;
}
2012-04-04 02:30:16 +02:00
}
2010-03-12 08:42:55 +01:00
return true ;
}
2011-03-29 23:44:36 +02:00
else {
2010-03-12 08:42:55 +01:00
return false ;
}
}
}
2011-03-08 21:19:19 +01:00
Unit * Gui : : getRelevantObjectFromSelection ( Selection : : UnitContainer * uc ) {
Unit * resultUnit = NULL ;
2013-11-19 07:14:06 +01:00
for ( int i = 0 ; i < ( int ) uc - > size ( ) ; + + i ) {
2011-03-08 21:19:19 +01:00
resultUnit = uc - > at ( i ) ;
if ( resultUnit - > getType ( ) - > hasSkillClass ( scMove ) ) { // moving units are more relevant than non moving ones
break ;
}
}
return resultUnit ;
}
2012-03-10 04:27:25 +01:00
void Gui : : saveGame ( XmlNode * rootNode ) const {
std : : map < string , string > mapTagReplacements ;
XmlNode * guiNode = rootNode - > addChild ( " Gui " ) ;
guiNode - > addAttribute ( " random " , intToStr ( random . getLastNumber ( ) ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " posObjWorld " , posObjWorld . getString ( ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " validPosObjWorld " , intToStr ( validPosObjWorld ) , mapTagReplacements ) ;
if ( choosenBuildingType ! = NULL ) {
2012-03-15 08:09:36 +01:00
const Faction * thisFaction = world - > getThisFaction ( ) ;
2013-06-13 10:55:48 +02:00
guiNode - > addAttribute ( " choosenBuildingType " , choosenBuildingType - > getName ( false ) , mapTagReplacements ) ;
2012-03-15 08:09:36 +01:00
guiNode - > addAttribute ( " choosenBuildingTypeFactionIndex " , intToStr ( thisFaction - > getIndex ( ) ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
}
if ( activeCommandType ! = NULL ) {
2013-06-13 10:55:48 +02:00
guiNode - > addAttribute ( " activeCommandType " , activeCommandType - > getName ( false ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
}
guiNode - > addAttribute ( " activeCommandClass " , intToStr ( activeCommandClass ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " activePos " , intToStr ( activePos ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " lastPosDisplay " , intToStr ( lastPosDisplay ) , mapTagReplacements ) ;
display . saveGame ( guiNode ) ;
selection . saveGame ( guiNode ) ;
guiNode - > addAttribute ( " lastQuadCalcFrame " , intToStr ( lastQuadCalcFrame ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " selectionCalculationFrameSkip " , intToStr ( selectionCalculationFrameSkip ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " minQuadSize " , intToStr ( minQuadSize ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " lastGroupRecall " , intToStr ( lastGroupRecall ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " selectingBuilding " , intToStr ( selectingBuilding ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " selectingPos " , intToStr ( selectingPos ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " selectingMeetingPoint " , intToStr ( selectingMeetingPoint ) , mapTagReplacements ) ;
guiNode - > addAttribute ( " selectedBuildingFacing " , intToStr ( selectedBuildingFacing ) , mapTagReplacements ) ;
2012-03-15 08:09:36 +01:00
}
void Gui : : loadGame ( const XmlNode * rootNode , World * world ) {
const XmlNode * guiNode = rootNode - > getChild ( " Gui " ) ;
2012-03-10 04:27:25 +01:00
2012-03-15 08:09:36 +01:00
random . setLastNumber ( guiNode - > getAttribute ( " random " ) - > getIntValue ( ) ) ;
posObjWorld = Vec2i : : strToVec2 ( guiNode - > getAttribute ( " posObjWorld " ) - > getValue ( ) ) ;
2012-04-16 22:15:57 +02:00
validPosObjWorld = guiNode - > getAttribute ( " validPosObjWorld " ) - > getIntValue ( ) ! = 0 ;
2012-03-15 08:09:36 +01:00
if ( guiNode - > hasAttribute ( " choosenBuildingType " ) = = true ) {
string unitType = guiNode - > getAttribute ( " choosenBuildingType " ) - > getValue ( ) ;
int factionIndex = guiNode - > getAttribute ( " choosenBuildingTypeFactionIndex " ) - > getIntValue ( ) ;
choosenBuildingType = world - > getFaction ( factionIndex ) - > getType ( ) - > getUnitType ( unitType ) ;
}
activePos = guiNode - > getAttribute ( " activePos " ) - > getIntValue ( ) ;
lastPosDisplay = guiNode - > getAttribute ( " lastPosDisplay " ) - > getIntValue ( ) ;
display . loadGame ( guiNode ) ;
selection . loadGame ( guiNode , world ) ;
2012-09-14 00:40:14 +02:00
// don't load this! lastQuadCalcFrame = guiNode->getAttribute("lastQuadCalcFrame")->getIntValue();
lastQuadCalcFrame = game - > getTotalRenderFps ( ) ;
2012-03-15 08:09:36 +01:00
selectionCalculationFrameSkip = guiNode - > getAttribute ( " selectionCalculationFrameSkip " ) - > getIntValue ( ) ;
minQuadSize = guiNode - > getAttribute ( " minQuadSize " ) - > getIntValue ( ) ;
lastGroupRecall = guiNode - > getAttribute ( " lastGroupRecall " ) - > getIntValue ( ) ;
2012-03-10 04:27:25 +01:00
}
2012-03-15 08:09:36 +01:00
2010-03-12 08:42:55 +01:00
} } //end namespace