Add tooltip when hovering over any kind of link sign

This commit is contained in:
jacob1 2015-06-27 20:44:48 -04:00
parent d67cb4b582
commit 6a88e42580
8 changed files with 52 additions and 17 deletions

View File

@ -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)
{
@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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;

View File

@ -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();
};