Better handling of save vector from client

This commit is contained in:
Simon Robertshaw 2012-01-21 00:17:42 +00:00
parent 0e5a46aa64
commit 36a952ca4d
8 changed files with 28 additions and 23 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@
*.user
*.dll
*.a
*.la
*.la
*~

View File

@ -38,10 +38,10 @@ Client::~Client()
http_done();
}
std::vector<Save> Client::SearchSaves(int start, int count, string query, string sort)
std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort)
{
lastError = "";
std::vector<Save> saveArray;
std::vector<Save*> * saveArray = new std::vector<Save*>();
std::stringstream urlStream;
char * data;
int dataStatus, dataLength;
@ -76,8 +76,8 @@ std::vector<Save> Client::SearchSaves(int start, int count, string query, string
json::Number tempScoreDown = savesArray[j]["ScoreDown"];
json::String tempUsername = savesArray[j]["Username"];
json::String tempName = savesArray[j]["Name"];
saveArray.push_back(
Save(
saveArray->push_back(
new Save(
tempID.Value(),
tempScoreUp.Value(),
tempScoreDown.Value(),

View File

@ -24,7 +24,7 @@ public:
Client();
~Client();
void ClearThumbnailRequests();
std::vector<Save> SearchSaves(int start, int count, string query, string sort);
std::vector<Save*> * SearchSaves(int start, int count, string query, string sort);
Thumbnail * GetThumbnail(int saveID, int saveDate);
std::string GetLastError() { return lastError; }
};

View File

@ -9,7 +9,7 @@
namespace ui {
SaveButton::SaveButton(Window* parent_state, Save save):
SaveButton::SaveButton(Window* parent_state, Save * save):
Component(parent_state),
save(save),
thumbnail(NULL),
@ -20,7 +20,7 @@ SaveButton::SaveButton(Window* parent_state, Save save):
}
SaveButton::SaveButton(Point position, Point size, Save save):
SaveButton::SaveButton(Point position, Point size, Save * save):
Component(position, size),
save(save),
thumbnail(NULL),
@ -31,7 +31,7 @@ SaveButton::SaveButton(Point position, Point size, Save save):
}
SaveButton::SaveButton(Save save):
SaveButton::SaveButton(Save * save):
Component(),
save(save),
thumbnail(NULL),
@ -48,6 +48,8 @@ SaveButton::~SaveButton()
delete thumbnail;
if(actionCallback)
delete actionCallback;
if(save)
delete save;
}
void SaveButton::Tick(float dt)
@ -56,7 +58,7 @@ void SaveButton::Tick(float dt)
float scaleFactorY = 1.0f, scaleFactorX = 1.0f;
if(!thumbnail)
{
tempThumb = Client::Ref().GetThumbnail(save.GetID(), 0);
tempThumb = Client::Ref().GetThumbnail(save->GetID(), 0);
if(tempThumb)
{
thumbnail = tempThumb; //Store a local copy of the thumbnail
@ -104,13 +106,13 @@ void SaveButton::Draw(const Point& screenPos)
if(isMouseInside)
{
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save.name.c_str()))/2, screenPos.Y+Size.Y - 21, save.name, 255, 255, 255, 255);
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save.userName.c_str()))/2, screenPos.Y+Size.Y - 10, save.userName, 200, 230, 255, 255);
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->name.c_str()))/2, screenPos.Y+Size.Y - 21, save->name, 255, 255, 255, 255);
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 200, 230, 255, 255);
}
else
{
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save.name.c_str()))/2, screenPos.Y+Size.Y - 21, save.name, 180, 180, 180, 255);
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save.userName.c_str()))/2, screenPos.Y+Size.Y - 10, save.userName, 100, 130, 160, 255);
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->name.c_str()))/2, screenPos.Y+Size.Y - 21, save->name, 180, 180, 180, 255);
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 100, 130, 160, 255);
}
}

View File

@ -19,14 +19,14 @@ public:
class SaveButton : public Component
{
Save save;
Save * save;
Thumbnail * thumbnail;
public:
SaveButton(Window* parent_state, Save save);
SaveButton(Window* parent_state, Save * save);
SaveButton(Point position, Point size, Save save);
SaveButton(Point position, Point size, Save * save);
SaveButton(Save save);
SaveButton(Save * save);
virtual ~SaveButton();
virtual void OnMouseClick(int x, int y, unsigned int button);

View File

@ -12,7 +12,9 @@ void SearchModel::UpdateSaveList(std::string query)
lastError = "";
saveList.clear();
notifySaveListChanged();
saveList = Client::Ref().SearchSaves(0, 12, query, "");
vector<Save*> * tempSaveList = Client::Ref().SearchSaves(0, 12, query, "");
saveList = *tempSaveList;
delete tempSaveList;
if(!saveList.size())
{
lastError = Client::Ref().GetLastError();
@ -24,7 +26,7 @@ void SearchModel::UpdateSaveList(std::string query)
notifySaveListChanged();
}
vector<Save> SearchModel::GetSaveList()
vector<Save*> SearchModel::GetSaveList()
{
return saveList;
}

View File

@ -14,13 +14,13 @@ class SearchModel
private:
string lastError;
vector<SearchView*> observers;
vector<Save> saveList;
vector<Save*> saveList;
void notifySaveListChanged();
public:
SearchModel();
void AddObserver(SearchView * observer);
void UpdateSaveList(std::string query);
vector<Save> GetSaveList();
vector<Save*> GetSaveList();
string GetLastError() { return lastError; }
};

View File

@ -52,7 +52,7 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 4, savesY = 3, buttonPadding = 2;
int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;
vector<Save> saves = sender->GetSaveList();
vector<Save*> saves = sender->GetSaveList();
if(!saves.size())
{
if(!errorLabel)