Skip to content

Commit

Permalink
Simplify observer calls
Browse files Browse the repository at this point in the history
  • Loading branch information
pskelton committed Mar 25, 2024
1 parent 14b9a66 commit f4b2794
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Engine/EngineCallObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ enum class EngineCall {
CALL_PLAY_SOUND,
CALL_DRAW_2D_TEXTURE,
CALL_DRAW_MESSAGE_BOX,
CALL_DRAW_MESSAGE_BOX_TEXT,
CALL_DRAW_GUIWindow_TEXT,

CALL_FIRST = CALL_PLAY_SOUND,
CALL_LAST = CALL_DRAW_MESSAGE_BOX_TEXT
CALL_LAST = CALL_DRAW_GUIWindow_TEXT
};
using enum EngineCall;

Expand Down
14 changes: 4 additions & 10 deletions src/GUI/GUIWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ GUIButton *GUIWindow::GetControl(unsigned int uID) {
}

void GUIWindow::DrawMessageBox(bool inside_game_viewport) {
_isMessageBox = true;
if (engine->callObserver && !sHint.empty()) {
// TODO(pskelton): Derived Messagebox types for different kinds of popup boxes
if (engine->callObserver) {
engine->callObserver->notify(CALL_DRAW_MESSAGE_BOX, sHint);
_observerNotified = true;
}

int x = 0;
Expand Down Expand Up @@ -327,11 +326,6 @@ void GUIWindow::DrawShops_next_generation_time_string(Duration time) {

//----- (0044D406) --------------------------------------------------------
void GUIWindow::DrawTitleText(GUIFont *pFont, int horizontalMargin, int verticalMargin, Color color, const std::string &text, int lineSpacing) {
if (engine->callObserver && _isMessageBox && !_observerNotified) {
engine->callObserver->notify(CALL_DRAW_MESSAGE_BOX, text);
_observerNotified = true;
}

int width = this->uFrameWidth - horizontalMargin;
std::string resString = pFont->FitTextInAWindow(text, this->uFrameWidth, horizontalMargin);
std::istringstream stream(resString);
Expand All @@ -348,8 +342,8 @@ void GUIWindow::DrawTitleText(GUIFont *pFont, int horizontalMargin, int vertical

//----- (0044CE08) --------------------------------------------------------
void GUIWindow::DrawText(GUIFont *font, Pointi position, Color color, const std::string &text, int maxHeight, Color shadowColor) {
if (_isMessageBox && engine->callObserver) {
engine->callObserver->notify(CALL_DRAW_MESSAGE_BOX_TEXT, text);
if (engine->callObserver) {
engine->callObserver->notify(CALL_DRAW_GUIWindow_TEXT, text);
}
font->DrawText(this, position, color, text, maxHeight, shadowColor);
}
Expand Down
4 changes: 0 additions & 4 deletions src/GUI/GUIWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ class GUIWindow {
std::vector<GUIButton*> vButtons;

std::shared_ptr<Io::Mouse> mouse = nullptr;

// TODO(pskelton): message box as child type?
bool _isMessageBox = false;
bool _observerNotified = false;
};

class OnButtonClick : public GUIWindow {
Expand Down
4 changes: 2 additions & 2 deletions test/Bin/GameTest/GameTests_1500.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ GAME_TEST(Issues, Issue1519) {
// message box body text was displayed.
auto flatMessageBoxes = messageBoxesTape.flattened();
auto flatMessageBoxesBody = messageBoxesBody.flattened();
EXPECT_TRUE(flatMessageBoxes.front().starts_with("Baby Dragon"));
EXPECT_TRUE(flatMessageBoxesBody.front().starts_with("The Baby Dragon"));
EXPECT_GT(flatMessageBoxes.size(), 0);
EXPECT_GT(flatMessageBoxesBody.filtered([](const auto &s) { return s.starts_with("The Baby Dragon"); }).size(), 0);
}

GAME_TEST(Issues, Issue1524) {
Expand Down
2 changes: 1 addition & 1 deletion test/Testing/Game/CommonTapeRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ TestMultiTape<std::string> CommonTapeRecorder::messageBoxes() {
}

TestMultiTape<std::string> CommonTapeRecorder::messageBoxesText() {
return _controller->recordFunctionTape<std::string>(CALL_DRAW_MESSAGE_BOX_TEXT);
return _controller->recordFunctionTape<std::string>(CALL_DRAW_GUIWindow_TEXT);
}

0 comments on commit f4b2794

Please sign in to comment.