Skip to content

Commit

Permalink
qtscript: Add setReticuleButton(id, tip, filename, filenameDown) to d…
Browse files Browse the repository at this point in the history
…efine the look of reticule UI buttons.
  • Loading branch information
perim committed Aug 2, 2013
1 parent 5bdc9c2 commit cd54d38
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 55 deletions.
8 changes: 8 additions & 0 deletions data/base/script/rules.js
Expand Up @@ -8,6 +8,14 @@ function eventGameInit()
{
setSky("texpages/page-25-sky-urban.png", 0.5, 10000.0);
}

setReticuleButton(0, _("Close"), "image_cancel_up.png", "image_cancel_down.png");
setReticuleButton(1, _("Manufacture (F1)"), "image_manufacture_up.png", "image_manufacture_down.png");
setReticuleButton(2, _("Research (F2)"), "image_research_up.png", "image_research_down.png");
setReticuleButton(3, _("Build (F3)"), "image_build_up.png", "image_build_down.png");
setReticuleButton(4, _("Design (F4)"), "image_design_up.png", "image_design_down.png");
setReticuleButton(5, _("Intelligence Display (F5)"), "image_intelmap_up.png", "image_intelmap_down.png");
setReticuleButton(6, _("Commanders (F6)"), "image_commanddroid_up.png", "image_commanddroid_down.png");
}

function eventStartLevel()
Expand Down
8 changes: 8 additions & 0 deletions data/mp/multiplay/skirmish/rules.js
Expand Up @@ -13,6 +13,14 @@ function eventGameInit()
{
receiveAllEvents(true);

setReticuleButton(0, _("Close"), "image_cancel_up.png", "image_cancel_down.png");
setReticuleButton(1, _("Manufacture (F1)"), "image_manufacture_up.png", "image_manufacture_down.png");
setReticuleButton(2, _("Research (F2)"), "image_research_up.png", "image_research_down.png");
setReticuleButton(3, _("Build (F3)"), "image_build_up.png", "image_build_down.png");
setReticuleButton(4, _("Design (F4)"), "image_design_up.png", "image_design_down.png");
setReticuleButton(5, _("Intelligence Display (F5)"), "image_intelmap_up.png", "image_intelmap_down.png");
setReticuleButton(6, _("Commanders (F6)"), "image_commanddroid_up.png", "image_commanddroid_down.png");

if (tilesetType != "ARIZONA")
{
setSky("texpages/page-25-sky-urban.png", 0.5, 10000.0);
Expand Down
52 changes: 18 additions & 34 deletions src/hci.cpp
Expand Up @@ -373,8 +373,6 @@ static DROID *CurrentDroid = NULL;
static DROID_TYPE CurrentDroidType = DROID_ANY;

/******************Power Bar Stuff!**************/
/* Add the power bars */
static bool intAddPower(void);

/* Set the shadow for the PowerBar */
static void intRunPower(void);
Expand Down Expand Up @@ -409,11 +407,22 @@ struct RETBUTSTATS
int downTime;
QString filename;
QString filenameDown;
QString tip;
int flashing;
int flashTime;
};
static RETBUTSTATS retbutstats[NUMRETBUTS];

void setReticuleStats(int ButId, QString tip, QString filename, QString filenameDown)
{
retbutstats[ButId].tip = tip;
retbutstats[ButId].filename = filename;
retbutstats[ButId].filenameDown = filenameDown;
retbutstats[ButId].downTime = 0;
retbutstats[ButId].flashing = 0;
retbutstats[ButId].flashTime = 0;
}

static void intDisplayReticuleButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset)
{
int x = xOffset + psWidget->x();
Expand Down Expand Up @@ -487,7 +496,7 @@ static void intDisplayReticuleButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yO

// Set the x,y members of a button widget initialiser given a reticule button index.
//
static void setReticuleBut(int ButId, QString tip, QString filename, QString filenameDown)
void setReticuleBut(int ButId)
{
/* Default button data */
W_BUTINIT sButInit;
Expand All @@ -498,14 +507,12 @@ static void setReticuleBut(int ButId, QString tip, QString filename, QString fil
sButInit.pDisplay = intDisplayReticuleButton;
sButInit.x = ReticuleOffsets[ButId].x + RETXOFFSET;
sButInit.y = ReticuleOffsets[ButId].y + RETYOFFSET;
sButInit.pTip = tip;
sButInit.pTip = retbutstats[ButId].tip;
sButInit.style = WBUT_SECONDARY;
sButInit.UserData = ButId;
retbutstats[ButId].downTime = 0;
retbutstats[ButId].flashing = 0;
retbutstats[ButId].flashTime = 0;
retbutstats[ButId].filename = filename;
retbutstats[ButId].filenameDown = filenameDown;
if (!widgAddButton(psWScreen, &sButInit))
{
debug(LOG_ERROR, "Failed to add reticule button");
Expand Down Expand Up @@ -561,21 +568,6 @@ bool intInitialise(void)

psWScreen = new W_SCREEN;

if (GetGameMode() == GS_NORMAL)
{

if (!intAddReticule())
{
debug(LOG_ERROR, "Couldn't create reticule widgets (Out of memory ?)");
return false;
}
if (!intAddPower())
{
debug(LOG_ERROR, "Couldn't create power Bar widget(Out of memory ?)");
return false;
}
}

/* Note the current screen state */
intMode = INT_NORMAL;

Expand Down Expand Up @@ -2762,22 +2754,14 @@ bool intAddReticule()
{
return true; // all fine
}

WIDGET *parent = psWScreen->psForm;

/* Create the basic form */
IntFormAnimated *retForm = new IntFormAnimated(parent, false);
retForm->id = IDRET_FORM;
retForm->setGeometry(RET_X, RET_Y, RET_FORMWIDTH, RET_FORMHEIGHT);

// normal reticule
setReticuleBut(RETBUT_COMMAND, _("Commanders (F6)"), "image_commanddroid_up.png", "image_commanddroid_down.png");
setReticuleBut(RETBUT_INTELMAP, _("Intelligence Display (F5)"), "image_intelmap_up.png", "image_intelmap_down.png");
setReticuleBut(RETBUT_FACTORY, _("Manufacture (F1)"), "image_manufacture_up.png", "image_manufacture_down.png");
setReticuleBut(RETBUT_DESIGN, _("Design (F4)"), "image_design_up.png", "image_design_down.png");
setReticuleBut(RETBUT_RESEARCH, _("Research (F2)"), "image_research_up.png", "image_research_down.png");
setReticuleBut(RETBUT_BUILD, _("Build (F3)"), "image_build_up.png", "image_build_down.png");
setReticuleBut(RETBUT_CANCEL, _("Close"), "image_cancel_up.png", "image_cancel_down.png");
for (int i = 0; i < NUMRETBUTS; i++)
{
setReticuleBut(i);
}
ReticuleUp = true;
return true;
}
Expand Down Expand Up @@ -2808,7 +2792,7 @@ void togglePowerBar(void)
}

/* Add the power bars to the screen */
bool intAddPower(void)
bool intAddPower()
{
W_BARINIT sBarInit;

Expand Down
6 changes: 4 additions & 2 deletions src/hci.h
Expand Up @@ -263,8 +263,10 @@ extern INT_RETVAL intRunWidgets(void);
extern void intDisplayWidgets(void);

/* Add the reticule widgets to the widget screen */
extern bool intAddReticule(void);
extern void intRemoveReticule(void);
bool intAddReticule();
bool intAddPower();
void intRemoveReticule();
void setReticuleStats(int ButId, QString tip, QString filename, QString filenameDown);

/* Set the map view point to the world coordinates x,y */
extern void intSetMapPos(UDWORD x, UDWORD y);
Expand Down
2 changes: 2 additions & 0 deletions src/init.cpp
Expand Up @@ -1221,6 +1221,8 @@ bool stageThreeInitialise(void)
eventFireCallbackTrigger((TRIGGER_TYPE)CALL_GAMEINIT);
triggerEvent(TRIGGER_GAME_INIT);
}
intAddReticule();
intAddPower();

return true;
}
Expand Down
39 changes: 20 additions & 19 deletions src/qtscriptfuncs.cpp
Expand Up @@ -2715,24 +2715,24 @@ static QScriptValue js_enableTemplate(QScriptContext *context, QScriptEngine *en
return QScriptValue();
}


//-- \subsection{addReticuleButton(button type)} Add reticule button. FIXME: This currently only works in tutorial.
//-- Valid parameters for this and \emph{removeReticuleButton}: MANUFACTURE, RESEARCH, BUILD, DESIGN, INTELMAP, COMMAND, CANCEL.
static QScriptValue js_addReticuleButton(QScriptContext *context, QScriptEngine *engine)
//-- \subsection{setReticuleButton(id, filename, filenameHigh, tooltip, callback)} Add reticule button. id is which
//-- button to change, where zero is zero is the middle button, then going clockwise from the uppermost
//-- button. filename is button graphics and filenameHigh is for highlighting. The tooltip is the text you see when you
//-- mouse over the button. Finally, the callback is which scripting function to call
static QScriptValue js_setReticuleButton(QScriptContext *context, QScriptEngine *engine)
{
int button = context->argument(0).toInt32();
SCRIPT_ASSERT(context, button != IDRET_OPTIONS, "Invalid button");
widgReveal(psWScreen, button);
SCRIPT_ASSERT(context, button >= 0 && button <= 6, "Invalid button %d", button);
QString tip = context->argument(1).toString();
QString file = context->argument(2).toString();
QString fileDown = context->argument(3).toString();
setReticuleStats(button, tip, file, fileDown);
return QScriptValue();
}

//-- \subsection{removeReticuleButton(button type)} Remove reticule button. FIXME: This currently only works in tutorial.
//-- \subsection{removeReticuleButton(button type)} Remove reticule button. DO NOT USE FOR ANYTHING.
static QScriptValue js_removeReticuleButton(QScriptContext *context, QScriptEngine *engine)
{
int button = context->argument(0).toInt32();
SCRIPT_ASSERT(context, button != IDRET_OPTIONS, "Invalid button");
// if (bInTutorial && bReset) intResetScreen(true);
widgHide(psWScreen, button);
return QScriptValue();
}

Expand Down Expand Up @@ -4486,7 +4486,8 @@ bool registerFunctions(QScriptEngine *engine, QString scriptName)
engine->globalObject().setProperty("setDesign", engine->newFunction(js_setDesign));
engine->globalObject().setProperty("enableTemplate", engine->newFunction(js_enableTemplate));
engine->globalObject().setProperty("setMiniMap", engine->newFunction(js_setMiniMap));
engine->globalObject().setProperty("addReticuleButton", engine->newFunction(js_addReticuleButton));
engine->globalObject().setProperty("setReticuleButton", engine->newFunction(js_setReticuleButton));
engine->globalObject().setProperty("addReticuleButton", engine->newFunction(js_removeReticuleButton)); // deprecated!!
engine->globalObject().setProperty("removeReticuleButton", engine->newFunction(js_removeReticuleButton));
engine->globalObject().setProperty("enableStructure", engine->newFunction(js_enableStructure));
engine->globalObject().setProperty("makeComponentAvailable", engine->newFunction(js_makeComponentAvailable));
Expand Down Expand Up @@ -4534,13 +4535,13 @@ bool registerFunctions(QScriptEngine *engine, QString scriptName)
engine->globalObject().setProperty("DORDER_STOP", DORDER_STOP, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("DORDER_REARM", DORDER_REARM, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("DORDER_RECYCLE", DORDER_RECYCLE, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("COMMAND", IDRET_COMMAND, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("BUILD", IDRET_BUILD, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("MANUFACTURE", IDRET_MANUFACTURE, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("RESEARCH", IDRET_RESEARCH, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("INTELMAP", IDRET_INTEL_MAP, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("DESIGN", IDRET_DESIGN, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("CANCEL", IDRET_CANCEL, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("COMMAND", IDRET_COMMAND, QScriptValue::ReadOnly | QScriptValue::Undeletable); // deprecated
engine->globalObject().setProperty("BUILD", IDRET_BUILD, QScriptValue::ReadOnly | QScriptValue::Undeletable); // deprecated
engine->globalObject().setProperty("MANUFACTURE", IDRET_MANUFACTURE, QScriptValue::ReadOnly | QScriptValue::Undeletable); // deprecated
engine->globalObject().setProperty("RESEARCH", IDRET_RESEARCH, QScriptValue::ReadOnly | QScriptValue::Undeletable); // deprecated
engine->globalObject().setProperty("INTELMAP", IDRET_INTEL_MAP, QScriptValue::ReadOnly | QScriptValue::Undeletable); // deprecated
engine->globalObject().setProperty("DESIGN", IDRET_DESIGN, QScriptValue::ReadOnly | QScriptValue::Undeletable); // deprecated
engine->globalObject().setProperty("CANCEL", IDRET_CANCEL, QScriptValue::ReadOnly | QScriptValue::Undeletable); // deprecated
engine->globalObject().setProperty("CAMP_CLEAN", CAMP_CLEAN, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("CAMP_BASE", CAMP_BASE, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("CAMP_WALLS", CAMP_WALLS, QScriptValue::ReadOnly | QScriptValue::Undeletable);
Expand Down

0 comments on commit cd54d38

Please sign in to comment.