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,15 +1821,27 @@ std::vector<std::string> * Client::RemoveTag(int saveID, std::string tag)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::istringstream dataStream(data);
|
std::istringstream dataStream(data);
|
||||||
json::Array tagsArray;
|
json::Object responseObject;
|
||||||
json::Reader::Read(tagsArray, dataStream);
|
json::Reader::Read(responseObject, dataStream);
|
||||||
|
|
||||||
tags = new std::vector<std::string>();
|
json::Number status = responseObject["Status"];
|
||||||
|
|
||||||
for(int j = 0; j < tagsArray.Size(); j++)
|
if(status.Value()==0)
|
||||||
{
|
{
|
||||||
json::String tempTag = tagsArray[j];
|
json::String error = responseObject["Error"];
|
||||||
tags->push_back(tempTag.Value());
|
lastError = error.Value();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
json::Array tagsArray = responseObject["Tags"];
|
||||||
|
|
||||||
|
tags = new std::vector<std::string>();
|
||||||
|
|
||||||
|
for(int j = 0; j < tagsArray.Size(); j++)
|
||||||
|
{
|
||||||
|
json::String tempTag = tagsArray[j];
|
||||||
|
tags->push_back(tempTag.Value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (json::Exception &e)
|
catch (json::Exception &e)
|
||||||
@ -1870,15 +1882,27 @@ std::vector<std::string> * Client::AddTag(int saveID, std::string tag)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::istringstream dataStream(data);
|
std::istringstream dataStream(data);
|
||||||
json::Array tagsArray;
|
json::Object responseObject;
|
||||||
json::Reader::Read(tagsArray, dataStream);
|
json::Reader::Read(responseObject, dataStream);
|
||||||
|
|
||||||
tags = new std::vector<std::string>();
|
json::Number status = responseObject["Status"];
|
||||||
|
|
||||||
for(int j = 0; j < tagsArray.Size(); j++)
|
if(status.Value()==0)
|
||||||
{
|
{
|
||||||
json::String tempTag = tagsArray[j];
|
json::String error = responseObject["Error"];
|
||||||
tags->push_back(tempTag.Value());
|
lastError = error.Value();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
json::Array tagsArray = responseObject["Tags"];
|
||||||
|
|
||||||
|
tags = new std::vector<std::string>();
|
||||||
|
|
||||||
|
for(int j = 0; j < tagsArray.Size(); j++)
|
||||||
|
{
|
||||||
|
json::String tempTag = tagsArray[j];
|
||||||
|
tags->push_back(tempTag.Value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (json::Exception &e)
|
catch (json::Exception &e)
|
||||||
|
@ -113,7 +113,7 @@ public:
|
|||||||
TagsCallback(GameController * cc_) { cc = cc_; }
|
TagsCallback(GameController * cc_) { cc = cc_; }
|
||||||
virtual void ControllerExit()
|
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:
|
case IconDelete:
|
||||||
if(invert)
|
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);
|
drawchar(x, y, 0x85, 0, 0, 0, alpha);
|
||||||
}
|
}
|
||||||
else
|
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);
|
drawchar(x, y, 0x85, 255, 255, 255, alpha);
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
if(invert)
|
if(invert)
|
||||||
drawchar(x, y, 't', 0, 0 ,0 ,alpha);
|
drawchar(x, y, 't', 0, 0 ,0 ,alpha);
|
||||||
|
@ -78,6 +78,7 @@ enum Icon
|
|||||||
IconFolder,
|
IconFolder,
|
||||||
IconSearch,
|
IconSearch,
|
||||||
IconDelete,
|
IconDelete,
|
||||||
|
IconAdd,
|
||||||
IconReport,
|
IconReport,
|
||||||
IconUsername,
|
IconUsername,
|
||||||
IconPassword,
|
IconPassword,
|
||||||
|
@ -68,7 +68,7 @@ public:
|
|||||||
string GetSort() { return currentSort; }
|
string GetSort() { return currentSort; }
|
||||||
void SetShowOwn(bool show) { if(!updateSaveListWorking) { if(show!=showOwn) { showOwn = show; } } notifyShowOwnChanged(); }
|
void SetShowOwn(bool show) { if(!updateSaveListWorking) { if(show!=showOwn) { showOwn = show; } } notifyShowOwnChanged(); }
|
||||||
bool GetShowOwn() { return showOwn; }
|
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; }
|
bool GetShowFavourite() { return showFavourite; }
|
||||||
void SetLoadedSave(SaveInfo * save);
|
void SetLoadedSave(SaveInfo * save);
|
||||||
SaveInfo * GetLoadedSave();
|
SaveInfo * GetLoadedSave();
|
||||||
|
@ -33,15 +33,38 @@ TagsView::TagsView():
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
closeButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(195, 16), "Close");
|
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));
|
closeButton->SetActionCallback(new CloseAction(this));
|
||||||
AddComponent(closeButton);
|
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);
|
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 = 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);
|
AddComponent(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,10 +113,14 @@ void TagsView::NotifyTagsChanged(TagsModel * sender)
|
|||||||
tags.push_back(tempLabel);
|
tags.push_back(tempLabel);
|
||||||
AddComponent(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");
|
ui::Button * tempButton = new ui::Button(ui::Point(15, 37+(16*i)), ui::Point(11, 12));
|
||||||
tempButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; tempButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
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]));
|
tempButton->SetActionCallback(new DeleteTagAction(this, sender->GetSave()->GetTags()[i]));
|
||||||
tags.push_back(tempButton);
|
tags.push_back(tempButton);
|
||||||
AddComponent(tempButton);
|
AddComponent(tempButton);
|
||||||
@ -116,21 +143,25 @@ void TagsView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
case KEY_RETURN:
|
case KEY_RETURN:
|
||||||
if(IsFocused(tagInput))
|
if(IsFocused(tagInput))
|
||||||
{
|
{
|
||||||
|
addTag();
|
||||||
try
|
|
||||||
{
|
|
||||||
c->AddTag(tagInput->GetText());
|
|
||||||
}
|
|
||||||
catch(TagsModelException & ex)
|
|
||||||
{
|
|
||||||
new ErrorMessage("Could not add tag", ex.what());
|
|
||||||
}
|
|
||||||
tagInput->SetText("");
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TagsView::addTag()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
c->AddTag(tagInput->GetText());
|
||||||
|
}
|
||||||
|
catch(TagsModelException & ex)
|
||||||
|
{
|
||||||
|
new ErrorMessage("Could not add tag", ex.what());
|
||||||
|
}
|
||||||
|
tagInput->SetText("");
|
||||||
|
}
|
||||||
|
|
||||||
TagsView::~TagsView() {
|
TagsView::~TagsView() {
|
||||||
// TODO Auto-generated destructor stub
|
// TODO Auto-generated destructor stub
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,12 @@ class TagsController;
|
|||||||
class TagsModel;
|
class TagsModel;
|
||||||
class TagsView: public ui::Window {
|
class TagsView: public ui::Window {
|
||||||
TagsController * c;
|
TagsController * c;
|
||||||
|
ui::Button * addButton;
|
||||||
ui::Button * closeButton;
|
ui::Button * closeButton;
|
||||||
ui::Label * title;
|
ui::Label * title;
|
||||||
ui::Textbox * tagInput;
|
ui::Textbox * tagInput;
|
||||||
std::vector<ui::Component*> tags;
|
std::vector<ui::Component*> tags;
|
||||||
|
void addTag();
|
||||||
public:
|
public:
|
||||||
TagsView();
|
TagsView();
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
|
Loading…
Reference in New Issue
Block a user