1 /* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #include "precompiled.h"
20 #include "CGUISetting.h"
23 #include "gui/ObjectBases/IGUIObject.h"
24 #include "ps/CLogger.h"
25 #include "scriptinterface/ScriptConversions.h"
27 IGUISetting::IGUISetting(const CStr
& name
, IGUIObject
* owner
) : m_pObject(*owner
)
29 m_pObject
.RegisterSetting(name
, this);
32 IGUISetting::IGUISetting(IGUISetting
&& o
) : m_pObject(o
.m_pObject
)
34 m_pObject
.ReregisterSetting(o
.GetName(), this);
37 bool IGUISetting::FromString(const CStrW
& value
, const bool sendMessage
)
39 if (!DoFromString(value
))
42 OnSettingChange(GetName(), sendMessage
);
47 * Parses the given JS::Value using ScriptInterface::FromJSVal and assigns it to the setting data.
49 bool IGUISetting::FromJSVal(const ScriptRequest
& rq
, JS::HandleValue value
, const bool sendMessage
)
51 if (!DoFromJSVal(rq
, value
))
54 OnSettingChange(GetName(), sendMessage
);
58 void IGUISetting::OnSettingChange(const CStr
& setting
, bool sendMessage
)
60 m_pObject
.SettingChanged(setting
, sendMessage
);
64 bool CGUISimpleSetting
<T
>::DoFromString(const CStrW
& value
)
66 return CGUI::ParseString
<T
>(&m_pObject
.GetGUI(), value
, m_Setting
);
70 bool CGUISimpleSetting
<CGUIColor
>::DoFromJSVal(const ScriptRequest
& rq
, JS::HandleValue value
)
75 if (!Script::FromJSVal(rq
, value
, name
))
78 if (!m_Setting
.ParseString(m_pObject
.GetGUI(), name
))
80 LOGERROR("Invalid color '%s'", name
.c_str());
85 return Script::FromJSVal
<CColor
>(rq
, value
, m_Setting
);
89 bool CGUISimpleSetting
<T
>::DoFromJSVal(const ScriptRequest
& rq
, JS::HandleValue value
)
91 return Script::FromJSVal
<T
>(rq
, value
, m_Setting
);
95 void CGUISimpleSetting
<T
>::ToJSVal(const ScriptRequest
& rq
, JS::MutableHandleValue value
)
97 Script::ToJSVal
<T
>(rq
, value
, m_Setting
);
101 * Explicitly instantiate CGUISimpleSetting for the basic types.
104 template class CGUISimpleSetting<T>;
114 // TODO: make these inherit from CGUISimpleSetting directly.
115 #include "gui/SettingTypes/CGUISize.h"
118 #include "gui/CGUISprite.h"
119 TYPE(CGUISpriteInstance
)
120 #include "gui/SettingTypes/CGUIString.h"
122 #include "gui/SettingTypes/EAlign.h"
125 #include "gui/SettingTypes/CGUIList.h"
127 #include "gui/SettingTypes/CGUISeries.h"