Skip to content

Commit

Permalink
Add tooltip when hovering over any kind of link sign
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Jun 28, 2015
1 parent d67cb4b commit 6a88e42
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 17 deletions.
13 changes: 8 additions & 5 deletions src/gui/game/GameController.cpp
Expand Up @@ -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<sign>::reverse_iterator iter = sim->signs.rbegin(), end = sim->signs.rend(); iter != end; ++iter)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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':
{
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
44 changes: 38 additions & 6 deletions src/gui/game/GameView.cpp
Expand Up @@ -59,14 +59,14 @@ class SplitButton : public ui::Button
{
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);
}
}
}
Expand Down Expand Up @@ -1218,24 +1218,27 @@ 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)
{
buttonTip = toolTip;
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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/game/GameView.h
Expand Up @@ -177,7 +177,7 @@ class GameView: public ui::Window
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);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/interface/Button.cpp
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/interface/Checkbox.cpp
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/interface/Window.h
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/render/RenderView.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/render/RenderView.h
Expand Up @@ -37,7 +37,7 @@ class RenderView: public ui::Window {
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();
};

Expand Down

0 comments on commit 6a88e42

Please sign in to comment.