Skip to content

Commit

Permalink
fix #6086
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Nov 21, 2018
1 parent 89b4773 commit 2b68b17
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
15 changes: 8 additions & 7 deletions rts/Game/UI/MouseHandler.cpp
Expand Up @@ -145,6 +145,8 @@ void CMouseHandler::ReloadCursors()
cursorCommandMap.reserve(32);
cursorFileMap.clear();
cursorFileMap.reserve(32);
activeCursorName.clear();
queuedCursorName.clear();

cursorCommandMap["none"] = loadedCursors.size() - 1;
cursorFileMap["null"] = loadedCursors.size() - 1;
Expand Down Expand Up @@ -612,7 +614,7 @@ std::string CMouseHandler::GetCurrentTooltip() const

void CMouseHandler::Update()
{
SetCursor(newCursor);
SetCursor(queuedCursorName);

if (!hideCursor)
return;
Expand Down Expand Up @@ -717,26 +719,25 @@ void CMouseHandler::ToggleHwCursor(bool enable)
}

// force hardware cursor rebinding, otherwise we get a standard b&w cursor
cursorText = "none";
activeCursorName = "none";
}


/******************************************************************************/

void CMouseHandler::ChangeCursor(const std::string& cmdName, const float scale)
{
newCursor = cmdName;
queuedCursorName = cmdName;
cursorScale = scale;
}


void CMouseHandler::SetCursor(const std::string& cmdName, const bool forceRebind)
{
if ((cursorText == cmdName) && !forceRebind)
if ((activeCursorName == cmdName) && !forceRebind)
return;

cursorText = cmdName;
const auto it = cursorCommandMap.find(cmdName);
const auto it = cursorCommandMap.find(activeCursorName = cmdName);

if (it != cursorCommandMap.end()) {
activeCursorIdx = it->second;
Expand Down Expand Up @@ -973,7 +974,7 @@ bool CMouseHandler::ReplaceMouseCursor(

// update current cursor if necessary
if (activeCursorIdx == fileIt->second)
SetCursor(cursorText, true);
SetCursor(activeCursorName, true);

return true;
}
Expand Down
10 changes: 7 additions & 3 deletions rts/Game/UI/MouseHandler.h
Expand Up @@ -28,6 +28,10 @@ class CMouseHandler

void ChangeCursor(const std::string& cmdName, const float scale = 1.0f);
void ReloadCursors();
void ResetCursor() {
ChangeCursor("");
Update();
}

void Update();
void UpdateCursors();
Expand Down Expand Up @@ -67,7 +71,7 @@ class CMouseHandler

std::string GetCurrentTooltip() const;

const std::string& GetCurrentCursor() const { return newCursor; }
const std::string& GetCurrentCursor() const { return queuedCursorName; }
float GetCurrentCursorScale() const { return cursorScale; }

void ToggleHwCursor(bool enable);
Expand Down Expand Up @@ -143,8 +147,8 @@ class CMouseHandler
float3 dir;

private:
std::string newCursor; /// cursor changes are delayed
std::string cursorText; /// current cursor name
std::string queuedCursorName; /// cursor changes are delayed until Update
std::string activeCursorName; /// current cursor name

std::vector<CMouseCursor> loadedCursors;
spring::unordered_map<std::string, size_t> cursorFileMap;
Expand Down
12 changes: 9 additions & 3 deletions rts/Menu/LuaMenuController.cpp
Expand Up @@ -39,14 +39,20 @@ CLuaMenuController::~CLuaMenuController()
}


void CLuaMenuController::Reset()
bool CLuaMenuController::Reset()
{
if (!Valid())
return;
if (!Valid()) {
// if no LuaMenu, cursor will not be updated (again) until game exists so force a reset
// calling ReloadCursors here is not possible since no archives are loaded at this point
mouse->ResetCursor();
return false;
}

LOG("[LuaMenuController::%s] using menu archive \"%s\"", __func__, menuArchive.c_str());
vfsHandler->AddArchiveWithDeps(menuArchive, false);

mouse->ReloadCursors();
return true;
}

bool CLuaMenuController::Activate(const std::string& msg)
Expand Down
2 changes: 1 addition & 1 deletion rts/Menu/LuaMenuController.h
Expand Up @@ -13,7 +13,7 @@ class CLuaMenuController : public CGameController
~CLuaMenuController();

// Reloads the archives but not LuaMenu
void Reset();
bool Reset();
bool Activate(const std::string& msg);

static bool ActivateInstance(const std::string& msg);
Expand Down

0 comments on commit 2b68b17

Please sign in to comment.