2011-04-09 01:20:44 +02:00
|
|
|
/* The MIT License
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-04-17 21:14:24 +02:00
|
|
|
#include <prerequisites.h>
|
|
|
|
#include <core/resources.h>
|
|
|
|
#include <graphics/textures.h>
|
|
|
|
#include <ui/uiskins.h>
|
|
|
|
#include <ui/uielementskin.h>
|
|
|
|
#include <ui/uibuttonskin.h>
|
|
|
|
#include <ui/uiwindowskin.h>
|
|
|
|
#include <ui/uitexteditskin.h>
|
|
|
|
#include <ui/uilabelskin.h>
|
2011-05-12 00:16:11 +02:00
|
|
|
#include <graphics/fonts.h>
|
2011-04-09 01:20:44 +02:00
|
|
|
|
|
|
|
UISkins g_uiSkins;
|
|
|
|
|
2011-05-19 19:11:05 +02:00
|
|
|
void UISkins::load(const std::string& skinName)
|
2011-04-10 03:13:12 +02:00
|
|
|
{
|
2011-05-19 19:11:05 +02:00
|
|
|
g_resources.pushCurrentPath("skins");
|
2011-04-09 01:20:44 +02:00
|
|
|
|
2011-05-19 19:11:05 +02:00
|
|
|
std::stringstream fin;
|
|
|
|
if(!g_resources.loadFile(skinName + ".yml", fin))
|
|
|
|
flogFatal("FATAL ERROR: Could not load skin \"%s", skinName.c_str());
|
2011-04-09 01:20:44 +02:00
|
|
|
|
2011-05-22 00:24:10 +02:00
|
|
|
try {
|
|
|
|
FML::Parser parser(fin, skinName);
|
2011-05-21 20:15:46 +02:00
|
|
|
FML::Node* doc = parser.getDocument();
|
2011-04-09 01:20:44 +02:00
|
|
|
|
2011-05-22 00:24:10 +02:00
|
|
|
m_defaultFont = g_fonts.get(doc->valueAt("default font"));
|
2011-05-12 00:16:11 +02:00
|
|
|
if(!m_defaultFont)
|
|
|
|
logFatal("FATAL ERROR: Could not load skin default font");
|
|
|
|
|
2011-05-21 20:15:46 +02:00
|
|
|
m_defaultFontColor = doc->readAt("default font color", Color::white);
|
2011-05-12 00:16:11 +02:00
|
|
|
|
2011-05-21 20:15:46 +02:00
|
|
|
std::string defaultTextureName = doc->readAt("default texture", std::string());
|
2011-05-12 00:16:11 +02:00
|
|
|
if(!defaultTextureName.empty())
|
2011-05-19 19:11:05 +02:00
|
|
|
m_defaultTexture = g_textures.get(defaultTextureName);
|
2011-04-09 01:20:44 +02:00
|
|
|
|
2011-05-22 00:24:10 +02:00
|
|
|
foreach(FML::Node* node, *doc) {
|
|
|
|
UIElementSkinPtr skin;
|
2011-05-21 20:15:46 +02:00
|
|
|
foreach(FML::Node* cnode, *node) {
|
2011-05-22 00:24:10 +02:00
|
|
|
if(node->tag() == "buttons")
|
|
|
|
skin = UIElementSkinPtr(new UIButtonSkin(cnode->tag()));
|
|
|
|
else if(node->tag() == "panels")
|
|
|
|
skin = UIElementSkinPtr(new UIElementSkin(cnode->tag(), UI::Panel));
|
|
|
|
else if(node->tag() == "windows")
|
|
|
|
skin = UIElementSkinPtr(new UIWindowSkin(cnode->tag()));
|
|
|
|
else if(node->tag() == "labels")
|
|
|
|
skin = UIElementSkinPtr(new UILabelSkin(cnode->tag()));
|
|
|
|
else if(node->tag() == "text edits")
|
|
|
|
skin = UIElementSkinPtr(new UITextEditSkin(cnode->tag()));
|
|
|
|
else if(node->tag() == "line decorations")
|
|
|
|
skin = UIElementSkinPtr(new UIElementSkin(cnode->tag(), UI::LineDecoration));
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
2011-05-21 20:15:46 +02:00
|
|
|
skin->load(cnode);
|
2011-04-09 21:07:35 +02:00
|
|
|
m_elementSkins.push_back(skin);
|
2011-04-09 01:20:44 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-22 00:24:10 +02:00
|
|
|
} catch(FML::Exception e) {
|
|
|
|
flogFatal("FATAL ERROR: Malformed skin file \"%s\":\n %s", skinName.c_str() % e.what());
|
2011-04-09 01:20:44 +02:00
|
|
|
}
|
2011-05-19 19:11:05 +02:00
|
|
|
|
|
|
|
g_resources.popCurrentPath();
|
2011-04-09 01:20:44 +02:00
|
|
|
}
|
|
|
|
|
2011-04-12 01:52:37 +02:00
|
|
|
void UISkins::terminate()
|
|
|
|
{
|
2011-04-17 21:14:24 +02:00
|
|
|
|
2011-04-12 01:52:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-09 22:38:01 +02:00
|
|
|
UIElementSkinPtr UISkins::getElementSkin(UI::ElementType elementType, const std::string& name)
|
2011-04-09 01:20:44 +02:00
|
|
|
{
|
|
|
|
for(auto it = m_elementSkins.begin(); it != m_elementSkins.end(); ++it) {
|
2011-04-17 21:14:24 +02:00
|
|
|
const UIElementSkinPtr& skin = (*it);
|
|
|
|
if(elementType == skin->getElementType() && name == skin->getName())
|
2011-04-09 01:20:44 +02:00
|
|
|
return skin;
|
|
|
|
}
|
2011-04-22 20:48:02 +02:00
|
|
|
flogWarning("Element skin '%s' not found", name.c_str());
|
2011-04-17 21:14:24 +02:00
|
|
|
return UIElementSkinPtr();
|
2011-04-09 01:20:44 +02:00
|
|
|
}
|