Properly set and get GUI objects' style attribute in JS
This fixes tab buttons not playing sounds when pressed. Original patch by: Stan Amended patch reviewed by: Stan Differential Revision: https://code.wildfiregames.com/D3109 This was SVN commit r24270.
This commit is contained in:
parent
8b720117ee
commit
4928508dcd
@ -389,6 +389,19 @@ void CGUI::SetFocusedObject(IGUIObject* pObject)
|
||||
}
|
||||
}
|
||||
|
||||
void CGUI::SetObjectStyle(IGUIObject* pObject, const CStr& styleName)
|
||||
{
|
||||
// If the style is not recognised (or an empty string) then ApplyStyle will
|
||||
// emit an error message. Thus we don't need to handle it here.
|
||||
if (pObject->ApplyStyle(styleName))
|
||||
pObject->m_Style = styleName;
|
||||
}
|
||||
|
||||
void CGUI::UnsetObjectStyle(IGUIObject* pObject)
|
||||
{
|
||||
SetObjectStyle(pObject, "default");
|
||||
}
|
||||
|
||||
void CGUI::SetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag)
|
||||
{
|
||||
if (!hotkeyTag.empty())
|
||||
@ -599,18 +612,11 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
//
|
||||
// Always load default (if it's available) first!
|
||||
//
|
||||
SetObjectStyle(object, "default");
|
||||
|
||||
CStr argStyle(attributes.GetNamedItem(attr_style));
|
||||
|
||||
if (m_Styles.find("default") != m_Styles.end())
|
||||
object->LoadStyle("default");
|
||||
|
||||
if (!argStyle.empty())
|
||||
{
|
||||
if (m_Styles.find(argStyle) == m_Styles.end())
|
||||
LOGERROR("GUI: Trying to use style '%s' that doesn't exist.", argStyle.c_str());
|
||||
else
|
||||
object->LoadStyle(argStyle);
|
||||
}
|
||||
SetObjectStyle(object, argStyle);
|
||||
|
||||
bool NameSet = false;
|
||||
bool ManuallySetZ = false;
|
||||
|
@ -137,6 +137,12 @@ public:
|
||||
void SetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag);
|
||||
void UnsetObjectHotkey(IGUIObject* pObject, const CStr& hotkeyTag);
|
||||
|
||||
/**
|
||||
* Allows the JS side to modify the style setting assigned to a GUI object.
|
||||
*/
|
||||
void SetObjectStyle(IGUIObject* pObject, const CStr& styleName);
|
||||
void UnsetObjectStyle(IGUIObject* pObject);
|
||||
|
||||
/**
|
||||
* Allows the JS side to add or remove global hotkeys.
|
||||
*/
|
||||
|
@ -162,6 +162,8 @@ void IGUIObject::SettingChanged(const CStr& Setting, const bool SendMessage)
|
||||
}
|
||||
else if (Setting == "hotkey")
|
||||
m_pGUI.SetObjectHotkey(this, GetSetting<CStr>(Setting));
|
||||
else if (Setting == "style")
|
||||
m_pGUI.SetObjectStyle(this, GetSetting<CStr>(Setting));
|
||||
|
||||
if (SendMessage)
|
||||
{
|
||||
@ -267,10 +269,13 @@ void IGUIObject::UpdateCachedSize()
|
||||
}
|
||||
}
|
||||
|
||||
void IGUIObject::LoadStyle(const CStr& StyleName)
|
||||
bool IGUIObject::ApplyStyle(const CStr& StyleName)
|
||||
{
|
||||
if (!m_pGUI.HasStyle(StyleName))
|
||||
debug_warn(L"IGUIObject::LoadStyle failed");
|
||||
{
|
||||
LOGERROR("IGUIObject: Trying to use style '%s' that doesn't exist.", StyleName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// The default style may specify settings for any GUI object.
|
||||
// Other styles are reported if they specify a Setting that does not exist,
|
||||
@ -283,6 +288,7 @@ void IGUIObject::LoadStyle(const CStr& StyleName)
|
||||
else if (StyleName != "default")
|
||||
LOGWARNING("GUI object has no setting \"%s\", but the style \"%s\" defines it", p.first, StyleName.c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
float IGUIObject::GetBufferedZ() const
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -322,9 +322,12 @@ protected:
|
||||
virtual InReaction ManuallyHandleKeys(const SDL_Event_* UNUSED(ev)) { return IN_PASS; }
|
||||
|
||||
/**
|
||||
* Loads a style.
|
||||
* Applies the given style to the object.
|
||||
*
|
||||
* Returns false if the style is not recognised (and thus has
|
||||
* not been applied).
|
||||
*/
|
||||
void LoadStyle(const CStr& StyleName);
|
||||
bool ApplyStyle(const CStr& StyleName);
|
||||
|
||||
/**
|
||||
* Returns not the Z value, but the actual buffered Z value, i.e. if it's
|
||||
|
Loading…
Reference in New Issue
Block a user