More rating bar and addon voting geniousness (server-side still needs update)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13412 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
6198c43728
commit
40de2f62ae
@ -17,7 +17,7 @@
|
||||
<label id="revision" width="100%" text=""/>
|
||||
</div>
|
||||
<div width="50%" height="32" layout="vertical-row" >
|
||||
<ratingbar id="rating" height="64" width="100%"/>
|
||||
<ratingbar id="rating" height="32" width="96" align="right"/>
|
||||
</div>
|
||||
</div>
|
||||
<spacer height="10" width="1"/>
|
||||
|
@ -5,17 +5,21 @@
|
||||
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
|
||||
I18N="In the vote dialog' dialog" text="Vote"/>
|
||||
|
||||
<spacer proportion="1" width="50">
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<div width="80%" height="fit" layout="vertical-row" >
|
||||
<ratingbar id="rating" height="64" width="100%"/>
|
||||
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" text=""/>
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<div width="90%" height="64" align="center" layout="vertical-row" >
|
||||
<ratingbar id="rating" align="center" height="64" width="192"/>
|
||||
</div>
|
||||
|
||||
<spacer proportion="1" width="50">
|
||||
<spacer height="40" width="50">
|
||||
|
||||
<buttonbar id="options" width="25%" height="15%" align="center">
|
||||
<icon-button id="submit" width="64" height="64" icon="gui/green_check.png"
|
||||
I18N="Vote dialog" text="Submit" label_location="none"/>
|
||||
<buttonbar id="options" width="25%" height="20%" align="center">
|
||||
<icon-button id="save" width="64" height="64" icon="gui/green_check.png"
|
||||
I18N="Vote dialog" text="Save" label_location="none"/>
|
||||
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
|
||||
I18N="Vote dialog" text="Cancel" label_location="none"/>
|
||||
</buttonbar>
|
||||
|
@ -833,13 +833,18 @@ void Skin::drawRatingBar(Widget *w, const core::recti &rect,
|
||||
}
|
||||
|
||||
// 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;
|
||||
const int x_from = rect.UpperLeftCorner.X; // + (rect.getWidth() - star_w) / 2;
|
||||
const int y_from = rect.UpperLeftCorner.Y; // + (rect.getHeight() - star_h) / 2;
|
||||
|
||||
core::recti stars_rect(x_from, y_from, x_from + (star_number * star_w), y_from + star_h);
|
||||
|
||||
ratingBar->setStepValuesByMouse(irr_driver->getDevice()->getCursorControl()->getPosition(), stars_rect);
|
||||
|
||||
SColor colors[] = { SColor(100,255,255,255),
|
||||
SColor(100,255,255,255),
|
||||
SColor(100,255,255,255),
|
||||
SColor(100,255,255,255) };
|
||||
|
||||
for (int i = 0; i < star_number; i++)
|
||||
{
|
||||
core::recti star_rect = rect;
|
||||
@ -856,7 +861,8 @@ void Skin::drawRatingBar(Widget *w, const core::recti &rect,
|
||||
|
||||
GUIEngine::getDriver()->draw2DImage(texture,
|
||||
star_rect, source_area,
|
||||
0 /* no clipping */, 0,
|
||||
0 /* no clipping */,
|
||||
(w->m_deactivated || ID_DEBUG) ? colors : 0,
|
||||
true /* alpha */);
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ using namespace irr;
|
||||
// -----------------------------------------------------------------------------
|
||||
RatingBarWidget::RatingBarWidget() : Widget(WTYPE_RATINGBAR)
|
||||
{
|
||||
m_allow_voting = false;
|
||||
m_rating = 0.0f;
|
||||
m_hover_rating = 0.0f;
|
||||
m_stars = 3;
|
||||
@ -45,7 +46,7 @@ RatingBarWidget::RatingBarWidget() : Widget(WTYPE_RATINGBAR)
|
||||
// -----------------------------------------------------------------------------
|
||||
void RatingBarWidget::add()
|
||||
{
|
||||
irr::core::rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
|
||||
const irr::core::recti 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);
|
||||
@ -103,23 +104,25 @@ void RatingBarWidget::setRating(float rating)
|
||||
|
||||
void RatingBarWidget::setStepValuesByMouse(const core::position2di & mouse_position, const core::recti & stars_rect)
|
||||
{
|
||||
if(stars_rect.isPointInside(mouse_position))
|
||||
{
|
||||
m_hovering = true;
|
||||
m_hover_rating = (float)(mouse_position.X - stars_rect.UpperLeftCorner.X) / (float)stars_rect.getWidth() * (float)m_stars;
|
||||
setStepValues(m_hover_rating );
|
||||
if(m_allow_voting & isActivated()){
|
||||
if(stars_rect.isPointInside(mouse_position))
|
||||
{
|
||||
m_hovering = true;
|
||||
m_hover_rating = (float)(mouse_position.X - stars_rect.UpperLeftCorner.X) / (float)stars_rect.getWidth() * (float)m_stars;
|
||||
setStepValues(m_hover_rating );
|
||||
}
|
||||
else if(m_hovering)
|
||||
{
|
||||
setStepValues(m_rating);
|
||||
m_hovering = false;
|
||||
}
|
||||
}
|
||||
else if(m_hovering)
|
||||
{
|
||||
setStepValues(m_rating);
|
||||
m_hovering = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RatingBarWidget::onClick()
|
||||
{
|
||||
m_rating = m_hover_rating;
|
||||
if(m_allow_voting & isActivated())
|
||||
m_rating = m_hover_rating;
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,6 +42,7 @@ namespace GUIEngine
|
||||
int m_steps;
|
||||
std::vector<int> m_star_values;
|
||||
bool m_hovering;
|
||||
bool m_allow_voting;
|
||||
|
||||
void setStepValues(float rating);
|
||||
|
||||
@ -73,6 +74,8 @@ namespace GUIEngine
|
||||
void setStepValuesByMouse(const core::position2di & mouse_position, const core::recti & stars_rect);
|
||||
|
||||
virtual void onClick();
|
||||
|
||||
void allowVoting() { m_allow_voting = true; }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ namespace Online{
|
||||
|
||||
// ============================================================================
|
||||
|
||||
const XMLRequest * CurrentUser::requestGetAddonVote( uint32_t addon_id)
|
||||
const XMLRequest * CurrentUser::requestGetAddonVote( const std::string & addon_id) const
|
||||
{
|
||||
assert(isRegisteredUser());
|
||||
XMLRequest * request = new XMLRequest();
|
||||
@ -261,7 +261,7 @@ namespace Online{
|
||||
|
||||
// ============================================================================
|
||||
|
||||
const XMLRequest * CurrentUser::requestSetAddonVote( uint32_t addon_id)
|
||||
const XMLRequest * CurrentUser::requestSetAddonVote( const std::string & addon_id, float rating) const
|
||||
{
|
||||
assert(isRegisteredUser());
|
||||
XMLRequest * request = new XMLRequest();
|
||||
@ -270,6 +270,7 @@ namespace Online{
|
||||
request->setParameter("token", getToken());
|
||||
request->setParameter("id", getUserID());
|
||||
request->setParameter("addon-id", addon_id);
|
||||
request->setParameter("rating", rating);
|
||||
HTTPManager::get()->addRequest(request);
|
||||
return request;
|
||||
}
|
||||
|
@ -129,8 +129,8 @@ namespace Online{
|
||||
const XMLRequest * requestRecovery(const irr::core::stringw &username,
|
||||
const irr::core::stringw &email);
|
||||
|
||||
const XMLRequest * requestGetAddonVote(uint32_t addon_id);
|
||||
const XMLRequest * requestSetAddonVote(uint32_t addon_id);
|
||||
const XMLRequest * requestGetAddonVote(const std::string & addon_id) const;
|
||||
const XMLRequest * requestSetAddonVote(const std::string & addon_id, float rating) const;
|
||||
|
||||
/** Returns the username if signed in. */
|
||||
const irr::core::stringw getUserName() const;
|
||||
|
@ -37,29 +37,47 @@ using namespace Online;
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
VoteDialog::VoteDialog(const std::string & addon_id)
|
||||
: ModalDialog(0.8f,0.8f)
|
||||
: ModalDialog(0.8f,0.6f), m_addon_id(addon_id)
|
||||
{
|
||||
m_fetch_vote_request = NULL;
|
||||
m_perform_vote_request = NULL;
|
||||
m_self_destroy = false;
|
||||
loadFromFile("online/vote_dialog.stkgui");
|
||||
|
||||
m_info_widget = getWidget<LabelWidget>("info");
|
||||
assert(m_info_widget != NULL);
|
||||
|
||||
m_rating_widget = getWidget<RatingBarWidget>("rating");
|
||||
assert(m_rating_widget != NULL);
|
||||
m_rating_widget->setRating(0);
|
||||
m_rating_widget->allowVoting();
|
||||
m_options_widget = getWidget<RibbonWidget>("options");
|
||||
assert(m_options_widget != NULL);
|
||||
m_submit_widget = getWidget<IconButtonWidget>("submit");
|
||||
assert(m_submit_widget != NULL);
|
||||
m_save_widget = getWidget<IconButtonWidget>("save");
|
||||
assert(m_save_widget != NULL);
|
||||
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
|
||||
assert(m_cancel_widget != NULL);
|
||||
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
m_fetch_vote_request = CurrentUser::get()->requestGetAddonVote(m_addon_id);
|
||||
|
||||
m_rating_widget->setDeactivated();
|
||||
m_save_widget->setDeactivated();
|
||||
m_cancel_widget->setDeactivated();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
VoteDialog::~VoteDialog()
|
||||
{
|
||||
//delete m_server_join_request;
|
||||
delete m_fetch_vote_request;
|
||||
delete m_perform_vote_request;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool VoteDialog::onEscapePressed()
|
||||
{
|
||||
return m_cancel_widget->isActivated();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -75,6 +93,19 @@ GUIEngine::EventPropagation VoteDialog::processEvent(const std::string& eventSou
|
||||
if (eventSource == m_options_widget->m_properties[PROP_ID])
|
||||
{
|
||||
const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
if (selection == m_cancel_widget->m_properties[PROP_ID])
|
||||
{
|
||||
m_self_destroy = true;
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (selection == m_save_widget->m_properties[PROP_ID])
|
||||
{
|
||||
m_perform_vote_request = CurrentUser::get()->requestSetAddonVote(m_addon_id, m_rating_widget->getRating());
|
||||
m_rating_widget->setDeactivated();
|
||||
m_save_widget->setDeactivated();
|
||||
m_cancel_widget->setDeactivated();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
}
|
||||
@ -83,6 +114,58 @@ GUIEngine::EventPropagation VoteDialog::processEvent(const std::string& eventSou
|
||||
|
||||
void VoteDialog::onUpdate(float dt)
|
||||
{
|
||||
if(m_fetch_vote_request != NULL)
|
||||
{
|
||||
if(m_fetch_vote_request->isDone())
|
||||
{
|
||||
if(m_fetch_vote_request->isSuccess())
|
||||
{
|
||||
m_info_widget->setDefaultColor();
|
||||
m_info_widget->setText(_("bla"), false); //FIXME
|
||||
m_options_widget->setActivated();
|
||||
m_rating_widget->setActivated();
|
||||
}
|
||||
else
|
||||
{
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
m_info_widget->setErrorColor();
|
||||
m_info_widget->setText(m_fetch_vote_request->getInfo(), false);
|
||||
m_cancel_widget->setActivated();
|
||||
}
|
||||
delete m_fetch_vote_request;
|
||||
m_fetch_vote_request = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_info_widget->setText(irr::core::stringw(_("Fetching last vote")) + Messages::loadingDots(), false);
|
||||
}
|
||||
}
|
||||
if(m_perform_vote_request != NULL)
|
||||
{
|
||||
if(m_perform_vote_request->isDone())
|
||||
{
|
||||
if(m_perform_vote_request->isSuccess())
|
||||
{
|
||||
m_info_widget->setDefaultColor();
|
||||
m_info_widget->setText(_("Vote cast! You can now close the window."), false);
|
||||
m_cancel_widget->setActivated();
|
||||
}
|
||||
else
|
||||
{
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
m_info_widget->setErrorColor();
|
||||
m_info_widget->setText(m_perform_vote_request->getInfo(), false);
|
||||
m_options_widget->setActivated();
|
||||
m_rating_widget->setActivated();
|
||||
}
|
||||
delete m_perform_vote_request;
|
||||
m_perform_vote_request = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_info_widget->setText(irr::core::stringw(_("Performing vote")) + Messages::loadingDots(), false);
|
||||
}
|
||||
}
|
||||
if (m_self_destroy)
|
||||
ModalDialog::dismiss();
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "guiengine/widgets.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "utils/types.hpp"
|
||||
#include "states_screens/dialogs/login_dialog.hpp"
|
||||
|
||||
|
||||
@ -44,14 +43,17 @@ public :
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
const std::string m_addon_id;
|
||||
bool m_self_destroy;
|
||||
//const Online::CurrentUser::AddonVoteRequest * m_addon_vote_request;
|
||||
const Online::XMLRequest * m_fetch_vote_request;
|
||||
const Online::XMLRequest * m_perform_vote_request;
|
||||
|
||||
GUIEngine::LabelWidget * m_info_widget;
|
||||
|
||||
GUIEngine::RatingBarWidget * m_rating_widget;
|
||||
|
||||
GUIEngine::RibbonWidget * m_options_widget;
|
||||
GUIEngine::IconButtonWidget * m_submit_widget;
|
||||
GUIEngine::IconButtonWidget * m_save_widget;
|
||||
GUIEngine::IconButtonWidget * m_cancel_widget;
|
||||
|
||||
public:
|
||||
@ -59,6 +61,7 @@ public:
|
||||
~VoteDialog();
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||
virtual void onUpdate(float dt);
|
||||
virtual bool onEscapePressed();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user