Added SaveButtons.
This commit is contained in:
parent
67fd69ca64
commit
73f3a8b8cf
5 changed files with 781 additions and 574 deletions
|
@ -1,11 +1,11 @@
|
|||
// ___________ _________ _____ __
|
||||
// \_ _____/______ ____ ____ \_ ___ \____________ _/ ____\/ |_
|
||||
// | __) \_ __ \_/ __ \_/ __ \/ \ \/\_ __ \__ \\ __\\ __\
|
||||
// | \ | | \/\ ___/\ ___/\ \____| | \// __ \| | | |
|
||||
// \___ / |__| \___ >\___ >\______ /|__| (____ /__| |__|
|
||||
// \_ _____/______ ____ ____ \_ ___ \____________ _/ ____\/ |_
|
||||
// | __) \_ __ \_/ __ \_/ __ \/ \ \/\_ __ \__ \\ __\\ __\
|
||||
// | \ | | \/\ ___/\ ___/\ \____| | \// __ \| | | |
|
||||
// \___ / |__| \___ >\___ >\______ /|__| (____ /__| |__|
|
||||
// \/ \/ \/ \/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// FreeCraft - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name interface.h - The user interface header file. */
|
||||
|
@ -33,26 +33,27 @@
|
|||
|
||||
/// Button Commands
|
||||
enum _button_cmd_ {
|
||||
B_Move, /// order move
|
||||
B_Stop, /// order stop
|
||||
B_Attack, /// order attack
|
||||
B_Repair, /// order repair
|
||||
B_Harvest, /// order harvest
|
||||
B_Button, /// choose other button set
|
||||
B_Build, /// order build
|
||||
B_Train, /// order train
|
||||
B_Patrol, /// order patrol
|
||||
B_StandGround, /// order stand ground
|
||||
B_AttackGround, /// order attack ground
|
||||
B_Return, /// order return goods
|
||||
B_Demolish, /// order demolish/explode
|
||||
B_SpellCast, /// order cast spell
|
||||
B_Research, /// order reseach
|
||||
B_UpgradeTo, /// order upgrade
|
||||
B_Unload, /// order unload unit
|
||||
B_Cancel, /// cancel
|
||||
B_CancelTrain, /// cancel training
|
||||
B_CancelBuild, /// cancel building
|
||||
ButtonMove, /// order move
|
||||
ButtonStop, /// order stop
|
||||
ButtonAttack, /// order attack
|
||||
ButtonRepair, /// order repair
|
||||
ButtonHarvest, /// order harvest
|
||||
ButtonButton, /// choose other button set
|
||||
ButtonBuild, /// order build
|
||||
ButtonTrain, /// order train
|
||||
ButtonPatrol, /// order patrol
|
||||
ButtonStandGround, /// order stand ground
|
||||
ButtonAttackGround, /// order attack ground
|
||||
ButtonReturn, /// order return goods
|
||||
ButtonDemolish, /// order demolish/explode
|
||||
ButtonSpellCast, /// order cast spell
|
||||
ButtonResearch, /// order reseach
|
||||
ButtonUpgradeTo, /// order upgrade
|
||||
ButtonUnload, /// order unload unit
|
||||
ButtonCancel, /// cancel
|
||||
ButtonCancelUpgrade, /// cancel upgrade
|
||||
ButtonCancelTrain, /// cancel training
|
||||
ButtonCancelBuild, /// cancel building
|
||||
};
|
||||
|
||||
/// typedef for action of button
|
||||
|
@ -60,18 +61,18 @@ typedef struct _button_action_ ButtonAction;
|
|||
|
||||
/// Action of button
|
||||
struct _button_action_ {
|
||||
int Pos; /// button position in the grid
|
||||
int Level; /// requires button level
|
||||
int Pos; /// button position in the grid
|
||||
int Level; /// requires button level
|
||||
IconConfig Icon; /// icon to display
|
||||
enum _button_cmd_ Action; /// command on button press
|
||||
int Value; /// extra value for command
|
||||
char* ValueStr; /// keep original value string
|
||||
char* ValueStr; /// keep original value string
|
||||
/// Check if this button is allowed
|
||||
int (*Allowed)(const Unit* unit,const ButtonAction* button);
|
||||
int (*Allowed)(const Unit* unit,const ButtonAction* button);
|
||||
char* AllowStr; /// argument for allowed
|
||||
int Key; /// alternative on keyboard
|
||||
char* Hint; /// tip text
|
||||
char* UMask; /// for which units is available
|
||||
char* UnitMask; /// for which units is it available
|
||||
};
|
||||
|
||||
/// current interface state
|
||||
|
@ -138,7 +139,7 @@ enum _mouse_buttons_ {
|
|||
// FIXME: support for double click and long hold
|
||||
|
||||
/// Left+Middle button on mouse
|
||||
LeftAndMiddleButton = LeftButton|MiddleButton,
|
||||
LeftAndMiddleButton = LeftButton|MiddleButton,
|
||||
/// Left+Right button on mouse
|
||||
LeftAndRightButton = LeftButton|RightButton,
|
||||
/// Middle+Right button on mouse
|
||||
|
@ -242,9 +243,12 @@ extern void InitButtons(void);
|
|||
extern void DoneButtons(void);
|
||||
/// Make a new button
|
||||
extern int AddButton(int pos,int level,const char* IconIdent,
|
||||
enum _button_cmd_ action,const char* value,
|
||||
const void* func,const void* arg,
|
||||
int key,const char* hint,const char* umask);
|
||||
enum _button_cmd_ action,const char* value,
|
||||
const void* func,const void* arg,
|
||||
int key,const char* hint,const char* umask);
|
||||
|
||||
/// Save all buttons
|
||||
extern void SaveButtons(FILE* file);
|
||||
|
||||
/// Called if any mouse button is pressed down
|
||||
extern void HandleButtonDown(int b);
|
||||
|
@ -289,6 +293,33 @@ extern void DoButtonButtonClicked(int button);
|
|||
/// Lookup key for bottom panel buttons.
|
||||
extern int DoButtonPanelKey(int key);
|
||||
|
||||
//
|
||||
// in button_table.c
|
||||
//
|
||||
/// Check is always true
|
||||
extern int ButtonCheckTrue(const Unit* unit,const ButtonAction* button);
|
||||
/// Check is always false
|
||||
extern int ButtonCheckFalse(const Unit* unit,const ButtonAction* button);
|
||||
/// Check if allowed upgrade is ready
|
||||
extern int ButtonCheckUpgrade(const Unit* unit,const ButtonAction* button);
|
||||
/// Check if allowed unit exists
|
||||
extern int ButtonCheckUnit(const Unit* unit,const ButtonAction* button);
|
||||
/// Check if allowed units exists
|
||||
extern int ButtonCheckUnits(const Unit* unit,const ButtonAction* button);
|
||||
/// Check if have network play
|
||||
extern int ButtonCheckNetwork(const Unit* unit,const ButtonAction* button);
|
||||
/// Check if unit isn't working (train,upgrade,research)
|
||||
extern int ButtonCheckNoWork(const Unit* unit,const ButtonAction* button);
|
||||
/// Check if unit isn't researching or upgrading
|
||||
extern int ButtonCheckNoResearch(const Unit* unit,const ButtonAction* button);
|
||||
|
||||
/// Check if all requirements for an attack to are meet
|
||||
extern int ButtonCheckAttack(const Unit* unit,const ButtonAction* button);
|
||||
/// Check if all requirements for an upgrade to are meet
|
||||
extern int ButtonCheckUpgradeTo(const Unit* unit,const ButtonAction* button);
|
||||
/// Check if all requirements for a research are meet
|
||||
extern int ButtonCheckResearch(const Unit* unit,const ButtonAction* button);
|
||||
|
||||
//@}
|
||||
|
||||
#endif // !__INTERFACE_H__
|
||||
|
|
|
@ -191,6 +191,7 @@ global void SaveAll(void)
|
|||
SaveUnits(file);
|
||||
SaveUpgrades(file);
|
||||
SaveDependencies(file);
|
||||
SaveButtons(file);
|
||||
SaveTileset(file);
|
||||
SaveMap(file);
|
||||
|
||||
|
|
|
@ -54,54 +54,201 @@
|
|||
-- Defines
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/// How many different buttons are allowed
|
||||
/// How many different buttons are allowed
|
||||
#define MAX_BUTTONS 2048
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/// for unit buttons sub-menus etc.
|
||||
/// for unit buttons sub-menus etc.
|
||||
global int CurrentButtonLevel;
|
||||
|
||||
/// Display the command key in the buttons.
|
||||
/// Display the command key in the buttons.
|
||||
global char ShowCommandKey;
|
||||
|
||||
/// All buttons for units
|
||||
/// All buttons for units
|
||||
local ButtonAction *UnitButtonTable[MAX_BUTTONS];
|
||||
/// buttons in UnitButtonTable
|
||||
/// buttons in UnitButtonTable
|
||||
local int UnitButtonCount;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef laterUSE_CCL
|
||||
|
||||
/**
|
||||
** Add buttons table.
|
||||
**
|
||||
** @param button Table of buttons to add.
|
||||
*/
|
||||
local void AddButtonTable(const ButtonAction* button)
|
||||
{
|
||||
for( ;button->Pos; ++button ) {
|
||||
AddButton(button->Pos,button->Level,button->Icon.Name
|
||||
,button->Action,button->ValueStr,button->Allowed
|
||||
,button->AllowStr,button->Key,button->Hint,button->UMask);
|
||||
,button->AllowStr,button->Key,button->Hint,button->UnitMask);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
** Initialize the buttons.
|
||||
*/
|
||||
global void InitButtons(void)
|
||||
{
|
||||
UnitButtonCount = 0;
|
||||
|
||||
#ifndef laterUSE_CCL
|
||||
//
|
||||
// Add all pre-defined buttons.
|
||||
//
|
||||
AddButtonTable(AllButtons);
|
||||
// FIXME: AddButtonTable(ExtensionButtons);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
** Save all buttons.
|
||||
*/
|
||||
global void SaveButtons(FILE* file)
|
||||
{
|
||||
unsigned i;
|
||||
int n;
|
||||
char* cp;
|
||||
|
||||
fprintf(file,"\n;;; -----------------------------------------\n");
|
||||
fprintf(file,";;; MODULE: buttons $Id$\n\n");
|
||||
|
||||
for( i=0; i<UnitButtonCount; ++i ) {
|
||||
fprintf(file,"(define-button 'pos %d 'level %d 'icon '%s\n",
|
||||
UnitButtonTable[i]->Pos,
|
||||
UnitButtonTable[i]->Level,
|
||||
IdentOfIcon(UnitButtonTable[i]->Icon.Icon));
|
||||
fprintf(file," 'action ");
|
||||
switch( UnitButtonTable[i]->Action ) {
|
||||
case ButtonMove:
|
||||
fprintf(file,"'move"); break;
|
||||
case ButtonStop:
|
||||
fprintf(file,"'stop"); break;
|
||||
case ButtonAttack:
|
||||
fprintf(file,"'attack"); break;
|
||||
case ButtonRepair:
|
||||
fprintf(file,"'repair"); break;
|
||||
case ButtonHarvest:
|
||||
fprintf(file,"'harvest"); break;
|
||||
case ButtonButton:
|
||||
fprintf(file,"'button"); break;
|
||||
case ButtonBuild:
|
||||
fprintf(file,"'build"); break;
|
||||
case ButtonTrain:
|
||||
fprintf(file,"'train-unit"); break;
|
||||
case ButtonPatrol:
|
||||
fprintf(file,"'patrol"); break;
|
||||
case ButtonStandGround:
|
||||
fprintf(file,"'stand-ground"); break;
|
||||
case ButtonAttackGround:
|
||||
fprintf(file,"'attack-ground"); break;
|
||||
case ButtonReturn:
|
||||
fprintf(file,"'return-goods"); break;
|
||||
case ButtonDemolish:
|
||||
fprintf(file,"'demolish"); break;
|
||||
case ButtonSpellCast:
|
||||
fprintf(file,"'cast-spell"); break;
|
||||
case ButtonResearch:
|
||||
fprintf(file,"'research"); break;
|
||||
case ButtonUpgradeTo:
|
||||
fprintf(file,"'upgrade-to"); break;
|
||||
case ButtonUnload:
|
||||
fprintf(file,"'unload"); break;
|
||||
case ButtonCancel:
|
||||
fprintf(file,"'cancel"); break;
|
||||
case ButtonCancelUpgrade:
|
||||
fprintf(file,"'cancel-upgrade"); break;
|
||||
case ButtonCancelTrain:
|
||||
fprintf(file,"'cancel-train-unit"); break;
|
||||
case ButtonCancelBuild:
|
||||
fprintf(file,"'cancel-build"); break;
|
||||
}
|
||||
if( UnitButtonTable[i]->ValueStr ) {
|
||||
if( isdigit(UnitButtonTable[i]->ValueStr[0]) ) {
|
||||
fprintf(file," 'value %s\n",UnitButtonTable[i]->ValueStr);
|
||||
} else {
|
||||
fprintf(file," 'value '%s\n",UnitButtonTable[i]->ValueStr);
|
||||
}
|
||||
} else {
|
||||
fprintf(file,"\n");
|
||||
}
|
||||
if( UnitButtonTable[i]->Allowed ) {
|
||||
fprintf(file," 'allowed ");
|
||||
if( UnitButtonTable[i]->Allowed == ButtonCheckTrue ) {
|
||||
fprintf(file,"'check-true");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckFalse ) {
|
||||
fprintf(file,"'check-false");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckUpgrade ) {
|
||||
fprintf(file,"'check-upgrade");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckUnit ) {
|
||||
fprintf(file,"'check-unit");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckUnits ) {
|
||||
fprintf(file,"'check-units");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckNetwork ) {
|
||||
fprintf(file,"'check-network");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckNoWork ) {
|
||||
fprintf(file,"'check-no-work");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckNoResearch ) {
|
||||
fprintf(file,"'check-no-research");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckAttack ) {
|
||||
fprintf(file,"'check-attack");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckUpgradeTo ) {
|
||||
fprintf(file,"'check-upgrade-to");
|
||||
} else if( UnitButtonTable[i]->Allowed == ButtonCheckResearch ) {
|
||||
fprintf(file,"'check-research");
|
||||
} else {
|
||||
fprintf(file,"%p",UnitButtonTable[i]->Allowed);
|
||||
}
|
||||
if( UnitButtonTable[i]->AllowStr ) {
|
||||
fprintf(file," (");
|
||||
cp=alloca(strlen(UnitButtonTable[i]->AllowStr));
|
||||
strcpy(cp,UnitButtonTable[i]->AllowStr);
|
||||
cp=strtok(cp,",");
|
||||
while( cp ) {
|
||||
fprintf(file,"'%s",cp);
|
||||
cp=strtok(NULL,",");
|
||||
if( cp ) {
|
||||
fprintf(file," ");
|
||||
}
|
||||
}
|
||||
fprintf(file,")");
|
||||
}
|
||||
fprintf(file,"\n");
|
||||
}
|
||||
fprintf(file," 'key \"");
|
||||
switch( UnitButtonTable[i]->Key ) {
|
||||
case '\e':
|
||||
fprintf(file,"\\%03o",UnitButtonTable[i]->Key);
|
||||
break;
|
||||
default:
|
||||
fprintf(file,"%c",UnitButtonTable[i]->Key);
|
||||
break;
|
||||
}
|
||||
fprintf(file,"\" 'hint \"%s\"\n",UnitButtonTable[i]->Hint);
|
||||
n=fprintf(file," 'for-unit (");
|
||||
cp=alloca(strlen(UnitButtonTable[i]->UnitMask));
|
||||
strcpy(cp,UnitButtonTable[i]->UnitMask);
|
||||
cp=strtok(cp,",");
|
||||
while( cp ) {
|
||||
if( n+strlen(cp)>78 ) {
|
||||
n=fprintf(file,"\n ");
|
||||
}
|
||||
n+=fprintf(file,"'%s",cp);
|
||||
cp=strtok(NULL,",");
|
||||
if( cp ) {
|
||||
n+=fprintf(file," ");
|
||||
}
|
||||
}
|
||||
fprintf(file,"))\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -143,19 +290,19 @@ int AddButton(int pos, int level, const char *IconIdent,
|
|||
if (value) {
|
||||
ba->ValueStr = strdup(value);
|
||||
switch (action) {
|
||||
case B_SpellCast:
|
||||
case ButtonSpellCast:
|
||||
ba->Value = SpellIdByIdent(value);
|
||||
break;
|
||||
case B_Train:
|
||||
case ButtonTrain:
|
||||
ba->Value = UnitTypeIdByIdent(value);
|
||||
break;
|
||||
case B_Research:
|
||||
case ButtonResearch:
|
||||
ba->Value = UpgradeIdByIdent(value);
|
||||
break;
|
||||
case B_UpgradeTo:
|
||||
case ButtonUpgradeTo:
|
||||
ba->Value = UnitTypeIdByIdent(value);
|
||||
break;
|
||||
case B_Build:
|
||||
case ButtonBuild:
|
||||
ba->Value = UnitTypeIdByIdent(value);
|
||||
break;
|
||||
default:
|
||||
|
@ -183,7 +330,7 @@ int AddButton(int pos, int level, const char *IconIdent,
|
|||
} else {
|
||||
sprintf(buf, ",%s,", umask);
|
||||
}
|
||||
ba->UMask = strdup(buf);
|
||||
ba->UnitMask = strdup(buf);
|
||||
UnitButtonTable[UnitButtonCount++] = ba;
|
||||
|
||||
DebugCheck(ba->Icon.Icon == NoIcon);// just checks, that's why at the end
|
||||
|
@ -199,7 +346,7 @@ global void DoneButtons(void)
|
|||
DebugCheck(!UnitButtonTable[z]);
|
||||
free(UnitButtonTable[z]->ValueStr);
|
||||
free(UnitButtonTable[z]->Hint);
|
||||
free(UnitButtonTable[z]->UMask);
|
||||
free(UnitButtonTable[z]->UnitMask);
|
||||
free(UnitButtonTable[z]);
|
||||
}
|
||||
UnitButtonCount = 0;
|
||||
|
@ -245,18 +392,18 @@ global void DrawButtonPanel(void)
|
|||
if( NumSelected==1 ) {
|
||||
#ifdef NEW_ORDERS
|
||||
switch( buttons[i].Action ) {
|
||||
case B_Stop:
|
||||
case ButtonStop:
|
||||
if( Selected[0]->Orders[0].Action==UnitActionStill ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_StandGround:
|
||||
case ButtonStandGround:
|
||||
if( Selected[0]->Orders[0].Action
|
||||
==UnitActionStandGround ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_Move:
|
||||
case ButtonMove:
|
||||
if( Selected[0]->Orders[0].Action==UnitActionMove
|
||||
|| Selected[0]->Orders[0].Action
|
||||
==UnitActionBuild
|
||||
|
@ -265,25 +412,25 @@ global void DrawButtonPanel(void)
|
|||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_Harvest:
|
||||
case B_Return:
|
||||
case ButtonHarvest:
|
||||
case ButtonReturn:
|
||||
if( Selected[0]->Orders[0].Action==UnitActionMineGold
|
||||
|| Selected[0]->Orders[0].Action
|
||||
==UnitActionHarvest ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_Attack:
|
||||
case ButtonAttack:
|
||||
if( Selected[0]->Orders[0].Action==UnitActionAttack ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_Demolish:
|
||||
case ButtonDemolish:
|
||||
if( Selected[0]->Orders[0].Action==UnitActionDemolish ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_AttackGround:
|
||||
case ButtonAttackGround:
|
||||
if( Selected[0]->Orders[0].Action
|
||||
==UnitActionAttackGround ) {
|
||||
v=IconSelected;
|
||||
|
@ -297,33 +444,33 @@ global void DrawButtonPanel(void)
|
|||
}
|
||||
#else
|
||||
switch( buttons[i].Action ) {
|
||||
case B_Stop:
|
||||
case ButtonStop:
|
||||
if( Selected[0]->Command.Action==UnitActionStill ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_StandGround:
|
||||
case ButtonStandGround:
|
||||
if( Selected[0]->Command.Action
|
||||
==UnitActionStandGround ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_Move:
|
||||
case ButtonMove:
|
||||
if( Selected[0]->Command.Action==UnitActionMove ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_Attack:
|
||||
case ButtonAttack:
|
||||
if( Selected[0]->Command.Action==UnitActionAttack ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_Demolish:
|
||||
case ButtonDemolish:
|
||||
if( Selected[0]->Command.Action==UnitActionDemolish ) {
|
||||
v=IconSelected;
|
||||
}
|
||||
break;
|
||||
case B_AttackGround:
|
||||
case ButtonAttackGround:
|
||||
if( Selected[0]->Command.Action
|
||||
==UnitActionAttackGround ) {
|
||||
v=IconSelected;
|
||||
|
@ -349,9 +496,9 @@ global void DrawButtonPanel(void)
|
|||
// FIXME: Draw costs
|
||||
v=buttons[i].Value;
|
||||
switch( buttons[i].Action ) {
|
||||
case B_Build:
|
||||
case B_Train:
|
||||
case B_UpgradeTo:
|
||||
case ButtonBuild:
|
||||
case ButtonTrain:
|
||||
case ButtonUpgradeTo:
|
||||
// FIXME: store pointer in button table!
|
||||
stats=&UnitTypes[v].Stats[ThisPlayer->Player];
|
||||
DebugLevel3("Upgrade to %s %d %d %d %d\n"
|
||||
|
@ -362,11 +509,11 @@ global void DrawButtonPanel(void)
|
|||
,stats->Costs[WoodCost]);
|
||||
SetCosts(0,stats->Costs);
|
||||
break;
|
||||
//case B_Upgrade:
|
||||
case B_Research:
|
||||
//case ButtonUpgrade:
|
||||
case ButtonResearch:
|
||||
SetCosts(0,Upgrades[v].Costs);
|
||||
break;
|
||||
case B_SpellCast:
|
||||
case ButtonSpellCast:
|
||||
SetCosts(SpellTypeById( v )->ManaCost,NULL);
|
||||
break;
|
||||
|
||||
|
@ -431,8 +578,8 @@ local void UpdateButtonPanelMultipleUnits(void)
|
|||
}
|
||||
|
||||
// any unit or unit in list
|
||||
if ( UnitButtonTable[z]->UMask[0] != '*'
|
||||
&& strstr( UnitButtonTable[z]->UMask, unit_ident ) ) {
|
||||
if ( UnitButtonTable[z]->UnitMask[0] != '*'
|
||||
&& strstr( UnitButtonTable[z]->UnitMask, unit_ident ) ) {
|
||||
int allow;
|
||||
|
||||
allow=0;
|
||||
|
@ -443,23 +590,23 @@ local void UpdateButtonPanelMultipleUnits(void)
|
|||
allow = 1;
|
||||
}
|
||||
} else {
|
||||
// there is not allow function -- should check dependencies
|
||||
// there is no allow function -- should check dependencies
|
||||
// any unit of the group must have this feature
|
||||
if ( UnitButtonTable[z]->Action == B_Attack ) {
|
||||
if ( UnitButtonTable[z]->Action == ButtonAttack ) {
|
||||
for( i=NumSelected; --i; ) {
|
||||
if( Selected[i]->Type->CanAttack ) {
|
||||
allow = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ( UnitButtonTable[z]->Action == B_AttackGround ) {
|
||||
} else if ( UnitButtonTable[z]->Action == ButtonAttackGround ) {
|
||||
for( i=NumSelected; --i; ) {
|
||||
if( Selected[i]->Type->GroundAttack ) {
|
||||
allow = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ( UnitButtonTable[z]->Action == B_Demolish ) {
|
||||
} else if ( UnitButtonTable[z]->Action == ButtonDemolish ) {
|
||||
for( i=NumSelected; --i; ) {
|
||||
if( Selected[i]->Type->Explodes ) {
|
||||
allow = 1;
|
||||
|
@ -489,28 +636,29 @@ global void UpdateButtonPanel(void)
|
|||
{
|
||||
Unit* unit;
|
||||
char unit_ident[128];
|
||||
ButtonAction* buttonaction;
|
||||
int z;
|
||||
int allow;
|
||||
|
||||
DebugLevel3Fn("update buttons\n");
|
||||
|
||||
CurrentButtons=NULL;
|
||||
|
||||
if( !NumSelected ) { // no unit selected
|
||||
// FIXME: need only redraw if same state
|
||||
MustRedraw|=RedrawButtonPanel;
|
||||
return;
|
||||
}
|
||||
|
||||
if( NumSelected>1 ) { // multiple selected
|
||||
int at;
|
||||
|
||||
for ( at=z = 1; z < NumSelected; z++ ) {
|
||||
for ( allow=z = 1; z < NumSelected; z++ ) {
|
||||
// if current type is equal to first one count it
|
||||
if ( Selected[z]->Type == Selected[0]->Type ) {
|
||||
at++;
|
||||
allow++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( at != NumSelected ) {
|
||||
if ( allow != NumSelected ) {
|
||||
// oops we have selected different units types
|
||||
// -- set default buttons and exit
|
||||
UpdateButtonPanelMultipleUnits();
|
||||
|
@ -535,10 +683,6 @@ global void UpdateButtonPanel(void)
|
|||
//
|
||||
// FIXME: johns: some hacks for cancel buttons
|
||||
//
|
||||
/* if( CursorBuilding ) {
|
||||
strcpy(unit_ident,",cancel-build,");
|
||||
// FIXME: johns: my ->Constructed didn't seem ok. if (unit->Constructed)
|
||||
} else */
|
||||
#ifdef NEW_ORDERS
|
||||
if( unit->Orders[0].Action==UnitActionBuilded ) {
|
||||
// Trick 17 to get the cancel-build button
|
||||
|
@ -569,75 +713,92 @@ global void UpdateButtonPanel(void)
|
|||
|
||||
for( z = 0; z < UnitButtonCount; z++ ) {
|
||||
//FIXME: we have to check and if these unit buttons are available
|
||||
// i.e. if button action is B_Train for example check if required
|
||||
// i.e. if button action is ButtonTrain for example check if required
|
||||
// unit is not restricted etc...
|
||||
if ( UnitButtonTable[z]->Level != CurrentButtonLevel ) {
|
||||
|
||||
buttonaction=UnitButtonTable[z];
|
||||
|
||||
// Same level
|
||||
if ( buttonaction->Level != CurrentButtonLevel ) {
|
||||
continue;
|
||||
}
|
||||
// any unit or unit in list
|
||||
if ( UnitButtonTable[z]->UMask[0] == '*'
|
||||
|| strstr( UnitButtonTable[z]->UMask, unit_ident ) ) {
|
||||
int allow;
|
||||
if ( buttonaction->UnitMask[0] != '*'
|
||||
&& !strstr( buttonaction->UnitMask, unit_ident ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( buttonaction->Allowed ) {
|
||||
// there is check function -- call it
|
||||
allow=buttonaction->Allowed( unit, buttonaction);
|
||||
} else {
|
||||
// there is no allow function -- should check dependencies
|
||||
allow=0;
|
||||
DebugLevel3("%d: %p\n",z,UnitButtonTable[z]->Allowed);
|
||||
if ( UnitButtonTable[z]->Allowed ) {
|
||||
// there is check function -- call it
|
||||
if (UnitButtonTable[z]->Allowed( unit, UnitButtonTable[z] )) {
|
||||
switch( buttonaction->Action ) {
|
||||
case ButtonMove:
|
||||
case ButtonStop:
|
||||
case ButtonRepair:
|
||||
case ButtonHarvest:
|
||||
case ButtonButton:
|
||||
case ButtonPatrol:
|
||||
case ButtonStandGround:
|
||||
case ButtonReturn:
|
||||
allow = 1;
|
||||
break;
|
||||
case ButtonAttack:
|
||||
if( Selected[0]->Type->CanAttack ) {
|
||||
allow = 1;
|
||||
}
|
||||
} else {
|
||||
// there is not allow function -- should check dependencies
|
||||
if ( UnitButtonTable[z]->Action == B_Attack ) {
|
||||
if( /*NumSelected==1 &&*/ Selected[0]->Type->CanAttack ) {
|
||||
allow = 1;
|
||||
}
|
||||
} else if ( UnitButtonTable[z]->Action == B_AttackGround ) {
|
||||
if( /*NumSelected==1 &&*/ Selected[0]->Type->GroundAttack ) {
|
||||
allow = 1;
|
||||
}
|
||||
} else if ( UnitButtonTable[z]->Action == B_Demolish ) {
|
||||
if( /*NumSelected==1 &&*/ Selected[0]->Type->Explodes ) {
|
||||
allow = 1;
|
||||
}
|
||||
} else if ( UnitButtonTable[z]->Action == B_Train
|
||||
// || UnitButtonTable[z]->Action == B_Upgrade
|
||||
|| UnitButtonTable[z]->Action == B_UpgradeTo
|
||||
|| UnitButtonTable[z]->Action == B_Research
|
||||
|| UnitButtonTable[z]->Action == B_Build
|
||||
) {
|
||||
allow = CheckDependByIdent( ThisPlayer,
|
||||
UnitButtonTable[z]->ValueStr );
|
||||
if ( allow && !strncmp( UnitButtonTable[z]->ValueStr,
|
||||
"upgrade-", 8 ) ) {
|
||||
allow=UpgradeIdentAllowed( ThisPlayer,
|
||||
UnitButtonTable[z]->ValueStr )=='A';
|
||||
}
|
||||
} else if ( UnitButtonTable[z]->Action == B_SpellCast ) {
|
||||
DebugLevel3("Magic: %d,%c\n",
|
||||
CheckDependByIdent( ThisPlayer,
|
||||
UnitButtonTable[z]->ValueStr ),
|
||||
UpgradeIdentAllowed( ThisPlayer,
|
||||
UnitButtonTable[z]->ValueStr ));
|
||||
allow = CheckDependByIdent( ThisPlayer,
|
||||
UnitButtonTable[z]->ValueStr )
|
||||
&& UpgradeIdentAllowed( ThisPlayer,
|
||||
UnitButtonTable[z]->ValueStr )=='R';
|
||||
} else if ( UnitButtonTable[z]->Action == B_Unload ) {
|
||||
DebugLevel3("Unload: %d\n",Selected[0]->Value);
|
||||
allow = Selected[0]->Value;
|
||||
} else {
|
||||
// so we have NULL check function
|
||||
// and button is not one of Train/Build/Research
|
||||
break;
|
||||
case ButtonAttackGround:
|
||||
if( Selected[0]->Type->GroundAttack ) {
|
||||
allow = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ButtonDemolish:
|
||||
if( Selected[0]->Type->Explodes ) {
|
||||
allow = 1;
|
||||
}
|
||||
break;
|
||||
case ButtonTrain:
|
||||
case ButtonUpgradeTo:
|
||||
case ButtonResearch:
|
||||
case ButtonBuild:
|
||||
allow = CheckDependByIdent( ThisPlayer,buttonaction->ValueStr);
|
||||
if ( allow && !strncmp( buttonaction->ValueStr,
|
||||
"upgrade-", 8 ) ) {
|
||||
allow=UpgradeIdentAllowed( ThisPlayer,
|
||||
buttonaction->ValueStr )=='A';
|
||||
}
|
||||
break;
|
||||
case ButtonSpellCast:
|
||||
allow = CheckDependByIdent( ThisPlayer,buttonaction->ValueStr)
|
||||
&& UpgradeIdentAllowed( ThisPlayer,
|
||||
buttonaction->ValueStr )=='R';
|
||||
break;
|
||||
case ButtonUnload:
|
||||
allow = Selected[0]->Value;
|
||||
break;
|
||||
case ButtonCancel:
|
||||
allow = 1;
|
||||
break;
|
||||
|
||||
if (allow) { // is button allowed after all?
|
||||
_current_buttons[UnitButtonTable[z]->Pos-1]
|
||||
= (*UnitButtonTable[z]);
|
||||
case ButtonCancelUpgrade:
|
||||
case ButtonCancelTrain:
|
||||
case ButtonCancelBuild:
|
||||
allow = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
DebugLevel0Fn("Unsupported button-action %d\n",
|
||||
buttonaction->Action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allow) { // is button allowed after all?
|
||||
_current_buttons[buttonaction->Pos-1] = (*buttonaction);
|
||||
}
|
||||
}
|
||||
|
||||
CurrentButtons = _current_buttons;
|
||||
|
@ -673,7 +834,7 @@ global void DoButtonButtonClicked(int button)
|
|||
DebugLevel3Fn("Button clicked %d=%d\n",button,
|
||||
CurrentButtons[button].Action);
|
||||
switch( CurrentButtons[button].Action ) {
|
||||
case B_Unload:
|
||||
case ButtonUnload:
|
||||
//
|
||||
// Unload on coast, unload all units.
|
||||
//
|
||||
|
@ -684,14 +845,14 @@ global void DoButtonButtonClicked(int button)
|
|||
,!(KeyModifiers&ModifierShift));
|
||||
break;
|
||||
}
|
||||
case B_Move:
|
||||
case B_Patrol:
|
||||
case B_Harvest:
|
||||
case B_Attack:
|
||||
case B_Repair:
|
||||
case B_AttackGround:
|
||||
case B_Demolish:
|
||||
case B_SpellCast:
|
||||
case ButtonMove:
|
||||
case ButtonPatrol:
|
||||
case ButtonHarvest:
|
||||
case ButtonAttack:
|
||||
case ButtonRepair:
|
||||
case ButtonAttackGround:
|
||||
case ButtonDemolish:
|
||||
case ButtonSpellCast:
|
||||
CursorState=CursorStateSelect;
|
||||
GameCursor=TheUI.YellowHair.Cursor;
|
||||
CursorAction=CurrentButtons[button].Action;
|
||||
|
@ -701,29 +862,30 @@ global void DoButtonButtonClicked(int button)
|
|||
MustRedraw|=RedrawCursor;
|
||||
SetStatusLine("Select Target");
|
||||
break;
|
||||
case B_Return:
|
||||
case ButtonReturn:
|
||||
for( i=0; i<NumSelected; ++i ) {
|
||||
SendCommandReturnGoods(Selected[i],NoUnitP
|
||||
,!(KeyModifiers&ModifierShift));
|
||||
}
|
||||
break;
|
||||
case B_Stop:
|
||||
case ButtonStop:
|
||||
for( i=0; i<NumSelected; ++i ) {
|
||||
SendCommandStopUnit(Selected[i]);
|
||||
}
|
||||
break;
|
||||
case B_StandGround:
|
||||
case ButtonStandGround:
|
||||
for( i=0; i<NumSelected; ++i ) {
|
||||
SendCommandStandGround(Selected[i]
|
||||
,!(KeyModifiers&ModifierShift));
|
||||
}
|
||||
break;
|
||||
case B_Button:
|
||||
case ButtonButton:
|
||||
CurrentButtonLevel=CurrentButtons[button].Value;
|
||||
UpdateButtonPanel();
|
||||
break;
|
||||
|
||||
case B_Cancel:
|
||||
case ButtonCancel:
|
||||
case ButtonCancelUpgrade:
|
||||
if ( NumSelected==1 && Selected[0]->Type->Building ) {
|
||||
#ifdef NEW_ORDERS
|
||||
if( Selected[0]->Orders[0].Action==UnitActionUpgradeTo ) {
|
||||
|
@ -749,7 +911,7 @@ global void DoButtonButtonClicked(int button)
|
|||
MustRedraw|=RedrawCursor;
|
||||
break;
|
||||
|
||||
case B_CancelTrain:
|
||||
case ButtonCancelTrain:
|
||||
#ifdef NEW_ORDERS
|
||||
DebugCheck( Selected[0]->Orders[0].Action!=UnitActionTrain
|
||||
|| !Selected[0]->Data.Train.Count );
|
||||
|
@ -762,7 +924,7 @@ global void DoButtonButtonClicked(int button)
|
|||
ClearCosts();
|
||||
break;
|
||||
|
||||
case B_CancelBuild:
|
||||
case ButtonCancelBuild:
|
||||
// FIXME: johns is this not sure, only building should have this?
|
||||
if( NumSelected==1 && Selected[0]->Type->Building ) {
|
||||
SendCommandCancelBuilding(Selected[0],
|
||||
|
@ -776,7 +938,7 @@ global void DoButtonButtonClicked(int button)
|
|||
ClearCosts();
|
||||
break;
|
||||
|
||||
case B_Build:
|
||||
case ButtonBuild:
|
||||
// FIXME: store pointer in button table!
|
||||
type=&UnitTypes[CurrentButtons[button].Value];
|
||||
if( !PlayerCheckUnitType(ThisPlayer,type) ) {
|
||||
|
@ -790,7 +952,7 @@ global void DoButtonButtonClicked(int button)
|
|||
}
|
||||
break;
|
||||
|
||||
case B_Train:
|
||||
case ButtonTrain:
|
||||
// FIXME: store pointer in button table!
|
||||
type=&UnitTypes[CurrentButtons[button].Value];
|
||||
// FIXME: Johns: I want to place commands in queue, even if not
|
||||
|
@ -814,7 +976,7 @@ global void DoButtonButtonClicked(int button)
|
|||
}
|
||||
break;
|
||||
|
||||
case B_UpgradeTo:
|
||||
case ButtonUpgradeTo:
|
||||
// FIXME: store pointer in button table!
|
||||
type=&UnitTypes[CurrentButtons[button].Value];
|
||||
if( !PlayerCheckUnitType(ThisPlayer,type) ) {
|
||||
|
@ -829,7 +991,7 @@ global void DoButtonButtonClicked(int button)
|
|||
ClearCosts();
|
||||
}
|
||||
break;
|
||||
case B_Research:
|
||||
case ButtonResearch:
|
||||
i=CurrentButtons[button].Value;
|
||||
if( !PlayerCheckCosts(ThisPlayer,Upgrades[i].Costs) ) {
|
||||
//PlayerSubCosts(ThisPlayer,Upgrades[i].Costs);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -836,7 +836,6 @@ local void SendSpellCast(int x,int y)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
** Send a command to selected units.
|
||||
**
|
||||
|
@ -850,31 +849,31 @@ local void SendCommand(int x,int y)
|
|||
CurrentButtonLevel = 0; // reset unit buttons to normal
|
||||
UpdateButtonPanel();
|
||||
switch( CursorAction ) {
|
||||
case B_Move:
|
||||
case ButtonMove:
|
||||
SendMove(x,y);
|
||||
break;
|
||||
case B_Repair:
|
||||
case ButtonRepair:
|
||||
SendRepair(x,y);
|
||||
break;
|
||||
case B_Attack:
|
||||
case ButtonAttack:
|
||||
SendAttack(x,y);
|
||||
break;
|
||||
case B_AttackGround:
|
||||
case ButtonAttackGround:
|
||||
SendAttackGround(x,y);
|
||||
break;
|
||||
case B_Patrol:
|
||||
case ButtonPatrol:
|
||||
SendPatrol(x,y);
|
||||
break;
|
||||
case B_Harvest:
|
||||
case ButtonHarvest:
|
||||
SendHarvest(x,y);
|
||||
break;
|
||||
case B_Unload:
|
||||
case ButtonUnload:
|
||||
SendUnload(x,y);
|
||||
break;
|
||||
case B_Demolish:
|
||||
case ButtonDemolish:
|
||||
SendDemolish(x,y);
|
||||
break;
|
||||
case B_SpellCast:
|
||||
case ButtonSpellCast:
|
||||
SendSpellCast(x,y);
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Add table
Reference in a new issue