diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 852dbb69f..191cebbc6 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -1821,15 +1821,27 @@ std::vector * Client::RemoveTag(int saveID, std::string tag) try { std::istringstream dataStream(data); - json::Array tagsArray; - json::Reader::Read(tagsArray, dataStream); + json::Object responseObject; + json::Reader::Read(responseObject, dataStream); - tags = new std::vector(); + json::Number status = responseObject["Status"]; - for(int j = 0; j < tagsArray.Size(); j++) + if(status.Value()==0) { - json::String tempTag = tagsArray[j]; - tags->push_back(tempTag.Value()); + json::String error = responseObject["Error"]; + lastError = error.Value(); + } + else + { + json::Array tagsArray = responseObject["Tags"]; + + tags = new std::vector(); + + for(int j = 0; j < tagsArray.Size(); j++) + { + json::String tempTag = tagsArray[j]; + tags->push_back(tempTag.Value()); + } } } catch (json::Exception &e) @@ -1870,15 +1882,27 @@ std::vector * Client::AddTag(int saveID, std::string tag) try { std::istringstream dataStream(data); - json::Array tagsArray; - json::Reader::Read(tagsArray, dataStream); + json::Object responseObject; + json::Reader::Read(responseObject, dataStream); - tags = new std::vector(); + json::Number status = responseObject["Status"]; - for(int j = 0; j < tagsArray.Size(); j++) + if(status.Value()==0) { - json::String tempTag = tagsArray[j]; - tags->push_back(tempTag.Value()); + json::String error = responseObject["Error"]; + lastError = error.Value(); + } + else + { + json::Array tagsArray = responseObject["Tags"]; + + tags = new std::vector(); + + for(int j = 0; j < tagsArray.Size(); j++) + { + json::String tempTag = tagsArray[j]; + tags->push_back(tempTag.Value()); + } } } catch (json::Exception &e) diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index fd6465484..e34fa5bf9 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -113,7 +113,7 @@ public: TagsCallback(GameController * cc_) { cc = cc_; } virtual void ControllerExit() { - cc->gameModel->SetSave(new SaveInfo(*(cc->tagsWindow->GetSave()))); + cc->gameView->NotifySaveChanged(cc->gameModel); } }; diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index c4c0d31e5..73a6e7b92 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -874,15 +874,27 @@ void Graphics::draw_icon(int x, int y, Icon icon, unsigned char alpha, bool inve case IconDelete: if(invert) { - drawchar(x, y, 0x86, 255, 55, 55, alpha); + drawchar(x, y, 0x86, 159, 47, 31, alpha); drawchar(x, y, 0x85, 0, 0, 0, alpha); } else { - drawchar(x, y, 0x86, 255, 55, 55, alpha); + drawchar(x, y, 0x86, 159, 47, 31, alpha); drawchar(x, y, 0x85, 255, 255, 255, alpha); } break; + case IconAdd: + if(invert) + { + drawchar(x, y, 0x86, 32, 144, 32, alpha); + drawchar(x, y, 0x89, 0, 0, 0, alpha); + } + else + { + drawchar(x, y, 0x86, 32, 144, 32, alpha); + drawchar(x, y, 0x89, 255, 255, 255, alpha); + } + break; default: if(invert) drawchar(x, y, 't', 0, 0 ,0 ,alpha); diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index 46d28b4d7..a51ed022b 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -78,6 +78,7 @@ enum Icon IconFolder, IconSearch, IconDelete, + IconAdd, IconReport, IconUsername, IconPassword, diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h index 4ac41c18b..a2ea5b704 100644 --- a/src/search/SearchModel.h +++ b/src/search/SearchModel.h @@ -68,7 +68,7 @@ public: string GetSort() { return currentSort; } void SetShowOwn(bool show) { if(!updateSaveListWorking) { if(show!=showOwn) { showOwn = show; } } notifyShowOwnChanged(); } bool GetShowOwn() { return showOwn; } - void SetShowFavourite(bool show) { if(show!=showFavourite) { showFavourite = show; } notifyShowFavouriteChanged(); } + void SetShowFavourite(bool show) { if(show!=showFavourite && !updateSaveListWorking) { showFavourite = show; } notifyShowFavouriteChanged(); } bool GetShowFavourite() { return showFavourite; } void SetLoadedSave(SaveInfo * save); SaveInfo * GetLoadedSave(); diff --git a/src/tags/TagsView.cpp b/src/tags/TagsView.cpp index 01c3b15b3..f5aef91ae 100644 --- a/src/tags/TagsView.cpp +++ b/src/tags/TagsView.cpp @@ -33,15 +33,38 @@ TagsView::TagsView(): } }; closeButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(195, 16), "Close"); - closeButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; closeButton->Appearance.VerticalAlign = ui::Appearance::AlignTop; + closeButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + closeButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; closeButton->SetActionCallback(new CloseAction(this)); AddComponent(closeButton); - tagInput = new ui::Textbox(ui::Point(8, Size.Y-40), ui::Point(Size.X-16, 16), ""); + + tagInput = new ui::Textbox(ui::Point(8, Size.Y-40), ui::Point(Size.X-60, 16), "", "[new tag]"); + tagInput->Appearance.icon = IconTag; + tagInput->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + tagInput->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; AddComponent(tagInput); + class AddTagAction : public ui::ButtonAction + { + TagsView * v; + public: + AddTagAction(TagsView * _v) { v = _v; } + void ActionCallback(ui::Button * sender) + { + v->addTag(); + } + }; + addButton = new ui::Button(ui::Point(tagInput->Position.X+tagInput->Size.X+4, tagInput->Position.Y), ui::Point(40, 16), "Add"); + addButton->Appearance.icon = IconAdd; + addButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + addButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + addButton->SetActionCallback(new AddTagAction(this)); + AddComponent(addButton); + title = new ui::Label(ui::Point(5, 5), ui::Point(185, 16), "Manage tags:"); - title->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; title->Appearance.VerticalAlign = ui::Appearance::AlignTop; + title->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + title->Appearance.VerticalAlign = ui::Appearance::AlignTop; AddComponent(title); } @@ -90,10 +113,14 @@ void TagsView::NotifyTagsChanged(TagsModel * sender) tags.push_back(tempLabel); AddComponent(tempLabel); - if(sender->GetSave()->GetUserName()==Client::Ref().GetAuthUser().Username) + if(sender->GetSave()->GetUserName() == Client::Ref().GetAuthUser().Username || Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin || Client::Ref().GetAuthUser().UserElevation == User::ElevationModerator) { - ui::Button * tempButton = new ui::Button(ui::Point(15, 35+(16*i)), ui::Point(14, 14), "x"); - tempButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; tempButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + ui::Button * tempButton = new ui::Button(ui::Point(15, 37+(16*i)), ui::Point(11, 12)); + tempButton->Appearance.icon = IconDelete; + tempButton->Appearance.Border = ui::Border(0); + 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])); tags.push_back(tempButton); AddComponent(tempButton); @@ -116,21 +143,25 @@ void TagsView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool case KEY_RETURN: if(IsFocused(tagInput)) { - - try - { - c->AddTag(tagInput->GetText()); - } - catch(TagsModelException & ex) - { - new ErrorMessage("Could not add tag", ex.what()); - } - tagInput->SetText(""); + addTag(); } break; } } +void TagsView::addTag() +{ + try + { + c->AddTag(tagInput->GetText()); + } + catch(TagsModelException & ex) + { + new ErrorMessage("Could not add tag", ex.what()); + } + tagInput->SetText(""); +} + TagsView::~TagsView() { // TODO Auto-generated destructor stub } diff --git a/src/tags/TagsView.h b/src/tags/TagsView.h index bac0fae6a..b2dabc0d3 100644 --- a/src/tags/TagsView.h +++ b/src/tags/TagsView.h @@ -22,10 +22,12 @@ class TagsController; class TagsModel; class TagsView: public ui::Window { TagsController * c; + ui::Button * addButton; ui::Button * closeButton; ui::Label * title; ui::Textbox * tagInput; std::vector tags; + void addTag(); public: TagsView(); virtual void OnDraw();