2019-07-26 11:57:28 -07:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-06-03 11:38:14 -07:00
|
|
|
#include "precompiled.h"
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "GUIutil.h"
|
2005-02-04 23:25:16 -08:00
|
|
|
|
2019-07-26 11:57:28 -07:00
|
|
|
#include "gui/GUI.h"
|
|
|
|
|
#include "gui/GUIManager.h"
|
2009-09-27 08:04:46 -07:00
|
|
|
#include "ps/CLogger.h"
|
2003-11-05 16:21:45 -08:00
|
|
|
|
2019-08-03 19:20:08 -07:00
|
|
|
template<typename T>
|
|
|
|
|
CGUISetting<T>::CGUISetting(IGUIObject& pObject, const CStr& Name)
|
|
|
|
|
: m_pSetting(T()), m_Name(Name), m_pObject(pObject)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
bool CGUISetting<T>::FromString(const CStrW& Value, const bool& SkipMessage)
|
|
|
|
|
{
|
|
|
|
|
T settingValue;
|
|
|
|
|
|
|
|
|
|
if (!GUI<T>::ParseString(Value, settingValue))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
GUI<T>::SetSetting(&m_pObject, m_Name, settingValue, SkipMessage);
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
bool CGUISetting<T>::FromJSVal(JSContext* cx, JS::HandleValue Value)
|
|
|
|
|
{
|
|
|
|
|
T settingValue;
|
|
|
|
|
if (!ScriptInterface::FromJSVal<T>(cx, Value, settingValue))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
GUI<T>::SetSetting(&m_pObject, m_Name, settingValue);
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
void CGUISetting<T>::ToJSVal(JSContext* cx, JS::MutableHandleValue Value)
|
|
|
|
|
{
|
|
|
|
|
ScriptInterface::ToJSVal<T>(cx, Value, m_pSetting);
|
|
|
|
|
};
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<bool>(const CStrW& Value, bool& Output)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2010-05-30 06:11:32 -07:00
|
|
|
if (Value == L"true")
|
2004-05-28 21:06:50 -07:00
|
|
|
Output = true;
|
2015-08-21 10:08:41 -07:00
|
|
|
else if (Value == L"false")
|
2004-05-28 21:06:50 -07:00
|
|
|
Output = false;
|
2015-08-21 10:08:41 -07:00
|
|
|
else
|
2004-05-28 21:06:50 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<int>(const CStrW& Value, int& Output)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
|
|
|
|
Output = Value.ToInt();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-25 14:26:31 -08:00
|
|
|
template <>
|
|
|
|
|
bool __ParseString<u32>(const CStrW& Value, u32& Output)
|
|
|
|
|
{
|
|
|
|
|
Output = Value.ToUInt();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<float>(const CStrW& Value, float& Output)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
|
|
|
|
Output = Value.ToFloat();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<CRect>(const CStrW& Value, CRect& Output)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2014-05-24 20:16:52 -07:00
|
|
|
const unsigned int NUM_COORDS = 4;
|
|
|
|
|
float coords[NUM_COORDS];
|
|
|
|
|
std::wstringstream stream;
|
|
|
|
|
stream.str(Value);
|
|
|
|
|
// Parse each coordinate
|
2015-08-21 10:08:41 -07:00
|
|
|
for (unsigned int i = 0; i < NUM_COORDS; ++i)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2014-05-24 20:16:52 -07:00
|
|
|
if (stream.eof())
|
|
|
|
|
{
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGWARNING("Too few CRect parameters (min %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2014-05-24 20:16:52 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
stream >> coords[i];
|
|
|
|
|
if ((stream.rdstate() & std::wstringstream::failbit) != 0)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGWARNING("Unable to parse CRect parameters. Your input: '%s'", Value.ToUTF8().c_str());
|
2004-05-28 21:06:50 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-24 20:16:52 -07:00
|
|
|
if (!stream.eof())
|
|
|
|
|
{
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGWARNING("Too many CRect parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2014-05-24 20:16:52 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
// Finally the rectangle values
|
2014-05-24 20:16:52 -07:00
|
|
|
Output = CRect(coords[0], coords[1], coords[2], coords[3]);
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<CClientArea>(const CStrW& Value, CClientArea& Output)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2011-02-17 12:08:20 -08:00
|
|
|
return Output.SetClientArea(Value.ToUTF8());
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
2019-07-26 11:57:28 -07:00
|
|
|
bool GUI<int>::ParseColor(const CStrW& Value, CGUIColor& Output, int DefaultAlpha)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2011-02-17 12:08:20 -08:00
|
|
|
return Output.ParseString(Value.ToUTF8(), DefaultAlpha);
|
2004-05-28 21:06:50 -07:00
|
|
|
}
|
|
|
|
|
|
2005-01-03 14:23:27 -08:00
|
|
|
template <>
|
2019-07-26 11:57:28 -07:00
|
|
|
bool __ParseString<CGUIColor>(const CStrW& Value, CGUIColor& Output)
|
2005-01-03 14:23:27 -08:00
|
|
|
{
|
2014-06-03 17:58:05 -07:00
|
|
|
return Output.ParseString(Value.ToUTF8());
|
2005-01-03 14:23:27 -08:00
|
|
|
}
|
|
|
|
|
|
2004-08-30 19:09:58 -07:00
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<CSize>(const CStrW& Value, CSize& Output)
|
2004-08-30 19:09:58 -07:00
|
|
|
{
|
2014-05-24 20:16:52 -07:00
|
|
|
const unsigned int NUM_COORDS = 2;
|
|
|
|
|
float coords[NUM_COORDS];
|
|
|
|
|
std::wstringstream stream;
|
|
|
|
|
stream.str(Value);
|
|
|
|
|
// Parse each coordinate
|
2015-08-21 10:08:41 -07:00
|
|
|
for (unsigned int i = 0; i < NUM_COORDS; ++i)
|
2004-08-30 19:09:58 -07:00
|
|
|
{
|
2014-05-24 20:16:52 -07:00
|
|
|
if (stream.eof())
|
|
|
|
|
{
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGWARNING("Too few CSize parameters (min %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2014-05-24 20:16:52 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
stream >> coords[i];
|
|
|
|
|
if ((stream.rdstate() & std::wstringstream::failbit) != 0)
|
|
|
|
|
{
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGWARNING("Unable to parse CSize parameters. Your input: '%s'", Value.ToUTF8().c_str());
|
2014-05-24 20:16:52 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2004-08-30 19:09:58 -07:00
|
|
|
}
|
|
|
|
|
|
2014-05-24 20:16:52 -07:00
|
|
|
Output.cx = coords[0];
|
|
|
|
|
Output.cy = coords[1];
|
2004-08-30 19:09:58 -07:00
|
|
|
|
2014-05-24 20:16:52 -07:00
|
|
|
if (!stream.eof())
|
2004-08-30 19:09:58 -07:00
|
|
|
{
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGWARNING("Too many CSize parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2004-08-30 19:09:58 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-21 05:37:24 -08:00
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<CPos>(const CStrW& Value, CPos& Output)
|
2004-12-21 05:37:24 -08:00
|
|
|
{
|
2014-05-24 20:16:52 -07:00
|
|
|
const unsigned int NUM_COORDS = 2;
|
|
|
|
|
float coords[NUM_COORDS];
|
|
|
|
|
std::wstringstream stream;
|
|
|
|
|
stream.str(Value);
|
|
|
|
|
// Parse each coordinate
|
2015-08-21 10:08:41 -07:00
|
|
|
for (unsigned int i = 0; i < NUM_COORDS; ++i)
|
2014-05-24 20:16:52 -07:00
|
|
|
{
|
|
|
|
|
if (stream.eof())
|
|
|
|
|
{
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGWARNING("Too few CPos parameters (min %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2014-05-24 20:16:52 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
stream >> coords[i];
|
|
|
|
|
if ((stream.rdstate() & std::wstringstream::failbit) != 0)
|
|
|
|
|
{
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGWARNING("Unable to parse CPos parameters. Your input: '%s'", Value.ToUTF8().c_str());
|
2014-05-24 20:16:52 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-19 12:43:05 -07:00
|
|
|
|
2014-05-24 20:16:52 -07:00
|
|
|
Output.x = coords[0];
|
|
|
|
|
Output.y = coords[1];
|
2010-04-19 12:43:05 -07:00
|
|
|
|
2014-05-24 20:16:52 -07:00
|
|
|
if (!stream.eof())
|
|
|
|
|
{
|
2015-01-22 12:36:24 -08:00
|
|
|
LOGWARNING("Too many CPos parameters (max %i). Your input: '%s'", NUM_COORDS, Value.ToUTF8().c_str());
|
2004-12-21 05:37:24 -08:00
|
|
|
return false;
|
2014-05-24 20:16:52 -07:00
|
|
|
}
|
2010-04-19 12:43:05 -07:00
|
|
|
|
|
|
|
|
return true;
|
2004-12-21 05:37:24 -08:00
|
|
|
}
|
|
|
|
|
|
2004-09-01 20:02:32 -07:00
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<EAlign>(const CStrW& Value, EAlign& Output)
|
2004-09-01 20:02:32 -07:00
|
|
|
{
|
2010-05-30 06:11:32 -07:00
|
|
|
if (Value == L"left")
|
2004-09-01 20:02:32 -07:00
|
|
|
Output = EAlign_Left;
|
2015-08-21 10:08:41 -07:00
|
|
|
else if (Value == L"center")
|
2004-09-01 20:02:32 -07:00
|
|
|
Output = EAlign_Center;
|
2015-08-21 10:08:41 -07:00
|
|
|
else if (Value == L"right")
|
2004-09-01 20:02:32 -07:00
|
|
|
Output = EAlign_Right;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<EVAlign>(const CStrW& Value, EVAlign& Output)
|
2004-09-01 20:02:32 -07:00
|
|
|
{
|
2010-05-30 06:11:32 -07:00
|
|
|
if (Value == L"top")
|
2004-09-01 20:02:32 -07:00
|
|
|
Output = EVAlign_Top;
|
2015-08-21 10:08:41 -07:00
|
|
|
else if (Value == L"center")
|
2004-09-01 20:02:32 -07:00
|
|
|
Output = EVAlign_Center;
|
2015-08-21 10:08:41 -07:00
|
|
|
else if (Value == L"bottom")
|
2004-09-01 20:02:32 -07:00
|
|
|
Output = EVAlign_Bottom;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<CGUIString>(const CStrW& Value, CGUIString& Output)
|
2004-05-28 21:06:50 -07:00
|
|
|
{
|
2010-05-30 06:11:32 -07:00
|
|
|
Output.SetValue(Value);
|
2004-05-28 21:06:50 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-16 16:05:37 -08:00
|
|
|
template <>
|
2010-05-30 06:11:32 -07:00
|
|
|
bool __ParseString<CStr>(const CStrW& Value, CStr& Output)
|
2004-12-16 16:05:37 -08:00
|
|
|
{
|
|
|
|
|
// Do very little.
|
2011-02-17 12:08:20 -08:00
|
|
|
Output = Value.ToUTF8();
|
2004-12-16 16:05:37 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-14 03:09:26 -07:00
|
|
|
template <>
|
2010-05-30 06:11:32 -07:00
|
|
|
bool __ParseString<CStrW>(const CStrW& Value, CStrW& Output)
|
2004-10-14 03:09:26 -07:00
|
|
|
{
|
2010-05-30 06:11:32 -07:00
|
|
|
Output = Value;
|
2004-10-14 03:09:26 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-15 13:24:46 -08:00
|
|
|
template <>
|
2015-08-21 10:08:41 -07:00
|
|
|
bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance& Output)
|
2004-12-15 13:24:46 -08:00
|
|
|
{
|
2011-02-17 12:08:20 -08:00
|
|
|
Output = CGUISpriteInstance(Value.ToUTF8());
|
2004-12-15 13:24:46 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-23 16:20:50 -07:00
|
|
|
template <>
|
2010-05-30 06:11:32 -07:00
|
|
|
bool __ParseString<CGUIList>(const CStrW& UNUSED(Value), CGUIList& UNUSED(Output))
|
2005-04-23 16:20:50 -07:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-07 11:03:54 -08:00
|
|
|
template <>
|
|
|
|
|
bool __ParseString<CGUISeries>(const CStrW& UNUSED(Value), CGUISeries& UNUSED(Output))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2005-04-23 16:20:50 -07:00
|
|
|
|
2004-12-16 16:05:37 -08:00
|
|
|
template <typename T>
|
2015-08-21 10:08:41 -07:00
|
|
|
PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value)
|
2004-12-16 16:05:37 -08:00
|
|
|
{
|
2011-04-30 06:01:45 -07:00
|
|
|
ENSURE(pObject != NULL);
|
2004-12-16 16:05:37 -08:00
|
|
|
|
2019-08-03 19:20:08 -07:00
|
|
|
std::map<CStr, IGUISetting*>::const_iterator it = pObject->m_Settings.find(Setting);
|
2007-06-15 10:03:26 -07:00
|
|
|
if (it == pObject->m_Settings.end())
|
2009-09-27 08:04:46 -07:00
|
|
|
{
|
2015-08-21 10:08:41 -07:00
|
|
|
LOGWARNING("setting %s was not found on object %s",
|
2009-09-27 08:04:46 -07:00
|
|
|
Setting.c_str(),
|
|
|
|
|
pObject->GetPresentableName().c_str());
|
|
|
|
|
return PSRETURN_GUI_InvalidSetting;
|
|
|
|
|
}
|
2004-12-16 16:05:37 -08:00
|
|
|
|
2019-08-03 19:20:08 -07:00
|
|
|
if (it->second == nullptr)
|
2009-09-27 08:04:46 -07:00
|
|
|
return PSRETURN_GUI_InvalidSetting;
|
2004-12-16 16:05:37 -08:00
|
|
|
|
|
|
|
|
// Get value
|
2019-08-03 19:20:08 -07:00
|
|
|
Value = &(static_cast<CGUISetting<T>* >(it->second)->m_pSetting);
|
2004-12-16 16:05:37 -08:00
|
|
|
|
2009-09-27 08:04:46 -07:00
|
|
|
return PSRETURN_OK;
|
2004-12-16 16:05:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2015-08-21 10:08:41 -07:00
|
|
|
PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value)
|
2004-12-16 16:05:37 -08:00
|
|
|
{
|
2010-02-03 11:43:39 -08:00
|
|
|
T* v = NULL;
|
2009-09-27 08:04:46 -07:00
|
|
|
PSRETURN ret = GetSettingPointer(pObject, Setting, v);
|
|
|
|
|
if (ret == PSRETURN_OK)
|
2004-12-16 16:05:37 -08:00
|
|
|
Value = *v;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 15:40:58 -07:00
|
|
|
template <typename T>
|
|
|
|
|
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage)
|
|
|
|
|
{
|
|
|
|
|
return SetSettingWrap(pObject, Setting, Value, SkipMessage,
|
|
|
|
|
[&pObject, &Setting, &Value]() {
|
2019-08-03 19:20:08 -07:00
|
|
|
static_cast<CGUISetting<T>* >(pObject->m_Settings[Setting])->m_pSetting = std::move(Value);
|
2019-07-28 15:40:58 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage)
|
|
|
|
|
{
|
|
|
|
|
return SetSettingWrap(pObject, Setting, Value, SkipMessage,
|
|
|
|
|
[&pObject, &Setting, &Value]() {
|
2019-08-03 19:20:08 -07:00
|
|
|
static_cast<CGUISetting<T>* >(pObject->m_Settings[Setting])->m_pSetting = Value;
|
2019-07-28 15:40:58 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-27 11:20:34 -08:00
|
|
|
// Helper function for SetSetting
|
|
|
|
|
template <typename T>
|
|
|
|
|
bool IsBoolTrue(const T&)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
template <>
|
|
|
|
|
bool IsBoolTrue<bool>(const bool& v)
|
|
|
|
|
{
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-16 16:05:37 -08:00
|
|
|
template <typename T>
|
2019-07-28 15:40:58 -07:00
|
|
|
PSRETURN GUI<T>::SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage, const std::function<void()>& valueSet)
|
2004-12-16 16:05:37 -08:00
|
|
|
{
|
2011-04-30 06:01:45 -07:00
|
|
|
ENSURE(pObject != NULL);
|
2004-12-16 16:05:37 -08:00
|
|
|
|
|
|
|
|
if (!pObject->SettingExists(Setting))
|
2009-09-27 08:04:46 -07:00
|
|
|
{
|
2015-08-21 10:08:41 -07:00
|
|
|
LOGWARNING("setting %s was not found on object %s",
|
2009-09-27 08:04:46 -07:00
|
|
|
Setting.c_str(),
|
|
|
|
|
pObject->GetPresentableName().c_str());
|
|
|
|
|
return PSRETURN_GUI_InvalidSetting;
|
|
|
|
|
}
|
2004-12-16 16:05:37 -08:00
|
|
|
|
2019-07-28 15:40:58 -07:00
|
|
|
valueSet();
|
2004-12-16 16:05:37 -08:00
|
|
|
|
|
|
|
|
// Some settings needs special attention at change
|
|
|
|
|
|
|
|
|
|
// If setting was "size", we need to re-cache itself and all children
|
2004-12-19 04:20:04 -08:00
|
|
|
if (Setting == "size")
|
2004-12-16 16:05:37 -08:00
|
|
|
{
|
|
|
|
|
RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
|
|
|
|
|
}
|
2015-08-21 10:08:41 -07:00
|
|
|
else if (Setting == "hidden")
|
2004-12-19 04:20:04 -08:00
|
|
|
{
|
|
|
|
|
// Hiding an object requires us to reset it and all children
|
2010-01-27 11:20:34 -08:00
|
|
|
if (IsBoolTrue(Value))
|
2019-07-27 19:39:52 -07:00
|
|
|
RecurseObject(0, pObject, &IGUIObject::ResetStates);
|
2004-12-19 04:20:04 -08:00
|
|
|
}
|
2004-12-16 16:05:37 -08:00
|
|
|
|
2005-02-04 23:25:16 -08:00
|
|
|
if (!SkipMessage)
|
2011-04-28 13:42:11 -07:00
|
|
|
{
|
|
|
|
|
SGUIMessage msg(GUIM_SETTINGS_UPDATED, Setting);
|
2019-07-27 19:39:52 -07:00
|
|
|
pObject->HandleMessage(msg);
|
2011-04-28 13:42:11 -07:00
|
|
|
}
|
2004-12-16 16:05:37 -08:00
|
|
|
|
2009-09-27 08:04:46 -07:00
|
|
|
return PSRETURN_OK;
|
2004-12-16 16:05:37 -08:00
|
|
|
}
|
|
|
|
|
|
2004-12-17 08:20:08 -08:00
|
|
|
// Instantiate templated functions:
|
2004-12-16 16:05:37 -08:00
|
|
|
#define TYPE(T) \
|
2015-08-21 10:08:41 -07:00
|
|
|
template PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value); \
|
|
|
|
|
template PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); \
|
2019-07-28 15:40:58 -07:00
|
|
|
template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage); \
|
2019-08-03 19:20:08 -07:00
|
|
|
template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage); \
|
|
|
|
|
template class CGUISetting<T>; \
|
|
|
|
|
|
2004-12-16 16:05:37 -08:00
|
|
|
#define GUITYPE_IGNORE_CGUISpriteInstance
|
|
|
|
|
#include "GUItypes.h"
|
2010-02-17 16:06:50 -08:00
|
|
|
#undef GUITYPE_IGNORE_CGUISpriteInstance
|
|
|
|
|
#undef TYPE
|
2004-12-16 16:05:37 -08:00
|
|
|
|
|
|
|
|
// Don't instantiate GetSetting<CGUISpriteInstance> - this will cause linker errors if
|
|
|
|
|
// you attempt to retrieve a sprite using GetSetting, since that copies the sprite
|
|
|
|
|
// and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer
|
|
|
|
|
// instead. (This is mainly useful to stop me accidentally using the wrong function.)
|
2015-08-21 10:08:41 -07:00
|
|
|
template PSRETURN GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance*& Value);
|
2019-07-28 15:40:58 -07:00
|
|
|
template PSRETURN GUI<CGUISpriteInstance>::SetSetting(IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance& Value, const bool& SkipMessage);
|
2019-08-03 19:20:08 -07:00
|
|
|
template class CGUISetting<CGUISpriteInstance>;
|