169 changes: 36 additions & 133 deletions src/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ static bool ChatDialogUp = false;
#define RETYOFFSET (0)
#define NUMRETBUTS 7 // Number of reticule buttons.

enum // Reticule button indecies.
{
RETBUT_CANCEL,
RETBUT_FACTORY,
RETBUT_RESEARCH,
RETBUT_BUILD,
RETBUT_DESIGN,
RETBUT_INTELMAP,
RETBUT_COMMAND,
};

struct BUTSTATE
{
UDWORD id;
Expand Down Expand Up @@ -366,8 +355,6 @@ static void processProximityButtons(UDWORD id);
static DROID *intCheckForDroid(UDWORD droidType);
static STRUCTURE *intCheckForStructure(UDWORD structType);

static void intCheckReticuleButtons();

// count the number of selected droids of a type
static SDWORD intNumSelectedDroids(UDWORD droidType);

Expand All @@ -381,29 +368,43 @@ struct RETBUTSTATS
QString filenameDown;
QString tip;
QString func;
int flashing = 0;
bool flashing = false;
int flashTime = 0;
W_BUTTON *button = nullptr;
QScriptEngine *engine = nullptr;
};
static RETBUTSTATS retbutstats[NUMRETBUTS];

void setReticuleFlash(int ButId, bool flash)
{
if (flash != retbutstats[ButId].flashing)
{
retbutstats[ButId].flashing = flash;
retbutstats[ButId].flashTime = 0;
}
}

void setReticuleStats(int ButId, QString tip, QString filename, QString filenameDown, QString func, QScriptEngine *engine)
{
retbutstats[ButId].tip = std::move(tip);
retbutstats[ButId].filename = std::move(filename);
retbutstats[ButId].filenameDown = std::move(filenameDown);
retbutstats[ButId].tip = tip;
retbutstats[ButId].filename = filename;
retbutstats[ButId].filenameDown = filenameDown;
retbutstats[ButId].downTime = 0;
retbutstats[ButId].flashing = 0;
retbutstats[ButId].flashing = false;
retbutstats[ButId].flashTime = 0;
retbutstats[ButId].func = std::move(func);
retbutstats[ButId].func = func;
retbutstats[ButId].engine = engine;

if (!retbutstats[ButId].button) // not quite set up yet
{
return;
}
retbutstats[ButId].button->setTip(retbutstats[ButId].tip);

if (!retbutstats[ButId].tip.isEmpty())
{
retbutstats[ButId].button->setTip(retbutstats[ButId].tip);
}

if (retbutstats[ButId].filename.isEmpty())
{
retbutstats[ButId].button->setState(WBUT_DISABLE);
Expand All @@ -416,13 +417,11 @@ void setReticuleStats(int ButId, QString tip, QString filename, QString filename

static void intDisplayReticuleButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset)
{
int x = xOffset + psWidget->x();
int y = yOffset + psWidget->y();
bool Hilight = false;
bool Down = false;
UBYTE DownTime = retbutstats[psWidget->UserData].downTime;
UBYTE flashing = retbutstats[psWidget->UserData].flashing;
UBYTE flashTime = retbutstats[psWidget->UserData].flashTime;
const int x = xOffset + psWidget->x();
const int y = yOffset + psWidget->y();
int DownTime = retbutstats[psWidget->UserData].downTime;
bool flashing = retbutstats[psWidget->UserData].flashing;
int flashTime = retbutstats[psWidget->UserData].flashTime;
ASSERT_OR_RETURN(, psWidget->type == WIDG_BUTTON, "Not a button");
W_BUTTON *psButton = (W_BUTTON *)psWidget;

Expand All @@ -432,8 +431,8 @@ static void intDisplayReticuleButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yO
return;
}

Down = psButton->state & (WBUT_DOWN | WBUT_CLICKLOCK);
Hilight = buttonIsHilite(psButton);
bool Down = psButton->state & (WBUT_DOWN | WBUT_CLICKLOCK);
bool Hilight = buttonIsHilite(psButton);

if (Down)
{
Expand Down Expand Up @@ -502,7 +501,7 @@ static void setReticuleBut(int ButId)
sButInit.style = WBUT_SECONDARY;
sButInit.UserData = ButId;
retbutstats[ButId].downTime = 0;
retbutstats[ButId].flashing = 0;
retbutstats[ButId].flashing = false;
retbutstats[ButId].flashTime = 0;
retbutstats[ButId].button = widgAddButton(psWScreen, &sButInit);
if (!retbutstats[ButId].button)
Expand Down Expand Up @@ -810,15 +809,12 @@ void intResetScreen(bool NoAnim)
NoAnim = true;
}

if (ReticuleUp)
for (auto& i : retbutstats)
{
/* Reset the reticule buttons */
widgSetButtonState(psWScreen, IDRET_COMMAND, 0);
widgSetButtonState(psWScreen, IDRET_BUILD, 0);
widgSetButtonState(psWScreen, IDRET_MANUFACTURE, 0);
widgSetButtonState(psWScreen, IDRET_INTEL_MAP, 0);
widgSetButtonState(psWScreen, IDRET_RESEARCH, 0);
widgSetButtonState(psWScreen, IDRET_DESIGN, 0);
if (i.button && ReticuleUp)
{
i.button->unlock();
}
}

/* Remove whatever extra screen was displayed */
Expand Down Expand Up @@ -2394,11 +2390,6 @@ static void intStopStructPosition()
/* Display the widgets for the in game interface */
void intDisplayWidgets()
{
if (ReticuleUp && !bInTutorial)
{
intCheckReticuleButtons();
}

/*draw the background for the design screen and the Intelligence screen*/
if (intMode == INT_DESIGN || intMode == INT_INTELMAP)
{
Expand Down Expand Up @@ -4356,7 +4347,7 @@ void flashReticuleButton(UDWORD buttonID)
WIDGET *psButton = widgGetFromID(psWScreen, buttonID);
if (psButton)
{
retbutstats[psButton->UserData].flashing = 1;
retbutstats[psButton->UserData].flashing = true;
}
}

Expand All @@ -4367,7 +4358,7 @@ void stopReticuleButtonFlash(UDWORD buttonID)
if (psButton)
{
retbutstats[psButton->UserData].flashTime = 0;
retbutstats[psButton->UserData].flashing = 0;
retbutstats[psButton->UserData].flashing = false;
}
}

Expand Down Expand Up @@ -4555,94 +4546,6 @@ static SDWORD intNumSelectedDroids(UDWORD droidType)
return num;
}

// Check that each reticule button has the structure or droid required for it and
// enable/disable accordingly.
//
void intCheckReticuleButtons()
{
STRUCTURE *psStruct;
DROID *psDroid;

ReticuleEnabled[RETBUT_CANCEL].Enabled = true;
ReticuleEnabled[RETBUT_FACTORY].Enabled = false;
ReticuleEnabled[RETBUT_RESEARCH].Enabled = false;
ReticuleEnabled[RETBUT_BUILD].Enabled = false;
ReticuleEnabled[RETBUT_DESIGN].Enabled = allowDesign;
ReticuleEnabled[RETBUT_INTELMAP].Enabled = true;
ReticuleEnabled[RETBUT_COMMAND].Enabled = false;

for (psStruct = interfaceStructList(); psStruct != nullptr; psStruct = psStruct->psNext)
{
if (psStruct->status == SS_BUILT)
{
switch (psStruct->pStructureType->type)
{
case REF_RESEARCH:
if (!missionLimboExpand())
{
ReticuleEnabled[RETBUT_RESEARCH].Enabled = true;
}
break;
case REF_FACTORY:
case REF_CYBORG_FACTORY:
case REF_VTOL_FACTORY:
if (!missionLimboExpand())
{
ReticuleEnabled[RETBUT_FACTORY].Enabled = true;
}
break;
default:
break;
}
}
}

for (psDroid = apsDroidLists[selectedPlayer]; psDroid != nullptr; psDroid = psDroid->psNext)
{
switch (psDroid->droidType)
{
case DROID_CONSTRUCT:
case DROID_CYBORG_CONSTRUCT:
ReticuleEnabled[RETBUT_BUILD].Enabled = true;
break;
case DROID_COMMAND:
ReticuleEnabled[RETBUT_COMMAND].Enabled = true;
break;
default:
break;
}
}

for (auto &i : ReticuleEnabled)
{
WIDGET *psWidget = widgGetFromID(psWScreen, i.id);

if (psWidget != nullptr)
{
if (psWidget->type != WIDG_LABEL)
{
if (i.Enabled)
{
widgSetButtonState(psWScreen, i.id, 0);
}
else
{
widgSetButtonState(psWScreen, i.id, WBUT_DISABLE);
}

if (i.Hidden)
{
widgHide(psWScreen, i.id);
}
else
{
widgReveal(psWScreen, i.id);
}
}
}
}
}

/*Checks to see if there are any research topics to do and flashes the button -
only if research facility is free*/
int intGetResearchState()
Expand Down
14 changes: 13 additions & 1 deletion src/hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ struct W_SCREEN;
struct iIMDShape;
struct QScriptEngine;

enum // Reticule button indecies.
{
RETBUT_CANCEL,
RETBUT_FACTORY,
RETBUT_RESEARCH,
RETBUT_BUILD,
RETBUT_DESIGN,
RETBUT_INTELMAP,
RETBUT_COMMAND,
};

#define BASE_COORDS_X (640)
#define BASE_COORDS_Y (460)
#define E_W (pie_GetVideoBufferWidth() - BASE_COORDS_X)
Expand Down Expand Up @@ -285,7 +296,8 @@ void intDisplayWidgets();
bool intAddReticule();
bool intAddPower();
void intRemoveReticule();
void setReticuleStats(int ButId, QString tip, QString filename, QString filenameDown, QString func, QScriptEngine *engine);
void setReticuleStats(int ButId, QString tip = QString(), QString filename = QString(), QString filenameDown = QString(), QString func = QString(), QScriptEngine *engine = nullptr);
void setReticuleFlash(int ButId, bool flash);

/* Set the map view point to the world coordinates x,y */
void intSetMapPos(UDWORD x, UDWORD y);
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ bool stageThreeInitialise()
}
}

countUpdate();
if (getLevelLoadType() != GTYPE_SAVE_MIDMISSION)
{
if (getDebugMappingStatus())
Expand Down
6 changes: 2 additions & 4 deletions src/levels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,11 @@ static bool levLoadSingleWRF(const char *name)
return true;
}


char *getLevelName()
const char *getLevelName()
{
return (currentLevelName);
return currentLevelName;
}


// load up the data for a level
bool levLoadData(char const *name, Sha256 const *hash, char *pSaveName, GAME_TYPE saveType)
{
Expand Down
2 changes: 1 addition & 1 deletion src/levels.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool levReleaseMissionData();
//get the type of level currently being loaded of GTYPE type
SDWORD getLevelLoadType();

char *getLevelName();
const char *getLevelName();

void levTest();

Expand Down
2 changes: 1 addition & 1 deletion src/loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ static GAMECODE renderLoop()
}

// Carry out the various counting operations we perform each loop
static void countUpdate(bool synch)
void countUpdate(bool synch)
{
for (unsigned i = 0; i < MAX_PLAYERS; i++)
{
Expand Down
2 changes: 2 additions & 0 deletions src/loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ void incNumDroids(UDWORD player);
void incNumCommandDroids(UDWORD player);
void incNumConstructorDroids(UDWORD player);

void countUpdate(bool synch = false);

#endif // __INCLUDED_SRC_LOOP_H__
3 changes: 3 additions & 0 deletions src/qtscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "difficulty.h"
#include "console.h"
#include "clparse.h"
#include "mission.h"

#include <set>
#include <utility>
Expand Down Expand Up @@ -599,6 +600,8 @@ QScriptEngine *loadPlayerScript(const QString& path, int player, int difficulty)
{
engine->globalObject().setProperty("difficulty", (int)getDifficultyLevel(), QScriptValue::ReadOnly | QScriptValue::Undeletable);
}
//== \item[levelType] The type of the current level.
engine->globalObject().setProperty("levelType", (int)mission.type, QScriptValue::ReadOnly | QScriptValue::Undeletable);
//== \item[mapName] The name of the current map.
engine->globalObject().setProperty("mapName", QString(game.map), QScriptValue::ReadOnly | QScriptValue::Undeletable); // QString cast to work around bug in Qt5 QScriptValue(char *) constructor.
//== \item[tilesetType] The area name of the map.
Expand Down
12 changes: 12 additions & 0 deletions src/qtscriptfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,16 @@ static QScriptValue js_setReticuleButton(QScriptContext *context, QScriptEngine
return QScriptValue();
}

//-- \subsection{setReticuleFlash(id, flash)} Set reticule flash on or off. (3.2.3+ only)
static QScriptValue js_setReticuleFlash(QScriptContext *context, QScriptEngine *engine)
{
int button = context->argument(0).toInt32();
SCRIPT_ASSERT(context, button >= 0 && button <= 6, "Invalid button %d", button);
bool flash = context->argument(1).toBoolean();
setReticuleFlash(button, flash);
return QScriptValue();
}

//-- \subsection{showInterface()} Show user interface. (3.2+ only)
static QScriptValue js_showInterface(QScriptContext *context, QScriptEngine *engine)
{
Expand Down Expand Up @@ -5575,6 +5585,7 @@ bool registerFunctions(QScriptEngine *engine, const QString& scriptName)
engine->globalObject().setProperty("removeTemplate", engine->newFunction(js_removeTemplate));
engine->globalObject().setProperty("setMiniMap", engine->newFunction(js_setMiniMap));
engine->globalObject().setProperty("setReticuleButton", engine->newFunction(js_setReticuleButton));
engine->globalObject().setProperty("setReticuleFlash", engine->newFunction(js_setReticuleFlash));
engine->globalObject().setProperty("showInterface", engine->newFunction(js_showInterface));
engine->globalObject().setProperty("hideInterface", engine->newFunction(js_hideInterface));
engine->globalObject().setProperty("addReticuleButton", engine->newFunction(js_removeReticuleButton)); // deprecated!!
Expand Down Expand Up @@ -5699,6 +5710,7 @@ bool registerFunctions(QScriptEngine *engine, const QString& scriptName)
engine->globalObject().setProperty("CAMP_MSG", MSG_CAMPAIGN, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("MISS_MSG", MSG_MISSION, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("RES_MSG", MSG_RESEARCH, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("LDS_EXPAND_LIMBO", LDS_EXPAND_LIMBO, QScriptValue::ReadOnly | QScriptValue::Undeletable);

/// Place to store group sizes
//== \item[groupSizes] A sparse array of group sizes. If a group has never been used, the entry in this array will
Expand Down
38 changes: 16 additions & 22 deletions src/scriptfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,30 +1296,27 @@ bool scrAddReticuleButton()
//set the appropriate flag to 'draw' the button
switch (val)
{
case IDRET_OPTIONS:
// bit of a hack here to keep compatibility with old scripts
widgReveal(psWScreen, IDRET_COMMAND);
break;
case IDRET_OPTIONS: // bit of a hack here to keep compatibility with old scripts
case IDRET_COMMAND:
widgReveal(psWScreen, IDRET_COMMAND);
setReticuleStats(RETBUT_COMMAND, _("Commanders (F6)"), "image_commanddroid_up.png", "image_commanddroid_down.png");
break;
case IDRET_BUILD:
widgReveal(psWScreen, IDRET_BUILD);
setReticuleStats(RETBUT_BUILD, _("Build (F3)"), "image_build_up.png", "image_build_down.png");
break;
case IDRET_MANUFACTURE:
widgReveal(psWScreen, IDRET_MANUFACTURE);
setReticuleStats(RETBUT_FACTORY, _("Manufacture (F1)"), "image_manufacture_up.png", "image_manufacture_down.png");
break;
case IDRET_RESEARCH:
widgReveal(psWScreen, IDRET_RESEARCH);
setReticuleStats(RETBUT_RESEARCH, _("Research (F2)"), "image_research_up.png", "image_research_down.png");
break;
case IDRET_INTEL_MAP:
widgReveal(psWScreen, IDRET_INTEL_MAP);
setReticuleStats(RETBUT_INTELMAP, _("Intelligence Display (F5)"), "image_intelmap_up.png", "image_intelmap_down.png");
break;
case IDRET_DESIGN:
widgReveal(psWScreen, IDRET_DESIGN);
setReticuleStats(RETBUT_DESIGN, _("Design (F4)"), "image_design_up.png", "image_design_down.png");
break;
case IDRET_CANCEL:
widgReveal(psWScreen, IDRET_CANCEL);
setReticuleStats(RETBUT_CANCEL, _("Close"), "image_cancel_up.png", "image_cancel_down.png");
break;
default:
ASSERT(false, "Invalid reticule Button ID");
Expand Down Expand Up @@ -1350,30 +1347,27 @@ bool scrRemoveReticuleButton()
}
switch (val)
{
case IDRET_OPTIONS:
// bit of a hack here to keep compatibility with old scripts
widgHide(psWScreen, IDRET_COMMAND);
break;
case IDRET_OPTIONS: // bit of a hack here to keep compatibility with old scripts
case IDRET_COMMAND:
widgHide(psWScreen, IDRET_COMMAND);
setReticuleStats(RETBUT_COMMAND);
break;
case IDRET_BUILD:
widgHide(psWScreen, IDRET_BUILD);
setReticuleStats(RETBUT_BUILD);
break;
case IDRET_MANUFACTURE:
widgHide(psWScreen, IDRET_MANUFACTURE);
setReticuleStats(RETBUT_FACTORY);
break;
case IDRET_RESEARCH:
widgHide(psWScreen, IDRET_RESEARCH);
setReticuleStats(RETBUT_RESEARCH);
break;
case IDRET_INTEL_MAP:
widgHide(psWScreen, IDRET_INTEL_MAP);
setReticuleStats(RETBUT_INTELMAP);
break;
case IDRET_DESIGN:
widgHide(psWScreen, IDRET_DESIGN);
setReticuleStats(RETBUT_DESIGN);
break;
case IDRET_CANCEL:
widgHide(psWScreen, IDRET_CANCEL);
setReticuleStats(RETBUT_CANCEL);
break;
default:
ASSERT(false, "Invalid reticule Button ID");
Expand Down