Ensure errors are caught and displayed during tag operations. Fix some issues with the Tag ui. Fixes #157
This commit is contained in:
parent
09c266f252
commit
5da70ef8a6
@ -1821,8 +1821,19 @@ std::vector<std::string> * 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);
|
||||
|
||||
json::Number status = responseObject["Status"];
|
||||
|
||||
if(status.Value()==0)
|
||||
{
|
||||
json::String error = responseObject["Error"];
|
||||
lastError = error.Value();
|
||||
}
|
||||
else
|
||||
{
|
||||
json::Array tagsArray = responseObject["Tags"];
|
||||
|
||||
tags = new std::vector<std::string>();
|
||||
|
||||
@ -1832,6 +1843,7 @@ std::vector<std::string> * Client::RemoveTag(int saveID, std::string tag)
|
||||
tags->push_back(tempTag.Value());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (json::Exception &e)
|
||||
{
|
||||
lastError = "Could not read response";
|
||||
@ -1870,8 +1882,19 @@ std::vector<std::string> * 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);
|
||||
|
||||
json::Number status = responseObject["Status"];
|
||||
|
||||
if(status.Value()==0)
|
||||
{
|
||||
json::String error = responseObject["Error"];
|
||||
lastError = error.Value();
|
||||
}
|
||||
else
|
||||
{
|
||||
json::Array tagsArray = responseObject["Tags"];
|
||||
|
||||
tags = new std::vector<std::string>();
|
||||
|
||||
@ -1881,6 +1904,7 @@ std::vector<std::string> * Client::AddTag(int saveID, std::string tag)
|
||||
tags->push_back(tempTag.Value());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (json::Exception &e)
|
||||
{
|
||||
lastError = "Could not read response";
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -78,6 +78,7 @@ enum Icon
|
||||
IconFolder,
|
||||
IconSearch,
|
||||
IconDelete,
|
||||
IconAdd,
|
||||
IconReport,
|
||||
IconUsername,
|
||||
IconPassword,
|
||||
|
@ -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();
|
||||
|
@ -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,7 +143,14 @@ void TagsView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
case KEY_RETURN:
|
||||
if(IsFocused(tagInput))
|
||||
{
|
||||
addTag();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TagsView::addTag()
|
||||
{
|
||||
try
|
||||
{
|
||||
c->AddTag(tagInput->GetText());
|
||||
@ -126,9 +160,6 @@ void TagsView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
new ErrorMessage("Could not add tag", ex.what());
|
||||
}
|
||||
tagInput->SetText("");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TagsView::~TagsView() {
|
||||
|
@ -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<ui::Component*> tags;
|
||||
void addTag();
|
||||
public:
|
||||
TagsView();
|
||||
virtual void OnDraw();
|
||||
|
Loading…
Reference in New Issue
Block a user