mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
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 <ralph.sennhauser@gmail.com>
This commit is contained in:
parent
0c0552a428
commit
fcbc3d3f71
3 changed files with 25 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue