diff --git a/src/client/Client.cpp b/src/client/Client.cpp index db5764282..3869fb182 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -1691,7 +1691,7 @@ SaveInfo * Client::GetSave(int saveID, int saveDate) json::Number tempVersion = objDocument["Version"]; json::Array tagsArray = objDocument["Tags"]; - std::vector tempTags; + std::list tempTags; for(int j = 0; j < tagsArray.Size(); j++) { @@ -1767,7 +1767,7 @@ RequestBroker::Request * Client::GetSaveAsync(int saveID, int saveDate) json::Number tempVersion = objDocument["Version"]; json::Array tagsArray = objDocument["Tags"]; - std::vector tempTags; + std::list tempTags; for(int j = 0; j < tagsArray.Size(); j++) { @@ -2205,10 +2205,10 @@ Thumbnail * Client::GetThumbnail(int saveID, int saveDate) return NULL; } -std::vector * Client::RemoveTag(int saveID, std::string tag) +std::list * Client::RemoveTag(int saveID, std::string tag) { lastError = ""; - std::vector * tags = NULL; + std::list * tags = NULL; std::stringstream urlStream; char * data = NULL; int dataStatus, dataLength; @@ -2243,7 +2243,7 @@ std::vector * Client::RemoveTag(int saveID, std::string tag) { json::Array tagsArray = responseObject["Tags"]; - tags = new std::vector(); + tags = new std::list(); for(int j = 0; j < tagsArray.Size(); j++) { @@ -2266,10 +2266,10 @@ std::vector * Client::RemoveTag(int saveID, std::string tag) return tags; } -std::vector * Client::AddTag(int saveID, std::string tag) +std::list * Client::AddTag(int saveID, std::string tag) { lastError = ""; - std::vector * tags = NULL; + std::list * tags = NULL; std::stringstream urlStream; char * data = NULL; int dataStatus, dataLength; @@ -2304,7 +2304,7 @@ std::vector * Client::AddTag(int saveID, std::string tag) { json::Array tagsArray = responseObject["Tags"]; - tags = new std::vector(); + tags = new std::list(); for(int j = 0; j < tagsArray.Size(); j++) { diff --git a/src/client/Client.h b/src/client/Client.h index 659f615c5..5f4850eb1 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -160,8 +160,8 @@ public: RequestStatus FavouriteSave(int saveID, bool favourite); void SetAuthUser(User user); User GetAuthUser(); - std::vector * RemoveTag(int saveID, std::string tag); //TODO RequestStatus - std::vector * AddTag(int saveID, std::string tag); + std::list * RemoveTag(int saveID, std::string tag); //TODO RequestStatus + std::list * AddTag(int saveID, std::string tag); std::string GetLastError() { return lastError; } diff --git a/src/client/SaveInfo.cpp b/src/client/SaveInfo.cpp index 97ac43917..05520f84d 100644 --- a/src/client/SaveInfo.cpp +++ b/src/client/SaveInfo.cpp @@ -13,11 +13,13 @@ SaveInfo::SaveInfo(SaveInfo & save): votesDown(save.votesDown), gameSave(NULL), vote(save.vote), - tags(save.tags), Comments(save.Comments), Views(save.Views), Version(save.Version) { + std::list tagsSorted = save.tags; + tagsSorted.sort(); + tags=tagsSorted; if(save.gameSave) gameSave = new GameSave(*save.gameSave); } @@ -41,7 +43,7 @@ SaveInfo::SaveInfo(int _id, int _date, int _votesUp, int _votesDown, std::string } -SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::vector tags_): +SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::list tags_): id(_id), votesUp(_votesUp), votesDown(_votesDown), @@ -52,12 +54,13 @@ SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, Published(published_), gameSave(NULL), vote(_vote), - tags(tags_), Comments(0), Views(0), Version(0) { - + std::list tagsSorted = tags_; + tagsSorted.sort(); + tags=tagsSorted; } SaveInfo::~SaveInfo() @@ -150,11 +153,14 @@ int SaveInfo::GetVersion() return Version; } -void SaveInfo::SetTags(std::vector tags) +void SaveInfo::SetTags(std::list tags) { - this->tags = tags; + std::list tagsSorted = tags; + tagsSorted.sort(); + this->tags=tagsSorted; } -std::vector SaveInfo::GetTags() + +std::list SaveInfo::GetTags() { return tags; } diff --git a/src/client/SaveInfo.h b/src/client/SaveInfo.h index 3f52c2532..11c49091a 100644 --- a/src/client/SaveInfo.h +++ b/src/client/SaveInfo.h @@ -1,6 +1,7 @@ #ifndef SAVE_H #define SAVE_H +#include #include #include #include @@ -26,7 +27,7 @@ public: SaveInfo(int _id, int _date, int _votesUp, int _votesDown, std::string _userName, std::string _name); - SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::vector tags); + SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::list tags); ~SaveInfo(); @@ -35,7 +36,7 @@ public: std::string Description; - std::vector tags; + std::list tags; int vote; @@ -68,8 +69,8 @@ public: void SetVersion(int version); int GetVersion(); - void SetTags(std::vector tags); - std::vector GetTags(); + void SetTags(std::list tags); + std::list GetTags(); GameSave * GetGameSave(); void SetGameSave(GameSave * gameSave); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index c245de3b9..8d62afec4 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -909,14 +909,14 @@ void GameView::NotifySaveChanged(GameModel * sender) if(sender->GetSave()->GetID()) { std::stringstream tagsStream; - std::vector tags = sender->GetSave()->GetTags(); + std::list tags = sender->GetSave()->GetTags(); if(tags.size()) { - for(int i = 0; i < tags.size(); i++) + for(std::list::const_iterator iter = tags.begin(), begin = tags.begin(), end = tags.end(); iter != end; iter++) { - tagsStream << sender->GetSave()->GetTags()[i]; - if(i < tags.size()-1) + if(iter != begin) tagsStream << " "; + tagsStream << *iter; } tagSimulationButton->SetText(tagsStream.str()); } diff --git a/src/gui/tags/TagsModel.cpp b/src/gui/tags/TagsModel.cpp index f3329adaa..9235b3f64 100644 --- a/src/gui/tags/TagsModel.cpp +++ b/src/gui/tags/TagsModel.cpp @@ -25,10 +25,10 @@ void TagsModel::RemoveTag(std::string tag) { if(save) { - std::vector * tags = Client::Ref().RemoveTag(save->GetID(), tag); + std::list * tags = Client::Ref().RemoveTag(save->GetID(), tag); if(tags) { - save->SetTags(std::vector(*tags)); + save->SetTags(std::list(*tags)); notifyTagsChanged(); delete tags; } @@ -43,10 +43,10 @@ void TagsModel::AddTag(std::string tag) { if(save) { - std::vector * tags = Client::Ref().AddTag(save->GetID(), tag); + std::list * tags = Client::Ref().AddTag(save->GetID(), tag); if(tags) { - save->SetTags(std::vector(*tags)); + save->SetTags(std::list(*tags)); notifyTagsChanged(); delete tags; } diff --git a/src/gui/tags/TagsView.cpp b/src/gui/tags/TagsView.cpp index e3812d168..3c49cf8fc 100644 --- a/src/gui/tags/TagsView.cpp +++ b/src/gui/tags/TagsView.cpp @@ -104,9 +104,11 @@ void TagsView::NotifyTagsChanged(TagsModel * sender) if(sender->GetSave()) { - for(int i = 0; i < sender->GetSave()->GetTags().size(); i++) + std::list Tags = sender->GetSave()->GetTags(); + int i = 0; + for(std::list::const_iterator iter = Tags.begin(), end = Tags.end(); iter != end; iter++) { - ui::Label * tempLabel = new ui::Label(ui::Point(35, 35+(16*i)), ui::Point(120, 16), sender->GetSave()->GetTags()[i]); + ui::Label * tempLabel = new ui::Label(ui::Point(35, 35+(16*i)), ui::Point(120, 16), *iter); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; tags.push_back(tempLabel); AddComponent(tempLabel); @@ -119,10 +121,11 @@ void TagsView::NotifyTagsChanged(TagsModel * sender) tempButton->Appearance.Margin.Top += 2; tempButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; tempButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - tempButton->SetActionCallback(new DeleteTagAction(this, sender->GetSave()->GetTags()[i])); + tempButton->SetActionCallback(new DeleteTagAction(this, *iter)); tags.push_back(tempButton); AddComponent(tempButton); } + i++; } } }