Implement JS support for GUI object "hotkey" setting missing from 6d8b9e33ef, refs #567, #2604, 9e499cdec5.

Allows JS GUI to assign hotkeys to GUI objects from JS instead of XML.

Differential Revision: https://code.wildfiregames.com/D2257
Comments By: nani
Tested By: nani, Jenkins
Tested on: clang, VS2015

This was SVN commit r22845.
This commit is contained in:
elexis 2019-09-04 15:29:36 +00:00
parent 0d47644b08
commit 33af6da5e1
4 changed files with 39 additions and 10 deletions

View file

@ -466,6 +466,28 @@ void CGUI::SetFocusedObject(IGUIObject* pObject)
}
}
void CGUI::SetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag)
{
if (!hotkeyTag.empty())
m_HotkeyObjects[hotkeyTag].push_back(pObject);
}
void CGUI::UnsetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag)
{
if (hotkeyTag.empty())
return;
std::vector<IGUIObject*>& assignment = m_HotkeyObjects[hotkeyTag];
assignment.erase(
std::remove_if(
assignment.begin(),
assignment.end(),
[&pObject](const IGUIObject* hotkeyObject)
{ return pObject == hotkeyObject; }),
assignment.end());
}
const SGUIScrollBarStyle* CGUI::GetScrollBarStyle(const CStr& style) const
{
std::map<CStr, const SGUIScrollBarStyle>::const_iterator it = m_ScrollBarStyles.find(style);
@ -603,7 +625,6 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
ATTR(style);
ATTR(type);
ATTR(name);
ATTR(hotkey);
ATTR(z);
ATTR(on);
ATTR(file);
@ -635,7 +656,6 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
bool ManuallySetZ = false;
CStrW inclusionPath;
CStr hotkeyTag;
for (XMBAttribute attr : attributes)
{
@ -659,9 +679,6 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
continue;
}
if (attr.Name == attr_hotkey)
hotkeyTag = attr.Value;
if (attr.Name == attr_z)
ManuallySetZ = true;
@ -679,9 +696,6 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
++m_InternalNameNumber;
}
if (!hotkeyTag.empty())
m_HotkeyObjects[hotkeyTag].push_back(object);
CStrW caption(Element.GetText().FromUTF8());
if (!caption.empty())
object->SetSettingFromString("caption", caption, false);

View file

@ -147,6 +147,12 @@ public:
*/
void LoadXmlFile(const VfsPath& Filename, boost::unordered_set<VfsPath>& Paths);
/**
* Allows the JS side to modify the hotkey setting assigned to a GUI object.
*/
void SetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag);
void UnsetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag);
/**
* Return the object which is an ancestor of every other GUI object.
*/
@ -625,8 +631,6 @@ private:
* Map from hotkey names to objects that listen to the hotkey.
* (This is an optimisation to avoid recursing over the whole GUI
* tree every time a hotkey is pressed).
* Currently this is only set at load time - dynamic changes to an
* object's hotkey property will be ignored.
*/
std::map<CStr, std::vector<IGUIObject*> > m_HotkeyObjects;

View file

@ -154,6 +154,7 @@ bool IGUIObject::SetSettingFromString(const CStr& Setting, const CStrW& Value, c
template <typename T>
void IGUIObject::SetSetting(const CStr& Setting, T& Value, const bool SendMessage)
{
PreSettingChange(Setting);
static_cast<CGUISetting<T>* >(m_Settings[Setting])->m_pSetting = std::move(Value);
SettingChanged(Setting, SendMessage);
}
@ -161,10 +162,17 @@ void IGUIObject::SetSetting(const CStr& Setting, T& Value, const bool SendMessag
template <typename T>
void IGUIObject::SetSetting(const CStr& Setting, const T& Value, const bool SendMessage)
{
PreSettingChange(Setting);
static_cast<CGUISetting<T>* >(m_Settings[Setting])->m_pSetting = Value;
SettingChanged(Setting, SendMessage);
}
void IGUIObject::PreSettingChange(const CStr& Setting)
{
if (Setting == "hotkey")
m_pGUI.UnsetObjectHotkey(this, GetSetting<CStr>(Setting));
}
void IGUIObject::SettingChanged(const CStr& Setting, const bool SendMessage)
{
if (Setting == "size")
@ -178,6 +186,8 @@ void IGUIObject::SettingChanged(const CStr& Setting, const bool SendMessage)
if (GetSetting<bool>(Setting))
RecurseObject(nullptr, &IGUIObject::ResetStates);
}
else if (Setting == "hotkey")
m_pGUI.SetObjectHotkey(this, GetSetting<CStr>(Setting));
if (SendMessage)
{

View file

@ -428,6 +428,7 @@ private:
/**
* Updates some internal data depending on the setting changed.
*/
void PreSettingChange(const CStr& Setting);
void SettingChanged(const CStr& Setting, const bool SendMessage);
/**