Moved requestGetAddonVote from CurrentUser into VoteDialog.
Some cosmetic only changes to VoteDialog to follow style guide.
This commit is contained in:
@@ -262,21 +262,6 @@ namespace Online
|
||||
//FIXME needs changes for actual valid joining
|
||||
} // ServerJoinRequest::callback
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
const XMLRequest*
|
||||
CurrentUser::requestGetAddonVote(const std::string & addon_id) const
|
||||
{
|
||||
assert(m_state == US_SIGNED_IN);
|
||||
XMLRequest * request = new XMLRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action", "get-addon-vote");
|
||||
request->addParameter("token", getToken());
|
||||
request->addParameter("userid", getID());
|
||||
request->addParameter("addonid", addon_id.substr(6));
|
||||
request->queue();
|
||||
return request;
|
||||
} // requestGetAddonVote
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** A request to the server, to perform a vote on an addon.
|
||||
* \param addon_id the id of the addon to vote for.
|
||||
|
||||
@@ -130,7 +130,6 @@ namespace Online
|
||||
void requestSignOut();
|
||||
ServerJoinRequest * requestServerJoin(uint32_t server_id, bool request_now = true);
|
||||
|
||||
const XMLRequest * requestGetAddonVote(const std::string & addon_id) const;
|
||||
const SetAddonVoteRequest * requestSetAddonVote(const std::string & addon_id, float rating) const;
|
||||
void requestFriendRequest(const uint32_t friend_id) const;
|
||||
void requestPasswordChange( const irr::core::stringw ¤t_password,
|
||||
|
||||
@@ -35,13 +35,14 @@ using namespace irr::gui;
|
||||
using namespace Online;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** Constructor.
|
||||
*/
|
||||
VoteDialog::VoteDialog(const std::string & addon_id)
|
||||
: ModalDialog(0.8f,0.6f), m_addon_id(addon_id)
|
||||
: ModalDialog(0.8f,0.6f), m_addon_id(addon_id)
|
||||
{
|
||||
m_fetch_vote_request = NULL;
|
||||
m_fetch_vote_request = NULL;
|
||||
m_perform_vote_request = NULL;
|
||||
m_self_destroy = false;
|
||||
m_self_destroy = false;
|
||||
loadFromFile("online/vote_dialog.stkgui");
|
||||
|
||||
m_info_widget = getWidget<LabelWidget>("info");
|
||||
@@ -57,43 +58,57 @@ VoteDialog::VoteDialog(const std::string & addon_id)
|
||||
assert(m_cancel_widget != NULL);
|
||||
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
m_fetch_vote_request = CurrentUser::get()->requestGetAddonVote(m_addon_id);
|
||||
|
||||
m_fetch_vote_request = new XMLRequest();
|
||||
CurrentUser::get()->setUserDetails(m_fetch_vote_request);
|
||||
m_fetch_vote_request->addParameter("action", "get-addon-vote");
|
||||
m_fetch_vote_request->addParameter("addonid", addon_id.substr(6));
|
||||
m_fetch_vote_request->queue();
|
||||
|
||||
m_rating_widget->setDeactivated();
|
||||
m_cancel_widget->setDeactivated();
|
||||
}
|
||||
} // VoteDialog
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Destructor, frees the various requests.
|
||||
*/
|
||||
VoteDialog::~VoteDialog()
|
||||
{
|
||||
delete m_fetch_vote_request;
|
||||
delete m_perform_vote_request;
|
||||
}
|
||||
} // ~VoteDialog
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** When escape is pressed, trigger a self destroy.
|
||||
*/
|
||||
bool VoteDialog::onEscapePressed()
|
||||
{
|
||||
if (m_cancel_widget->isActivated())
|
||||
m_self_destroy = true;
|
||||
return false;
|
||||
}
|
||||
} // onEscapePressed
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
GUIEngine::EventPropagation VoteDialog::processEvent(const std::string& eventSource)
|
||||
/** Callback when a user event is triggered.
|
||||
* \param event Information about the event that was triggered.
|
||||
*/
|
||||
GUIEngine::EventPropagation VoteDialog::processEvent(const std::string& event)
|
||||
{
|
||||
|
||||
if (eventSource == m_rating_widget->m_properties[PROP_ID])
|
||||
if (event == m_rating_widget->m_properties[PROP_ID])
|
||||
{
|
||||
m_perform_vote_request = CurrentUser::get()->requestSetAddonVote(m_addon_id, m_rating_widget->getRating());
|
||||
m_perform_vote_request = CurrentUser::get()
|
||||
->requestSetAddonVote(m_addon_id,
|
||||
m_rating_widget->getRating());
|
||||
m_rating_widget->setDeactivated();
|
||||
m_cancel_widget->setDeactivated();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
|
||||
if (eventSource == m_options_widget->m_properties[PROP_ID])
|
||||
if (event == m_options_widget->m_properties[PROP_ID])
|
||||
{
|
||||
const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
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;
|
||||
@@ -101,50 +116,66 @@ GUIEngine::EventPropagation VoteDialog::processEvent(const std::string& eventSou
|
||||
}
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
}
|
||||
} // processEvent
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Updates a potentiall still outstanding fetch vote request.
|
||||
*/
|
||||
void VoteDialog::updateFetchVote()
|
||||
{
|
||||
// No request, nothing to do
|
||||
if (!m_fetch_vote_request) return;
|
||||
if (!m_fetch_vote_request->isDone())
|
||||
{
|
||||
// request still pending
|
||||
m_info_widget->setText(irr::core::stringw(_("Fetching last vote"))
|
||||
+ Messages::loadingDots(), false);
|
||||
return;
|
||||
} // !isDone
|
||||
|
||||
if (m_fetch_vote_request->isSuccess())
|
||||
{
|
||||
m_info_widget->setDefaultColor();
|
||||
std::string voted("");
|
||||
m_fetch_vote_request->getXMLData()->get("voted", &voted);
|
||||
if (voted == "yes")
|
||||
{
|
||||
float rating;
|
||||
m_fetch_vote_request->getXMLData()->get("rating", &rating);
|
||||
m_rating_widget->setRating(rating);
|
||||
m_info_widget->setText(_("You can adapt your previous rating by "
|
||||
"clicking the stars beneath."), false);
|
||||
}
|
||||
else if (voted == "no")
|
||||
{
|
||||
m_info_widget->setText(_("You have not yet voted for this addon. "
|
||||
"Select your desired rating by clicking "
|
||||
"the stars beneath"), false);
|
||||
}
|
||||
m_cancel_widget->setActivated();
|
||||
m_rating_widget->setActivated();
|
||||
} // isSuccess
|
||||
else
|
||||
{
|
||||
sfx_manager->quickSound("anvil");
|
||||
m_info_widget->setErrorColor();
|
||||
m_info_widget->setText(m_fetch_vote_request->getInfo(), false);
|
||||
m_cancel_widget->setActivated();
|
||||
} // !isSuccess
|
||||
|
||||
delete m_fetch_vote_request;
|
||||
m_fetch_vote_request = NULL;
|
||||
|
||||
} // updateFetchVote
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Called every frame. Checks if any of the pending requests are finished.
|
||||
* \param dt Time step size.
|
||||
*/
|
||||
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();
|
||||
std::string voted("");
|
||||
m_fetch_vote_request->getXMLData()->get("voted", &voted);
|
||||
if(voted == "yes")
|
||||
{
|
||||
float rating;
|
||||
m_fetch_vote_request->getXMLData()->get("rating", &rating);
|
||||
m_rating_widget->setRating(rating);
|
||||
m_info_widget->setText(_("You can adapt your previous rating by clicking the stars beneath."), false);
|
||||
}
|
||||
else if(voted == "no")
|
||||
{
|
||||
m_info_widget->setText(_("You have not yet voted for this addon. Select your desired rating by clicking the stars beneath"), false);
|
||||
}
|
||||
m_cancel_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);
|
||||
}
|
||||
}
|
||||
updateFetchVote();
|
||||
|
||||
if(m_perform_vote_request != NULL)
|
||||
{
|
||||
if(m_perform_vote_request->isDone())
|
||||
@@ -152,9 +183,10 @@ void VoteDialog::onUpdate(float dt)
|
||||
if(m_perform_vote_request->isSuccess())
|
||||
{
|
||||
m_info_widget->setDefaultColor();
|
||||
m_info_widget->setText(_("Vote successful! You can now close the window."), false);
|
||||
m_info_widget->setText(_("Vote successful! You can now close "
|
||||
"the window."), false);
|
||||
m_cancel_widget->setActivated();
|
||||
}
|
||||
} // isSuccess
|
||||
else
|
||||
{
|
||||
sfx_manager->quickSound( "anvil" );
|
||||
@@ -162,15 +194,18 @@ void VoteDialog::onUpdate(float dt)
|
||||
m_info_widget->setText(m_perform_vote_request->getInfo(), false);
|
||||
m_cancel_widget->setActivated();
|
||||
m_rating_widget->setActivated();
|
||||
}
|
||||
} // !isSuccess
|
||||
delete m_perform_vote_request;
|
||||
m_perform_vote_request = NULL;
|
||||
}
|
||||
} // isDone
|
||||
else
|
||||
{
|
||||
m_info_widget->setText(irr::core::stringw(_("Performing vote")) + Messages::loadingDots(), false);
|
||||
}
|
||||
m_info_widget->setText(irr::core::stringw(_("Performing vote"))
|
||||
+ Messages::loadingDots(), false);
|
||||
} // !isDone
|
||||
}
|
||||
|
||||
if (m_self_destroy)
|
||||
ModalDialog::dismiss();
|
||||
}
|
||||
|
||||
} // onUpdate
|
||||
|
||||
@@ -34,7 +34,7 @@ class VoteDialog : public GUIEngine::ModalDialog
|
||||
private:
|
||||
const std::string m_addon_id;
|
||||
bool m_self_destroy;
|
||||
const Online::XMLRequest * m_fetch_vote_request;
|
||||
Online::XMLRequest * m_fetch_vote_request;
|
||||
const Online::CurrentUser::SetAddonVoteRequest * m_perform_vote_request;
|
||||
|
||||
GUIEngine::LabelWidget * m_info_widget;
|
||||
@@ -44,6 +44,7 @@ private:
|
||||
GUIEngine::RibbonWidget * m_options_widget;
|
||||
GUIEngine::IconButtonWidget * m_cancel_widget;
|
||||
|
||||
void updateFetchVote();
|
||||
public:
|
||||
VoteDialog(const std::string & addon_id);
|
||||
~VoteDialog();
|
||||
|
||||
Reference in New Issue
Block a user