Add comment box to save preview - doesn't work yet

This commit is contained in:
Simon Robertshaw 2012-07-17 19:14:05 +01:00
parent 2329f98f0a
commit 2479b8664d
12 changed files with 163 additions and 11 deletions

View File

@ -211,11 +211,31 @@ void Client::notifyUpdateAvailable()
}
}
void Client::notifyAuthUserChanged()
{
for (std::vector<ClientListener*>::iterator iterator = listeners.begin(), end = listeners.end(); iterator != end; ++iterator)
{
(*iterator)->NotifyAuthUserChanged(this);
}
}
void Client::AddListener(ClientListener * listener)
{
listeners.push_back(listener);
}
void Client::RemoveListener(ClientListener * listener)
{
for (std::vector<ClientListener*>::iterator iterator = listeners.begin(), end = listeners.end(); iterator != end; ++iterator)
{
if((*iterator) == listener)
{
listeners.erase(iterator);
return;
}
}
}
void Client::Shutdown()
{
ClearThumbnailRequests();
@ -256,6 +276,7 @@ Client::~Client()
void Client::SetAuthUser(User user)
{
authUser = user;
notifyAuthUserChanged();
}
User Client::GetAuthUser()

View File

@ -67,6 +67,7 @@ private:
void updateStamps();
static vector<std::string> explodePropertyString(std::string property);
void notifyUpdateAvailable();
void notifyAuthUserChanged();
//Config file handle
json::Object configDocument;
@ -79,6 +80,7 @@ public:
~Client();
void AddListener(ClientListener * listener);
void RemoveListener(ClientListener * listener);
RequestStatus ExecVote(int saveID, int direction);
RequestStatus UploadSave(SaveInfo * save);

View File

@ -16,6 +16,7 @@ public:
virtual ~ClientListener() {}
virtual void NotifyUpdateAvailable(Client * sender) {}
virtual void NotifyAuthUserChanged(Client * sender) {}
};

View File

@ -8,13 +8,15 @@
using namespace ui;
Textbox::Textbox(Point position, Point size, std::string textboxText):
Textbox::Textbox(Point position, Point size, std::string textboxText, std::string textboxPlaceholder):
Label(position, size, ""),
actionCallback(NULL),
masked(false),
border(true),
mouseDown(false)
{
placeHolder = textboxPlaceholder;
SetText(textboxText);
cursor = text.length();
}
@ -231,6 +233,10 @@ void Textbox::Draw(const Point& screenPos)
}
else
{
if(!text.length())
{
g->drawtext(screenPos.X+textPosition.X, screenPos.Y+textPosition.Y, placeHolder, textColour.Red, textColour.Green, textColour.Blue, 170);
}
if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 160, 160, 160, 255);
}
}

View File

@ -25,8 +25,9 @@ protected:
int cursor, cursorPosition;
TextboxAction *actionCallback;
std::string backingText;
std::string placeHolder;
public:
Textbox(Point position, Point size, std::string textboxText);
Textbox(Point position, Point size, std::string textboxText = "", std::string textboxPlaceholder = "");
virtual ~Textbox();
virtual void SetDisplayText(std::string text);

View File

@ -7,6 +7,7 @@
#include "LoginController.h"
#include "client/User.h"
#include "client/Client.h"
LoginController::LoginController(ControllerCallback * callback):
HasExited(false)
@ -40,6 +41,10 @@ void LoginController::Exit()
}
if(callback)
callback->ControllerExit();
else
{
Client::Ref().SetAuthUser(loginModel->GetUser());
}
HasExited = true;
}

View File

@ -12,11 +12,13 @@
#include "PreviewModel.h"
#include "PreviewModelException.h"
#include "dialogues/ErrorMessage.h"
#include "login/LoginController.h"
#include "Controller.h"
PreviewController::PreviewController(int saveID, ControllerCallback * callback):
HasExited(false),
saveId(saveID)
saveId(saveID),
loginWindow(NULL)
{
previewModel = new PreviewModel();
previewView = new PreviewView();
@ -25,11 +27,24 @@ PreviewController::PreviewController(int saveID, ControllerCallback * callback):
previewModel->UpdateSave(saveID, 0);
if(Client::Ref().GetAuthUser().ID)
{
previewModel->SetCommentBoxEnabled(true);
}
Client::Ref().AddListener(this);
this->callback = callback;
}
void PreviewController::Update()
{
if(loginWindow && loginWindow->HasExited == true)
{
delete loginWindow;
loginWindow = NULL;
}
try
{
previewModel->Update();
@ -45,6 +60,17 @@ void PreviewController::Update()
}
}
void PreviewController::ShowLogin()
{
loginWindow = new LoginController();
ui::Engine::Ref().ShowWindow(loginWindow->GetView());
}
void PreviewController::NotifyAuthUserChanged(Client * sender)
{
previewModel->SetCommentBoxEnabled(sender->GetAuthUser().ID);
}
SaveInfo * PreviewController::GetSave()
{
return previewModel->GetSave();
@ -114,6 +140,7 @@ PreviewController::~PreviewController() {
{
ui::Engine::Ref().CloseWindow();
}
Client::Ref().RemoveListener(this);
delete previewModel;
delete previewView;
if(callback)

View File

@ -12,21 +12,27 @@
#include "preview/PreviewView.h"
#include "Controller.h"
#include "client/SaveInfo.h"
#include "client/ClientListener.h"
class LoginController;
class PreviewModel;
class PreviewView;
class PreviewController {
class PreviewController: public ClientListener {
int saveId;
PreviewModel * previewModel;
PreviewView * previewView;
LoginController * loginWindow;
ControllerCallback * callback;
public:
virtual void NotifyAuthUserChanged(Client * sender);
bool HasExited;
PreviewController(int saveID, ControllerCallback * callback);
void Exit();
void DoOpen();
void OpenInBrowser();
void Report(std::string message);
void ShowLogin();
bool GetDoOpen();
SaveInfo * GetSave();
PreviewView * GetView() { return previewView; }

View File

@ -21,7 +21,8 @@ PreviewModel::PreviewModel():
updateSaveCommentsWorking(false),
updateSaveCommentsFinished(false),
commentsTotal(0),
commentsPageNumber(1)
commentsPageNumber(1),
commentBoxEnabled(false)
{
// TODO Auto-generated constructor stub
@ -77,6 +78,20 @@ void PreviewModel::SetFavourite(bool favourite)
}
}
bool PreviewModel::GetCommentBoxEnabled()
{
return commentBoxEnabled;
}
void PreviewModel::SetCommentBoxEnabled(bool enabledState)
{
if(enabledState != commentBoxEnabled)
{
commentBoxEnabled = enabledState;
notifyCommentBoxEnabledChanged();
}
}
void PreviewModel::UpdateSave(int saveID, int saveDate)
{
this->tSaveID = saveID;
@ -189,6 +204,14 @@ void PreviewModel::notifySaveChanged()
}
}
void PreviewModel::notifyCommentBoxEnabledChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifyCommentBoxEnabledChanged(this);
}
}
void PreviewModel::notifyCommentsPageChanged()
{
for(int i = 0; i < observers.size(); i++)
@ -210,6 +233,7 @@ void PreviewModel::AddObserver(PreviewView * observer) {
observer->NotifySaveChanged(this);
observer->NotifyCommentsChanged(this);
observer->NotifyCommentsPageChanged(this);
observer->NotifyCommentBoxEnabledChanged(this);
}
void PreviewModel::Update()

View File

@ -27,6 +27,7 @@ struct SaveData
class PreviewView;
class PreviewModel {
bool doOpen;
bool commentBoxEnabled;
vector<PreviewView*> observers;
SaveInfo * save;
vector<char> saveDataBuffer;
@ -34,6 +35,7 @@ class PreviewModel {
void notifySaveChanged();
void notifySaveCommentsChanged();
void notifyCommentsPageChanged();
void notifyCommentBoxEnabledChanged();
//Background retrieval
int tSaveID;
@ -66,6 +68,9 @@ public:
SaveInfo * GetSave();
std::vector<SaveComment*> * GetComments();
bool GetCommentBoxEnabled();
void SetCommentBoxEnabled(bool enabledState);
bool GetCommentsLoaded();
int GetCommentsPageNum();
int GetCommentsPageCount();

View File

@ -13,9 +13,21 @@
#include "simulation/SaveRenderer.h"
#include "interface/Point.h"
#include "interface/Window.h"
#include "interface/Textbox.h"
#include "Style.h"
#include "search/Thumbnail.h"
class PreviewView::LoginAction: public ui::ButtonAction
{
PreviewView * v;
public:
LoginAction(PreviewView * v_){ v = v_; }
virtual void ActionCallback(ui::Button * sender)
{
v->c->ShowLogin();
}
};
PreviewView::PreviewView():
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
savePreview(NULL),
@ -24,7 +36,10 @@ PreviewView::PreviewView():
commentsVel(0),
maxOffset(0),
commentsBegin(true),
commentsEnd(false)
commentsEnd(false),
addCommentBox(NULL),
submitCommentButton(NULL),
commentBoxHeight(20)
{
class OpenAction: public ui::ButtonAction
{
@ -118,8 +133,9 @@ PreviewView::PreviewView():
authorDateLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
AddComponent(authorDateLabel);
pageInfo = new ui::Label(ui::Point((XRES/2) + 5, Size.Y-15), ui::Point(Size.X-((XRES/2) + 10), 15), "Page 1 of 1");
pageInfo = new ui::Label(ui::Point((XRES/2) + 5, Size.Y+1), ui::Point(Size.X-((XRES/2) + 10), 15), "Page 1 of 1");
pageInfo->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; authorDateLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(pageInfo);
}
@ -149,7 +165,7 @@ void PreviewView::OnDraw()
g->draw_image(savePreview->Data, (Position.X+1)+(((XRES/2)-savePreview->Size.X)/2), (Position.Y+1)+(((YRES/2)-savePreview->Size.Y)/2), savePreview->Size.X, savePreview->Size.Y, 255);
}
g->drawrect(Position.X, Position.Y, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 100);
g->draw_line(Position.X+XRES/2, Position.Y+1, Position.X+XRES/2, Position.Y+Size.Y-2, 200, 200, 200, 255);
g->draw_line(Position.X+1+XRES/2, Position.Y+1, Position.X+XRES/2, Position.Y+Size.Y-2, 200, 200, 200, 255);
g->draw_line(Position.X+1, Position.Y+12+YRES/2, Position.X-1+XRES/2, Position.Y+12+YRES/2, 100, 100, 100,255);
@ -289,7 +305,7 @@ void PreviewView::displayComments(int yOffset)
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
currentY += 16;
if(currentY > Size.Y || usernameY < 0)
if(currentY > Size.Y-commentBoxHeight || usernameY < 0)
{
delete tempUsername;
if(currentY > Size.Y)
@ -308,7 +324,7 @@ void PreviewView::displayComments(int yOffset)
tempComment->SetTextColour(ui::Colour(180, 180, 180));
currentY += tempComment->Size.Y+4;
if(currentY > Size.Y || commentY < 0)
if(currentY > Size.Y-commentBoxHeight || commentY < 0)
{
delete tempComment;
if(currentY > Size.Y)
@ -323,6 +339,37 @@ void PreviewView::displayComments(int yOffset)
}
}
void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
{
if(addCommentBox)
{
RemoveComponent(addCommentBox);
addCommentBox = NULL;
delete addCommentBox;
}
if(submitCommentButton)
{
RemoveComponent(submitCommentButton);
submitCommentButton = NULL;
delete submitCommentButton;
}
if(sender->GetCommentBoxEnabled())
{
addCommentBox = new ui::Textbox(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 17), "", "Add Comment");
addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
AddComponent(addCommentBox);
submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit");
//submitCommentButton->Enabled = false;
AddComponent(submitCommentButton);
}
else
{
submitCommentButton = new ui::Button(ui::Point(XRES/2, Size.Y-19), ui::Point(Size.X-(XRES/2), 19), "Login to comment");
submitCommentButton->SetActionCallback(new LoginAction(this));
AddComponent(submitCommentButton);
}
}
void PreviewView::NotifyCommentsPageChanged(PreviewModel * sender)
{
std::stringstream pageInfoStream;
@ -361,7 +408,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
}
maxOffset = (maxY-Size.Y)+16;
maxOffset = (maxY-(Size.Y-commentBoxHeight))+16;
commentsBegin = true;
commentsEnd = false;
commentsOffset = 0;

View File

@ -16,16 +16,20 @@
#include "interface/Button.h"
#include "search/Thumbnail.h"
#include "interface/Label.h"
#include "interface/Textbox.h"
class PreviewModel;
class PreviewController;
class PreviewView: public ui::Window {
class LoginAction;
PreviewController * c;
Thumbnail * savePreview;
ui::Button * openButton;
ui::Button * browserOpenButton;
ui::Button * favButton;
ui::Button * reportButton;
ui::Button * submitCommentButton;
ui::Textbox * addCommentBox;
ui::Label * saveNameLabel;
ui::Label * authorDateLabel;
ui::Label * pageInfo;
@ -43,6 +47,8 @@ class PreviewView: public ui::Window {
float commentsOffset;
float commentsVel;
int commentBoxHeight;
void displayComments(int yOffset);
public:
void AttachController(PreviewController * controller) { c = controller;}
@ -50,6 +56,7 @@ public:
void NotifySaveChanged(PreviewModel * sender);
void NotifyCommentsChanged(PreviewModel * sender);
void NotifyCommentsPageChanged(PreviewModel * sender);
void NotifyCommentBoxEnabledChanged(PreviewModel * sender);
virtual void OnDraw();
virtual void DoDraw();
virtual void OnTick(float dt);