Better handling of save vector from client
This commit is contained in:
parent
0e5a46aa64
commit
36a952ca4d
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,5 @@
|
|||||||
*.user
|
*.user
|
||||||
*.dll
|
*.dll
|
||||||
*.a
|
*.a
|
||||||
*.la
|
*.la
|
||||||
|
*~
|
||||||
|
@ -38,10 +38,10 @@ Client::~Client()
|
|||||||
http_done();
|
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 = "";
|
lastError = "";
|
||||||
std::vector<Save> saveArray;
|
std::vector<Save*> * saveArray = new std::vector<Save*>();
|
||||||
std::stringstream urlStream;
|
std::stringstream urlStream;
|
||||||
char * data;
|
char * data;
|
||||||
int dataStatus, dataLength;
|
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::Number tempScoreDown = savesArray[j]["ScoreDown"];
|
||||||
json::String tempUsername = savesArray[j]["Username"];
|
json::String tempUsername = savesArray[j]["Username"];
|
||||||
json::String tempName = savesArray[j]["Name"];
|
json::String tempName = savesArray[j]["Name"];
|
||||||
saveArray.push_back(
|
saveArray->push_back(
|
||||||
Save(
|
new Save(
|
||||||
tempID.Value(),
|
tempID.Value(),
|
||||||
tempScoreUp.Value(),
|
tempScoreUp.Value(),
|
||||||
tempScoreDown.Value(),
|
tempScoreDown.Value(),
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
Client();
|
Client();
|
||||||
~Client();
|
~Client();
|
||||||
void ClearThumbnailRequests();
|
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);
|
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
||||||
std::string GetLastError() { return lastError; }
|
std::string GetLastError() { return lastError; }
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
SaveButton::SaveButton(Window* parent_state, Save save):
|
SaveButton::SaveButton(Window* parent_state, Save * save):
|
||||||
Component(parent_state),
|
Component(parent_state),
|
||||||
save(save),
|
save(save),
|
||||||
thumbnail(NULL),
|
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),
|
Component(position, size),
|
||||||
save(save),
|
save(save),
|
||||||
thumbnail(NULL),
|
thumbnail(NULL),
|
||||||
@ -31,7 +31,7 @@ SaveButton::SaveButton(Point position, Point size, Save save):
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveButton::SaveButton(Save save):
|
SaveButton::SaveButton(Save * save):
|
||||||
Component(),
|
Component(),
|
||||||
save(save),
|
save(save),
|
||||||
thumbnail(NULL),
|
thumbnail(NULL),
|
||||||
@ -48,6 +48,8 @@ SaveButton::~SaveButton()
|
|||||||
delete thumbnail;
|
delete thumbnail;
|
||||||
if(actionCallback)
|
if(actionCallback)
|
||||||
delete actionCallback;
|
delete actionCallback;
|
||||||
|
if(save)
|
||||||
|
delete save;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::Tick(float dt)
|
void SaveButton::Tick(float dt)
|
||||||
@ -56,7 +58,7 @@ void SaveButton::Tick(float dt)
|
|||||||
float scaleFactorY = 1.0f, scaleFactorX = 1.0f;
|
float scaleFactorY = 1.0f, scaleFactorX = 1.0f;
|
||||||
if(!thumbnail)
|
if(!thumbnail)
|
||||||
{
|
{
|
||||||
tempThumb = Client::Ref().GetThumbnail(save.GetID(), 0);
|
tempThumb = Client::Ref().GetThumbnail(save->GetID(), 0);
|
||||||
if(tempThumb)
|
if(tempThumb)
|
||||||
{
|
{
|
||||||
thumbnail = tempThumb; //Store a local copy of the thumbnail
|
thumbnail = tempThumb; //Store a local copy of the thumbnail
|
||||||
@ -104,13 +106,13 @@ void SaveButton::Draw(const Point& screenPos)
|
|||||||
if(isMouseInside)
|
if(isMouseInside)
|
||||||
{
|
{
|
||||||
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
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->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->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 200, 230, 255, 255);
|
||||||
}
|
}
|
||||||
else
|
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->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->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 100, 130, 160, 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,14 +19,14 @@ public:
|
|||||||
|
|
||||||
class SaveButton : public Component
|
class SaveButton : public Component
|
||||||
{
|
{
|
||||||
Save save;
|
Save * save;
|
||||||
Thumbnail * thumbnail;
|
Thumbnail * thumbnail;
|
||||||
public:
|
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 ~SaveButton();
|
||||||
|
|
||||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||||
|
@ -12,7 +12,9 @@ void SearchModel::UpdateSaveList(std::string query)
|
|||||||
lastError = "";
|
lastError = "";
|
||||||
saveList.clear();
|
saveList.clear();
|
||||||
notifySaveListChanged();
|
notifySaveListChanged();
|
||||||
saveList = Client::Ref().SearchSaves(0, 12, query, "");
|
vector<Save*> * tempSaveList = Client::Ref().SearchSaves(0, 12, query, "");
|
||||||
|
saveList = *tempSaveList;
|
||||||
|
delete tempSaveList;
|
||||||
if(!saveList.size())
|
if(!saveList.size())
|
||||||
{
|
{
|
||||||
lastError = Client::Ref().GetLastError();
|
lastError = Client::Ref().GetLastError();
|
||||||
@ -24,7 +26,7 @@ void SearchModel::UpdateSaveList(std::string query)
|
|||||||
notifySaveListChanged();
|
notifySaveListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Save> SearchModel::GetSaveList()
|
vector<Save*> SearchModel::GetSaveList()
|
||||||
{
|
{
|
||||||
return saveList;
|
return saveList;
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,13 @@ class SearchModel
|
|||||||
private:
|
private:
|
||||||
string lastError;
|
string lastError;
|
||||||
vector<SearchView*> observers;
|
vector<SearchView*> observers;
|
||||||
vector<Save> saveList;
|
vector<Save*> saveList;
|
||||||
void notifySaveListChanged();
|
void notifySaveListChanged();
|
||||||
public:
|
public:
|
||||||
SearchModel();
|
SearchModel();
|
||||||
void AddObserver(SearchView * observer);
|
void AddObserver(SearchView * observer);
|
||||||
void UpdateSaveList(std::string query);
|
void UpdateSaveList(std::string query);
|
||||||
vector<Save> GetSaveList();
|
vector<Save*> GetSaveList();
|
||||||
string GetLastError() { return lastError; }
|
string GetLastError() { return lastError; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
|
|||||||
int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 4, savesY = 3, buttonPadding = 2;
|
int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 4, savesY = 3, buttonPadding = 2;
|
||||||
int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;
|
int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;
|
||||||
|
|
||||||
vector<Save> saves = sender->GetSaveList();
|
vector<Save*> saves = sender->GetSaveList();
|
||||||
if(!saves.size())
|
if(!saves.size())
|
||||||
{
|
{
|
||||||
if(!errorLabel)
|
if(!errorLabel)
|
||||||
|
Loading…
Reference in New Issue
Block a user