diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-17 18:14:05 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-07-17 18:14:05 (GMT) |
| commit | 2479b8664d5c4cdd47208bdbca970828ba1a2520 (patch) | |
| tree | d453fa8de5272d83d03a4a72f776c6808c5f641e /src/preview | |
| parent | 2329f98f0af9dffda5375aca7b05f9e76a84d06a (diff) | |
| download | powder-2479b8664d5c4cdd47208bdbca970828ba1a2520.zip powder-2479b8664d5c4cdd47208bdbca970828ba1a2520.tar.gz | |
Add comment box to save preview - doesn't work yet
Diffstat (limited to 'src/preview')
| -rw-r--r-- | src/preview/PreviewController.cpp | 29 | ||||
| -rw-r--r-- | src/preview/PreviewController.h | 8 | ||||
| -rw-r--r-- | src/preview/PreviewModel.cpp | 26 | ||||
| -rw-r--r-- | src/preview/PreviewModel.h | 5 | ||||
| -rw-r--r-- | src/preview/PreviewView.cpp | 59 | ||||
| -rw-r--r-- | src/preview/PreviewView.h | 7 |
6 files changed, 125 insertions, 9 deletions
diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp index 63d37c3..d5e1a93 100644 --- a/src/preview/PreviewController.cpp +++ b/src/preview/PreviewController.cpp @@ -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) diff --git a/src/preview/PreviewController.h b/src/preview/PreviewController.h index 815ca5d..81c457b 100644 --- a/src/preview/PreviewController.h +++ b/src/preview/PreviewController.h @@ -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; } diff --git a/src/preview/PreviewModel.cpp b/src/preview/PreviewModel.cpp index f62e3f5..59c1c0b 100644 --- a/src/preview/PreviewModel.cpp +++ b/src/preview/PreviewModel.cpp @@ -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() diff --git a/src/preview/PreviewModel.h b/src/preview/PreviewModel.h index f00a418..11618a0 100644 --- a/src/preview/PreviewModel.h +++ b/src/preview/PreviewModel.h @@ -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(); diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index b6b2e02..0eb29b6 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -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; diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index fbc2adc..f6be29f 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -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); |
