First blood
This commit is contained in:
1 parent
04f270f322
commit
5720f8322b
250 files changed
+33215
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,415 @@
|
||||
#include "include/Engine.h"
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
const std::string CONST_HOLD_SIGNAL_NAME = "OnHold";
|
||||
const std::string CONST_CLICK_SIGNAL_NAME = "OnClick";
|
||||
const std::string CONST_DRAG_SIGNAL_NAME = "OnDrag";
|
||||
|
||||
|
||||
TGUIManager::~TGUIManager()
|
||||
{
|
||||
|
||||
WidgetTrasfromTaskList.clear();
|
||||
|
||||
WidgetArr.clear();
|
||||
|
||||
*Console<<"GUI Manager deleting...";
|
||||
}
|
||||
|
||||
|
||||
void TGUIManager::AddWidget(std::shared_ptr<TInstancingWidgetAncestor> widgetAncestor, const std::string& name, const std::string& groupName, int order)
|
||||
{
|
||||
for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); i++)
|
||||
{
|
||||
if (i->Name == name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
WidgetArr.push_back(TWidgetStruct(name, groupName, widgetAncestor, order));
|
||||
std::stable_sort(WidgetArr.begin(), WidgetArr.end());
|
||||
}
|
||||
|
||||
void TGUIManager::DeleteWidget(std::string name)
|
||||
{
|
||||
for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); i++)
|
||||
{
|
||||
if (i->Name == name)
|
||||
{
|
||||
WidgetArr.erase(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TGUIManager::DeleteWidgetGroup(std::string groupName)
|
||||
{
|
||||
bool widgetErased;
|
||||
for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end();)
|
||||
{
|
||||
widgetErased = false;
|
||||
if (i->GroupName == groupName)
|
||||
{
|
||||
i = WidgetArr.erase(i);
|
||||
widgetErased = true;
|
||||
}
|
||||
|
||||
if (i != WidgetArr.end() & !widgetErased)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TGUIManager::DeleteWidgetOnUpdate(const std::string& name)
|
||||
{
|
||||
PostUpdateSignal.connect(boost::bind(&TGUIManager::DeleteWidget, this, name));
|
||||
}
|
||||
|
||||
void TGUIManager::DeleteWidgetGroupOnUpdate(const std::string& groupName)
|
||||
{
|
||||
PostUpdateSignal.connect(boost::bind(&TGUIManager::DeleteWidgetGroup, this, groupName));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TGUIManager::AddWidgetTransformTask(TWidgetTransformTask widgetTransformTask)
|
||||
{
|
||||
WidgetTrasfromTaskList.push_back(widgetTransformTask);
|
||||
}
|
||||
|
||||
void TGUIManager::Update(cardinal dt)
|
||||
{
|
||||
|
||||
WidgetListMutex.lock();
|
||||
|
||||
for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); ++i)
|
||||
{
|
||||
i->Widget->Update(dt);
|
||||
|
||||
if (i->IsMouseDown)
|
||||
{
|
||||
(*(i->SignalMap[CONST_HOLD_SIGNAL_NAME]))(TSignalParam(dt));
|
||||
|
||||
}
|
||||
|
||||
for (TRenderPairList::iterator itr = i->Widget->TriangleListVector.begin(); itr != i->Widget->TriangleListVector.end(); ++itr)
|
||||
{
|
||||
if (itr->second.NeedRefreshBuffer)
|
||||
{
|
||||
itr->second.RefreshBuffer();
|
||||
itr->second.NeedRefreshBuffer = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (TWidgetTrasfromTaskList::iterator i = WidgetTrasfromTaskList.begin(); i != WidgetTrasfromTaskList.end(); )
|
||||
{
|
||||
int prevCurrentTime = i->CurrentTime;
|
||||
|
||||
i->CurrentTime += dt;
|
||||
|
||||
if (i->CurrentTime >= i->TotalTime)
|
||||
{
|
||||
i->CurrentTime = i->TotalTime;
|
||||
}
|
||||
|
||||
vec2 oldPos;
|
||||
vec2 newPos;
|
||||
|
||||
float t0 = clamp<float>((prevCurrentTime + 0.f)/i->TotalTime, 0, 1);
|
||||
float t = clamp<float>((i->CurrentTime + 0.f)/i->TotalTime, 0, 1);
|
||||
|
||||
if (i->MoveStyle == TWidgetTransformTask::MS_LINEAR)
|
||||
{
|
||||
oldPos = InterpolateLinear<vec2>(vec2(0,0), i->PosTo, t0);
|
||||
newPos = InterpolateLinear<vec2>(vec2(0,0), i->PosTo, t);
|
||||
}
|
||||
if (i->MoveStyle == TWidgetTransformTask::MS_SQR)
|
||||
{
|
||||
oldPos = InterpolateSqr<vec2>(vec2(0,0), i->PosTo, t0);
|
||||
newPos = InterpolateSqr<vec2>(vec2(0,0), i->PosTo, t);
|
||||
}
|
||||
if (i->MoveStyle == TWidgetTransformTask::MS_SQRT)
|
||||
{
|
||||
oldPos = InterpolateSqrt<vec2>(vec2(0,0), i->PosTo, t0);
|
||||
newPos = InterpolateSqrt<vec2>(vec2(0,0), i->PosTo, t);
|
||||
}
|
||||
|
||||
vec2 moveDistance = newPos - oldPos;
|
||||
|
||||
for (TWidgetArr::iterator j = WidgetArr.begin(); j != WidgetArr.end(); ++j)
|
||||
{
|
||||
if (j->GroupName == i->GroupName)
|
||||
{
|
||||
MoveWidgetByIterator(j, moveDistance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (i->CurrentTime == i->TotalTime)
|
||||
{
|
||||
i = WidgetTrasfromTaskList.erase(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
WidgetListMutex.unlock();
|
||||
|
||||
PostUpdateSignal();
|
||||
|
||||
PostUpdateSignal.disconnect_all_slots();
|
||||
}
|
||||
|
||||
void TGUIManager::Draw()
|
||||
{
|
||||
|
||||
TWidgetArr::iterator i;
|
||||
for (i = WidgetArr.begin(); i != WidgetArr.end(); ++i)
|
||||
{
|
||||
|
||||
TRenderPairList::iterator j;
|
||||
|
||||
for (j = i->Widget->TriangleListVector.begin(); j != i->Widget->TriangleListVector.end(); ++j)
|
||||
{
|
||||
|
||||
TRenderParamsSetter paramSetter(j->first);
|
||||
|
||||
Renderer->DrawTriangleList(j->second);
|
||||
|
||||
CheckGlError("TGUIManager::Draw()");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TWidgetArr::iterator TGUIManager::FindWidgetInArr(const std::string& widgetName)
|
||||
{
|
||||
TWidgetArr::iterator i;
|
||||
|
||||
for (i = WidgetArr.begin(); i != WidgetArr.end(); ++i)
|
||||
{
|
||||
if (i->Name == widgetName)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == WidgetArr.end())
|
||||
{
|
||||
throw ErrorToLog("ERROR: widget not found: "+widgetName);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void TGUIManager::MoveWidgetByIterator(TWidgetArr::iterator widget, vec2 shift)
|
||||
{
|
||||
widget->Widget->LeftBottomPos += shift;
|
||||
|
||||
std::vector<vec3>::iterator i;
|
||||
|
||||
TRenderPairList::iterator itr;
|
||||
|
||||
for (itr = widget->Widget->TriangleListVector.begin(); itr != widget->Widget->TriangleListVector.end(); ++itr)
|
||||
{
|
||||
std::vector<vec3>& vertexCoordVec = itr->second.Data.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB];
|
||||
|
||||
for (i = vertexCoordVec.begin(); i != vertexCoordVec.end(); ++i)
|
||||
{
|
||||
*i += vec3(shift, 0);
|
||||
}
|
||||
|
||||
itr->second.NeedRefreshBuffer = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TGUIManager::MoveWidget(const std::string& widgetName, vec2 shift)
|
||||
{
|
||||
|
||||
TWidgetArr::iterator widget = FindWidgetInArr(widgetName);
|
||||
MoveWidgetByIterator(widget, shift);
|
||||
}
|
||||
|
||||
void TGUIManager::MoveWidgetGroup(const std::string& widgetGroupName, const std::string& exceptWidget, vec2 shift)
|
||||
{
|
||||
for (TWidgetArr::iterator i = WidgetArr.begin(); i != WidgetArr.end(); ++i)
|
||||
{
|
||||
if (i->GroupName == widgetGroupName && i->Name != exceptWidget)
|
||||
{
|
||||
MoveWidgetByIterator(i, shift);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TGUIManager::OnMouseDown(vec2 pos)
|
||||
{
|
||||
//Xperimental - need to call widget methods and signals NOT IN "FOR" LOOP
|
||||
|
||||
WidgetListMutex.lock();
|
||||
|
||||
TWidgetArr::reverse_iterator i;
|
||||
|
||||
LastTapPos = pos;
|
||||
TotalShift = vec2(0,0);
|
||||
|
||||
for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i)
|
||||
{
|
||||
if (i->Widget->CheckClick(pos))
|
||||
{
|
||||
bool isTransparentForInput = i->Widget->IsTransparentForInput();
|
||||
|
||||
i->Widget->OnTapDown(pos);
|
||||
i->IsMouseDown = true;
|
||||
|
||||
if (! isTransparentForInput)
|
||||
{
|
||||
WidgetListMutex.unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WidgetListMutex.unlock();
|
||||
}
|
||||
|
||||
void TGUIManager::OnMouseUp(vec2 pos)
|
||||
{
|
||||
//Xperimental - need to call widget methods and signals NOT IN "FOR" LOOP
|
||||
|
||||
WidgetListMutex.lock();
|
||||
|
||||
TWidgetArr::reverse_iterator i;
|
||||
|
||||
for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i)
|
||||
{
|
||||
if (i->Widget->CheckClick(pos))
|
||||
{
|
||||
bool isTransparentForInput = i->Widget->IsTransparentForInput();
|
||||
i->Widget->OnTapUp(pos);
|
||||
i->IsMouseDown = false;
|
||||
(*(i->SignalMap[CONST_CLICK_SIGNAL_NAME]))(TSignalParam(pos));
|
||||
|
||||
if (! isTransparentForInput)
|
||||
{
|
||||
WidgetListMutex.unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WidgetListMutex.unlock();
|
||||
}
|
||||
|
||||
void TGUIManager::OnMove(vec2 shift)
|
||||
{
|
||||
//Xperimental - need to call widget methods and signals NOT IN "FOR" LOOP
|
||||
|
||||
|
||||
TWidgetArr::reverse_iterator i;
|
||||
|
||||
bool moveIsProcessed = false;
|
||||
bool moveOutIsProcessed = false;
|
||||
|
||||
TotalShift += shift;
|
||||
|
||||
for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i)
|
||||
{
|
||||
if (!moveIsProcessed && i->Widget->CheckClick(LastTapPos-TotalShift))
|
||||
{
|
||||
bool isTransparentForInput = i->Widget->IsTransparentForInput();
|
||||
|
||||
i->Widget->OnMove(shift);
|
||||
(*(i->SignalMap[CONST_DRAG_SIGNAL_NAME]))(TSignalParam(shift));
|
||||
|
||||
if (! isTransparentForInput)
|
||||
{
|
||||
moveIsProcessed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = WidgetArr.rbegin(); i != WidgetArr.rend(); ++i)
|
||||
{
|
||||
if (!moveOutIsProcessed && i->Widget->CheckClick(LastTapPos) && !i->Widget->CheckClick(LastTapPos-TotalShift))
|
||||
{
|
||||
bool isTransparentForInput = i->Widget->IsTransparentForInput();
|
||||
|
||||
i->Widget->OnMoveOut();
|
||||
i->IsMouseDown = false;
|
||||
if (! isTransparentForInput)
|
||||
{
|
||||
moveOutIsProcessed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TGUIManager::PrintWidgetList()
|
||||
{
|
||||
TWidgetArr::iterator i;
|
||||
|
||||
for (i = WidgetArr.begin(); i != WidgetArr.end(); ++i)
|
||||
{
|
||||
std::string widgetRow = i->Name + " (" + tostr(i->Widget->LeftBottomPos.v[0]) + ", " + tostr(i->Widget->LeftBottomPos.v[1]) + ")";
|
||||
Console->PrintImmediate(widgetRow);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<boost::signal<void (TSignalParam)>> TGUIManager::GetOnClickSignal(const std::string& widgetName)
|
||||
{
|
||||
|
||||
TWidgetArr::iterator i = FindWidgetInArr(widgetName);
|
||||
|
||||
return i->SignalMap[CONST_CLICK_SIGNAL_NAME];
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<boost::signal<void (TSignalParam)>> TGUIManager::GetOnHoldSignal(const std::string& widgetName)
|
||||
{
|
||||
|
||||
TWidgetArr::iterator i = FindWidgetInArr(widgetName);
|
||||
|
||||
return i->SignalMap[CONST_HOLD_SIGNAL_NAME];
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<boost::signal<void (TSignalParam)>> TGUIManager::GetSignal(const std::string& signalName, const std::string& widgetName)
|
||||
{
|
||||
|
||||
TWidgetArr::iterator i = FindWidgetInArr(widgetName);
|
||||
|
||||
if (i->SignalMap.count(signalName) == 0)
|
||||
{
|
||||
throw ErrorToLog("Illegal signal: "+signalName);
|
||||
}
|
||||
|
||||
return i->SignalMap[signalName];
|
||||
}
|
||||
|
||||
void TGUIManager::SQ_MoveWidget(const SQChar *widgetName, float x, float y)
|
||||
{
|
||||
MoveWidget(std::string(widgetName), vec2(x,y));
|
||||
}
|
||||
|
||||
|
||||
void TGUIManager::BindFunctions()
|
||||
{
|
||||
ResourceManager->ScriptManager.AddFunction("pwl",
|
||||
TScriptInfo("PrintWidgetList"),
|
||||
ResourceManager->GUIManager,
|
||||
&TGUIManager::PrintWidgetList);
|
||||
|
||||
ResourceManager->ScriptManager.AddFunction("mw",
|
||||
TScriptInfo("MoveWidget"),
|
||||
ResourceManager->GUIManager,
|
||||
&TGUIManager::SQ_MoveWidget);
|
||||
}
|
||||
|
||||
} //namespace SE
|
||||
@@ -0,0 +1,514 @@
|
||||
#include "include/Engine.h"
|
||||
|
||||
|
||||
namespace SE
|
||||
{
|
||||
|
||||
void TStaticWidgetParser::Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
std::string widgetType = propertyTree.get<std::string>("<xmlattr>.type");
|
||||
std::string name = propertyTree.get<std::string>("<xmlattr>.name");
|
||||
std::string group = propertyTree.get<std::string>("<xmlattr>.group");
|
||||
|
||||
float xCenter = propertyTree.get<float>("<xmlattr>.xCenter");
|
||||
float yCenter = propertyTree.get<float>("<xmlattr>.yCenter");
|
||||
float width = propertyTree.get<float>("<xmlattr>.width");
|
||||
float height = propertyTree.get<float>("<xmlattr>.height");
|
||||
int order = propertyTree.get<int>("<xmlattr>.order", 0);
|
||||
|
||||
vec2 posFrom(xCenter - width*0.5f, yCenter - height*0.5f);
|
||||
vec2 posTo(xCenter + width*0.5f, yCenter + height*0.5f);
|
||||
|
||||
//boost::property_tree::ptree& fillerTree = propertyTree.find("Filler")->second;
|
||||
|
||||
std::vector<boost::function<void(TSquareStatic*)>> fillerFuncArr;
|
||||
|
||||
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, propertyTree)
|
||||
{
|
||||
if (v.first == "Filler")
|
||||
{
|
||||
boost::property_tree::ptree& fillerTree = v.second;
|
||||
|
||||
if (fillerTree.get<std::string>("<xmlattr>.type") == "StaticTextureFiller")
|
||||
{
|
||||
std::string normTexName = fillerTree.get<std::string>("<xmlattr>.texName");
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TSquareStatic::StaticTextureFiller, posFrom, posTo, normTexName, _1));
|
||||
|
||||
}
|
||||
else if (fillerTree.get<std::string>("<xmlattr>.type") == "StaticTextFiller")
|
||||
{
|
||||
TTextParams textParamsNormal;
|
||||
|
||||
boost::property_tree::ptree& textParamsNormalTree = fillerTree.find("TextParams")->second;
|
||||
|
||||
textParamsNormal.Serialize(textParamsNormalTree);
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TSquareStatic::StaticTextFiller, posFrom, posTo, textParamsNormal, _1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ResourceManager->GUIManager.AddWidget(
|
||||
std::shared_ptr<TInstancingWidgetAncestor>(TSquareStatic::CreateStaticWithFillers(posFrom, posTo, fillerFuncArr)),
|
||||
name,
|
||||
group,
|
||||
order);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TDynamicTextWidgetParser::Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
std::string widgetType = propertyTree.get<std::string>("<xmlattr>.type");
|
||||
std::string name = propertyTree.get<std::string>("<xmlattr>.name");
|
||||
std::string group = propertyTree.get<std::string>("<xmlattr>.group");
|
||||
|
||||
float xCenter = propertyTree.get<float>("<xmlattr>.xCenter");
|
||||
float yCenter = propertyTree.get<float>("<xmlattr>.yCenter");
|
||||
float width = propertyTree.get<float>("<xmlattr>.width");
|
||||
float height = propertyTree.get<float>("<xmlattr>.height");
|
||||
int order = propertyTree.get<int>("<xmlattr>.order", 0);
|
||||
|
||||
vec2 posFrom(xCenter - width*0.5f, yCenter - height*0.5f);
|
||||
vec2 posTo(xCenter + width*0.5f, yCenter + height*0.5f);
|
||||
|
||||
//boost::property_tree::ptree& fillerTree = propertyTree.find("Filler")->second;
|
||||
|
||||
std::vector<boost::function<void(TDynamicText*)>> fillerFuncArr;
|
||||
|
||||
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, propertyTree)
|
||||
{
|
||||
if (v.first == "Filler")
|
||||
{
|
||||
boost::property_tree::ptree& fillerTree = v.second;
|
||||
|
||||
if (fillerTree.get<std::string>("<xmlattr>.type") == "TextParamsFiller")
|
||||
{
|
||||
TTextParams textParamsNormal;
|
||||
|
||||
boost::property_tree::ptree& textParamsNormalTree = fillerTree.find("TextParams")->second;
|
||||
|
||||
textParamsNormal.Serialize(textParamsNormalTree);
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TDynamicText::TextParamsFiller, posFrom, posTo, textParamsNormal, _1));
|
||||
}
|
||||
else if (fillerTree.get<std::string>("<xmlattr>.type") == "SmartValueTextFiller")
|
||||
{
|
||||
std::string dictionaryName = fillerTree.get<std::string>("<xmlattr>.dictionaryName");
|
||||
std::string smartValueName = fillerTree.get<std::string>("<xmlattr>.smartValueName");
|
||||
fillerFuncArr.push_back(boost::bind(TDynamicText::SmartValueTextFiller, dictionaryName, smartValueName, _1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ResourceManager->GUIManager.AddWidget(
|
||||
std::shared_ptr<TInstancingWidgetAncestor>(TDynamicText::CreateDynamicTextWithFillers(posFrom, posTo, fillerFuncArr)),
|
||||
name,
|
||||
group,
|
||||
order);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TButtonWidgetParser::Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
|
||||
std::string widgetType = propertyTree.get<std::string>("<xmlattr>.type");
|
||||
std::string name = propertyTree.get<std::string>("<xmlattr>.name");
|
||||
std::string group = propertyTree.get<std::string>("<xmlattr>.group");
|
||||
|
||||
float xCenter = propertyTree.get<float>("<xmlattr>.xCenter");
|
||||
float yCenter = propertyTree.get<float>("<xmlattr>.yCenter");
|
||||
float width = propertyTree.get<float>("<xmlattr>.width");
|
||||
float height = propertyTree.get<float>("<xmlattr>.height");
|
||||
int order = propertyTree.get<int>("<xmlattr>.order", 0);
|
||||
|
||||
vec2 posFrom(xCenter - width*0.5f, yCenter - height*0.5f);
|
||||
vec2 posTo(xCenter + width*0.5f, yCenter + height*0.5f);
|
||||
|
||||
std::vector<boost::function<void(TUniversalButton*)> > fillerFuncArr;
|
||||
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, propertyTree)
|
||||
{
|
||||
if (v.first == "Filler")
|
||||
{
|
||||
|
||||
boost::property_tree::ptree& fillerTree = v.second;
|
||||
|
||||
if (fillerTree.get<std::string>("<xmlattr>.type") == "SquareButtonFiller")
|
||||
{
|
||||
std::string normTexName = fillerTree.get<std::string>("<xmlattr>.normTexName");
|
||||
std::string pressedTexName = fillerTree.get<std::string>("<xmlattr>.pressedTexName");
|
||||
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TUniversalButton::SquareButtonFiller, posFrom, posTo, normTexName, pressedTexName, _1));
|
||||
|
||||
}
|
||||
else if (fillerTree.get<std::string>("<xmlattr>.type") == "TextButtonFiller")
|
||||
{
|
||||
TTextParams textParamsNormal;
|
||||
TTextParams textParamsPressed;
|
||||
|
||||
boost::property_tree::ptree& textParamsNormalTree = fillerTree.find("TextParamsNormal")->second;
|
||||
|
||||
textParamsNormal.Serialize(textParamsNormalTree);
|
||||
|
||||
boost::property_tree::ptree& textParamsPressedTree = fillerTree.find("TextParamsPressed")->second;
|
||||
|
||||
textParamsPressed.Serialize(textParamsPressedTree);
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TUniversalButton::TextButtonFiller, posFrom, posTo, textParamsNormal, textParamsPressed, _1));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ResourceManager->GUIManager.AddWidget(
|
||||
std::shared_ptr<TInstancingWidgetAncestor>(
|
||||
TUniversalButton::CreateButtonWithFillers(posFrom, posTo, fillerFuncArr)
|
||||
),
|
||||
name,
|
||||
group,
|
||||
order);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TEditWidgetParser::Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
std::string widgetType = propertyTree.get<std::string>("<xmlattr>.type");
|
||||
std::string name = propertyTree.get<std::string>("<xmlattr>.name");
|
||||
std::string group = propertyTree.get<std::string>("<xmlattr>.group");
|
||||
|
||||
float xCenter = propertyTree.get<float>("<xmlattr>.xCenter");
|
||||
float yCenter = propertyTree.get<float>("<xmlattr>.yCenter");
|
||||
float width = propertyTree.get<float>("<xmlattr>.width");
|
||||
float height = propertyTree.get<float>("<xmlattr>.height");
|
||||
int order = propertyTree.get<int>("<xmlattr>.order", 0);
|
||||
|
||||
vec2 posFrom(xCenter - width*0.5f, yCenter - height*0.5f);
|
||||
vec2 posTo(xCenter + width*0.5f, yCenter + height*0.5f);
|
||||
/*
|
||||
//The only one filler
|
||||
std::string texName = propertyTree.get<std::string>("Filler.<xmlattr>.texName");
|
||||
|
||||
TTextParams textParams;
|
||||
|
||||
boost::property_tree::ptree& textParamsTree = propertyTree.find("Filler")->second.find("TextParams")->second;
|
||||
|
||||
textParams.Serialize(textParamsTree);
|
||||
|
||||
ResourceManager->GUIManager.AddWidget(
|
||||
std::shared_ptr<TInstancingWidgetAncestor>(TEdit::CreateEdit(posFrom, posTo, texName, textParams)),
|
||||
name,
|
||||
group,
|
||||
order);*/
|
||||
|
||||
std::vector<boost::function<void(TEdit*)>> fillerFuncArr;
|
||||
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, propertyTree)
|
||||
{
|
||||
if (v.first == "Filler")
|
||||
{
|
||||
|
||||
boost::property_tree::ptree& fillerTree = v.second;
|
||||
|
||||
if (fillerTree.get<std::string>("<xmlattr>.type") == "EditFiller")
|
||||
{
|
||||
|
||||
std::string texName = fillerTree.get<std::string>("<xmlattr>.texName");
|
||||
|
||||
TTextParams textParams;
|
||||
|
||||
boost::property_tree::ptree& textParamsTree = fillerTree.find("TextParams")->second;
|
||||
|
||||
textParams.Serialize(textParamsTree);
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TEdit::EditFiller, posFrom, posTo, texName, textParams, _1));
|
||||
|
||||
|
||||
}
|
||||
else if (fillerTree.get<std::string>("<xmlattr>.type") == "SmartValueTextFiller")
|
||||
{
|
||||
|
||||
std::string dictionaryName = fillerTree.get<std::string>("<xmlattr>.dictionaryName");
|
||||
std::string smartValueName = fillerTree.get<std::string>("<xmlattr>.smartValueName");
|
||||
fillerFuncArr.push_back(boost::bind(TEdit::SmartValueTextFiller, dictionaryName, smartValueName, _1));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ResourceManager->GUIManager.AddWidget(
|
||||
std::shared_ptr<TInstancingWidgetAncestor>(
|
||||
TEdit::CreateEditWithFillers(posFrom, posTo, fillerFuncArr)
|
||||
),
|
||||
name,
|
||||
group,
|
||||
order);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void TCheckBoxWidgetParser::Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
std::string widgetType = propertyTree.get<std::string>("<xmlattr>.type");
|
||||
std::string name = propertyTree.get<std::string>("<xmlattr>.name");
|
||||
std::string group = propertyTree.get<std::string>("<xmlattr>.group");
|
||||
|
||||
float xCenter = propertyTree.get<float>("<xmlattr>.xCenter");
|
||||
float yCenter = propertyTree.get<float>("<xmlattr>.yCenter");
|
||||
float width = propertyTree.get<float>("<xmlattr>.width");
|
||||
float height = propertyTree.get<float>("<xmlattr>.height");
|
||||
int order = propertyTree.get<int>("<xmlattr>.order", 0);
|
||||
|
||||
vec2 posFrom(xCenter - width*0.5f, yCenter - height*0.5f);
|
||||
vec2 posTo(xCenter + width*0.5f, yCenter + height*0.5f);
|
||||
|
||||
std::vector<boost::function<void(TCheckBox*)> > fillerFuncArr;
|
||||
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, propertyTree)
|
||||
{
|
||||
if (v.first == "Filler")
|
||||
{
|
||||
|
||||
boost::property_tree::ptree& fillerTree = v.second;
|
||||
|
||||
if (fillerTree.get<std::string>("<xmlattr>.type") == "TextureFiller")
|
||||
{
|
||||
std::string texName = fillerTree.get<std::string>("<xmlattr>.texName");
|
||||
std::string checkedTexName = fillerTree.get<std::string>("<xmlattr>.checkedTexName");
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TCheckBox::TextureFiller, posFrom, posTo, texName, checkedTexName, _1));
|
||||
|
||||
}
|
||||
else if (fillerTree.get<std::string>("<xmlattr>.type") == "TextFiller")
|
||||
{
|
||||
TTextParams textParams;
|
||||
|
||||
boost::property_tree::ptree& textParamsTree = fillerTree.find("TextParams")->second;
|
||||
|
||||
textParams.Serialize(textParamsTree);
|
||||
|
||||
float textXCenter = fillerTree.get<float>("<xmlattr>.xCenter");
|
||||
float textYCenter = fillerTree.get<float>("<xmlattr>.yCenter");
|
||||
float textWidth = fillerTree.get<float>("<xmlattr>.width");
|
||||
float textHeight = fillerTree.get<float>("<xmlattr>.height");
|
||||
|
||||
vec2 textPosFrom(textXCenter - textWidth*0.5f, textYCenter - textHeight*0.5f);
|
||||
vec2 textPosTo(textXCenter + textWidth*0.5f, textYCenter + textHeight*0.5f);
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TCheckBox::TextFiller, textPosFrom, textPosTo, textParams, _1));
|
||||
|
||||
}
|
||||
else if (fillerTree.get<std::string>("<xmlattr>.type") == "RadioButtonGroupFiller")
|
||||
{
|
||||
//std::string radioGroupName = fillerTree.get<std::string>("");
|
||||
//fillerFuncArr.push_back(boost::bind(TCheckBox::RadioButtonGroupFiller, radioGroupName, _1));
|
||||
throw ErrorToLog("RadioButtonGroupFiller is not allowed for checkboxes!");
|
||||
}
|
||||
else if (fillerTree.get<std::string>("<xmlattr>.type") == "SmartValueFiller")
|
||||
{
|
||||
std::string dictionaryName = fillerTree.get<std::string>("<xmlattr>.dictionaryName");
|
||||
std::string smartValueName = fillerTree.get<std::string>("<xmlattr>.smartValueName");
|
||||
fillerFuncArr.push_back(boost::bind(TCheckBox::SmartValueFiller, dictionaryName, smartValueName, _1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
ResourceManager->GUIManager.AddWidget(
|
||||
std::shared_ptr<TInstancingWidgetAncestor>(
|
||||
TCheckBox::CreateCheckBoxWithFillers(posFrom, posTo, fillerFuncArr)
|
||||
),
|
||||
name,
|
||||
group,
|
||||
order);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TRadioButtonWidgetParser::Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
std::string widgetType = propertyTree.get<std::string>("<xmlattr>.type");
|
||||
std::string name = propertyTree.get<std::string>("<xmlattr>.name");
|
||||
std::string group = propertyTree.get<std::string>("<xmlattr>.group");
|
||||
|
||||
float xCenter = propertyTree.get<float>("<xmlattr>.xCenter");
|
||||
float yCenter = propertyTree.get<float>("<xmlattr>.yCenter");
|
||||
float width = propertyTree.get<float>("<xmlattr>.width");
|
||||
float height = propertyTree.get<float>("<xmlattr>.height");
|
||||
int order = propertyTree.get<int>("<xmlattr>.order", 0);
|
||||
|
||||
vec2 posFrom(xCenter - width*0.5f, yCenter - height*0.5f);
|
||||
vec2 posTo(xCenter + width*0.5f, yCenter + height*0.5f);
|
||||
|
||||
std::vector<boost::function<void(TRadioButton*)> > fillerFuncArr;
|
||||
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, propertyTree)
|
||||
{
|
||||
if (v.first == "Filler")
|
||||
{
|
||||
|
||||
boost::property_tree::ptree& fillerTree = v.second;
|
||||
|
||||
if (fillerTree.get<std::string>("<xmlattr>.type") == "TextureFiller")
|
||||
{
|
||||
std::string texName = fillerTree.get<std::string>("<xmlattr>.texName");
|
||||
std::string checkedTexName = fillerTree.get<std::string>("<xmlattr>.checkedTexName");
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TRadioButton::TextureFiller, posFrom, posTo, texName, checkedTexName, _1));
|
||||
|
||||
}
|
||||
else if (fillerTree.get<std::string>("<xmlattr>.type") == "TextFiller")
|
||||
{
|
||||
TTextParams textParams;
|
||||
|
||||
boost::property_tree::ptree& textParamsTree = fillerTree.find("TextParams")->second;
|
||||
|
||||
textParams.Serialize(textParamsTree);
|
||||
|
||||
float textXCenter = fillerTree.get<float>("<xmlattr>.xCenter");
|
||||
float textYCenter = fillerTree.get<float>("<xmlattr>.yCenter");
|
||||
float textWidth = fillerTree.get<float>("<xmlattr>.width");
|
||||
float textHeight = fillerTree.get<float>("<xmlattr>.height");
|
||||
|
||||
vec2 textPosFrom(textXCenter - textWidth*0.5f, textYCenter - textHeight*0.5f);
|
||||
vec2 textPosTo(textXCenter + textWidth*0.5f, textYCenter + textHeight*0.5f);
|
||||
|
||||
fillerFuncArr.push_back(boost::bind(TRadioButton::TextFiller, textPosFrom, textPosTo, textParams, _1));
|
||||
|
||||
}
|
||||
else if (fillerTree.get<std::string>("<xmlattr>.type") == "SmartValueFiller")
|
||||
{
|
||||
std::string dictionaryName = fillerTree.get<std::string>("<xmlattr>.dictionaryName");
|
||||
std::string smartValueName = fillerTree.get<std::string>("<xmlattr>.smartValueName");
|
||||
|
||||
std::string smartValueType = fillerTree.get<std::string>("type");
|
||||
|
||||
if (smartValueType == "int")
|
||||
{
|
||||
int value = fillerTree.get<int>("value");
|
||||
fillerFuncArr.push_back(boost::bind(TRadioButton::SmartValueFiller<int>, dictionaryName, smartValueName, value, _1));
|
||||
}
|
||||
else if (smartValueType == "float")
|
||||
{
|
||||
float value = fillerTree.get<float>("value");
|
||||
fillerFuncArr.push_back(boost::bind(TRadioButton::SmartValueFiller<float>, dictionaryName, smartValueName, value, _1));
|
||||
}
|
||||
else if (smartValueType == "bool")
|
||||
{
|
||||
bool value = fillerTree.get<bool>("value");
|
||||
fillerFuncArr.push_back(boost::bind(TRadioButton::SmartValueFiller<bool>, dictionaryName, smartValueName, value, _1));
|
||||
}
|
||||
else if (smartValueType == "string")
|
||||
{
|
||||
std::string value = fillerTree.get<std::string>("value");
|
||||
fillerFuncArr.push_back(boost::bind(TRadioButton::SmartValueFiller<std::string>, dictionaryName, smartValueName, value, _1));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ErrorToLog("Unknown type: "+smartValueType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
ResourceManager->GUIManager.AddWidget(
|
||||
std::shared_ptr<TInstancingWidgetAncestor>(
|
||||
TRadioButton::CreateRadioButtonWithFillers(posFrom, posTo, fillerFuncArr)
|
||||
),
|
||||
name,
|
||||
group,
|
||||
order);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
void TWidgetParser::Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, propertyTree.begin()->second)
|
||||
{
|
||||
std::string widgetType = v.second.get<std::string>("<xmlattr>.type");
|
||||
|
||||
|
||||
if (widgetType == "Button")
|
||||
{
|
||||
TButtonWidgetParser().Serialize(v.second);
|
||||
}
|
||||
if (widgetType == "Static")
|
||||
{
|
||||
TStaticWidgetParser().Serialize(v.second);
|
||||
}
|
||||
if (widgetType == "Edit")
|
||||
{
|
||||
TEditWidgetParser().Serialize(v.second);
|
||||
}
|
||||
if (widgetType == "CheckBox")
|
||||
{
|
||||
TCheckBoxWidgetParser().Serialize(v.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void TWidgetParser::Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
|
||||
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, propertyTree)
|
||||
{
|
||||
std::string widgetType = v.second.get<std::string>("<xmlattr>.type");
|
||||
|
||||
|
||||
if (widgetType == "Button")
|
||||
{
|
||||
TButtonWidgetParser().Serialize(v.second);
|
||||
}
|
||||
if (widgetType == "Static")
|
||||
{
|
||||
TStaticWidgetParser().Serialize(v.second);
|
||||
}
|
||||
if (widgetType == "DynamicText")
|
||||
{
|
||||
TDynamicTextWidgetParser().Serialize(v.second);
|
||||
}
|
||||
if (widgetType == "Edit")
|
||||
{
|
||||
TEditWidgetParser().Serialize(v.second);
|
||||
}
|
||||
if (widgetType == "CheckBox")
|
||||
{
|
||||
TCheckBoxWidgetParser().Serialize(v.second);
|
||||
}
|
||||
if (widgetType == "RadioButton")
|
||||
{
|
||||
TRadioButtonWidgetParser().Serialize(v.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TWidgetListParser::Serialize(boost::property_tree::ptree& propertyTree)
|
||||
{
|
||||
TWidgetParser().Serialize(propertyTree.begin()->second);
|
||||
}
|
||||
|
||||
|
||||
} //namespace SE
|
||||
Reference in new issue
Block a user