From fcbc3d3f7112612772d3d82f30dec0870f481d80 Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Sat, 30 May 2026 18:36:07 +0200 Subject: [PATCH] Limit max PlayerID in Atlas hotkeys 9 isn't a valid playerID, setting this value causes a JS error and corrupting the viewport. Further limit selectable max playerID to what the mapSettings say. Signed-off-by: Ralph Sennhauser --- .../ScenarioEditor/Tools/ActorViewerTool.cpp | 10 +++++++--- .../AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp | 14 +++++++++----- .../ScenarioEditor/Tools/TransformObject.cpp | 14 +++++++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/ActorViewerTool.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/ActorViewerTool.cpp index 04acb7d93c..e7955c6d95 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/ActorViewerTool.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/ActorViewerTool.cpp @@ -164,14 +164,18 @@ public: bool OnKey(ActorViewerTool* obj, wxKeyEvent& evt, KeyEventType type) { - if (type == KEY_DOWN && (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '9')) + if (type == KEY_DOWN && (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '8')) { // (TODO: this should probably be 'char' not 'down'; but we don't get // 'char' unless we return false from this function, in which case the // scenario editor intercepts some other keys for itself) + const int maxPlayerID = obj->GetScenarioEditor().GetMapSettings()["PlayerData"]["item"].count(); int playerID = evt.GetKeyCode() - '0'; - obj->GetScenarioEditor().GetObjectSettings().SetPlayerID(playerID); - obj->GetScenarioEditor().GetObjectSettings().NotifyObservers(); + if (playerID <= maxPlayerID) + { + obj->GetScenarioEditor().GetObjectSettings().SetPlayerID(playerID); + obj->GetScenarioEditor().GetObjectSettings().NotifyObservers(); + } } // Prevent keys from passing through to the scenario editor diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp index 2137f7fe47..108d288fba 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp @@ -189,12 +189,16 @@ public: } bool OnKey(PlaceObject* obj, wxKeyEvent& evt, KeyEventType type) { - if (type == KEY_CHAR && (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '9')) + if (type == KEY_CHAR && (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '8')) { - int playerID = evt.GetKeyCode() - '0'; - obj->GetScenarioEditor().GetObjectSettings().SetPlayerID(playerID); - obj->GetScenarioEditor().GetObjectSettings().NotifyObservers(); - obj->SendObjectMsg(true); + const int maxPlayerID = obj->GetScenarioEditor().GetMapSettings()["PlayerData"]["item"].count(); + const int playerID = evt.GetKeyCode() - '0'; + if (playerID <= maxPlayerID) + { + obj->GetScenarioEditor().GetObjectSettings().SetPlayerID(playerID); + obj->GetScenarioEditor().GetObjectSettings().NotifyObservers(); + obj->SendObjectMsg(true); + } return true; } else diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp index b9b6ddefde..1324fb65df 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -344,11 +344,15 @@ public: POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects)); return true; } - else if (type == KEY_CHAR && (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '9')) + else if (type == KEY_CHAR && (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '8')) { - int playerID = evt.GetKeyCode() - '0'; - obj->GetScenarioEditor().GetObjectSettings().SetPlayerID(playerID); - obj->GetScenarioEditor().GetObjectSettings().NotifyObservers(); + const int maxPlayerID = obj->GetScenarioEditor().GetMapSettings()["PlayerData"]["item"].count(); + const int playerID = evt.GetKeyCode() - '0'; + if (playerID <= maxPlayerID) + { + obj->GetScenarioEditor().GetObjectSettings().SetPlayerID(playerID); + obj->GetScenarioEditor().GetObjectSettings().NotifyObservers(); + } return true; } else if (evt.GetModifiers() == wxMOD_CONTROL)