From 4f3e03e3176789ba095b714d1cca214409b27c06 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 14 Aug 2012 13:06:10 +0100 Subject: [PATCH] Update gitignore, show votes correctly, fixes #97 --- .gitignore | 2 ++ src/client/Client.cpp | 22 ++++++++-------------- src/game/GameController.cpp | 11 ++++++++++- src/game/GameModel.cpp | 4 ++++ src/game/GameView.cpp | 10 ++++++---- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 02658a0b4..cf76a2317 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ Makefile.me config.log *.sconsign.dblite *.sconf_temp +*.gch +*.pyc diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 29bec17a0..69344093f 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -927,24 +927,18 @@ RequestStatus Client::ExecVote(int saveID, int direction) int dataLength = 0; std::stringstream idStream; idStream << saveID; - std::string directionS; - if(direction==1) - { - directionS = "Up"; - } - else - { - directionS = "Down"; - } - std::stringstream userIDStream; - userIDStream << authUser.ID; + + std::string saveIDText = format::NumberToString(saveID); + std::string directionText = direction==1?"Up":"Down"; + + std::string userIDText = format::NumberToString(authUser.ID); if(authUser.ID) { char * postNames[] = { "ID", "Action", NULL }; - char * postDatas[] = { (char*)(idStream.str().c_str()), (char*)(directionS.c_str()) }; - int postLengths[] = { idStream.str().length(), directionS.length() }; + char * postDatas[] = { (char*)(saveIDText.c_str()), (char*)(directionText.c_str()) }; + int postLengths[] = { saveIDText.length(), directionText.length() }; //std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl; - data = http_multipart_post("http://" SERVER "/Vote.api", postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength); + data = http_multipart_post("http://" SERVER "/Vote.api", postNames, postDatas, postLengths, (char *)(userIDText.c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength); } else { diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 32e6754c7..0855d041c 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -1028,7 +1028,16 @@ void GameController::FrameStep() void GameController::Vote(int direction) { if(gameModel->GetSave() && gameModel->GetUser().ID && gameModel->GetSave()->GetID() && gameModel->GetSave()->GetVote()==0) - gameModel->SetVote(direction); + { + try + { + gameModel->SetVote(direction); + } + catch(GameModelException & ex) + { + new ErrorMessage("Error while voting", ex.what()); + } + } } void GameController::ChangeBrush() diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index c897877b1..9505397ce 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -263,6 +263,10 @@ void GameModel::SetVote(int direction) currentSave->vote = direction; notifySaveChanged(); } + else + { + throw GameModelException("Could not vote: "+Client::Ref().GetLastError()); + } } } diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index c03ccf535..d95a7b99d 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -873,14 +873,16 @@ void GameView::NotifySaveChanged(GameModel * sender) reloadButton->Enabled = true; upVoteButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==0); if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==1) - upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 200, 40)); + upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 200, 40, 100)); else - upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); + downVoteButton->Enabled = upVoteButton->Enabled; if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==-1) - downVoteButton->Appearance.BackgroundInactive = (ui::Colour(200, 40, 40)); + downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(200, 40, 40, 100)); else - downVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); + tagSimulationButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID); if(sender->GetSave()->GetID()) {