Change stamp storage to a list, insert new stamps at the begining, 'l' loads the first stamp or the previously used stamp, 'k' shows the stamp browser
This commit is contained in:
parent
cdc4b4df86
commit
fd572e9da6
@ -253,12 +253,12 @@ SaveFile * Client::GetStamp(string stampID)
|
||||
|
||||
void Client::DeleteStamp(string stampID)
|
||||
{
|
||||
for(int i = 0; i < stampIDs.size(); i++)
|
||||
for (std::list<string>::iterator iterator = stampIDs.begin(), end = stampIDs.end(); iterator != end; ++iterator)
|
||||
{
|
||||
if(stampIDs[i] == stampID)
|
||||
if((*iterator) == stampID)
|
||||
{
|
||||
remove(string(STAMPS_DIR PATH_SEP + stampID + ".stm").c_str());
|
||||
stampIDs.erase(stampIDs.begin()+i);
|
||||
stampIDs.erase(iterator);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -294,7 +294,7 @@ string Client::AddStamp(GameSave * saveData)
|
||||
stampStream.write((const char *)gameData, gameDataLength);
|
||||
stampStream.close();
|
||||
|
||||
stampIDs.push_back(saveID.str());
|
||||
stampIDs.push_front(saveID.str());
|
||||
|
||||
updateStamps();
|
||||
|
||||
@ -312,18 +312,35 @@ void Client::updateStamps()
|
||||
|
||||
std::ofstream stampsStream;
|
||||
stampsStream.open(string(STAMPS_DIR PATH_SEP "stamps.def").c_str(), ios::binary);
|
||||
for(int i = 0; i < stampIDs.size(); i++)
|
||||
for (std::list<string>::const_iterator iterator = stampIDs.begin(), end = stampIDs.end(); iterator != end; ++iterator)
|
||||
{
|
||||
stampsStream.write(stampIDs[i].c_str(), 10);
|
||||
stampsStream.write((*iterator).c_str(), 10);
|
||||
}
|
||||
stampsStream.write("\0", 1);
|
||||
stampsStream.close();
|
||||
return;
|
||||
}
|
||||
|
||||
vector<string> Client::GetStamps()
|
||||
int Client::GetStampsCount()
|
||||
{
|
||||
return stampIDs;
|
||||
return stampIDs.size();
|
||||
}
|
||||
|
||||
vector<string> Client::GetStamps(int start, int count)
|
||||
{
|
||||
//if(start+count > stampIDs.size()) {
|
||||
// if(start > stampIDs.size())
|
||||
// return vector<string>();
|
||||
// count = stampIDs.size()-start;
|
||||
//}
|
||||
|
||||
vector<string> stampRange;
|
||||
int index = 0;
|
||||
for (std::list<string>::const_iterator iterator = stampIDs.begin(), end = stampIDs.end(); iterator != end; ++iterator, ++index) {
|
||||
if(index>=start && index < start+count)
|
||||
stampRange.push_back(*iterator);
|
||||
}
|
||||
return stampRange;
|
||||
}
|
||||
|
||||
RequestStatus Client::ExecVote(int saveID, int direction)
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <fstream>
|
||||
|
||||
#include "Config.h"
|
||||
@ -30,7 +31,7 @@ class Client: public Singleton<Client> {
|
||||
private:
|
||||
std::string lastError;
|
||||
|
||||
vector<string> stampIDs;
|
||||
list<string> stampIDs;
|
||||
int lastStampTime;
|
||||
int lastStampName;
|
||||
|
||||
@ -58,7 +59,9 @@ public:
|
||||
SaveFile * GetStamp(string stampID);
|
||||
void DeleteStamp(string stampID);
|
||||
string AddStamp(GameSave * saveData);
|
||||
vector<string> GetStamps();
|
||||
vector<string> GetStamps(int start, int count);
|
||||
int GetStampsCount();
|
||||
SaveFile * GetFirstStamp();
|
||||
|
||||
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
||||
LoginStatus Login(string username, string password, User & user);
|
||||
|
@ -109,8 +109,6 @@ public:
|
||||
cc->gameModel->SetStamp(cc->localBrowser->GetSave()->GetGameSave());
|
||||
cc->LoadStamp();
|
||||
}
|
||||
else
|
||||
cc->gameModel->SetStamp(NULL);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -130,6 +130,15 @@ GameModel::GameModel():
|
||||
{
|
||||
currentUser = Client::Ref().GetAuthUser();
|
||||
}
|
||||
|
||||
//Set stamp to first stamp in list
|
||||
vector<string> stamps = Client::Ref().GetStamps(0, 1);
|
||||
if(stamps.size()>0)
|
||||
{
|
||||
SaveFile * stampFile = Client::Ref().GetStamp(stamps[0]);
|
||||
if(stampFile && stampFile->GetGameSave())
|
||||
stamp = stampFile->GetGameSave();
|
||||
}
|
||||
}
|
||||
|
||||
GameModel::~GameModel()
|
||||
@ -430,7 +439,10 @@ void GameModel::SetStamp(GameSave * save)
|
||||
{
|
||||
if(stamp)
|
||||
delete stamp;
|
||||
stamp = new GameSave(*save);
|
||||
if(save)
|
||||
stamp = new GameSave(*save);
|
||||
else
|
||||
stamp = NULL;
|
||||
}
|
||||
|
||||
void GameModel::SetPlaceSave(GameSave * save)
|
||||
|
@ -741,6 +741,11 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
}
|
||||
break;
|
||||
case 'l':
|
||||
c->LoadStamp();
|
||||
selectPoint2 = ui::Point(-1, -1);
|
||||
selectPoint1 = selectPoint2;
|
||||
break;
|
||||
case 'k':
|
||||
selectPoint2 = ui::Point(-1, -1);
|
||||
selectPoint1 = selectPoint2;
|
||||
c->OpenStamps();
|
||||
|
@ -15,7 +15,8 @@ LocalBrowserModel::LocalBrowserModel():
|
||||
currentPage(1)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
stampIDs = Client::Ref().GetStamps();
|
||||
//stampIDs = Client::Ref().GetStamps();
|
||||
stampIDs = Client::Ref().GetStamps(0, 16);
|
||||
}
|
||||
|
||||
|
||||
@ -72,9 +73,9 @@ void LocalBrowserModel::UpdateSavesList(int pageNumber)
|
||||
delete tempStampsList[i];
|
||||
}*/
|
||||
|
||||
int stampsEnd = pageNumber*20;
|
||||
stampIDs = Client::Ref().GetStamps((pageNumber-1)*20, 20);
|
||||
|
||||
for(int i = stampsEnd-20; i<stampIDs.size() && i<stampsEnd; i++)
|
||||
for(int i = 0; i<stampIDs.size(); i++)
|
||||
{
|
||||
SaveFile * tempSave = Client::Ref().GetStamp(stampIDs[i]);
|
||||
if(tempSave)
|
||||
|
Reference in New Issue
Block a user