Commit d4ecb00c authored by nanahira's avatar nanahira

skin

parent eea8f007
......@@ -53,6 +53,7 @@
/fonts
/replay
/single
/skin
/sound/*.wav
/sound/custom
/sound/BGM
......
#include "CConfigMap.h"
core::stringc CConfigMap::getConfig( const core::stringc& name )
{
core::map<core::stringc,core::stringc>::Node* node = Map.find(name);
if ( node == 0 )
return core::stringc();
return node->getValue();
}
s32 CConfigMap::getConfigAsInt( const core::stringc& name )
{
core::stringc cfg = getConfig(name);
if ( cfg.size() == 0 )
return 0;
s32 x = 0;
sscanf( cfg.c_str(), "%d", &x );
return x;
}
f32 CConfigMap::getConfigAsFloat( const core::stringc& name )
{
core::stringc cfg = getConfig(name);
if ( cfg.size() == 0 )
return 0;
f32 x = 0.0f;
sscanf( cfg.c_str(), "%f", &x );
return x;
}
core::vector2df CConfigMap::getConfigAsVector2df( const core::stringc& name )
{
core::stringc cfg = getConfig(name);
if ( cfg.size() == 0 )
return core::vector2df(0,0);
core::vector2df vec;
sscanf( cfg.c_str(), "%f , %f", &vec.X, &vec.Y );
return vec;
}
core::vector3df CConfigMap::getConfigAsVector3df( const core::stringc& name )
{
core::stringc cfg = getConfig(name);
if ( cfg.size() == 0 )
return core::vector3df(0,0,0);
core::vector3df vec;
sscanf( cfg.c_str(), "%f , %f , %f", &vec.X, &vec.Y, &vec.Z );
return vec;
}
bool CConfigMap::hasConfig( const core::stringc& name )
{
core::map<core::stringc,core::stringc>::Node* node = Map.find(name);
return ( node != 0 );
}
void CConfigMap::setConfig( const core::stringc& name, const core::stringc& value )
{
Map.set(name,value);
}
#ifndef CCONFIGMAP_H_
#define CCONFIGMAP_H_
#include <irrMap.h>
#include <irrString.h>
#include <irrTypes.h>
#include <vector2d.h>
#include <vector3d.h>
using namespace irr;
class CConfigMap
{
public:
core::stringc getConfig( const core::stringc& name );
s32 getConfigAsInt( const core::stringc& name );
f32 getConfigAsFloat( const core::stringc& name );
core::vector2df getConfigAsVector2df( const core::stringc& name );
core::vector3df getConfigAsVector3df( const core::stringc& name );
bool hasConfig( const core::stringc& name );
void setConfig( const core::stringc& name, const core::stringc& value );
private:
core::map<core::stringc,core::stringc> Map;
};
#endif
#include "CGUIProgressBar.h"
#include <IGUIEnvironment.h>
#include "CImageGUISkin.h"
#include <IGUIFont.h>
namespace irr
{
namespace gui
{
CGUIProgressBar::CGUIProgressBar( IGUIElement* parent, IGUIEnvironment* environment, const core::rect<s32>& rectangle, s32 id,bool bind )
: IGUIElement( EGUIET_ELEMENT, environment, parent, id, rectangle )
{
FilledRatio = 0.0f;
FillColor = video::SColor(255,255,0,0);
EmptyColor = video::SColor();
AutomaticTextFormat = L"%2.0f %%";
bindColorsToSkin = bind;
}
void CGUIProgressBar::setAutomaticText( const wchar_t* text )
{
AutomaticTextFormat = text? text:L"";
if ( AutomaticTextFormat != L"" )
{
wchar_t* buffer = new wchar_t[ AutomaticTextFormat.size() + 10 ];
swprintf( buffer, AutomaticTextFormat.size() + 10, AutomaticTextFormat.c_str(), 100*FilledRatio );
Text = buffer;
delete buffer;
}
}
void CGUIProgressBar::setFillColor( video::SColor fill )
{
FillColor = fill;
}
video::SColor CGUIProgressBar::getFillColor() const
{
return FillColor;
}
void CGUIProgressBar::setEmptyColor( video::SColor empty )
{
EmptyColor = empty;
}
video::SColor CGUIProgressBar::getEmptyColor() const
{
return EmptyColor;
}
void CGUIProgressBar::setProgress( f32 progress )
{
FilledRatio = progress;
if ( AutomaticTextFormat != L"" )
{
wchar_t* buffer = new wchar_t[ AutomaticTextFormat.size() + 10 ];
swprintf( buffer, AutomaticTextFormat.size() + 10, AutomaticTextFormat.c_str(), 100*FilledRatio );
Text = buffer;
delete buffer;
}
}
f32 CGUIProgressBar::getProgress() const
{
return FilledRatio;
}
void CGUIProgressBar::draw()
{
CImageGUISkin* skin = static_cast<CImageGUISkin*>( Environment->getSkin() );
// Madoc added these changes to let the progress bar get its fill colors from the skin
if(bindColorsToSkin) {
EmptyColor = ((gui::SImageGUISkinConfig)skin->getConfig()).ProgressBar.Color;
FillColor = ((gui::SImageGUISkinConfig)skin->getConfig()).ProgressBarFilled.Color;
}
// End Madoc changes
skin->drawHorizontalProgressBar( this, AbsoluteRect, &AbsoluteClippingRect, FilledRatio, FillColor, EmptyColor );
// Draw text in center
skin->getFont(EGDF_DEFAULT)->draw( Text.c_str(), AbsoluteRect, skin->getColor(EGDC_BUTTON_TEXT), true, true, &AbsoluteClippingRect );
}
}
}
#ifndef CGUIPROGRESSBAR_H_
#define CGUIPROGRESSBAR_H_
#include <IGUIElement.h>
#include <SColor.h>
namespace irr
{
namespace gui
{
/*!
* A horizontal progess bar. ONLY works with CImageGUISkin applied - will fail
* if another skin is used.
*/
class CGUIProgressBar : public IGUIElement
{
public:
// If you want your progress bar colors to be independent of the skin set bind to false -- Madoc
CGUIProgressBar( IGUIElement* parent, IGUIEnvironment* environment, const core::rect<s32>& rectangle, s32 id=-1 ,bool bind=true);
//! Automatically updates the progress bar's text every time the progress changes.
//! Set format to NULL or an empty string to disable automatic text.
void setAutomaticText( const wchar_t* format );
void setFillColor( video::SColor fill );
video::SColor getFillColor() const;
void setEmptyColor( video::SColor empty );
video::SColor getEmptyColor() const;
void setProgress( f32 progress );
f32 getProgress() const;
virtual void draw();
private:
video::SColor FillColor;
video::SColor EmptyColor;
bool bindColorsToSkin;
f32 FilledRatio;
core::stringw AutomaticTextFormat;
};
} // namespace gui
} // namespace irr
#endif
This diff is collapsed.
#ifndef __C_GUISKIN_SYSTEM_H_INCLUDED__
#define __C_GUISKIN_SYSTEM_H_INCLUDED__
#ifdef _WIN32
#include <irrlicht.h>
#endif
#include "CImageGUISkin.h"
#include "CGUIProgressBar.h"
//#include "SkinLoader.h"
#include "../CXMLRegistry/CXMLRegistry.h"
#ifndef _WIN32
// gcc dosnt do 'debug'
#ifndef _DEBUG
#define _DEBUG
#endif
#endif
#define SKINSYSTEM_SKINFILE "/skin.xml"
using namespace irr;
class CGUISkinSystem {
private :
IrrlichtDevice *device;
io::IFileSystem *fs;
io::path skinsPath;
core::array<core::stringw> skinsList;
CXMLRegistry *registry;
gui::CImageGUISkin* loadSkinFromFile(const c8 *skinfile);
void ParseGUIElementStyle(gui::SImageGUIElementStyle& elem, const core::stringc& name,bool nullcolors=false);
bool checkSkinColor(gui::EGUI_DEFAULT_COLOR colToSet,const wchar_t *context,gui::CImageGUISkin *skin);
bool checkSkinSize(gui::EGUI_DEFAULT_SIZE sizeToSet,const wchar_t *context,const wchar_t *key,gui::CImageGUISkin *skin);
bool loadProperty(core::stringw key,gui::CImageGUISkin *skin);
public:
// Constructor
// path = Path to skins
// dev = Irrlicht device
CGUISkinSystem(core::string<char*> path,IrrlichtDevice *dev);
~CGUISkinSystem();
core::array<core::stringw> listSkins();
bool loadSkinList();
bool applySkin(const wchar_t *skinname);
gui::CGUIProgressBar *addProgressBar(gui::IGUIElement *parent,core::rect<s32> rect,bool bindColorsToSkin=true);
// Gets property from current skin
core::stringw getProperty(core::stringw key);
bool populateTreeView(gui::IGUITreeView *control,const core::stringc& skinname);
};
#endif
This diff is collapsed.
#ifndef CIMAGEGUISKIN_H_
#define CIMAGEGUISKIN_H_
#include <IGUISkin.h>
#include <irrString.h>
#include <irrMap.h>
#include <IGUISpriteBank.h>
namespace irr
{
namespace video
{
class IVideoDriver;
class ITexture;
}
namespace gui
{
struct SImageGUIElementStyle
{
struct SBorder
{
s32 Top, Left, Bottom, Right;
SBorder() : Top(0), Left(0), Bottom(0), Right(0) {}
};
SBorder SrcBorder;
SBorder DstBorder;
video::ITexture* Texture;
video::SColor Color;
SImageGUIElementStyle() : Texture(0), Color(255,255,255,255) {}
};
struct SImageGUISkinConfig
{
SImageGUIElementStyle SunkenPane, Window, Button, ButtonPressed, ButtonDisabled, ProgressBar, ProgressBarFilled, TabButton, TabButtonPressed, TabBody, MenuBar, MenuPane, MenuPressed, CheckBox, CheckBoxDisabled, ComboBox, ComboBoxDisabled;
video::SColor CheckBoxColor;
};
class CImageGUISkin : public IGUISkin
{
public:
CImageGUISkin( video::IVideoDriver* videoDriver, IGUISkin* fallbackSkin );
virtual ~CImageGUISkin();
void loadConfig( const SImageGUISkinConfig& config );
//! returns default color
virtual video::SColor getColor(EGUI_DEFAULT_COLOR color) const;
//! sets a default color
virtual void setColor(EGUI_DEFAULT_COLOR which, video::SColor newColor);
//! returns default color
virtual s32 getSize(EGUI_DEFAULT_SIZE size) const;
//! Returns a default text.
virtual const wchar_t* getDefaultText(EGUI_DEFAULT_TEXT text) const;
//! Sets a default text.
virtual void setDefaultText(EGUI_DEFAULT_TEXT which, const wchar_t* newText);
//! sets a default size
virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size);
//! returns the default font
virtual IGUIFont* getFont(EGUI_DEFAULT_FONT defaultFont) const;
//! sets a default font
virtual void setFont(IGUIFont* font, EGUI_DEFAULT_FONT defaultFont);
//! returns the sprite bank
virtual IGUISpriteBank* getSpriteBank() const;
//! sets the sprite bank
virtual void setSpriteBank(IGUISpriteBank* bank);
virtual u32 getIcon(EGUI_DEFAULT_ICON icon) const;
virtual void setIcon(EGUI_DEFAULT_ICON icon, u32 index);
virtual void draw3DButtonPaneStandard(IGUIElement* element,
const core::rect<s32>& rect,
const core::rect<s32>* clip=0);
virtual void draw3DButtonPanePressed(IGUIElement* element,
const core::rect<s32>& rect,
const core::rect<s32>* clip=0);
virtual void draw3DSunkenPane(IGUIElement* element,
video::SColor bgcolor, bool flat, bool fillBackGround,
const core::rect<s32>& rect,
const core::rect<s32>* clip=0);
/* Updates for irrlicht 1.7 by Mamnarock
virtual core::rect<s32> draw3DWindowBackground(IGUIElement* element,
bool drawTitleBar, video::SColor titleBarColor,
const core::rect<s32>& rect,
const core::rect<s32>* clip=0);
*/
virtual core::rect<s32> draw3DWindowBackground(IGUIElement* element,
bool drawTitleBar, video::SColor titleBarColor,
const core::rect<s32>& rect,
const core::rect<s32>* clip=0,
core::rect<s32>* checkClientArea=0);
virtual void draw3DMenuPane(IGUIElement* element,
const core::rect<s32>& rect,
const core::rect<s32>* clip=0);
virtual void draw3DToolBar(IGUIElement* element,
const core::rect<s32>& rect,
const core::rect<s32>* clip=0);
virtual void draw3DTabButton(IGUIElement* element, bool active,
const core::rect<s32>& rect, const core::rect<s32>* clip=0, EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT);
virtual void draw3DTabBody(IGUIElement* element, bool border, bool background,
const core::rect<s32>& rect, const core::rect<s32>* clip=0,s32 tabHeight=-1, gui::EGUI_ALIGNMENT alignment=EGUIA_UPPERLEFT );
virtual void drawIcon(IGUIElement* element, EGUI_DEFAULT_ICON icon,
const core::position2di position, u32 starttime=0, u32 currenttime=0,
bool loop=false, const core::rect<s32>* clip=0);
// Madoc - I had to add some things
// Exposes config so we can get the progress bar colors
virtual SImageGUISkinConfig getConfig() { return Config; }
// End Madoc adds
virtual void drawHorizontalProgressBar( IGUIElement* element, const core::rect<s32>& rectangle, const core::rect<s32>* clip,
f32 filledRatio, video::SColor fillColor, video::SColor emptyColor );
virtual void draw2DRectangle(IGUIElement* element, const video::SColor &color,
const core::rect<s32>& pos, const core::rect<s32>* clip = 0);
virtual void setProperty(core::stringw key, core::stringw value);
virtual core::stringw getProperty(core::stringw key);
private:
void drawElementStyle( const SImageGUIElementStyle& elem, const core::rect<s32>& rect, const core::rect<s32>* clip, video::SColor* color=0 );
video::IVideoDriver* VideoDriver;
IGUISkin* FallbackSkin;
SImageGUISkinConfig Config;
core::map<core::stringw,core::stringw> properties;
};
}
}
#endif
#ifndef _CLIP_RECTS_H_
#define _CLIP_RECTS_H_
#include <rect.h>
namespace irr
{
//! Workaround for a bug in IVideoDriver::draw2DImage( ITexture* tex, rect<s32> dstRect, rect<s32> srcRect, rect<s32>* clip, SColor* colors, bool alpha )
//! It modifies dstRect and srcRect so the resulting dstRect is entirely inside the clipping rect.
//! srcRect is scaled so the same part of the image is displayed.
//! Returns false if dstRect is entirely outside clip, or true if at least some of it is inside.
inline bool clipRects( core::rect<s32>& dstRect, core::rect<s32>& srcRect, const core::rect<s32>& clip )
{
// Clip left side
if ( dstRect.UpperLeftCorner.X < clip.UpperLeftCorner.X )
{
s32 w = clip.UpperLeftCorner.X - dstRect.UpperLeftCorner.X;
f32 percentRemoved = (f32)w / (f32)dstRect.getWidth();
dstRect.UpperLeftCorner.X = clip.UpperLeftCorner.X;
srcRect.UpperLeftCorner.X += (s32)(percentRemoved * srcRect.getWidth());
}
// Clip top side
if ( dstRect.UpperLeftCorner.Y < clip.UpperLeftCorner.Y )
{
s32 w = clip.UpperLeftCorner.Y - dstRect.UpperLeftCorner.Y;
f32 percentRemoved = (f32)w / (f32)dstRect.getHeight();
dstRect.UpperLeftCorner.Y = clip.UpperLeftCorner.Y;
srcRect.UpperLeftCorner.Y += (s32)(percentRemoved * srcRect.getHeight());
}
// Clip right side
if ( dstRect.LowerRightCorner.X > clip.LowerRightCorner.X )
{
s32 w = dstRect.LowerRightCorner.X - clip.LowerRightCorner.X;
f32 percentRemoved = (f32)w / (f32)dstRect.getWidth();
dstRect.LowerRightCorner.X = clip.LowerRightCorner.X;
srcRect.LowerRightCorner.X -= (s32)(percentRemoved * srcRect.getWidth());
}
// Clip bottom side
if ( dstRect.LowerRightCorner.Y > clip.LowerRightCorner.Y )
{
s32 w = dstRect.LowerRightCorner.Y - clip.LowerRightCorner.Y;
f32 percentRemoved = (f32)w / (f32)dstRect.getHeight();
dstRect.LowerRightCorner.Y = clip.LowerRightCorner.Y;
srcRect.LowerRightCorner.Y -= (s32)(percentRemoved * srcRect.getHeight());
}
return ( dstRect.getWidth() > 0 && dstRect.getHeight() > 0 );
}
} // namespace irr
#endif
......@@ -9,6 +9,7 @@
#include "duelclient.h"
#include "netserver.h"
#include "single_mode.h"
#include <sstream>
#ifndef _WIN32
#include <sys/types.h>
......@@ -34,6 +35,15 @@ bool Game::Initialize() {
device = irr::createDeviceEx(params);
if(!device)
return false;
// Apply skin
if(gameConf.skin_index >= 0) {
skinSystem = new CGUISkinSystem("skin", device);
core::array<core::stringw> skins = skinSystem->listSkins();
if((size_t)gameConf.skin_index < skins.size()) {
int index = skins.size() - gameConf.skin_index - 1; // reverse index
skinSystem->applySkin(skins[index].c_str());
}
}
linePatternD3D = 0;
linePatternGL = 0x0f0f;
waitFrame = 0;
......@@ -1109,6 +1119,7 @@ void Game::LoadConfig() {
gameConf.window_height = 640;
gameConf.resize_popup_menu = false;
gameConf.chkEnablePScale = 1;
gameConf.skin_index = -1;
if(fp) {
while(fgets(linebuf, 256, fp)) {
sscanf(linebuf, "%s = %s", strbuf, valbuf);
......@@ -1194,6 +1205,8 @@ void Game::LoadConfig() {
gameConf.resize_popup_menu = atoi(valbuf) > 0;
} else if(!strcmp(strbuf, "enable_pendulum_scale")) {
gameConf.chkEnablePScale = atoi(valbuf);
} else if (!strcmp(strbuf, "skin_index")) {
gameConf.skin_index = atoi(valbuf);
} else {
// options allowing multiple words
sscanf(linebuf, "%s = %240[^\n]", strbuf, valbuf);
......@@ -1297,6 +1310,8 @@ void Game::LoadConfig() {
gameConf.resize_popup_menu = atoi(valbuf) > 0;
} else if(!strcmp(strbuf, "enable_pendulum_scale")) {
gameConf.chkEnablePScale = atoi(valbuf);
} else if (!strcmp(strbuf, "skin_index")) {
gameConf.skin_index = atoi(valbuf);
} else {
// options allowing multiple words
sscanf(linebuf, "%s = %240[^\n]", strbuf, valbuf);
......@@ -1381,6 +1396,7 @@ void Game::SaveConfig() {
fprintf(fp, "window_height = %d\n", gameConf.window_height);
fprintf(fp, "resize_popup_menu = %d\n", gameConf.resize_popup_menu ? 1 : 0);
fprintf(fp, "enable_pendulum_scale = %d\n", ((mainGame->chkEnablePScale->isChecked()) ? 1 : 0));
fprintf(fp, "skin_index = %d\n", gameConf.skin_index);
fclose(fp);
}
void Game::ShowCardInfo(int code, bool resize) {
......
......@@ -8,6 +8,7 @@
#include <unordered_map>
#include <vector>
#include <list>
#include "CGUISkinSystem/CGUISkinSystem.h"
namespace ygo {
......@@ -52,6 +53,7 @@ struct Config {
double music_volume;
int music_mode;
int chkEnablePScale;
int skin_index;
};
struct DuelInfo {
......@@ -219,6 +221,8 @@ public:
irr::core::dimension2d<irr::u32> window_size;
float xScale;
float yScale;
CGUISkinSystem *skinSystem;
ClientField dField;
DeckBuilder deckBuilder;
......
......@@ -42,3 +42,4 @@ window_width = 1024
window_height = 640
resize_popup_menu = 0
enable_pendulum_scale = 1
skin_index = 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment