More work on Tags - display tags in Tag window and Tag button
This commit is contained in:
parent
7e3d45bbfb
commit
23873eae71
@ -359,6 +359,16 @@ Save * Client::GetSave(int saveID, int saveDate)
|
||||
json::String tempDescription = objDocument["Description"];
|
||||
json::Number tempDate = objDocument["Date"];
|
||||
json::Boolean tempPublished = objDocument["Published"];
|
||||
|
||||
json::Array tagsArray = objDocument["Tags"];
|
||||
vector<string> tempTags;
|
||||
|
||||
for(int j = 0; j < tagsArray.Size(); j++)
|
||||
{
|
||||
json::String tempTag = tagsArray[j];
|
||||
tempTags.push_back(tempTag.Value());
|
||||
}
|
||||
|
||||
return new Save(
|
||||
tempID.Value(),
|
||||
tempDate.Value(),
|
||||
@ -368,7 +378,8 @@ Save * Client::GetSave(int saveID, int saveDate)
|
||||
tempUsername.Value(),
|
||||
tempName.Value(),
|
||||
tempDescription.Value(),
|
||||
tempPublished.Value()
|
||||
tempPublished.Value(),
|
||||
tempTags
|
||||
);
|
||||
}
|
||||
catch (json::Exception &e)
|
||||
|
@ -66,6 +66,17 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class GameController::TagsCallback: public ControllerCallback
|
||||
{
|
||||
GameController * cc;
|
||||
public:
|
||||
TagsCallback(GameController * cc_) { cc = cc_; }
|
||||
virtual void ControllerExit()
|
||||
{
|
||||
cc->gameModel->SetSave(new Save(*(cc->tagsWindow->GetSave())));
|
||||
}
|
||||
};
|
||||
|
||||
GameController::GameController():
|
||||
search(NULL),
|
||||
renderOptions(NULL),
|
||||
@ -338,8 +349,22 @@ void GameController::OpenLogin()
|
||||
|
||||
void GameController::OpenTags()
|
||||
{
|
||||
tagsWindow = new TagsController(NULL);
|
||||
ui::Engine::Ref().ShowWindow(tagsWindow->GetView());
|
||||
if(gameModel->GetUser().ID)
|
||||
{
|
||||
if(gameModel->GetSave() && gameModel->GetSave()->GetID())
|
||||
{
|
||||
tagsWindow = new TagsController(new TagsCallback(this), gameModel->GetSave());
|
||||
ui::Engine::Ref().ShowWindow(tagsWindow->GetView());
|
||||
}
|
||||
else
|
||||
{
|
||||
new ErrorMessage("Error", "No save open");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new ErrorMessage("Error", "You need to login to edit tags.");
|
||||
}
|
||||
}
|
||||
|
||||
void GameController::OpenDisplayOptions()
|
||||
|
@ -40,6 +40,7 @@ public:
|
||||
class SearchCallback;
|
||||
class RenderCallback;
|
||||
class SSaveCallback;
|
||||
class TagsCallback;
|
||||
GameController();
|
||||
~GameController();
|
||||
GameView * GetView();
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "Config.h"
|
||||
#include "GameView.h"
|
||||
#include "interface/Window.h"
|
||||
@ -426,6 +428,18 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
||||
else
|
||||
downVoteButton->SetBackgroundColour(ui::Colour(0, 0, 0));
|
||||
tagSimulationButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID);
|
||||
if(sender->GetSave()->GetID())
|
||||
{
|
||||
std::stringstream tagsStream;
|
||||
std::vector<string> tags = sender->GetSave()->GetTags();
|
||||
for(int i = 0; i < tags.size(); i++)
|
||||
{
|
||||
tagsStream << sender->GetSave()->GetTags()[i];
|
||||
if(i < tags.size()-1)
|
||||
tagsStream << " ";
|
||||
}
|
||||
tagSimulationButton->SetText(tagsStream.str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -436,6 +450,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
||||
downVoteButton->Enabled = false;
|
||||
upVoteButton->SetBackgroundColour(ui::Colour(0, 0, 0));
|
||||
tagSimulationButton->Enabled = false;
|
||||
tagSimulationButton->SetText("");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
Save::Save(Save & save) :
|
||||
userName(save.userName), name(save.name), Description(save.Description), date(
|
||||
save.date), Published(save.Published), id(save.id), votesUp(
|
||||
save.votesUp), votesDown(save.votesDown), data(NULL), vote(save.vote) {
|
||||
save.votesUp), votesDown(save.votesDown), data(NULL), vote(save.vote), tags(save.tags) {
|
||||
if (save.data) {
|
||||
std::cout << data << " " << save.data << std::endl;
|
||||
data = (unsigned char *) malloc(save.dataLength);
|
||||
@ -24,14 +24,14 @@ Save::Save(int _id, int _date, int _votesUp, int _votesDown, string _userName,
|
||||
string _name) :
|
||||
id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name(
|
||||
_name), Description("No description provided"), date(_date), Published(
|
||||
true), data(NULL), vote(0) {
|
||||
true), data(NULL), vote(0), tags() {
|
||||
}
|
||||
|
||||
Save::Save(int _id, int date_, int _votesUp, int _votesDown, int _vote, string _userName,
|
||||
string _name, string description_, bool published_) :
|
||||
string _name, string description_, bool published_, vector<string> tags_) :
|
||||
id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name(
|
||||
_name), Description(description_), date(date_), Published(
|
||||
published_), data(NULL), vote(_vote) {
|
||||
published_), data(NULL), vote(_vote), tags(tags_) {
|
||||
}
|
||||
|
||||
Save::~Save()
|
||||
@ -86,6 +86,15 @@ int Save::GetVotesDown() {
|
||||
return votesDown;
|
||||
}
|
||||
|
||||
void Save::SetTags(vector<string> tags)
|
||||
{
|
||||
this->tags = tags;
|
||||
}
|
||||
vector<string> Save::GetTags()
|
||||
{
|
||||
return tags;
|
||||
}
|
||||
|
||||
unsigned char * Save::GetData() {
|
||||
if (!data) {
|
||||
data = Client::Ref().GetSaveData(id, date, dataLength);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef SAVE_H
|
||||
#define SAVE_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
@ -22,7 +23,7 @@ public:
|
||||
|
||||
Save(int _id, int _date, int _votesUp, int _votesDown, string _userName, string _name);
|
||||
|
||||
Save(int _id, int date_, int _votesUp, int _votesDown, int _vote, string _userName, string _name, string description_, bool published_);
|
||||
Save(int _id, int date_, int _votesUp, int _votesDown, int _vote, string _userName, string _name, string description_, bool published_, vector<string> tags);
|
||||
|
||||
~Save();
|
||||
|
||||
@ -31,6 +32,8 @@ public:
|
||||
|
||||
string Description;
|
||||
|
||||
vector<string> tags;
|
||||
|
||||
int vote;
|
||||
|
||||
bool Published;
|
||||
@ -53,6 +56,9 @@ public:
|
||||
void SetVotesDown(int votesDown);
|
||||
int GetVotesDown();
|
||||
|
||||
void SetTags(vector<string> tags);
|
||||
vector<string> GetTags();
|
||||
|
||||
unsigned char * GetData();
|
||||
void SetData(unsigned char * data_, int dataLength);
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "TagsModel.h"
|
||||
#include "TagsView.h"
|
||||
|
||||
TagsController::TagsController(ControllerCallback * callback):
|
||||
TagsController::TagsController(ControllerCallback * callback, Save * save):
|
||||
HasDone(false)
|
||||
{
|
||||
tagsModel = new TagsModel();
|
||||
@ -19,9 +19,16 @@ TagsController::TagsController(ControllerCallback * callback):
|
||||
tagsView->AttachController(this);
|
||||
tagsModel->AddObserver(tagsView);
|
||||
|
||||
tagsModel->SetSave(save);
|
||||
|
||||
this->callback = callback;
|
||||
}
|
||||
|
||||
Save * TagsController::GetSave()
|
||||
{
|
||||
return tagsModel->GetSave();
|
||||
}
|
||||
|
||||
void TagsController::Exit()
|
||||
{
|
||||
if(ui::Engine::Ref().GetWindow() == tagsView)
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "Controller.h"
|
||||
#include "TagsView.h"
|
||||
#include "search/Save.h"
|
||||
|
||||
class TagsView;
|
||||
class TagsModel;
|
||||
@ -19,8 +20,9 @@ class TagsController {
|
||||
TagsModel * tagsModel;
|
||||
public:
|
||||
bool HasDone;
|
||||
TagsController(ControllerCallback * callback);
|
||||
TagsController(ControllerCallback * callback, Save * save);
|
||||
TagsView * GetView() {return tagsView;}
|
||||
Save * GetSave();
|
||||
void Exit();
|
||||
virtual ~TagsController();
|
||||
};
|
||||
|
@ -6,15 +6,38 @@
|
||||
*/
|
||||
|
||||
#include "TagsModel.h"
|
||||
#include "TagsView.h"
|
||||
|
||||
TagsModel::TagsModel() {
|
||||
TagsModel::TagsModel():
|
||||
save(NULL)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
void TagsModel::SetSave(Save * save)
|
||||
{
|
||||
this->save = save;
|
||||
notifyTagsChanged();
|
||||
}
|
||||
|
||||
Save * TagsModel::GetSave()
|
||||
{
|
||||
return save;
|
||||
}
|
||||
|
||||
void TagsModel::AddObserver(TagsView * observer)
|
||||
{
|
||||
observers.push_back(observer);
|
||||
observer->NotifyTagsChanged(this);
|
||||
}
|
||||
|
||||
void TagsModel::notifyTagsChanged()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
{
|
||||
observers[i]->NotifyTagsChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
TagsModel::~TagsModel() {
|
||||
|
@ -9,13 +9,18 @@
|
||||
#define TAGSMODEL_H_
|
||||
|
||||
#include <vector>
|
||||
#include "search/Save.h"
|
||||
|
||||
class TagsView;
|
||||
class TagsModel {
|
||||
Save * save;
|
||||
std::vector<TagsView*> observers;
|
||||
void notifyTagsChanged();
|
||||
public:
|
||||
TagsModel();
|
||||
void AddObserver(TagsView * observer);
|
||||
void SetSave(Save * save);
|
||||
Save * GetSave();
|
||||
virtual ~TagsModel();
|
||||
};
|
||||
|
||||
|
@ -11,9 +11,12 @@
|
||||
#include "TagsModel.h"
|
||||
|
||||
TagsView::TagsView():
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 300)){
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 300))
|
||||
{
|
||||
submitButton = new ui::Button(ui::Point(Size.X-56, Size.Y-24), ui::Point(50, 16));
|
||||
AddComponent(submitButton);
|
||||
tagInput = new ui::Textbox(ui::Point(6, Size.Y-24), ui::Point(Size.X-80, 16), "");
|
||||
AddComponent(tagInput);
|
||||
}
|
||||
|
||||
void TagsView::OnDraw()
|
||||
@ -23,6 +26,26 @@ void TagsView::OnDraw()
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
void TagsView::NotifyTagsChanged(TagsModel * sender)
|
||||
{
|
||||
for(int i = 0; i < tags.size(); i++)
|
||||
{
|
||||
RemoveComponent(tags[i]);
|
||||
delete tags[i];
|
||||
}
|
||||
tags.clear();
|
||||
|
||||
if(sender->GetSave())
|
||||
{
|
||||
for(int i = 0; i < sender->GetSave()->GetTags().size(); i++)
|
||||
{
|
||||
ui::Label * tempLabel = new ui::Label(ui::Point(5, 10*i), ui::Point(50, 16), sender->GetSave()->GetTags()[i]);
|
||||
tags.push_back(tempLabel);
|
||||
AddComponent(tempLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TagsView::~TagsView() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
@ -8,16 +8,24 @@
|
||||
#ifndef TAGSVIEW_H_
|
||||
#define TAGSVIEW_H_
|
||||
|
||||
#include <vector>
|
||||
#include "interface/Window.h"
|
||||
#include "interface/Button.h"
|
||||
#include "interface/Textbox.h"
|
||||
#include "interface/Label.h"
|
||||
|
||||
class TagsController;
|
||||
class TagsModel;
|
||||
class TagsView: public ui::Window {
|
||||
TagsController * c;
|
||||
ui::Button * submitButton;
|
||||
ui::Textbox * tagInput;
|
||||
std::vector<ui::Label*> tags;
|
||||
public:
|
||||
TagsView();
|
||||
virtual void OnDraw();
|
||||
void AttachController(TagsController * c_) { c = c_; };
|
||||
void NotifyTagsChanged(TagsModel * sender);
|
||||
virtual ~TagsView();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user