Skip to content

Commit 08552bf

Browse files
committed
Replaced MapViewState::mTooltipSystemButton with GameViewContainer::mGameOptionsButton
1 parent 51824ee commit 08552bf

6 files changed

+16
-27
lines changed

appOPHD/States/MapViewState.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,6 @@ void MapViewState::onMouseDown(NAS2D::MouseButton button, NAS2D::Point<int> posi
553553

554554
if (button == NAS2D::MouseButton::Left)
555555
{
556-
if (mTooltipSystemButton.area().contains(MOUSE_COORDS))
557-
{
558-
onSystemMenu();
559-
}
560-
561556
const auto oldDepth = mMapView->currentDepth();
562557
mNavControl->onClick(MOUSE_COORDS);
563558
if (oldDepth != mMapView->currentDepth())
@@ -729,12 +724,6 @@ void MapViewState::onClickMap()
729724
}
730725

731726

732-
void MapViewState::onSystemMenu()
733-
{
734-
mGameOptionsDialog.show();
735-
resetUi();
736-
}
737-
738727
/**
739728
* Handle side effects of changing depth view
740729
*/

appOPHD/States/MapViewState.h

-3
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ class MapViewState : public Wrapper
151151

152152
void onClickMap();
153153

154-
void onSystemMenu();
155-
156154
// ROBOT EVENT HANDLERS
157155
void onDozerTaskComplete(Robot& robot);
158156
void onDiggerTaskComplete(Robot& robot);
@@ -348,7 +346,6 @@ class MapViewState : public Wrapper
348346
Button mBtnTogglePoliceOverlay;
349347

350348
// Bare Control's use for ToolTips
351-
Control mTooltipSystemButton;
352349
Control mTooltipCurrentTurns;
353350

354351
ToolTip mToolTip;

appOPHD/States/MapViewStateDraw.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,13 @@ void MapViewState::drawSystemButton() const
2525
{
2626
auto& renderer = NAS2D::Utility<NAS2D::Renderer>::get();
2727

28-
auto position = NAS2D::Point{renderer.size().x - 80, constants::MarginTight};
28+
auto xOffsetFromRight = 100;
29+
auto position = NAS2D::Point{renderer.size().x - xOffsetFromRight, constants::MarginTight};
2930
constexpr auto textOffset = NAS2D::Vector{constants::ResourceIconSize + constants::Margin, 3 - constants::MarginTight};
3031

3132
// Turns
3233
const auto turnImageRect = NAS2D::Rectangle<int>{{128, 0}, {constants::ResourceIconSize, constants::ResourceIconSize}};
3334
renderer.drawSubImage(mUiIcons, position, turnImageRect);
3435
const auto& font = Control::getDefaultFont();
3536
renderer.drawText(font, std::to_string(mTurnCount), position + textOffset, NAS2D::Color::White);
36-
37-
position = mTooltipSystemButton.area().position + NAS2D::Vector{constants::MarginTight, constants::MarginTight};
38-
bool isMouseInMenu = mTooltipSystemButton.area().contains(MOUSE_COORDS);
39-
int menuGearHighlightOffsetX = isMouseInMenu ? 144 : 128;
40-
const auto menuImageRect = NAS2D::Rectangle<int>{{menuGearHighlightOffsetX, 32}, {constants::ResourceIconSize, constants::ResourceIconSize}};
41-
renderer.drawSubImage(mUiIcons, position, menuImageRect);
4237
}

appOPHD/States/MapViewStateUi.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ void MapViewState::initUi()
164164
constexpr auto hudHeight = constants::ResourceIconSize + constants::MarginTight * 2;
165165

166166
mTooltipCurrentTurns.size({45, hudHeight});
167-
mTooltipSystemButton.size({hudHeight, hudHeight});
168167

169168
// Tool Tips
170169
mToolTip.add(mBtnTurns, constants::ToolTipBtnTurns);
@@ -174,7 +173,6 @@ void MapViewState::initUi()
174173
mToolTip.add(mBtnToggleRouteOverlay, constants::ToolTipBtnRoutes);
175174
mToolTip.add(mBtnTogglePoliceOverlay, constants::ToolTipBtnPolice);
176175
mToolTip.add(mTooltipCurrentTurns, constants::ToolTipCurrentTurns);
177-
mToolTip.add(mTooltipSystemButton, constants::ToolTipSystemMenu);
178176
}
179177

180178

@@ -187,7 +185,6 @@ void MapViewState::setupUiPositions(NAS2D::Vector<int> size)
187185
mBottomUiRect = {{0, size.y - constants::BottomUiHeight}, {size.x, constants::BottomUiHeight}};
188186

189187
// Menu / System Icon
190-
mTooltipSystemButton.position({size.x - (constants::ResourceIconSize + constants::MarginTight * 2), 0});
191188
mTooltipCurrentTurns.position({size.x - 80 , 0});
192189

193190
mRobotDeploymentSummary.area({{8, size.y - constants::BottomUiHeight - 8 - 100}, {200, 100}});

appOPHD/UI/GameViewContainer.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
#include "../States/GameState.h"
44

5-
GameViewContainer::GameViewContainer(GameState& gameState) :
6-
UIContainer{{&mFileIoDialog}},
7-
mFileIoDialog{gameState.fileLoadDelegate(), gameState.fileSaveDelegate()}
5+
GameViewContainer::GameViewContainer(GameState& gameState) :
6+
UIContainer{{&mFileIoDialog, &mGameOptionsDialog, &mGameOptionsButton}},
7+
mFileIoDialog{gameState.fileLoadDelegate(), gameState.fileSaveDelegate()},
8+
mGameOptionsButton{"Menu", {this, &GameViewContainer::onGameOptionsButton}}
89
{
910
mGameOptionsDialog.hide();
1011

@@ -17,6 +18,13 @@ GameViewContainer::GameViewContainer(GameState& gameState) :
1718
const auto rendererCenter = NAS2D::Utility<NAS2D::Renderer>::get().center().to<int>();
1819
const auto centerPosition = [&rendererCenter](const Control& control) { return (rendererCenter - control.size() / 2); };
1920
mFileIoDialog.position(NAS2D::Point{centerPosition(mFileIoDialog).x, centerPosition(mFileIoDialog).y});
21+
22+
constexpr auto hudHeight = constants::ResourceIconSize + constants::MarginTight * 2;
23+
const auto rendererSize = NAS2D::Utility<NAS2D::Renderer>::get().size();
24+
const auto gameOptionsButtonSize = getDefaultFont().size(mGameOptionsButton.text());
25+
26+
mGameOptionsButton.size({gameOptionsButtonSize.x + constants::Margin, hudHeight});
27+
mGameOptionsButton.position({rendererSize.x - mGameOptionsButton.size().x, constants::MarginTight / 2});
2028
}
2129

2230

appOPHD/UI/GameViewContainer.h

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "GameOptionsDialog.h"
55

66
#include "../Constants/Strings.h"
7+
#include "../Constants/UiConstants.h"
78

89
#include <libControls/UIContainer.h>
910
#include <libControls/Button.h>
@@ -18,8 +19,10 @@ class GameViewContainer : public UIContainer
1819
GameOptionsDialog& gameOptionsDialog() { return mGameOptionsDialog; }
1920

2021
private:
22+
void onGameOptionsButton() { mGameOptionsDialog.show(); }
2123
void showSaveDialog() { mGameOptionsDialog.hide(); mFileIoDialog.showSave(constants::SaveGamePath); }
2224
void showLoadDialog() { mGameOptionsDialog.hide(); mFileIoDialog.showOpen(constants::SaveGamePath); }
2325
FileIo mFileIoDialog;
2426
GameOptionsDialog mGameOptionsDialog;
27+
Button mGameOptionsButton;
2528
};

0 commit comments

Comments
 (0)