Apply patch by xenux to replace the text rating with star icons. Thanks\!
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12954 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
6b01328169
commit
4039b9a7ef
@ -16,8 +16,8 @@
|
|||||||
<label id="size" width="100%" text=""/>
|
<label id="size" width="100%" text=""/>
|
||||||
<label id="revision" width="100%" text=""/>
|
<label id="revision" width="100%" text=""/>
|
||||||
</div>
|
</div>
|
||||||
<div width="50%" height="100%" layout="vertical-row" >
|
<div width="50%" height="32" layout="vertical-row" >
|
||||||
<label id="rating" width="100%" text=""/>
|
<ratingbar id="rating" height="32" width="100%" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<spacer height="10"/>
|
<spacer height="10"/>
|
||||||
|
@ -211,4 +211,7 @@ when the border that intersect at this corner are enabled.
|
|||||||
<color type="text_field" state="neutral" a="255" r="215" g="215" b="215" />
|
<color type="text_field" state="neutral" a="255" r="215" g="215" b="215" />
|
||||||
<color type="text_field" state="focused" a="255" r="0" g="150" b="0" />
|
<color type="text_field" state="focused" a="255" r="0" g="150" b="0" />
|
||||||
|
|
||||||
|
<!-- Rating star image -->
|
||||||
|
<element type="rating" state="neutral" image="glass/rating_star.png" />
|
||||||
|
|
||||||
</skin>
|
</skin>
|
||||||
|
@ -211,4 +211,7 @@ when the border that intersect at this corner are enabled.
|
|||||||
<color type="text_field" state="neutral" a="255" r="215" g="215" b="215" />
|
<color type="text_field" state="neutral" a="255" r="215" g="215" b="215" />
|
||||||
<color type="text_field" state="focused" a="255" r="138" g="138" b="138" />
|
<color type="text_field" state="focused" a="255" r="138" g="138" b="138" />
|
||||||
|
|
||||||
|
<!-- Rating star image -->
|
||||||
|
<element type="rating" state="neutral" image="ocean/rating_star.png" />
|
||||||
|
|
||||||
</skin>
|
</skin>
|
||||||
|
@ -210,4 +210,7 @@ when the border that intersect at this corner are enabled.
|
|||||||
<color type="text_field" state="neutral" a="255" r="215" g="215" b="215" />
|
<color type="text_field" state="neutral" a="255" r="215" g="215" b="215" />
|
||||||
<color type="text_field" state="focused" a="255" r="138" g="138" b="138" />
|
<color type="text_field" state="focused" a="255" r="138" g="138" b="138" />
|
||||||
|
|
||||||
|
<!-- Rating star image -->
|
||||||
|
<element type="rating" state="neutral" image="peach/rating_star.png" />
|
||||||
|
|
||||||
</skin>
|
</skin>
|
||||||
|
BIN
data/gui/skins/glass/rating_star.png
Normal file
BIN
data/gui/skins/glass/rating_star.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 965 B |
BIN
data/gui/skins/ocean/rating_star.png
Normal file
BIN
data/gui/skins/ocean/rating_star.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 965 B |
BIN
data/gui/skins/peach/rating_star.png
Normal file
BIN
data/gui/skins/peach/rating_star.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 965 B |
@ -73,6 +73,7 @@ src/guiengine/widgets/progress_bar_widget.cpp
|
|||||||
src/guiengine/widgets/ribbon_widget.cpp
|
src/guiengine/widgets/ribbon_widget.cpp
|
||||||
src/guiengine/widgets/spinner_widget.cpp
|
src/guiengine/widgets/spinner_widget.cpp
|
||||||
src/guiengine/widgets/text_box_widget.cpp
|
src/guiengine/widgets/text_box_widget.cpp
|
||||||
|
src/guiengine/widgets/rating_bar_widget.cpp
|
||||||
src/input/binding.cpp
|
src/input/binding.cpp
|
||||||
src/input/device_manager.cpp
|
src/input/device_manager.cpp
|
||||||
src/input/input_device.cpp
|
src/input/input_device.cpp
|
||||||
@ -318,6 +319,7 @@ src/guiengine/widgets/progress_bar_widget.hpp
|
|||||||
src/guiengine/widgets/ribbon_widget.hpp
|
src/guiengine/widgets/ribbon_widget.hpp
|
||||||
src/guiengine/widgets/spinner_widget.hpp
|
src/guiengine/widgets/spinner_widget.hpp
|
||||||
src/guiengine/widgets/text_box_widget.hpp
|
src/guiengine/widgets/text_box_widget.hpp
|
||||||
|
src/guiengine/widgets/rating_bar_widget.hpp
|
||||||
src/input/binding.hpp
|
src/input/binding.hpp
|
||||||
src/input/device_manager.hpp
|
src/input/device_manager.hpp
|
||||||
src/input/input.hpp
|
src/input/input.hpp
|
||||||
|
@ -164,6 +164,8 @@ supertuxkart_SOURCES = \
|
|||||||
guiengine/widgets/text_box_widget.hpp \
|
guiengine/widgets/text_box_widget.hpp \
|
||||||
guiengine/widgets/progress_bar_widget.cpp \
|
guiengine/widgets/progress_bar_widget.cpp \
|
||||||
guiengine/widgets/progress_bar_widget.hpp \
|
guiengine/widgets/progress_bar_widget.hpp \
|
||||||
|
guiengine/widgets/rating_bar_widget.cpp \
|
||||||
|
guiengine/widgets/rating_bar_widget.hpp \
|
||||||
input/binding.cpp \
|
input/binding.cpp \
|
||||||
input/binding.hpp \
|
input/binding.hpp \
|
||||||
input/device_manager.cpp \
|
input/device_manager.cpp \
|
||||||
|
@ -175,6 +175,10 @@ void Screen::parseScreenFileDiv(irr::io::IXMLReader* xml, PtrVector<Widget>& app
|
|||||||
{
|
{
|
||||||
append_to.push_back(new TextBoxWidget());
|
append_to.push_back(new TextBoxWidget());
|
||||||
}
|
}
|
||||||
|
else if (wcscmp(L"ratingbar", xml->getNodeName()) == 0)
|
||||||
|
{
|
||||||
|
append_to.push_back(new RatingBarWidget());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "/!\\ Warning /!\\ : unknown tag found in STK GUI file : '"
|
std::cerr << "/!\\ Warning /!\\ : unknown tag found in STK GUI file : '"
|
||||||
|
@ -805,6 +805,60 @@ void Skin::drawProgress(Widget* w, const core::recti &rect,
|
|||||||
}
|
}
|
||||||
} // drawProgress
|
} // drawProgress
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @param focused whether this element is focus by the master player (focus
|
||||||
|
* for other players is not supported)
|
||||||
|
*/
|
||||||
|
void Skin::drawRatingBar(Widget *w, const core::recti &rect,
|
||||||
|
const bool pressed, const bool focused)
|
||||||
|
{
|
||||||
|
static const int step_number = 3; // Harcoded number of step.
|
||||||
|
|
||||||
|
const ITexture *texture = SkinConfig::m_render_params["rating::neutral"].getImage();
|
||||||
|
const int texture_w = texture->getSize().Width / 4;
|
||||||
|
const int texture_h = texture->getSize().Height;
|
||||||
|
const float aspect_ratio = 1.0f;
|
||||||
|
|
||||||
|
RatingBarWidget *ratingBar = (RatingBarWidget*)w;
|
||||||
|
const int star_number = ratingBar->getStarNumber();
|
||||||
|
|
||||||
|
int star_h = rect.getHeight();
|
||||||
|
int star_w = (int)(aspect_ratio * star_h);
|
||||||
|
|
||||||
|
if (rect.getWidth() < star_w * star_number)
|
||||||
|
{
|
||||||
|
const float scale_factor = rect.getWidth() / (float)(star_w * star_number);
|
||||||
|
star_w = (int)(star_w * scale_factor);
|
||||||
|
star_h = (int)(star_h * scale_factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// center horizontally and vertically
|
||||||
|
const int x_from = rect.UpperLeftCorner.X + (rect.getWidth() - star_w) / 2;
|
||||||
|
const int y_from = rect.UpperLeftCorner.Y + (rect.getHeight() - star_h) / 2;
|
||||||
|
|
||||||
|
for (int i = 0; i < star_number; i++)
|
||||||
|
{
|
||||||
|
core::recti star_rect = rect;
|
||||||
|
|
||||||
|
star_rect.UpperLeftCorner.X = x_from + i * star_w;
|
||||||
|
star_rect.UpperLeftCorner.Y = y_from;
|
||||||
|
star_rect.LowerRightCorner.X = x_from + (i + 1) * star_w;
|
||||||
|
star_rect.LowerRightCorner.Y = y_from + star_h;
|
||||||
|
|
||||||
|
int step = ratingBar->getStepOfStar(i, step_number);
|
||||||
|
|
||||||
|
const core::recti source_area(texture_w * step, 0,
|
||||||
|
texture_w * (step + 1), texture_h);
|
||||||
|
|
||||||
|
GUIEngine::getDriver()->draw2DImage(texture,
|
||||||
|
star_rect, source_area,
|
||||||
|
0 /* no clipping */, 0,
|
||||||
|
true /* alpha */);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // drawRatingBar
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
SColor Skin::getColor(const std::string &name)
|
SColor Skin::getColor(const std::string &name)
|
||||||
{
|
{
|
||||||
@ -1810,6 +1864,10 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect,
|
|||||||
{
|
{
|
||||||
drawCheckBox(rect, widget, focused);
|
drawCheckBox(rect, widget, focused);
|
||||||
}
|
}
|
||||||
|
else if(type == WTYPE_RATINGBAR)
|
||||||
|
{
|
||||||
|
drawRatingBar(widget, rect, pressed, focused);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ID_DEBUG && id != -1 && Widget::isFocusableId(id))
|
if (ID_DEBUG && id != -1 && Widget::isFocusableId(id))
|
||||||
|
@ -293,6 +293,8 @@ namespace GUIEngine
|
|||||||
const bool pressed, const bool focused);
|
const bool pressed, const bool focused);
|
||||||
void drawProgress(Widget* w, const core::rect< s32 > &rect,
|
void drawProgress(Widget* w, const core::rect< s32 > &rect,
|
||||||
const bool pressed, const bool focused);
|
const bool pressed, const bool focused);
|
||||||
|
void drawRatingBar(Widget* w, const core::rect< s32 > &rect,
|
||||||
|
const bool pressed, const bool focused);
|
||||||
void drawRibbon(const core::rect< s32 > &rect, Widget* widget,
|
void drawRibbon(const core::rect< s32 > &rect, Widget* widget,
|
||||||
const bool pressed, bool focused);
|
const bool pressed, bool focused);
|
||||||
void drawRibbonChild(const core::rect< s32 > &rect, Widget* widget,
|
void drawRibbonChild(const core::rect< s32 > &rect, Widget* widget,
|
||||||
|
@ -52,7 +52,8 @@ namespace GUIEngine
|
|||||||
WTYPE_MODEL_VIEW,
|
WTYPE_MODEL_VIEW,
|
||||||
WTYPE_LIST,
|
WTYPE_LIST,
|
||||||
WTYPE_TEXTBOX,
|
WTYPE_TEXTBOX,
|
||||||
WTYPE_PROGRESS
|
WTYPE_PROGRESS,
|
||||||
|
WTYPE_RATINGBAR
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BadgeType
|
enum BadgeType
|
||||||
|
@ -13,3 +13,4 @@
|
|||||||
#include "guiengine/widgets/text_box_widget.hpp"
|
#include "guiengine/widgets/text_box_widget.hpp"
|
||||||
#include "guiengine/widgets/label_widget.hpp"
|
#include "guiengine/widgets/label_widget.hpp"
|
||||||
#include "guiengine/widgets/check_box_widget.hpp"
|
#include "guiengine/widgets/check_box_widget.hpp"
|
||||||
|
#include "guiengine/widgets/rating_bar_widget.hpp"
|
||||||
|
85
src/guiengine/widgets/rating_bar_widget.cpp
Normal file
85
src/guiengine/widgets/rating_bar_widget.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
// Copyright (C) 2009 Marianne Gagnon
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation; either version 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
#include "guiengine/engine.hpp"
|
||||||
|
#include "guiengine/widgets/rating_bar_widget.hpp"
|
||||||
|
#include "utils/string_utils.hpp"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <IGUIEnvironment.h>
|
||||||
|
#include <IGUIElement.h>
|
||||||
|
#include <IGUIButton.h>
|
||||||
|
|
||||||
|
using namespace GUIEngine;
|
||||||
|
using namespace irr::core;
|
||||||
|
using namespace irr;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
RatingBarWidget::RatingBarWidget() : Widget(WTYPE_RATINGBAR)
|
||||||
|
{
|
||||||
|
m_rating = 0;
|
||||||
|
m_star_number = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void RatingBarWidget::add()
|
||||||
|
{
|
||||||
|
rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
|
||||||
|
m_element = GUIEngine::getGUIEnv()->addButton(widget_size, m_parent, getNewNoFocusID(), NULL, L"");
|
||||||
|
|
||||||
|
m_id = m_element->getID();
|
||||||
|
m_element->setTabStop(false);
|
||||||
|
m_element->setTabGroup(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
/** Get the current step of the star
|
||||||
|
*
|
||||||
|
* \param index The index of the star.
|
||||||
|
* \param max_step The number of different steps that a star can display. Two
|
||||||
|
* step are obligatory: full and empty.
|
||||||
|
* \return The current step of the star.
|
||||||
|
*/
|
||||||
|
int RatingBarWidget::getStepOfStar(int index, int max_step)
|
||||||
|
{
|
||||||
|
assert(index >= 0 && index < m_star_number); // Index must be between 0 and m_star_number - 1.
|
||||||
|
assert(max_step >= 2); // The maximun number of step must be superior or equals to 2.
|
||||||
|
|
||||||
|
if (m_rating < index)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (m_rating > index + 1)
|
||||||
|
{
|
||||||
|
return max_step - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float step_size = 1 / (float)(max_step - 1);
|
||||||
|
|
||||||
|
for (int i = 0; i < max_step; i++)
|
||||||
|
{
|
||||||
|
if (m_rating > index + step_size * (i - 0.5)
|
||||||
|
&& m_rating < index + step_size * (i + 0.5))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
// TODO: Assert or throws a exception, what type?
|
||||||
|
} // getStepOfStar
|
||||||
|
|
66
src/guiengine/widgets/rating_bar_widget.hpp
Normal file
66
src/guiengine/widgets/rating_bar_widget.hpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
// Copyright (C) 2009 Marianne Gagnon
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation; either version 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef HEADER_RATING_BAR_HPP
|
||||||
|
#define HEADER_RATING_BAR_HPP
|
||||||
|
|
||||||
|
#include <irrString.h>
|
||||||
|
|
||||||
|
#include "guiengine/widget.hpp"
|
||||||
|
#include "utils/leak_check.hpp"
|
||||||
|
#include "utils/ptr_vector.hpp"
|
||||||
|
|
||||||
|
namespace GUIEngine
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* \brief A rating bar widget.
|
||||||
|
* \ingroup widgetsgroup
|
||||||
|
*/
|
||||||
|
class RatingBarWidget : public Widget
|
||||||
|
{
|
||||||
|
|
||||||
|
float m_rating;
|
||||||
|
int m_star_number;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
LEAK_CHECK()
|
||||||
|
|
||||||
|
RatingBarWidget();
|
||||||
|
virtual ~RatingBarWidget() {}
|
||||||
|
|
||||||
|
void add();
|
||||||
|
|
||||||
|
/** Change the rating value of the widget. */
|
||||||
|
void setRating(float rating) { m_rating = rating; };
|
||||||
|
|
||||||
|
/** Get the current value of the widget. */
|
||||||
|
int getRating() {return m_rating; };
|
||||||
|
|
||||||
|
/** Change the number of star of the widget. */
|
||||||
|
void setStarNumber(int star_number) { m_star_number = star_number; };
|
||||||
|
|
||||||
|
/** Get the current number of star of the widget. */
|
||||||
|
int getStarNumber() {return m_star_number; };
|
||||||
|
|
||||||
|
int getStepOfStar(int index, int max_step);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -83,8 +83,8 @@ void AddonsLoading::beforeAddingWidgets()
|
|||||||
m_progress = getWidget<ProgressBarWidget>("progress");
|
m_progress = getWidget<ProgressBarWidget>("progress");
|
||||||
m_back_button = getWidget<IconButtonWidget> ("back" );
|
m_back_button = getWidget<IconButtonWidget> ("back" );
|
||||||
|
|
||||||
|
|
||||||
RibbonWidget* r = getWidget<RibbonWidget>("actions");
|
RibbonWidget* r = getWidget<RibbonWidget>("actions");
|
||||||
|
RatingBarWidget* rating = getWidget<RatingBarWidget>("rating");
|
||||||
|
|
||||||
if (m_addon.isInstalled())
|
if (m_addon.isInstalled())
|
||||||
{
|
{
|
||||||
@ -107,11 +107,8 @@ void AddonsLoading::beforeAddingWidgets()
|
|||||||
->setText(m_addon.getDescription().c_str());
|
->setText(m_addon.getDescription().c_str());
|
||||||
core::stringw revision = _("Version: %d", m_addon.getRevision());
|
core::stringw revision = _("Version: %d", m_addon.getRevision());
|
||||||
getWidget<LabelWidget>("revision")->setText(revision, false);
|
getWidget<LabelWidget>("revision")->setText(revision, false);
|
||||||
char rating_val[4];
|
rating->setRating(m_addon.getRating());
|
||||||
std::sprintf(rating_val, "%.1f", m_addon.getRating());
|
rating->setStarNumber(3);
|
||||||
//I18N: for add-on rating, "Rating: 1.5/3.0"
|
|
||||||
core::stringw rating = _("Rating: %s/%s", rating_val, "3.0");
|
|
||||||
getWidget<LabelWidget>("rating")->setText(rating, false);
|
|
||||||
|
|
||||||
// Display flags for this addon
|
// Display flags for this addon
|
||||||
// ============================
|
// ============================
|
||||||
|
Loading…
Reference in New Issue
Block a user