Update gitignore, show votes correctly, fixes #97

This commit is contained in:
Simon Robertshaw 2012-08-14 13:06:10 +01:00
parent c877e445b9
commit 4f3e03e317
5 changed files with 30 additions and 19 deletions

2
.gitignore vendored
View File

@ -35,3 +35,5 @@ Makefile.me
config.log
*.sconsign.dblite
*.sconf_temp
*.gch
*.pyc

View File

@ -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<int>(saveID);
std::string directionText = direction==1?"Up":"Down";
std::string userIDText = format::NumberToString<int>(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
{

View File

@ -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()

View File

@ -263,6 +263,10 @@ void GameModel::SetVote(int direction)
currentSave->vote = direction;
notifySaveChanged();
}
else
{
throw GameModelException("Could not vote: "+Client::Ref().GetLastError());
}
}
}

View File

@ -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())
{