diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index faf5e2940c..8d6eb36691 100755 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -20,6 +20,7 @@ gee@pyro.nu #include "CText.h" #include "CCheckBox.h" #include "CRadioButton.h" +#include "CProgressBar.h" #include "MiniMap.h" #include "ps/Xeromyces.h" @@ -264,6 +265,7 @@ void CGUI::Initialize() AddObjectType("text", &CText::ConstructObject); AddObjectType("checkbox", &CCheckBox::ConstructObject); AddObjectType("radiobutton", &CRadioButton::ConstructObject); + AddObjectType("progressbar", &CProgressBar::ConstructObject); AddObjectType("minimap", &CMiniMap::ConstructObject); } @@ -997,7 +999,6 @@ void CGUI::LoadXMLFile(const string &Filename) try { - if (root_name == "objects") { Xeromyces_ReadRootObjects(node, &XeroFile); diff --git a/source/gui/CProgressBar.cpp b/source/gui/CProgressBar.cpp new file mode 100755 index 0000000000..4f67e75846 --- /dev/null +++ b/source/gui/CProgressBar.cpp @@ -0,0 +1,75 @@ +/* +CProgressBar +by Gustav Larsson +gee@pyro.nu +*/ + +#include "precompiled.h" +#include "GUI.h" +#include "CProgressBar.h" + +#include "ogl.h" + +using namespace std; + +//------------------------------------------------------------------- +// Constructor / Destructor +//------------------------------------------------------------------- +CProgressBar::CProgressBar() +{ + AddSetting(GUIST_CStr, "sprite-background"); + AddSetting(GUIST_CStr, "sprite-bar"); + AddSetting(GUIST_float, "caption"); // aka value from 0 to 100 +} + +CProgressBar::~CProgressBar() +{ +} + +void CProgressBar::HandleMessage(const SGUIMessage &Message) +{ + // Important + IGUIObject::HandleMessage(Message); + + switch (Message.type) + { + case GUIM_SETTINGS_UPDATED: + // Update scroll-bar + // TODO Gee: (2004-09-01) Is this really updated each time it should? + if (Message.value == CStr("caption")) + { + float value; + GUI::GetSetting(this, "caption", value); + if (value > 100.f) + GUI::SetSetting(this, "caption", 100.f); + else + if (value < 0.f) + GUI::SetSetting(this, "caption", 0.f); + } + break; + default: + break; + } +} + +void CProgressBar::Draw() +{ + if (GetGUI()) + { + float bz = GetBufferedZ(); + + CStr sprite_background, sprite_bar; + float value; + GUI::GetSetting(this, "sprite-background", sprite_background); + GUI::GetSetting(this, "sprite-bar", sprite_bar); + GUI::GetSetting(this, "caption", value); + + GetGUI()->DrawSprite(sprite_background, bz, m_CachedActualSize); + + + // Get size of bar (notice it is drawn slightly closer, to appear above the background) + CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top, + m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom); + GetGUI()->DrawSprite(sprite_bar, bz+0.01f, bar_size); + } +} diff --git a/source/gui/CProgressBar.h b/source/gui/CProgressBar.h new file mode 100755 index 0000000000..1b1cb5e176 --- /dev/null +++ b/source/gui/CProgressBar.h @@ -0,0 +1,61 @@ +/* +GUI Object - Progress bar +by Gustav Larsson +gee@pyro.nu + +--Overview-- + + GUI Object to show progress or a value visually. + +--More info-- + + Check GUI.h + +*/ + +#ifndef CProgressBar_H +#define CProgressBar_H + +//-------------------------------------------------------- +// Includes / Compiler directives +//-------------------------------------------------------- +#include "GUI.h" + +//-------------------------------------------------------- +// Macros +//-------------------------------------------------------- + +//-------------------------------------------------------- +// Types +//-------------------------------------------------------- + +//-------------------------------------------------------- +// Declarations +//-------------------------------------------------------- + +/** + * @author Gustav Larsson + * + * Object used to draw a value from 0 to 100 visually. + * + * @see IGUIObject + */ +class CProgressBar : public IGUIObject +{ + GUI_OBJECT(CProgressBar) + +public: + CProgressBar(); + virtual ~CProgressBar(); + +protected: + /** + * Draws the progress bar + */ + virtual void Draw(); + + // If caption is set, make sure it's within the interval 0-100 + void HandleMessage(const SGUIMessage &Message); +}; + +#endif diff --git a/source/gui/GUItext.cpp b/source/gui/GUItext.cpp index 92268af2f2..a332df4d34 100755 --- a/source/gui/GUItext.cpp +++ b/source/gui/GUItext.cpp @@ -141,7 +141,18 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback, TextCall.m_Size = size; SpriteCall.m_Area = size; - // TODO Gee: (2004-08-16) Eventually shouldn't be hardcoded + // Now displace the sprite if the additional value in the tag + // exists + if (itTextChunk->m_Tags[0].m_TagAdditionalValue != string()) + { + CSize displacement; + // Parse the value + if (!GUI::ParseString(itTextChunk->m_Tags[0].m_TagAdditionalValue, displacement)) + LOG(ERROR, LOG_CATEGORY, "Error parsing 'displace' value for tag [ICON]"); + else + SpriteCall.m_Area += displacement; + } + SpriteCall.m_TextureName = icon.m_TextureName; // Add sprite call @@ -288,7 +299,8 @@ void CGUIString::SetValue(const CStrW& str) // Setup parser // TODO Gee: (2004-08-16) Create and store this parser object somewhere to save loading time. CParser Parser; - Parser.InputTaskType("start", "$ident[_=_$value]"); + // I've added the option of an additional parameter. Only used for icons when writing this. + Parser.InputTaskType("start", "$ident[_=_$value_[$ident_=_$value_]]"); Parser.InputTaskType("end", "/$ident"); long position = 0; @@ -354,7 +366,7 @@ void CGUIString::SetValue(const CStrW& str) { if (Line.m_TaskTypeName == "start") { - // The tag + // The tag TextChunk::Tag tag; std::string Str_TagType; @@ -367,9 +379,26 @@ void CGUIString::SetValue(const CStrW& str) else { // Check for possible value-strings - if (Line.GetArgCount() == 2) + if (Line.GetArgCount() >= 2) Line.GetArgString(1, tag.m_TagValue); + // Check if an additional parameter was specified + if (Line.GetArgCount() == 4) + { + string str; + Line.GetArgString(2, str); + + if (tag.m_TagType == TextChunk::Tag::TAG_ICON && + str == "displace") + { + Line.GetArgString(3, tag.m_TagAdditionalValue); + } + else + { + LOG(WARNING, LOG_CATEGORY, "Trying to declare an additional attribute ('%s') in a [%s]-tag, which the tag isn't accepting", str.c_str(), Str_TagType.c_str()); + } + } + // Finalize last if (curpos != from_nonraw) { diff --git a/source/gui/GUItext.h b/source/gui/GUItext.h index d395f41594..234cf361cd 100755 --- a/source/gui/GUItext.h +++ b/source/gui/GUItext.h @@ -202,6 +202,11 @@ public: * m_TagValue is 'Hello' */ std::string m_TagValue; + + /** + * Some tags need an additional value + */ + std::string m_TagAdditionalValue; }; /**