Skip to content

Commit

Permalink
Allow designing and building obsolete tanks.
Browse files Browse the repository at this point in the history
Since you sometimes might want to a bunch of cheap MG tanks as a decoy, even if you have twin AG researched.

Also, remove an unrelated uselessly-duplicated test in action.cpp.
  • Loading branch information
Cyp committed May 22, 2013
1 parent 5625def commit 714727e
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 151 deletions.
6 changes: 6 additions & 0 deletions data/base/images/intfac.img
Expand Up @@ -344,6 +344,12 @@
0,0,image_vdp_down.png
0,0,image_vdp_up.png
-1,-1,image_vdp_hi.png
0,0,image_obsolete_hide_up.png
0,0,image_obsolete_hide_down.png
-1,-1,image_obsolete_hide_hi.png
0,0,image_obsolete_show_up.png
0,0,image_obsolete_show_down.png
-1,-1,image_obsolete_show_hi.png
0,0,image_gn_star.png
0,0,image_gn_15.png
0,0,image_gn_14.png
Expand Down
Binary file added data/base/images/intfac/image_obsolete_hide_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/base/images/intfac/image_obsolete_hide_hi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/base/images/intfac/image_obsolete_hide_up.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/base/images/intfac/image_obsolete_show_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/base/images/intfac/image_obsolete_show_hi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/base/images/intfac/image_obsolete_show_up.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 61 additions & 16 deletions lib/widget/button.cpp
Expand Up @@ -192,20 +192,20 @@ void W_BUTTON::display(int xOffset, int yOffset)
bool isHighlight = (state & WBUT_HIGHLIGHT) != 0;

// Display the button.
if (!image.isNull())
if (!images.normal.isNull())
{
iV_DrawImage(image, x0, y0);
if (isDown && !imageDown.isNull())
iV_DrawImage(images.normal, x0, y0);
if (isDown && !images.down.isNull())
{
iV_DrawImage(imageDown, x0, y0);
iV_DrawImage(images.down, x0, y0);
}
if (isDisabled && !imageDisabled.isNull())
if (isDisabled && !images.disabled.isNull())
{
iV_DrawImage(imageDisabled, x0, y0);
iV_DrawImage(images.disabled, x0, y0);
}
if (isHighlight && !imageHighlight.isNull())
if (isHighlight && !images.highlighted.isNull())
{
iV_DrawImage(imageHighlight, x0, y0);
iV_DrawImage(images.highlighted, x0, y0);
}
}
else
Expand Down Expand Up @@ -238,21 +238,66 @@ void W_BUTTON::display(int xOffset, int yOffset)
iV_DrawText(textBytes.constData(), fx, fy);
}

if (isDisabled && !image.isNull() && imageDisabled.isNull())
if (isDisabled && !images.normal.isNull() && images.disabled.isNull())
{
// disabled, render something over it!
iV_TransBoxFill(x0, y0, x0 + width(), y0 + height());
}
}

void W_BUTTON::setImages(Image image_, Image imageDown_, Image imageHighlight_, Image imageDisabled_)
void W_BUTTON::setImages(Images const &images_)
{
image = image_;
imageDown = imageDown_;
imageDisabled = imageDisabled_;
imageHighlight = imageHighlight_;
if (!image.isNull())
images = images_;
if (!images.normal.isNull())
{
setGeometry(x(), y(), image.width(), image.height());
setGeometry(x(), y(), images.normal.width(), images.normal.height());
}
}

void W_BUTTON::setImages(Image image, Image imageDown, Image imageHighlight, Image imageDisabled)
{
setImages(Images(image, imageDown, imageHighlight, imageDisabled));
}

void StateButton::setState(int state)
{
if (currentState == state)
{
return;
}

currentState = state;
std::map<int, Images>::const_iterator image = imageSets.find(state);
if (image != imageSets.end())
{
W_BUTTON::setImages(image->second);
}
std::map<int, QString>::const_iterator tip = tips.find(state);
if (tip != tips.end())
{
W_BUTTON::setTip(tip->second);
}
}

void StateButton::setTip(int state, QString string)
{
tips[state] = string;
if (currentState == state)
{
W_BUTTON::setTip(string);
}
}

void StateButton::setTip(int state, char const *stringUtf8)
{
setTip(state, QString::fromUtf8(stringUtf8));
}

void StateButton::setImages(int state, Images const &images)
{
imageSets[state] = images;
if (currentState == state)
{
W_BUTTON::setImages(images);
}
}
37 changes: 32 additions & 5 deletions lib/widget/button.h
Expand Up @@ -26,13 +26,25 @@

#include "widget.h"
#include "widgbase.h"
#include "lib/ivis_opengl/textdraw.h"
#include <map>


class W_BUTTON : public WIDGET
{
Q_OBJECT

public:
struct Images
{
Images() {}
Images(Image normal, Image down, Image highlighted, Image disabled = Image()) : normal(normal), down(down), highlighted(highlighted), disabled(disabled) {}

Image normal; ///< The image for the button.
Image down; ///< The image for the button, when down. Is overlaid over image.
Image highlighted; ///< The image for the button, when highlighted. Is overlaid over image.
Image disabled; ///< The image for the button, when disabled. Is overlaid over image.
};

public:
W_BUTTON(W_BUTINIT const *init);
W_BUTTON(WIDGET *parent);
Expand All @@ -50,6 +62,7 @@ class W_BUTTON : public WIDGET
void setString(QString string);
void setTip(QString string);

void setImages(Images const &images);
void setImages(Image image, Image imageDown, Image imageHighlight, Image imageDisabled = Image());

void setString(char const *stringUtf8) { WIDGET::setString(stringUtf8); } // Unhide the WIDGET::setString(char const *) function...
Expand All @@ -61,15 +74,29 @@ class W_BUTTON : public WIDGET
public:
UDWORD state; // The current button state
QString pText; // The text for the button
Image image; ///< The image for the button.
Image imageDown; ///< The image for the button, when down. Is overlaid over image.
Image imageDisabled; ///< The image for the button, when disabled. Is overlaid over image.
Image imageHighlight; ///< The image for the button, when highlighted. Is overlaid over image.
Images images; ///< The images for the button.
QString pTip; // The tool tip for the button
SWORD HilightAudioID; // Audio ID for form clicked sound
SWORD ClickedAudioID; // Audio ID for form hilighted sound
WIDGET_AUDIOCALLBACK AudioCallback; // Pointer to audio callback function
iV_fonts FontID;
};

class StateButton : public W_BUTTON
{
Q_OBJECT

public:
StateButton(WIDGET *parent) : W_BUTTON(parent) {}
void setState(int state);
void setTip(int state, QString string);
void setTip(int state, char const *stringUtf8);
void setImages(int state, Images const &images);

private:
int currentState;
std::map<int, QString> tips;
std::map<int, Images> imageSets;
};

#endif // __INCLUDED_LIB_WIDGET_BUTTON_H__
2 changes: 2 additions & 0 deletions lib/widget/widgbase.h
Expand Up @@ -42,6 +42,8 @@ class W_BARGRAPH;
class W_BUTTON;
class W_LABEL;
class W_SLIDER;
class StateButton;
class ListWidget;

/* The display function prototype */
typedef void (*WIDGET_DISPLAY)(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset);
Expand Down
2 changes: 1 addition & 1 deletion src/action.cpp
Expand Up @@ -671,7 +671,7 @@ static bool actionRemoveDroidsFromBuildPos(unsigned player, Vector2i pos, uint16
void actionSanity(DROID *psDroid)
{
// Don't waste ammo unless given a direct attack order.
bool avoidOverkill = psDroid->order.type != DORDER_ATTACK && psDroid->order.type != DORDER_ATTACK &&
bool avoidOverkill = psDroid->order.type != DORDER_ATTACK &&
(psDroid->action == DACTION_ATTACK || psDroid->action == DACTION_MOVEFIRE || psDroid->action == DACTION_MOVETOATTACK ||
psDroid->action == DACTION_ROTATETOATTACK || psDroid->action == DACTION_VTOLATTACK);

Expand Down
68 changes: 36 additions & 32 deletions src/design.cpp
Expand Up @@ -150,7 +150,7 @@ char StringBuffer[STRING_BUFFER_SIZE];
#define DES_LEFTFORMX RET_X
#define DES_LEFTFORMY DESIGN_Y
#define DES_LEFTFORMWIDTH RET_FORMWIDTH
#define DES_LEFTFORMHEIGHT 258
#define DES_LEFTFORMHEIGHT 273
#define DES_LEFTFORMBUTX 2
#define DES_LEFTFORMBUTY 2

Expand Down Expand Up @@ -245,7 +245,7 @@ static bool intAddTemplateButtons(ListTabWidget *templList, DROID_TEMPLATE *psSe
static void intDisplayDesignForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset);

/* Set the current mode of the design screen, and display the appropriate component lists */
static void intSetDesignMode(DES_COMPMODE newCompMode);
static void intSetDesignMode(DES_COMPMODE newCompMode, bool forceRefresh = false);
/* Set all the design bar graphs from a design template */
static void intSetDesignStats(DROID_TEMPLATE *psTemplate);
/* Set up the system clickable form of the design screen given a set of stats */
Expand Down Expand Up @@ -351,7 +351,7 @@ extern bool bRender3DOnly;


/* Add the design widgets to the widget screen */
static bool _intAddDesign(bool bShowCentreScreen)
bool intAddDesign(bool bShowCentreScreen)
{
W_FORMINIT sFormInit;
W_LABINIT sLabInit;
Expand Down Expand Up @@ -777,29 +777,32 @@ void desSetupDesignTemplates(void)
psTempl->droidType != DROID_CYBORG_CONSTRUCT &&
psTempl->droidType != DROID_CYBORG_REPAIR &&
psTempl->droidType != DROID_PERSON &&
researchedTemplate(psTempl, selectedPlayer))
researchedTemplate(psTempl, selectedPlayer, includeRedundantDesigns))
{
apsTemplateList.push_back(psTempl);
}
}
}

/* Add the design template form */
static bool _intAddTemplateForm(DROID_TEMPLATE *psSelected)
static bool intAddTemplateForm(DROID_TEMPLATE *psSelected)
{
WIDGET *parent = psWScreen->psForm;

/* add a form to place the tabbed form on */
IntFormAnimated *templbaseForm = new IntFormAnimated(parent, false);
templbaseForm->id = IDDES_TEMPLBASE;
templbaseForm->setGeometry(RET_X, DESIGN_Y, RET_FORMWIDTH, DES_LEFTFORMHEIGHT + 4);
templbaseForm->setGeometry(RET_X, DESIGN_Y, RET_FORMWIDTH, DES_LEFTFORMHEIGHT);

// Add the obsolete items button.
makeObsoleteButton(templbaseForm);

/* Add the design templates form */
IntListTabWidget *templList = new IntListTabWidget(templbaseForm);
templList->setChildSize(DES_TABBUTWIDTH, DES_TABBUTHEIGHT);
templList->setChildSpacing(DES_TABBUTGAP, DES_TABBUTGAP);
int templListWidth = OBJ_BUTWIDTH*2 + DES_TABBUTGAP;
templList->setGeometry((RET_FORMWIDTH - templListWidth)/2, 2, templListWidth, templbaseForm->height() - 2);
templList->setGeometry((RET_FORMWIDTH - templListWidth)/2, 18, templListWidth, templbaseForm->height() - 18);

/* Put the buttons on it */
return intAddTemplateButtons(templList, psSelected);
Expand Down Expand Up @@ -878,11 +881,11 @@ static bool intAddTemplateButtons(ListTabWidget *templList, DROID_TEMPLATE *psSe
* component lists
* added case IDES_TURRET_A,IDES_TURRET_B
*/
static void intSetDesignMode(DES_COMPMODE newCompMode)
static void intSetDesignMode(DES_COMPMODE newCompMode, bool forceRefresh)
{
UDWORD weaponIndex;

if (newCompMode == desCompMode)
if (newCompMode == desCompMode && !forceRefresh)
{
return;
}
Expand Down Expand Up @@ -1141,7 +1144,7 @@ static void intSetDesignStats(DROID_TEMPLATE *psTemplate)
}

/* Set up the system clickable form of the design screen given a set of stats */
static bool _intSetSystemForm(COMPONENT_STATS *psStats)
static bool intSetSystemForm(COMPONENT_STATS *psStats)
{
DES_SYSMODE newSysMode = (DES_SYSMODE)0;

Expand Down Expand Up @@ -1709,7 +1712,7 @@ static ListTabWidget *intAddComponentForm()
/* add a form to place the tabbed form on */
IntFormAnimated *rightBase = new IntFormAnimated(parent, false);
rightBase->id = IDDES_RIGHTBASE;
rightBase->setGeometry(RADTLX - 2, DESIGN_Y, RET_FORMWIDTH, DES_RIGHTFORMHEIGHT + 4);
rightBase->setGeometry(RADTLX - 2, DESIGN_Y, RET_FORMWIDTH, DES_RIGHTFORMHEIGHT);

//now a single form
IntListTabWidget *compList = new IntListTabWidget(rightBase);
Expand Down Expand Up @@ -1849,7 +1852,7 @@ static bool intAddComponentButtons(ListTabWidget *compList, COMPONENT_STATS *psS
}

/* Skip unavailable entries and non-design ones*/
if (!(aAvailable[i] & AVAILABLE) || !psCurrStats->designable)
if (!(aAvailable[i] == AVAILABLE || (includeRedundantDesigns && aAvailable[i] == REDUNDANT)) || !psCurrStats->designable)
{
/* Update the stats pointer for the next button */
psCurrStats = (COMPONENT_STATS *)(((UBYTE *)psCurrStats) + size);
Expand Down Expand Up @@ -1980,8 +1983,7 @@ static bool intAddExtraSystemButtons(ListTabWidget *compList, unsigned sensorInd
}

// Skip unavailable entries or non-design ones
if (!(aAvailable[i] & AVAILABLE)
|| !psCurrStats->designable)
if (!(aAvailable[i] == AVAILABLE || (includeRedundantDesigns && aAvailable[i] == REDUNDANT)) || !psCurrStats->designable)
{
// Update the stats pointer for the next button
psCurrStats = (COMPONENT_STATS *)(((UBYTE *)psCurrStats) + size);
Expand Down Expand Up @@ -3687,6 +3689,26 @@ void intProcessDesign(UDWORD id)
widgHide(psWScreen, IDDES_BODYFORM);
widgReveal(psWScreen, IDDES_PROPFORM);

break;
case IDSTAT_OBSOLETE_BUTTON:
includeRedundantDesigns = !includeRedundantDesigns;
StateButton *obsoleteButton = (StateButton *)widgGetFromID(psWScreen, IDSTAT_OBSOLETE_BUTTON);
obsoleteButton->setState(includeRedundantDesigns);
// Refresh lists.
if (droidTemplID != IDDES_TEMPLSTART)
{
intRemoveDesign();
intAddDesign(false);
}
else
{
desSetupDesignTemplates();
widgDelete(psWScreen, IDDES_TEMPLBASE);
intAddTemplateForm(templateFromButtonId(droidTemplID));
intSetDesignMode(desCompMode, true);
droidTemplID = IDDES_TEMPLSTART;
widgSetButtonState(psWScreen, droidTemplID, WBUT_LOCK);
}
break;
}
}
Expand Down Expand Up @@ -4134,24 +4156,6 @@ static bool intCheckValidWeaponForProp(void)
return checkValidWeaponForProp(&sCurrDesign);
}

bool intAddDesign(bool bShowCentreScreen)
{
return _intAddDesign(bShowCentreScreen);
}


/* Set up the system clickable form of the design screen given a set of stats */
static bool intSetSystemForm(COMPONENT_STATS *psStats)
{
return _intSetSystemForm(psStats);
}


static bool intAddTemplateForm(DROID_TEMPLATE *psSelected)
{
return _intAddTemplateForm(psSelected);
}

//checks if the template has PROPULSION_TYPE_LIFT propulsion attached - returns true if it does
bool checkTemplateIsVtol(DROID_TEMPLATE *psTemplate)
{
Expand Down

0 comments on commit 714727e

Please sign in to comment.