Skip to content

Commit

Permalink
open reticule menu from JS API(rules.js)
Browse files Browse the repository at this point in the history
Add function to open reticule menu from JS API
Example rules.js addons (not included)

//Bind standart hotkey F1-F5 from rules.js
function eventKeyPressed(meta, key){
    switch(key){
        case 282:
            showReticuleWidget(1);
            break;
        case 283:
            showReticuleWidget(2);
            break;
        case 284:
            showReticuleWidget(3);
            break;
        case 285:
            showReticuleWidget(4);
            break;
        case 286:
            showReticuleWidget(5);
            break;
        case 287:
            showReticuleWidget(6);
            break;
    }
}

Removed typos
  • Loading branch information
EuPhobos authored and perim committed Jan 25, 2018
1 parent d49d9de commit 42db8f7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/hci.cpp
Expand Up @@ -4386,6 +4386,54 @@ void stopReticuleButtonFlash(UDWORD buttonID)
}
}

// show selected widget from reticule menu
void intShowWidget(int buttonID)
{
switch (buttonID)
{
case RETBUT_FACTORY:
intResetScreen(true);
widgSetButtonState(psWScreen, IDRET_MANUFACTURE, WBUT_CLICKLOCK);
intAddManufacture(nullptr);
reticuleCallback(RETBUT_FACTORY);
break;
case RETBUT_RESEARCH:
intResetScreen(true);
widgSetButtonState(psWScreen, IDRET_RESEARCH, WBUT_CLICKLOCK);
(void)intAddResearch(nullptr);
reticuleCallback(RETBUT_RESEARCH);
break;
case RETBUT_BUILD:
intResetScreen(true);
widgSetButtonState(psWScreen, IDRET_BUILD, WBUT_CLICKLOCK);
intAddBuild(nullptr);
reticuleCallback(RETBUT_BUILD);
break;
case RETBUT_DESIGN:
intResetScreen(true);
widgSetButtonState(psWScreen, IDRET_DESIGN, WBUT_CLICKLOCK);
/*add the power bar - for looks! */
intShowPowerBar();
intAddDesign(false);
intMode = INT_DESIGN;
reticuleCallback(RETBUT_DESIGN);
triggerEvent(TRIGGER_MENU_DESIGN_UP);
break;
case RETBUT_COMMAND:
intResetScreen(false);
widgSetButtonState(psWScreen, IDRET_COMMAND, WBUT_CLICKLOCK);
intAddCommand(nullptr);
reticuleCallback(RETBUT_COMMAND);
break;
default:
intResetScreen(false);
psCurrentMsg = nullptr;
reticuleCallback(RETBUT_CANCEL);
break;
}
}


//displays the Power Bar
void intShowPowerBar()
{
Expand Down
2 changes: 2 additions & 0 deletions src/hci.h
Expand Up @@ -365,6 +365,8 @@ void togglePowerBar();
void intShowPowerBar();
void intHidePowerBar();

void intShowWidget(int buttonID);

//hides the power bar from the display - regardless of what player requested!
void forceHidePowerBar();

Expand Down
10 changes: 10 additions & 0 deletions src/qtscriptfuncs.cpp
Expand Up @@ -3186,6 +3186,15 @@ static QScriptValue js_setReticuleButton(QScriptContext *context, QScriptEngine
return QScriptValue();
}

//-- \subsection{showReticuleWidget(id)} Open the reticule menu widget. (3.2.4+ only)
static QScriptValue js_showReticuleWidget(QScriptContext *context, QScriptEngine *engine)
{
int button = context->argument(0).toInt32();
SCRIPT_ASSERT(context, button >= 0 && button <= 6, "Invalid button %d", button);
intShowWidget(button);
return QScriptValue();
}

//-- \subsection{setReticuleFlash(id, flash)} Set reticule flash on or off. (3.2.3+ only)
static QScriptValue js_setReticuleFlash(QScriptContext *context, QScriptEngine *engine)
{
Expand Down Expand Up @@ -5644,6 +5653,7 @@ bool registerFunctions(QScriptEngine *engine, const QString& scriptName)
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("showReticuleWidget", engine->newFunction(js_showReticuleWidget));
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

0 comments on commit 42db8f7

Please sign in to comment.