summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-03-22 13:50:43 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-03-22 13:50:43 (GMT)
commit23873eae719a1c0a1227a4e108a158a9ec625462 (patch)
treed397224fa7a0d01de2f18d2449c3b5d4fcaa6638 /src
parent7e3d45bbfb701a5eca3e93b589680d8651ada016 (diff)
downloadpowder-23873eae719a1c0a1227a4e108a158a9ec625462.zip
powder-23873eae719a1c0a1227a4e108a158a9ec625462.tar.gz
More work on Tags - display tags in Tag window and Tag button
Diffstat (limited to 'src')
-rw-r--r--src/client/Client.cpp13
-rw-r--r--src/game/GameController.cpp29
-rw-r--r--src/game/GameController.h1
-rw-r--r--src/game/GameView.cpp15
-rw-r--r--src/search/Save.cpp17
-rw-r--r--src/search/Save.h8
-rw-r--r--src/tags/TagsController.cpp9
-rw-r--r--src/tags/TagsController.h4
-rw-r--r--src/tags/TagsModel.cpp25
-rw-r--r--src/tags/TagsModel.h5
-rw-r--r--src/tags/TagsView.cpp29
-rw-r--r--src/tags/TagsView.h8
12 files changed, 149 insertions, 14 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index 1fbff93..f6c2ecb 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -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)
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 25f02e9..80f45ff 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -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()
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 7944dc7..d405051 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -40,6 +40,7 @@ public:
class SearchCallback;
class RenderCallback;
class SSaveCallback;
+ class TagsCallback;
GameController();
~GameController();
GameView * GetView();
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 82293e4..1fa039c 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -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("");
}
}
diff --git a/src/search/Save.cpp b/src/search/Save.cpp
index 407b739..3c7b1f9 100644
--- a/src/search/Save.cpp
+++ b/src/search/Save.cpp
@@ -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);
diff --git a/src/search/Save.h b/src/search/Save.h
index 74097fd..00387ae 100644
--- a/src/search/Save.h
+++ b/src/search/Save.h
@@ -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);
diff --git a/src/tags/TagsController.cpp b/src/tags/TagsController.cpp
index 88356c7..5a457a1 100644
--- a/src/tags/TagsController.cpp
+++ b/src/tags/TagsController.cpp
@@ -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)
diff --git a/src/tags/TagsController.h b/src/tags/TagsController.h
index 5c613f0..151cb73 100644
--- a/src/tags/TagsController.h
+++ b/src/tags/TagsController.h
@@ -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();
};
diff --git a/src/tags/TagsModel.cpp b/src/tags/TagsModel.cpp
index cfff371..b623ef7 100644
--- a/src/tags/TagsModel.cpp
+++ b/src/tags/TagsModel.cpp
@@ -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() {
diff --git a/src/tags/TagsModel.h b/src/tags/TagsModel.h
index fe7c057..3d633c3 100644
--- a/src/tags/TagsModel.h
+++ b/src/tags/TagsModel.h
@@ -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();
};
diff --git a/src/tags/TagsView.cpp b/src/tags/TagsView.cpp
index f9eafbc..b531190 100644
--- a/src/tags/TagsView.cpp
+++ b/src/tags/TagsView.cpp
@@ -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
}
diff --git a/src/tags/TagsView.h b/src/tags/TagsView.h
index 3126e5a..e401516 100644
--- a/src/tags/TagsView.h
+++ b/src/tags/TagsView.h
@@ -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();
};