Skip to content

Commit

Permalink
Add in-game options button
Browse files Browse the repository at this point in the history
To trigger the in-game options / pause menu
  • Loading branch information
past-due committed Oct 25, 2024
1 parent 4468c15 commit bb62939
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 2 deletions.
2 changes: 2 additions & 0 deletions data/base/images/intfac.img
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,5 @@
0,0,image_indicator_dot.png
0,0,image_indicator_dot_expand.png
0,0,image_sidebar_list.png
0,0,image_ingameoptions_up.png
0,0,image_ingameoptions_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions src/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,9 +2148,123 @@ bool intShowGroupSelectionMenu()
return true;
}

class W_INGAMEOPTIONS_BUTTON : public W_BUTTON
{
protected:
W_INGAMEOPTIONS_BUTTON()
{ }
void initialize();
public:
static std::shared_ptr<W_INGAMEOPTIONS_BUTTON> make();

void display(int xOffset, int yOffset) override;
std::string getTip() override;
};

std::shared_ptr<W_INGAMEOPTIONS_BUTTON> W_INGAMEOPTIONS_BUTTON::make()
{
class make_shared_enabler: public W_INGAMEOPTIONS_BUTTON {};
auto widget = std::make_shared<make_shared_enabler>();
widget->initialize();
return widget;
}

void W_INGAMEOPTIONS_BUTTON::initialize()
{
id = IDRET_OPTIONS;
setGeometry(0, 0, RET_BUTWIDTH, RET_BUTHEIGHT);
}

void W_INGAMEOPTIONS_BUTTON::display(int xOffset, int yOffset)
{
const int x0 = xOffset + x();
const int y0 = yOffset + y();
bool butDisabled = getState() & WBUT_DISABLE;

if (butDisabled)
{
iV_DrawImage2("image_reticule_grey.png", x0, y0, width(), height());
return;
}

bool Down = getState() & (WBUT_DOWN | WBUT_CLICKLOCK);
if (Down)
{
iV_DrawImage2("image_ingameoptions_down.png", x0, y0, width(), height());
}
else
{
iV_DrawImage2("image_ingameoptions_up.png", x0, y0, width(), height());
}

bool highlighted = ((getState() & WBUT_HIGHLIGHT) != 0) || InGameOpUp;
if (highlighted)
{
iV_DrawImage2("image_reticule_hilight.png", x0, y0, width(), height());
}
}

std::string W_INGAMEOPTIONS_BUTTON::getTip()
{
if (!InGameOpUp)
{
return _("Open In-Game Options");
}
else
{
return _("Close In-Game Options");
}
}

bool intAddInGameOptionsButton()
{
auto psExistingBut = widgGetFromID(psWScreen, IDRET_OPTIONS);
if (psExistingBut != nullptr)
{
psExistingBut->show();
return false;
}

auto button = W_INGAMEOPTIONS_BUTTON::make();
if (!button)
{
debug(LOG_ERROR, "Failed to create in game options button");
}
else
{
psWScreen->psForm->attach(button);
setReticuleButtonDimensions(*button, "image_ingameoptions_up.png");
button->setCalcLayout(LAMBDA_CALCLAYOUT_SIMPLE({
int w = psWidget->width();
int h = psWidget->height();
int x0 = screenWidth - (w + 16);
int y0 = 18;
psWidget->setGeometry(x0, y0, w, h);
}));
button->addOnClickHandler([](W_BUTTON&) {
widgScheduleTask([](){
kf_addInGameOptions();
});
});
}

return true;
}

void intHideInGameOptionsButton()
{
auto psOptionsBut = widgGetFromID(psWScreen, IDRET_OPTIONS);
if (psOptionsBut != nullptr)
{
psOptionsBut->hide();
}
}

/* Add the reticule widgets to the widget screen */
bool intAddReticule()
{
intAddInGameOptionsButton();

if (ReticuleUp)
{
return true; // all fine
Expand Down
1 change: 1 addition & 0 deletions src/hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ bool intAddReticule();
bool intShowGroupSelectionMenu();
bool intAddPower();
void intRemoveReticule();
void intHideInGameOptionsButton();
void setReticuleStats(int ButId, std::string tip = std::string(), std::string filename = std::string(), std::string filenameDown = std::string(), const playerCallbackFunc& callbackFunc = nullptr);
void setReticulesEnabled(bool enabled);
void setReticuleFlash(int ButId, bool flash);
Expand Down
4 changes: 3 additions & 1 deletion src/intfac.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,9 @@ enum INTFAC_TYPE
IMAGE_BUT_INNER_GLOW,
IMAGE_INDICATOR_DOT,
IMAGE_INDICATOR_DOT_EXPAND,
IMAGE_INTFAC_SIDEBAR_LIST
IMAGE_INTFAC_SIDEBAR_LIST,
IMAGE_INGAMEOPTIONS_UP,
IMAGE_INGAMEOPTIONS_DOWN,
};

#endif //__INCLUDED_SRC_INTFAC_H__
1 change: 1 addition & 0 deletions src/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ bool addLoadSave(LOADSAVE_MODE savemode, const char *title)

forceHidePowerBar();
intRemoveReticule();
intHideInGameOptionsButton();
intHideGroupSelectionMenu();
}

Expand Down
3 changes: 2 additions & 1 deletion src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ bool intAddMissionTimer()
sFormInit.x = (SWORD)(RADTLX + RADWIDTH - sFormInit.width);
sFormInit.y = (SWORD)TIMER_Y;
sFormInit.calcLayout = LAMBDA_CALCLAYOUT_SIMPLE({
psWidget->move((SWORD)(RADTLX + RADWIDTH - psWidget->width()), TIMER_Y);
psWidget->move((SWORD)(RADTLX + RADWIDTH - psWidget->width() - 18), TIMER_Y);
});
sFormInit.UserData = PACKDWORD_TRI(0, IMAGE_MISSION_CLOCK, IMAGE_MISSION_CLOCK_UP);
sFormInit.pDisplay = intDisplayMissionClock;
Expand Down Expand Up @@ -2287,6 +2287,7 @@ static void missionResetInGameState()
intRemoveReticule();
intRemoveMissionTimer();
intRemoveTransporterTimer();
intHideInGameOptionsButton();
intHideGroupSelectionMenu();
}

Expand Down
1 change: 1 addition & 0 deletions src/multiopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ bool multiStartScreenInit()
bDisplayMultiJoiningStatus = 1; // always display this
gameTimeStop();
intHideInterface(true);
intHideInGameOptionsButton();
createGameStartScreen([] {
// on game start overlay screen close...
bDisplayMultiJoiningStatus = 0;
Expand Down

0 comments on commit bb62939

Please sign in to comment.