From 6a88e425805a8e5a3ce48133e09a431319522aab Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 27 Jun 2015 20:44:48 -0400 Subject: [PATCH] Add tooltip when hovering over any kind of link sign --- src/gui/game/GameController.cpp | 13 ++++++---- src/gui/game/GameView.cpp | 44 ++++++++++++++++++++++++++++----- src/gui/game/GameView.h | 2 +- src/gui/interface/Button.cpp | 2 +- src/gui/interface/Checkbox.cpp | 2 +- src/gui/interface/Window.h | 2 +- src/gui/render/RenderView.cpp | 2 +- src/gui/render/RenderView.h | 2 +- 8 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index c76a62f66..3a84a3a41 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -258,7 +258,8 @@ GameView * GameController::GetView() return gameView; } -sign * GameController::GetSignAt(int x, int y){ +sign * GameController::GetSignAt(int x, int y) +{ Simulation * sim = gameModel->GetSimulation(); for (std::vector::reverse_iterator iter = sim->signs.rbegin(), end = sim->signs.rend(); iter != end; ++iter) { @@ -604,7 +605,8 @@ bool GameController::MouseUp(int x, int y, unsigned button) if (!gameModel->GetActiveTool(0) || gameModel->GetActiveTool(0)->GetIdentifier() != "DEFAULT_UI_SIGN" || button != BUTTON_LEFT) //If it's not a sign tool or you are right/middle clicking { sign * foundSign = GetSignAt(x, y); - if(foundSign) { + if (foundSign) + { const char* str = foundSign->text.c_str(); char type; int pos = sign::splitsign(str, &type); @@ -616,7 +618,7 @@ bool GameController::MouseUp(int x, int y, unsigned button) char buff[256]; strcpy(buff, str+3); buff[pos-3] = 0; - switch (str[1]) + switch (type) { case 'c': { @@ -637,7 +639,8 @@ bool GameController::MouseUp(int x, int y, unsigned button) OpenSearch(buff); break; } - } else if (type == 'b') + } + else if (type == 'b') { Simulation * sim = gameModel->GetSimulation(); sim->create_part(-1, foundSign->x, foundSign->y, PT_SPRK); @@ -1119,7 +1122,7 @@ void GameController::OpenLocalSaveWindow(bool asCurrent) GameController * c; public: LocalSaveCallback(GameController * _c): c(_c) {} - virtual ~LocalSaveCallback() {}; + virtual ~LocalSaveCallback() {} virtual void FileSaved(SaveFile* file) { c->gameModel->SetSaveFile(file); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index f28565dbb..2aa1b934f 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -59,14 +59,14 @@ public: { if(toolTip2.length()>0 && GetParentWindow()) { - GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip2); + GetParentWindow()->ToolTip(Position, toolTip2); } } else if(x < splitPosition) { if(toolTip.length()>0 && GetParentWindow()) { - GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip); + GetParentWindow()->ToolTip(Position, toolTip); } } } @@ -1218,9 +1218,10 @@ void GameView::ExitPrompt() new ConfirmPrompt("You are about to quit", "Are you sure you want to exit the game?", new ExitConfirmation()); } -void GameView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip) +void GameView::ToolTip(ui::Point senderPosition, std::string toolTip) { - if(sender->Position.Y > Size.Y-17) + // buttom button tooltips + if (senderPosition.Y > Size.Y-17) { if (selectMode == PlaceSave || selectMode == SelectNone) { @@ -1228,14 +1229,16 @@ void GameView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::str isButtonTipFadingIn = true; } } - else if(sender->Position.X > Size.X-BARSIZE)// < Size.Y-(quickOptionButtons.size()+1)*16) + // quickoption and menu tooltips + else if(senderPosition.X > Size.X-BARSIZE)// < Size.Y-(quickOptionButtons.size()+1)*16) { this->toolTip = toolTip; - toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), sender->Position.Y+3); + toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), senderPosition.Y+3); if(toolTipPosition.Y+10 > Size.Y-MENUSIZE) toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), Size.Y-MENUSIZE-10); isToolTipFadingIn = true; } + // element tooltips else { this->toolTip = toolTip; @@ -1635,6 +1638,35 @@ void GameView::OnTick(float dt) { c->DrawLine(toolIndex, c->PointTranslate(drawPoint1), lineSnapCoords(c->PointTranslate(drawPoint1), currentMouse)); } + + sign * foundSign = c->GetSignAt(mousePosition.X, mousePosition.Y); + if (foundSign) + { + const char* str = foundSign->text.c_str(); + char type; + int pos = sign::splitsign(str, &type); + if (type == 'c' || type == 't' || type == 's') + { + char buff[256]; + strcpy(buff, str+3); + buff[pos-3] = 0; + std::stringstream tooltip; + switch (type) + { + case 'c': + tooltip << "Go to save ID:" << buff; + break; + case 't': + tooltip << "Open forum thread " << buff << " in browser"; + break; + case 's': + tooltip << "Search for " << buff; + break; + } + ToolTip(ui::Point(0, Size.Y), tooltip.str()); + } + } + if(introText) { introText -= int(dt)>0?((int)dt < 5? dt:5):1; diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index 63726a9c1..ce835bd04 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -177,7 +177,7 @@ public: void NotifyLastToolChanged(GameModel * sender); - virtual void ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip); + virtual void ToolTip(ui::Point senderPosition, std::string toolTip); virtual void OnMouseMove(int x, int y, int dx, int dy); virtual void OnMouseDown(int x, int y, unsigned button); diff --git a/src/gui/interface/Button.cpp b/src/gui/interface/Button.cpp index 31d00a74b..1f8984a5d 100644 --- a/src/gui/interface/Button.cpp +++ b/src/gui/interface/Button.cpp @@ -191,7 +191,7 @@ void Button::OnMouseHover(int x, int y) { if(Enabled && toolTip.length()>0 && GetParentWindow()) { - GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip); + GetParentWindow()->ToolTip(Position, toolTip); } } diff --git a/src/gui/interface/Checkbox.cpp b/src/gui/interface/Checkbox.cpp index c92a6520a..b26b5dc54 100644 --- a/src/gui/interface/Checkbox.cpp +++ b/src/gui/interface/Checkbox.cpp @@ -59,7 +59,7 @@ void Checkbox::OnMouseHover(int x, int y) { if(toolTip.length()>0 && GetParentWindow()) { - GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip); + GetParentWindow()->ToolTip(Position, toolTip); } } diff --git a/src/gui/interface/Window.h b/src/gui/interface/Window.h index 20a3bef3e..b9bf1e038 100644 --- a/src/gui/interface/Window.h +++ b/src/gui/interface/Window.h @@ -50,7 +50,7 @@ enum ChromeStyle // Remove a component from state. NOTE: This WILL free component from memory. void RemoveComponent(unsigned idx); - virtual void ToolTip(Component * sender, ui::Point mousePosition, std::string toolTip) {} + virtual void ToolTip(ui::Point senderPosition, std::string toolTip) {} virtual void DoInitialized(); virtual void DoExit(); diff --git a/src/gui/render/RenderView.cpp b/src/gui/render/RenderView.cpp index b7bec4606..c9a1cc393 100644 --- a/src/gui/render/RenderView.cpp +++ b/src/gui/render/RenderView.cpp @@ -410,7 +410,7 @@ void RenderView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bo } } -void RenderView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip) +void RenderView::ToolTip(ui::Point senderPosition, std::string toolTip) { this->toolTip = toolTip; this->isToolTipFadingIn = true; diff --git a/src/gui/render/RenderView.h b/src/gui/render/RenderView.h index 4cf8cf0da..85f4847c0 100644 --- a/src/gui/render/RenderView.h +++ b/src/gui/render/RenderView.h @@ -37,7 +37,7 @@ public: virtual void OnDraw(); virtual void OnTick(float dt); virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); - virtual void ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip); + virtual void ToolTip(ui::Point senderPosition, std::string toolTip); virtual ~RenderView(); };