From 2329f98f0af9dffda5375aca7b05f9e76a84d06a Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 17 Jul 2012 16:57:12 +0100 Subject: Varying update notifications diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 8ece34b..260d99a 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -681,7 +681,18 @@ void GameController::NotifyUpdateAvailable(Client * sender) } }; - gameModel->AddNotification(new UpdateNotification(this, "A new version is available - click here to download")); + switch(sender->GetUpdateInfo().Type) + { + case UpdateInfo::Snapshot: + gameModel->AddNotification(new UpdateNotification(this, std::string("A new snapshot is available - click here to update"))); + break; + case UpdateInfo::Stable: + gameModel->AddNotification(new UpdateNotification(this, std::string("A new version is available - click here to update"))); + break; + case UpdateInfo::Beta: + gameModel->AddNotification(new UpdateNotification(this, std::string("A new beta is available - click here to update"))); + break; + } } void GameController::RemoveNotification(Notification * notification) diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index dd03987..8adb9e1 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -975,16 +975,18 @@ void GameView::NotifyNotificationsChanged(GameModel * sender) } }; - for(std::vector::iterator iter = notificationComponents.begin(); iter != notificationComponents.end(); ++iter) { - RemoveComponent(*iter); - delete *iter; + for(std::vector::const_iterator iter = notificationComponents.begin(), end = notificationComponents.end(); iter != end; ++iter) { + ui::Component * cNotification = *iter; + RemoveComponent(cNotification); + delete cNotification; } notificationComponents.clear(); + std::vector notifications = sender->GetNotifications(); int currentY = YRES-17; - for(std::vector::iterator iter = notifications.begin(); iter != notifications.end(); ++iter) + for(std::vector::iterator iter = notifications.begin(), end = notifications.end(); iter != end; ++iter) { int width = (Graphics::textwidth((*iter)->Message.c_str()))+8; ui::Button * tempButton = new ui::Button(ui::Point(XRES-width-22, currentY), ui::Point(width, 15), (*iter)->Message); -- cgit v0.9.2-21-gd62e From 2479b8664d5c4cdd47208bdbca970828ba1a2520 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 17 Jul 2012 19:14:05 +0100 Subject: Add comment box to save preview - doesn't work yet diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 3a46e23..d851e55 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -211,11 +211,31 @@ void Client::notifyUpdateAvailable() } } +void Client::notifyAuthUserChanged() +{ + for (std::vector::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::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() diff --git a/src/client/Client.h b/src/client/Client.h index b2822d4..adaa449 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -67,6 +67,7 @@ private: void updateStamps(); static vector 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); diff --git a/src/client/ClientListener.h b/src/client/ClientListener.h index 308721c..4fc2d89 100644 --- a/src/client/ClientListener.h +++ b/src/client/ClientListener.h @@ -16,6 +16,7 @@ public: virtual ~ClientListener() {} virtual void NotifyUpdateAvailable(Client * sender) {} + virtual void NotifyAuthUserChanged(Client * sender) {} }; diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 12a4698..66af516 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -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); } } diff --git a/src/interface/Textbox.h b/src/interface/Textbox.h index 120194e..1410405 100644 --- a/src/interface/Textbox.h +++ b/src/interface/Textbox.h @@ -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); diff --git a/src/login/LoginController.cpp b/src/login/LoginController.cpp index a44e9ea..f27ad59 100644 --- a/src/login/LoginController.cpp +++ b/src/login/LoginController.cpp @@ -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; } 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 observers; SaveInfo * save; vector 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 * 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); -- cgit v0.9.2-21-gd62e From d91d4223b8ada310dd9df5f9950c66f534b2f008 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 17 Jul 2012 22:21:20 +0100 Subject: Improve spacing of multiline labels, multiline cursor for Textbox, autoresizing textbox for PreviewView comments diff --git a/src/interface/Component.cpp b/src/interface/Component.cpp index a0c55f4..648635c 100644 --- a/src/interface/Component.cpp +++ b/src/interface/Component.cpp @@ -79,7 +79,7 @@ void Component::TextPosition(std::string displayText) switch(Appearance.VerticalAlign) { case ui::Appearance::AlignTop: - textPosition.Y = Appearance.Margin.Top; + textPosition.Y = Appearance.Margin.Top+2; break; case ui::Appearance::AlignMiddle: textPosition.Y = Appearance.Margin.Top+((textAreaHeight-textHeight)/2); diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 66af516..3180cb7 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -42,11 +42,11 @@ void Textbox::SetText(std::string newText) if(cursor) { - cursorPosition = Graphics::textnwidth((char *)text.c_str(), cursor); + Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY); } else { - cursorPosition = 0; + cursorPositionY = cursorPositionX = 0; } } @@ -175,25 +175,25 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool if(cursor) { - cursorPosition = Graphics::textnwidth((char *)text.c_str(), cursor); + Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY); } else { - cursorPosition = 0; + cursorPositionY = cursorPositionX = 0; } } void Textbox::OnMouseClick(int x, int y, unsigned button) { mouseDown = true; - cursor = Graphics::CharIndexAtPosition((char*)text.c_str(), x-textPosition.X, y-textPosition.Y); + cursor = Graphics::CharIndexAtPosition(multiline?((char*)textLines.c_str()):((char*)text.c_str()), x-textPosition.X, y-textPosition.Y); if(cursor) { - cursorPosition = Graphics::textnwidth((char *)text.c_str(), cursor); + Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY); } else { - cursorPosition = 0; + cursorPositionY = cursorPositionX = 0; } Label::OnMouseClick(x, y, button); } @@ -208,14 +208,14 @@ void Textbox::OnMouseMoved(int localx, int localy, int dx, int dy) { if(mouseDown) { - cursor = Graphics::CharIndexAtPosition((char*)text.c_str(), localx-textPosition.X, localy-textPosition.Y); + cursor = Graphics::CharIndexAtPosition(multiline?((char*)textLines.c_str()):((char*)text.c_str()), localx-textPosition.X, localy-textPosition.Y); if(cursor) { - cursorPosition = Graphics::textnwidth((char *)text.c_str(), cursor); + Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY); } else { - cursorPosition = 0; + cursorPositionY = cursorPositionX = 0; } } Label::OnMouseMoved(localx, localy, dx, dy); @@ -229,7 +229,7 @@ void Textbox::Draw(const Point& screenPos) if(IsFocused()) { if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255); - g->draw_line(screenPos.X+textPosition.X+cursorPosition, screenPos.Y+3, screenPos.X+textPosition.X+cursorPosition, screenPos.Y+12, 255, 255, 255, XRES+BARSIZE); + g->draw_line(screenPos.X+textPosition.X+cursorPositionX+1, screenPos.Y-2+textPosition.Y+cursorPositionY, screenPos.X+textPosition.X+cursorPositionX+1, screenPos.Y+10+textPosition.Y+cursorPositionY, 255, 255, 255, XRES+BARSIZE); } else { diff --git a/src/interface/Textbox.h b/src/interface/Textbox.h index 1410405..700974a 100644 --- a/src/interface/Textbox.h +++ b/src/interface/Textbox.h @@ -22,7 +22,7 @@ class Textbox : public Label protected: bool mouseDown; bool masked, border; - int cursor, cursorPosition; + int cursor, cursorPositionX, cursorPositionY; TextboxAction *actionCallback; std::string backingText; std::string placeHolder; diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 0eb29b6..417e258 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -28,6 +28,16 @@ public: } }; +class PreviewView::AutoCommentSizeAction: public ui::TextboxAction +{ + PreviewView * v; +public: + AutoCommentSizeAction(PreviewView * v): v(v) {} + virtual void TextChangedCallback(ui::Textbox * sender) { + v->commentBoxAutoHeight(); + } +}; + PreviewView::PreviewView(): ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)), savePreview(NULL), @@ -139,6 +149,30 @@ PreviewView::PreviewView(): AddComponent(pageInfo); } +void PreviewView::commentBoxAutoHeight() +{ + if(!addCommentBox) + return; + int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str()); + if(textWidth+5 > Size.X-(XRES/2)-48) + { + commentBoxHeight = 58; + addCommentBox->SetMultiline(true); + addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop; + addCommentBox->Position = ui::Point((XRES/2)+4, Size.Y-58); + addCommentBox->Size = ui::Point(Size.X-(XRES/2)-8, 37); + } + else + { + commentBoxHeight = 20; + addCommentBox->SetMultiline(false); + addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + addCommentBox->Position = ui::Point((XRES/2)+4, Size.Y-19); + addCommentBox->Size = ui::Point(Size.X-(XRES/2)-48, 17); + } + displayComments(commentsOffset); +} + void PreviewView::DoDraw() { Window::DoDraw(); @@ -305,10 +339,10 @@ void PreviewView::displayComments(int yOffset) tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom; currentY += 16; - if(currentY > Size.Y-commentBoxHeight || usernameY < 0) + if(currentY+5 > Size.Y-commentBoxHeight || usernameY < 0) { delete tempUsername; - if(currentY > Size.Y) + if(currentY+5 > Size.Y-commentBoxHeight) break; } else @@ -324,10 +358,10 @@ void PreviewView::displayComments(int yOffset) tempComment->SetTextColour(ui::Colour(180, 180, 180)); currentY += tempComment->Size.Y+4; - if(currentY > Size.Y-commentBoxHeight || commentY < 0) + if(currentY+5 > Size.Y-commentBoxHeight || commentY < 0) { delete tempComment; - if(currentY > Size.Y) + if(currentY+5 > Size.Y-commentBoxHeight) break; } else @@ -356,6 +390,7 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender) 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->SetActionCallback(new AutoCommentSizeAction(this)); 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"); diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index f6be29f..f817a1a 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -22,6 +22,7 @@ class PreviewModel; class PreviewController; class PreviewView: public ui::Window { class LoginAction; + class AutoCommentSizeAction; PreviewController * c; Thumbnail * savePreview; ui::Button * openButton; @@ -50,6 +51,7 @@ class PreviewView: public ui::Window { int commentBoxHeight; void displayComments(int yOffset); + void commentBoxAutoHeight(); public: void AttachController(PreviewController * controller) { c = controller;} PreviewView(); -- cgit v0.9.2-21-gd62e From 78c4aba468a35166bf4ef5056b8e15be4098ba07 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 17 Jul 2012 22:40:47 +0100 Subject: Fancy animation for textbox autosize diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 417e258..d7c44b3 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -159,16 +159,22 @@ void PreviewView::commentBoxAutoHeight() commentBoxHeight = 58; addCommentBox->SetMultiline(true); addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop; - addCommentBox->Position = ui::Point((XRES/2)+4, Size.Y-58); - addCommentBox->Size = ui::Point(Size.X-(XRES/2)-8, 37); + + commentBoxPositionX = (XRES/2)+4; + commentBoxPositionY = Size.Y-58; + commentBoxSizeX = Size.X-(XRES/2)-8; + commentBoxSizeY = 37; } else { commentBoxHeight = 20; addCommentBox->SetMultiline(false); addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; - addCommentBox->Position = ui::Point((XRES/2)+4, Size.Y-19); - addCommentBox->Size = ui::Point(Size.X-(XRES/2)-48, 17); + + commentBoxPositionX = (XRES/2)+4; + commentBoxPositionY = Size.Y-19; + commentBoxSizeX = Size.X-(XRES/2)-48; + commentBoxSizeY = 17; } displayComments(commentsOffset); } @@ -263,6 +269,42 @@ void PreviewView::OnTick(float dt) displayComments(commentsOffset); } + if(addCommentBox) + { + ui::Point positionDiff = ui::Point(commentBoxPositionX, commentBoxPositionY)-addCommentBox->Position; + ui::Point sizeDiff = ui::Point(commentBoxSizeX, commentBoxSizeY)-addCommentBox->Size; + + if(positionDiff.X!=0) + { + int xdiff = positionDiff.X/5; + if(xdiff == 0) + xdiff = 1*isign(positionDiff.X); + addCommentBox->Position.X += xdiff; + } + if(positionDiff.Y!=0) + { + int ydiff = positionDiff.Y/5; + if(ydiff == 0) + ydiff = 1*isign(positionDiff.Y); + addCommentBox->Position.Y += ydiff; + } + + if(sizeDiff.X!=0) + { + int xdiff = sizeDiff.X/5; + if(xdiff == 0) + xdiff = 1*isign(sizeDiff.X); + addCommentBox->Size.X += xdiff; + } + if(sizeDiff.Y!=0) + { + int ydiff = sizeDiff.Y/5; + if(ydiff == 0) + ydiff = 1*isign(sizeDiff.Y); + addCommentBox->Size.Y += ydiff; + } + } + c->Update(); } @@ -389,6 +431,11 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender) } if(sender->GetCommentBoxEnabled()) { + commentBoxPositionX = (XRES/2)+4; + commentBoxPositionY = Size.Y-19; + commentBoxSizeX = Size.X-(XRES/2)-48; + commentBoxSizeY = 17; + addCommentBox = new ui::Textbox(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 17), "", "Add Comment"); addCommentBox->SetActionCallback(new AutoCommentSizeAction(this)); addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index f817a1a..7b85ea5 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -49,6 +49,10 @@ class PreviewView: public ui::Window { float commentsVel; int commentBoxHeight; + float commentBoxPositionX; + float commentBoxPositionY; + float commentBoxSizeX; + float commentBoxSizeY; void displayComments(int yOffset); void commentBoxAutoHeight(); -- cgit v0.9.2-21-gd62e From a8e4221f38edefb5b342f470407b1f100d0248a3 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 18 Jul 2012 13:07:33 +0100 Subject: Working comment submission diff --git a/src/client/Client.cpp b/src/client/Client.cpp index d851e55..5ecb8ac 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -685,6 +685,67 @@ failure: return RequestFailure; } +RequestStatus Client::AddComment(int saveID, std::string comment) +{ + lastError = ""; + std::vector * tags = NULL; + std::stringstream urlStream; + char * data = NULL; + int dataStatus, dataLength; + urlStream << "http://" << SERVER << "/Browse/Comments.json?ID=" << saveID << "&Key=" << authUser.SessionKey; + if(authUser.ID) + { + std::stringstream userIDStream; + userIDStream << authUser.ID; + + char * postNames[] = { "Comment", NULL }; + char * postDatas[] = { (char*)(comment.c_str()) }; + int postLengths[] = { comment.length() }; + data = http_multipart_post((char *)urlStream.str().c_str(), postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength); + } + else + { + lastError = "Not authenticated"; + return RequestFailure; + } + if(dataStatus == 200 && data) + { + try + { + std::istringstream dataStream(data); + json::Object objDocument; + json::Reader::Read(objDocument, dataStream); + + int status = ((json::Number)objDocument["Status"]).Value(); + + if(status!=1) + { + lastError = ((json::Number)objDocument["Error"]).Value(); + } + + if(status!=1) + goto failure; + } + catch (json::Exception &e) + { + lastError = "Could not read response"; + goto failure; + } + } + else + { + lastError = http_ret_text(dataStatus); + goto failure; + } + if(data) + free(data); + return RequestOkay; +failure: + if(data) + free(data); + return RequestFailure; +} + RequestStatus Client::FavouriteSave(int saveID, bool favourite) { lastError = ""; diff --git a/src/client/Client.h b/src/client/Client.h index adaa449..a2d8720 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -92,6 +92,8 @@ public: int GetStampsCount(); SaveFile * GetFirstStamp(); + RequestStatus AddComment(int saveID, std::string comment); + unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength); LoginStatus Login(string username, string password, User & user); void ClearThumbnailRequests(); diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 3180cb7..7d939fd 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -27,6 +27,11 @@ Textbox::~Textbox() delete actionCallback; } +void Textbox::SetPlaceholder(std::string text) +{ + placeHolder = text; +} + void Textbox::SetText(std::string newText) { backingText = newText; diff --git a/src/interface/Textbox.h b/src/interface/Textbox.h index 700974a..e8e9d22 100644 --- a/src/interface/Textbox.h +++ b/src/interface/Textbox.h @@ -34,6 +34,8 @@ public: virtual void SetText(std::string text); virtual std::string GetText(); + virtual void SetPlaceholder(std::string text); + void SetBorder(bool border) { this->border = border; }; void SetHidden(bool hidden) { masked = hidden; } bool GetHidden() { return masked; } diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp index d5e1a93..a922bc6 100644 --- a/src/preview/PreviewController.cpp +++ b/src/preview/PreviewController.cpp @@ -60,6 +60,26 @@ void PreviewController::Update() } } +void PreviewController::SubmitComment(std::string comment) +{ + if(comment.length() < 4) + { + new ErrorMessage("Error", "Comment is too short"); + } + else + { + RequestStatus status = Client::Ref().AddComment(saveId, comment); + if(status != RequestOkay) + { + new ErrorMessage("Error Submitting comment", Client::Ref().GetLastError()); + } + else + { + previewModel->UpdateComments(1); + } + } +} + void PreviewController::ShowLogin() { loginWindow = new LoginController(); diff --git a/src/preview/PreviewController.h b/src/preview/PreviewController.h index 81c457b..e6b8caa 100644 --- a/src/preview/PreviewController.h +++ b/src/preview/PreviewController.h @@ -38,6 +38,7 @@ public: PreviewView * GetView() { return previewView; } void Update(); void FavouriteSave(); + void SubmitComment(std::string comment); void NextCommentPage(); void PrevCommentPage(); diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index d7c44b3..79d2cdd 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -28,6 +28,17 @@ public: } }; +class PreviewView::SubmitCommentAction: public ui::ButtonAction +{ + PreviewView * v; +public: + SubmitCommentAction(PreviewView * v_){ v = v_; } + virtual void ActionCallback(ui::Button * sender) + { + v->submitComment(); + } +}; + class PreviewView::AutoCommentSizeAction: public ui::TextboxAction { PreviewView * v; @@ -361,6 +372,23 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender) } } +void PreviewView::submitComment() +{ + if(addCommentBox) + { + std::string comment = std::string(addCommentBox->GetText()); + submitCommentButton->Enabled = false; + addCommentBox->SetText(""); + addCommentBox->SetPlaceholder("Submitting comment"); + FocusComponent(NULL); + + c->SubmitComment(comment); + + addCommentBox->SetPlaceholder("Add comment"); + submitCommentButton->Enabled = true; + } +} + void PreviewView::displayComments(int yOffset) { for(int i = 0; i < commentComponents.size(); i++) @@ -441,6 +469,7 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender) 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->SetActionCallback(new SubmitCommentAction(this)); //submitCommentButton->Enabled = false; AddComponent(submitCommentButton); } diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index 7b85ea5..2e94b85 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -21,6 +21,7 @@ class PreviewModel; class PreviewController; class PreviewView: public ui::Window { + class SubmitCommentAction; class LoginAction; class AutoCommentSizeAction; PreviewController * c; @@ -56,6 +57,7 @@ class PreviewView: public ui::Window { void displayComments(int yOffset); void commentBoxAutoHeight(); + void submitComment(); public: void AttachController(PreviewController * controller) { c = controller;} PreviewView(); -- cgit v0.9.2-21-gd62e From 80044bb0f06b4186bcc2f07e1c5ddc4e195f2426 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 18 Jul 2012 17:22:35 +0100 Subject: Renderer Presets and default graphics function diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 260d99a..0740554 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -402,6 +402,14 @@ void GameController::Exit() HasDone = true; } +void GameController::LoadRenderPreset(RenderPreset preset) +{ + Renderer * renderer = gameModel->GetRenderer(); + renderer->SetRenderMode(preset.RenderModes); + renderer->SetDisplayMode(preset.DisplayModes); + renderer->SetColourMode(preset.ColourMode); +} + void GameController::Update() { ui::Point pos = gameView->GetMousePosition(); diff --git a/src/game/GameController.h b/src/game/GameController.h index 4e2b43a..2388c5d 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -17,6 +17,7 @@ #include "cat/LuaScriptInterface.h" #include "options/OptionsController.h" #include "client/ClientListener.h" +#include "RenderPreset.h" #include "Menu.h" using namespace std; @@ -63,6 +64,7 @@ public: void Tick(); void Exit(); + void LoadRenderPreset(RenderPreset preset); void SetZoomEnabled(bool zoomEnable); void SetZoomPosition(ui::Point position); void AdjustBrushSize(int direction, bool logarithmic = false); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 8adb9e1..62fd6a9 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -255,6 +255,59 @@ GameView::GameView(): tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2); tempButton->SetActionCallback(new ElementSearchAction(this)); AddComponent(tempButton); + + //Render mode presets. Possibly load from config in future? + renderModePresets = new RenderPreset[10]; + + renderModePresets[0].Name = "Alternative Velocity Display"; + renderModePresets[0].RenderModes.push_back(RENDER_EFFE); + renderModePresets[0].RenderModes.push_back(RENDER_BASC); + renderModePresets[0].DisplayModes.push_back(DISPLAY_AIRC); + + renderModePresets[1].Name = "Velocity Display"; + renderModePresets[1].RenderModes.push_back(RENDER_EFFE); + renderModePresets[1].RenderModes.push_back(RENDER_BASC); + renderModePresets[1].DisplayModes.push_back(DISPLAY_AIRV); + + renderModePresets[2].Name = "Pressure Display"; + renderModePresets[2].RenderModes.push_back(RENDER_EFFE); + renderModePresets[2].RenderModes.push_back(RENDER_BASC); + renderModePresets[2].DisplayModes.push_back(DISPLAY_AIRP); + + renderModePresets[3].Name = "Persistent Display"; + renderModePresets[3].RenderModes.push_back(RENDER_EFFE); + renderModePresets[3].RenderModes.push_back(RENDER_BASC); + renderModePresets[3].DisplayModes.push_back(DISPLAY_PERS); + + renderModePresets[4].Name = "Fire Display"; + renderModePresets[4].RenderModes.push_back(RENDER_FIRE); + renderModePresets[4].RenderModes.push_back(RENDER_EFFE); + renderModePresets[4].RenderModes.push_back(RENDER_BASC); + + renderModePresets[5].Name = "Blob Display"; + renderModePresets[5].RenderModes.push_back(RENDER_FIRE); + renderModePresets[5].RenderModes.push_back(RENDER_EFFE); + renderModePresets[5].RenderModes.push_back(RENDER_BLOB); + + renderModePresets[6].Name = "Heat Display"; + renderModePresets[6].RenderModes.push_back(RENDER_BASC); + renderModePresets[6].DisplayModes.push_back(DISPLAY_AIRH); + renderModePresets[6].ColourMode = COLOUR_HEAT; + + renderModePresets[7].Name = "Fancy Display"; + renderModePresets[7].RenderModes.push_back(RENDER_FIRE); + renderModePresets[7].RenderModes.push_back(RENDER_GLOW); + renderModePresets[7].RenderModes.push_back(RENDER_BLUR); + renderModePresets[7].RenderModes.push_back(RENDER_EFFE); + renderModePresets[7].RenderModes.push_back(RENDER_BASC); + renderModePresets[7].DisplayModes.push_back(DISPLAY_WARP); + + renderModePresets[8].Name = "Nothing Display"; + renderModePresets[8].RenderModes.push_back(RENDER_BASC); + + renderModePresets[9].Name = "Heat Gradient Display"; + renderModePresets[9].RenderModes.push_back(RENDER_BASC); + renderModePresets[9].ColourMode = COLOUR_GRAD; } class GameView::MenuAction: public ui::ButtonAction @@ -819,6 +872,11 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool c->AdjustBrushSize(-1, true); break; } + + if(key >= '0' && key <= '9') + { + c->LoadRenderPreset(renderModePresets[key-'0']); + } } void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) diff --git a/src/game/GameView.h b/src/game/GameView.h index 4576b13..324f716 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -12,6 +12,7 @@ #include "interface/Button.h" #include "interface/Slider.h" #include "ToolButton.h" +#include "RenderPreset.h" #include "Brush.h" using namespace std; @@ -76,6 +77,8 @@ private: ui::Point mousePosition; + RenderPreset * renderModePresets; + Thumbnail * placeSaveThumb; Particle sample; diff --git a/src/game/RenderPreset.h b/src/game/RenderPreset.h new file mode 100644 index 0000000..9cc9f4c --- /dev/null +++ b/src/game/RenderPreset.h @@ -0,0 +1,19 @@ +#ifndef RENDER_PRESET_H +#define RENDER_PRESET_H +class RenderPreset +{ +public: + std::string Name; + std::vector RenderModes; + std::vector DisplayModes; + unsigned int ColourMode; + + RenderPreset(): Name(""), ColourMode(0) {} + RenderPreset(std::string name, std::vector renderModes, std::vector displayModes, unsigned int colourMode): + Name(name), + RenderModes(renderModes), + DisplayModes(displayModes), + ColourMode(colourMode) + {} +}; +#endif \ No newline at end of file diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index ef3b8aa..5bf8eef 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -617,6 +617,8 @@ void Renderer::render_gravlensing() void Renderer::render_fire() { #ifndef OGLR + if(!(render_mode & FIREMODE)) + return; int i,j,x,y,r,g,b,nx,ny; for (j=0; j Date: Wed, 18 Jul 2012 18:33:44 +0100 Subject: Info tip for changing display modes diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 0740554..72c38c0 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -405,6 +405,7 @@ void GameController::Exit() void GameController::LoadRenderPreset(RenderPreset preset) { Renderer * renderer = gameModel->GetRenderer(); + gameModel->SetInfoTip(preset.Name); renderer->SetRenderMode(preset.RenderModes); renderer->SetDisplayMode(preset.DisplayModes); renderer->SetColourMode(preset.ColourMode); diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 668b755..bec2c98 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -517,6 +517,28 @@ void GameModel::RemoveNotification(Notification * notification) notifyNotificationsChanged(); } +void GameModel::SetToolTip(std::string text) +{ + toolTip = text; + notifyToolTipChanged(); +} + +void GameModel::SetInfoTip(std::string text) +{ + infoTip = text; + notifyInfoTipChanged(); +} + +std::string GameModel::GetToolTip() +{ + return toolTip; +} + +std::string GameModel::GetInfoTip() +{ + return infoTip; +} + void GameModel::notifyNotificationsChanged() { for(std::vector::iterator iter = observers.begin(); iter != observers.end(); ++iter) @@ -644,3 +666,19 @@ void GameModel::notifyLogChanged(string entry) observers[i]->NotifyLogChanged(this, entry); } } + +void GameModel::notifyInfoTipChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyInfoTipChanged(this); + } +} + +void GameModel::notifyToolTipChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyToolTipChanged(this); + } +} \ No newline at end of file diff --git a/src/game/GameModel.h b/src/game/GameModel.h index 5f656c1..28b86e6 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -53,6 +53,9 @@ private: User currentUser; bool colourSelector; ui::Colour colour; + + std::string infoTip; + std::string toolTip; //bool zoomEnabled; void notifyRendererChanged(); void notifySimulationChanged(); @@ -71,6 +74,8 @@ private: void notifyColourSelectorVisibilityChanged(); void notifyNotificationsChanged(); void notifyLogChanged(string entry); + void notifyInfoTipChanged(); + void notifyToolTipChanged(); public: GameModel(); ~GameModel(); @@ -81,6 +86,11 @@ public: void SetColourSelectorColour(ui::Colour colour); ui::Colour GetColourSelectorColour(); + void SetToolTip(std::string text); + void SetInfoTip(std::string text); + std::string GetToolTip(); + std::string GetInfoTip(); + void SetVote(int direction); SaveInfo * GetSave(); Brush * GetBrush(); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 62fd6a9..8fee0ed 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -33,7 +33,10 @@ GameView::GameView(): placeSaveThumb(NULL), mousePosition(0, 0), lastOffset(0), - drawSnap(false) + drawSnap(false), + toolTip(""), + infoTip(""), + infoTipPresence(0) { int currentX = 1; @@ -520,6 +523,17 @@ void GameView::NotifyPausedChanged(GameModel * sender) pauseButton->SetToggleState(sender->GetPaused()); } +void GameView::NotifyToolTipChanged(GameModel * sender) +{ + toolTip = sender->GetToolTip(); +} + +void GameView::NotifyInfoTipChanged(GameModel * sender) +{ + infoTip = sender->GetInfoTip(); + infoTipPresence = 120; +} + void GameView::NotifySaveChanged(GameModel * sender) { if(sender->GetSave()) @@ -922,6 +936,12 @@ void GameView::OnTick(float dt) { c->DrawFill(toolIndex, currentMouse); } + if(infoTipPresence>0) + { + infoTipPresence -= int(dt)>0?int(dt):1; + if(infoTipPresence<0) + infoTipPresence = 0; + } c->Update(); if(lastLogEntry > -0.1f) lastLogEntry -= 0.16*dt; @@ -1227,6 +1247,12 @@ void GameView::OnDraw() sampleInfo << ", Ctype: " << c->ElementResolve(sample.ctype); g->drawtext(XRES+BARSIZE-(10+Graphics::textwidth((char*)sampleInfo.str().c_str())), 10, (const char*)sampleInfo.str().c_str(), 255, 255, 255, 255); + + if(infoTipPresence) + { + int infoTipAlpha = (infoTipPresence>50?50:infoTipPresence)*5; + g->drawtext((XRES-Graphics::textwidth((char*)infoTip.c_str()))/2, (YRES/2)-2, (char*)infoTip.c_str(), 255, 255, 255, infoTipAlpha); + } } ui::Point GameView::lineSnapCoords(ui::Point point1, ui::Point point2) diff --git a/src/game/GameView.h b/src/game/GameView.h index 324f716..59861bf 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -38,6 +38,11 @@ private: bool zoomCursorFixed; bool drawSnap; int toolIndex; + + int infoTipPresence; + std::string toolTip; + std::string infoTip; + queue pointQueue; GameController * c; Renderer * ren; @@ -111,6 +116,9 @@ public: void NotifyPlaceSaveChanged(GameModel * sender); void NotifyNotificationsChanged(GameModel * sender); void NotifyLogChanged(GameModel * sender, string entry); + void NotifyToolTipChanged(GameModel * sender); + void NotifyInfoTipChanged(GameModel * sender); + virtual void OnMouseMove(int x, int y, int dx, int dy); virtual void OnMouseDown(int x, int y, unsigned button); virtual void OnMouseUp(int x, int y, unsigned button); -- cgit v0.9.2-21-gd62e From dd0e6e7f4ddc5a1a9c25111275187b767d51bdb4 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 18 Jul 2012 20:34:58 +0100 Subject: Add descriptions to toolbuttons, add Tooltips to Button, ToolTip event for Windows diff --git a/src/game/DecorationTool.h b/src/game/DecorationTool.h index c45eca3..be79e6b 100644 --- a/src/game/DecorationTool.h +++ b/src/game/DecorationTool.h @@ -16,8 +16,8 @@ public: unsigned char Blue; unsigned char Alpha; - DecorationTool(ToolType decoMode_, string name, int r, int g, int b): - Tool(0, name, r, g, b), + DecorationTool(ToolType decoMode_, string name, string description, int r, int g, int b): + Tool(0, name, description, r, g, b), decoMode(decoMode_), Red(0), Green(0), diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index bec2c98..d9c2d72 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -61,7 +61,7 @@ GameModel::GameModel(): { if(sim->elements[i].MenuSection < 12 && sim->elements[i].Enabled && sim->elements[i].MenuVisible) { - Tool * tempTool = new ElementTool(i, sim->elements[i].Name, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour)); + Tool * tempTool = new ElementTool(i, sim->elements[i].Name, sim->elements[i].Description, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour)); menuList[sim->elements[i].MenuSection]->AddTool(tempTool); } } @@ -69,14 +69,14 @@ GameModel::GameModel(): //Build menu for GOL types for(int i = 0; i < NGOL; i++) { - Tool * tempTool = new GolTool(i, sim->gmenu[i].name, PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour)); + Tool * tempTool = new GolTool(i, sim->gmenu[i].name, std::string(sim->gmenu[i].description), PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour)); menuList[SC_LIFE]->AddTool(tempTool); } //Build other menus from wall data for(int i = 0; i < UI_WALLCOUNT; i++) { - Tool * tempTool = new WallTool(i, "", PIXR(sim->wtypes[i].colour), PIXG(sim->wtypes[i].colour), PIXB(sim->wtypes[i].colour)); + Tool * tempTool = new WallTool(i, "", std::string(sim->wtypes[i].descs), PIXR(sim->wtypes[i].colour), PIXG(sim->wtypes[i].colour), PIXB(sim->wtypes[i].colour)); menuList[SC_WALL]->AddTool(tempTool); //sim->wtypes[i] } @@ -88,17 +88,17 @@ GameModel::GameModel(): //Build menu for simtools for(int i = 0; i < sim->tools.size(); i++) { - Tool * tempTool = new Tool(i, sim->tools[i]->Name, PIXR(sim->tools[i]->Colour), PIXG(sim->tools[i]->Colour), PIXB(sim->tools[i]->Colour)); + Tool * tempTool = new Tool(i, sim->tools[i]->Name, sim->tools[i]->Description, PIXR(sim->tools[i]->Colour), PIXG(sim->tools[i]->Colour), PIXB(sim->tools[i]->Colour)); menuList[SC_TOOL]->AddTool(tempTool); } //Add decoration tools to menu - menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendAdd, "ADD", 0, 0, 0)); - menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendRemove, "SUB", 0, 0, 0)); - menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendMultiply, "MUL", 0, 0, 0)); - menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendDivide, "DIV", 0, 0, 0)); - menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendSmudge, "SMDG", 0, 0, 0)); - menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendSet, "SET", 0, 0, 0)); + menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendAdd, "ADD", "Colour blending: Add", 0, 0, 0)); + menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendRemove, "SUB", "Colour blending: Subtract", 0, 0, 0)); + menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendMultiply, "MUL", "Colour blending: Multiply", 0, 0, 0)); + menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendDivide, "DIV", "Colour blending: Divide" , 0, 0, 0)); + menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendSmudge, "SMDG", "Smudge colour", 0, 0, 0)); + menuList[SC_DECO]->AddTool(new DecorationTool(DecorationTool::BlendSet, "SET", "Set colour (No blending)", 0, 0, 0)); //Set default brush palette brushList.push_back(new EllipseBrush(ui::Point(4, 4))); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 8fee0ed..763312d 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -36,7 +36,8 @@ GameView::GameView(): drawSnap(false), toolTip(""), infoTip(""), - infoTipPresence(0) + infoTipPresence(0), + toolTipPosition(-1, -1) { int currentX = 1; @@ -435,7 +436,7 @@ void GameView::NotifyToolListChanged(GameModel * sender) for(int i = 0; i < toolList.size(); i++) { //ToolButton * tempButton = new ToolButton(ui::Point(XRES+1, currentY), ui::Point(28, 15), toolList[i]->GetName()); - ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), toolList[i]->GetName()); + ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), toolList[i]->GetName(), toolList[i]->GetDescription()); //currentY -= 17; currentX -= 31; tempButton->SetActionCallback(new ToolAction(this, toolList[i])); @@ -742,6 +743,12 @@ void GameView::OnMouseUp(int x, int y, unsigned button) } } +void GameView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip) +{ + this->toolTip = toolTip; + toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), Size.Y-MENUSIZE-10); +} + void GameView::OnMouseWheel(int x, int y, int d) { if(!d) @@ -1253,6 +1260,11 @@ void GameView::OnDraw() int infoTipAlpha = (infoTipPresence>50?50:infoTipPresence)*5; g->drawtext((XRES-Graphics::textwidth((char*)infoTip.c_str()))/2, (YRES/2)-2, (char*)infoTip.c_str(), 255, 255, 255, infoTipAlpha); } + + if(toolTipPosition.X!=-1 && toolTipPosition.Y!=-1 && toolTip.length()) + { + g->drawtext(toolTipPosition.X, toolTipPosition.Y, (char*)toolTip.c_str(), 255, 255, 255, 255); + } } ui::Point GameView::lineSnapCoords(ui::Point point1, ui::Point point2) diff --git a/src/game/GameView.h b/src/game/GameView.h index 59861bf..4a841c1 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -41,8 +41,9 @@ private: int infoTipPresence; std::string toolTip; + ui::Point toolTipPosition; std::string infoTip; - + queue pointQueue; GameController * c; Renderer * ren; @@ -119,6 +120,8 @@ public: void NotifyToolTipChanged(GameModel * sender); void NotifyInfoTipChanged(GameModel * sender); + virtual void ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip); + virtual void OnMouseMove(int x, int y, int dx, int dy); virtual void OnMouseDown(int x, int y, unsigned button); virtual void OnMouseUp(int x, int y, unsigned button); diff --git a/src/game/Tool.cpp b/src/game/Tool.cpp index 2467d3f..22d21ea 100644 --- a/src/game/Tool.cpp +++ b/src/game/Tool.cpp @@ -12,15 +12,17 @@ using namespace std; -Tool::Tool(int id, string name, int r, int g, int b): +Tool::Tool(int id, string name, string description, int r, int g, int b): toolID(id), toolName(name), + toolDescription(description), colRed(r), colGreen(g), colBlue(b) { } string Tool::GetName() { return toolName; } +string Tool::GetDescription() { return toolDescription; } Tool::~Tool() {} void Tool::Click(Simulation * sim, Brush * brush, ui::Point position) { } void Tool::Draw(Simulation * sim, Brush * brush, ui::Point position) { @@ -34,8 +36,8 @@ void Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Po } void Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {}; -ElementTool::ElementTool(int id, string name, int r, int g, int b): - Tool(id, name, r, g, b) +ElementTool::ElementTool(int id, string name, string description, int r, int g, int b): + Tool(id, name, description, r, g, b) { } ElementTool::~ElementTool() {} @@ -53,8 +55,8 @@ void ElementTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) } -WallTool::WallTool(int id, string name, int r, int g, int b): -Tool(id, name, r, g, b) +WallTool::WallTool(int id, string name, string description, int r, int g, int b): +Tool(id, name, description, r, g, b) { } WallTool::~WallTool() {} @@ -72,8 +74,8 @@ void WallTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { } -GolTool::GolTool(int id, string name, int r, int g, int b): - Tool(id, name, r, g, b) +GolTool::GolTool(int id, string name, string description, int r, int g, int b): + Tool(id, name, description, r, g, b) { } GolTool::~GolTool() {} diff --git a/src/game/Tool.h b/src/game/Tool.h index 819620d..4172772 100644 --- a/src/game/Tool.h +++ b/src/game/Tool.h @@ -22,9 +22,11 @@ class Tool protected: int toolID; string toolName; + string toolDescription; public: - Tool(int id, string name, int r, int g, int b); + Tool(int id, string name, string description, int r, int g, int b); string GetName(); + string GetDescription(); virtual ~Tool(); virtual void Click(Simulation * sim, Brush * brush, ui::Point position); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); @@ -38,7 +40,7 @@ class SignTool: public Tool { public: SignTool(): - Tool(0, "SIGN", 0, 0, 0) + Tool(0, "SIGN", "Sign. Click a sign to edit or anywhere else to create a new one", 0, 0, 0) { } virtual ~SignTool() {} @@ -53,7 +55,7 @@ class PropertyTool: public Tool { public: PropertyTool(): - Tool(0, "PROP", 0, 0, 0) + Tool(0, "PROP", "Property Edit. Click to alter the properties of elements in the field", 0, 0, 0) { } virtual ~PropertyTool() {} @@ -67,7 +69,7 @@ public: class ElementTool: public Tool { public: - ElementTool(int id, string name, int r, int g, int b); + ElementTool(int id, string name, string description, int r, int g, int b); virtual ~ElementTool(); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); @@ -78,7 +80,7 @@ public: class WallTool: public Tool { public: - WallTool(int id, string name, int r, int g, int b); + WallTool(int id, string name, string description, int r, int g, int b); virtual ~WallTool(); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); @@ -89,7 +91,7 @@ public: class GolTool: public Tool { public: - GolTool(int id, string name, int r, int g, int b); + GolTool(int id, string name, string description, int r, int g, int b); virtual ~GolTool(); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); diff --git a/src/game/ToolButton.cpp b/src/game/ToolButton.cpp index f1c5583..5c9f2d4 100644 --- a/src/game/ToolButton.cpp +++ b/src/game/ToolButton.cpp @@ -8,8 +8,8 @@ #include "ToolButton.h" #include "interface/Keys.h" -ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_): - ui::Button(position, size, text_) +ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolTip): + ui::Button(position, size, text_, toolTip) { SetSelectionState(-1); Appearance.BorderActive = ui::Colour(255, 0, 0); diff --git a/src/game/ToolButton.h b/src/game/ToolButton.h index 94042a9..db0cfac 100644 --- a/src/game/ToolButton.h +++ b/src/game/ToolButton.h @@ -13,7 +13,7 @@ class ToolButton: public ui::Button { int currentSelection; public: - ToolButton(ui::Point position, ui::Point size, std::string text_); + ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolTip = ""); virtual void OnMouseUp(int x, int y, unsigned int button); virtual void OnMouseClick(int x, int y, unsigned int button); virtual void Draw(const ui::Point& screenPos); diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp index ac1f87e..b70d41e 100644 --- a/src/interface/Button.cpp +++ b/src/interface/Button.cpp @@ -13,7 +13,7 @@ namespace ui { -Button::Button(Point position, Point size, std::string buttonText): +Button::Button(Point position, Point size, std::string buttonText, std::string toolTip): Component(position, size), ButtonText(buttonText), isMouseInside(false), @@ -21,7 +21,8 @@ Button::Button(Point position, Point size, std::string buttonText): isTogglable(false), toggle(false), actionCallback(NULL), - Enabled(true) + Enabled(true), + toolTip(toolTip) { TextPosition(); } @@ -141,6 +142,10 @@ void Button::OnMouseEnter(int x, int y) return; if(actionCallback) actionCallback->MouseEnterCallback(this); + if(toolTip.length()>0 && GetParentWindow()) + { + GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip); + } } diff --git a/src/interface/Button.h b/src/interface/Button.h index 19f7fe7..2358d49 100644 --- a/src/interface/Button.h +++ b/src/interface/Button.h @@ -27,7 +27,7 @@ public: class Button : public Component { public: - Button(Point position = Point(0, 0), Point size = Point(0, 0), std::string buttonText = ""); + Button(Point position = Point(0, 0), Point size = Point(0, 0), std::string buttonText = "", std::string toolTip = ""); virtual ~Button(); bool Toggleable; @@ -55,6 +55,7 @@ public: void SetIcon(Icon icon); protected: + std::string toolTip; std::string buttonDisplayText; std::string ButtonText; diff --git a/src/interface/Window.h b/src/interface/Window.h index c077abb..c2c5e16 100644 --- a/src/interface/Window.h +++ b/src/interface/Window.h @@ -46,6 +46,8 @@ enum ChromeStyle // Remove a component from state. NOTE: This WILL free component from memory. void RemoveComponent(unsigned idx); + virtual void ToolTip(Component * sender, ui::Point mousePosition, std::string toolTip) {} + virtual void DoInitialized(); virtual void DoExit(); virtual void DoTick(float dt); -- cgit v0.9.2-21-gd62e From 2b4ec998948e022be89330a4f04880ab11fbcb94 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 19 Jul 2012 16:37:56 +0100 Subject: Use two functions for renderer drawing instead of several, fix alignment with Zoom Window border diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 763312d..08fcfe6 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -1133,13 +1133,7 @@ void GameView::OnDraw() if(ren) { ren->clearScreen(1.0f); - ren->draw_air(); - ren->render_parts(); - ren->render_fire(); - ren->draw_grav(); - ren->DrawWalls(); - ren->DrawSigns(); - ren->FinaliseParts(); + ren->RenderBegin(); if(activeBrush && currentMouse.X > 0 && currentMouse.X < XRES && currentMouse.Y > 0 && currentMouse.Y < YRES) { ui::Point finalCurrentMouse = c->PointTranslate(currentMouse); @@ -1169,7 +1163,7 @@ void GameView::OnDraw() activeBrush->RenderPoint(g, finalCurrentMouse); } } - ren->RenderZoom(); + ren->RenderEnd(); if(selectMode!=SelectNone) { diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 5bf8eef..30f1bfd 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -35,6 +35,29 @@ extern "C" #define drawrect(args) g->drawrect(args) #endif +void Renderer::RenderBegin() +{ + + draw_air(); + render_parts(); + render_fire(); + draw_grav(); + DrawWalls(); + DrawSigns(); +#ifndef OGLR + RenderZoom(); + FinaliseParts(); +#endif +} + +void Renderer::RenderEnd() +{ +#ifdef OGLR + RenderZoom(); + FinaliseParts(); +#endif +} + void Renderer::clearScreen(float alpha) { #ifdef OGLR @@ -245,7 +268,7 @@ void Renderer::FinaliseParts() } glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable( GL_TEXTURE_2D ); -#else +#elif defined(OGLI) g->draw_image(vid, 0, 0, VIDXRES, VIDYRES, 255); #endif } @@ -254,7 +277,7 @@ void Renderer::RenderZoom() { if(!zoomEnabled) return; - #ifdef OGLR + #if defined(OGLR) int sdl_scale = 1; int origBlendSrc, origBlendDst; float zcx1, zcx0, zcy1, zcy0, yfactor, xfactor, i; //X-Factor is shit, btw @@ -344,8 +367,8 @@ void Renderer::RenderZoom() int x, y, i, j; pixel pix; pixel * img = vid; - drawrect(zoomWindowPosition.X-2, zoomWindowPosition.Y-2, zoomScopeSize*ZFACTOR+2, zoomScopeSize*ZFACTOR+2, 192, 192, 192, 255); - drawrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR, 0, 0, 0, 255); + drawrect(zoomWindowPosition.X-2, zoomWindowPosition.Y-2, zoomScopeSize*ZFACTOR+4, zoomScopeSize*ZFACTOR+4, 192, 192, 192, 255); + drawrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR+2, zoomScopeSize*ZFACTOR+2, 0, 0, 0, 255); clearrect(zoomWindowPosition.X, zoomWindowPosition.Y, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR); for (j=0; jclearScreen(1.0f); - ren->draw_air(); - ren->render_parts(); - ren->render_fire(); - ren->draw_grav(); - ren->DrawWalls(); - ren->DrawSigns(); - ren->FinaliseParts(); + ren->RenderBegin(); + ren->RenderEnd(); } g->draw_line(0, YRES, XRES-1, YRES, 255, 255, 255, XRES+BARSIZE); g->draw_line(180, YRES, 180, YRES+MENUSIZE, 200, 200, 200, XRES+BARSIZE); diff --git a/src/simulation/SaveRenderer.cpp b/src/simulation/SaveRenderer.cpp index 73b486e..f3b419f 100644 --- a/src/simulation/SaveRenderer.cpp +++ b/src/simulation/SaveRenderer.cpp @@ -55,9 +55,12 @@ Thumbnail * SaveRenderer::Render(GameSave * save) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); + ren->clearScreen(1.0f); - ren->render_parts(); - ren->FinaliseParts(); + ren->ClearAccumulation(); + ren->RenderBegin(); + ren->RenderEnd(); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glTranslated(0, -MENUSIZE, 0); @@ -90,8 +93,10 @@ Thumbnail * SaveRenderer::Render(GameSave * save) pixel * pData = NULL; pixel * dst; pixel * src = g->vid; - ren->render_parts(); - ren->FinaliseParts(); + + ren->ClearAccumulation(); + ren->RenderBegin(); + ren->RenderEnd(); pData = (pixel *)malloc(PIXELSIZE * ((width*CELL)*(height*CELL))); dst = pData; -- cgit v0.9.2-21-gd62e From c2873180e224b93632daf01e40c6e6d0636bf86d Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 19 Jul 2012 17:05:01 +0100 Subject: GOL loads gol colours for use diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 08fcfe6..4f9c41a 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -365,7 +365,7 @@ void GameView::NotifyMenuListChanged(GameModel * sender) std::string tempString = ""; Menu * item = *iter; tempString += item->GetIcon(); - ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, currentY), ui::Point(15, 15), tempString); + ui::Button * tempButton = new ui::Button(ui::Point(XRES+BARSIZE-16, currentY), ui::Point(15, 15), tempString, item->GetDescription()); tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2); tempButton->SetTogglable(true); tempButton->SetActionCallback(new MenuAction(this, item)); diff --git a/src/simulation/elements/LIFE.cpp b/src/simulation/elements/LIFE.cpp index 84cec67..4207931 100644 --- a/src/simulation/elements/LIFE.cpp +++ b/src/simulation/elements/LIFE.cpp @@ -1,4 +1,8 @@ #include "simulation/Elements.h" + +bool Element_GOL_colourInit = false; +pixel Element_GOL_colour[NGOL]; + //#TPT-Directive ElementClass Element_LIFE PT_LIFE 78 Element_LIFE::Element_LIFE() { @@ -44,8 +48,23 @@ Element_LIFE::Element_LIFE() Update = NULL; Graphics = &Element_LIFE::graphics; + + if(!Element_GOL_colourInit) + { + Element_GOL_colourInit = true; + + + int golMenuCount; + gol_menu * golMenuT = LoadGOLMenu(golMenuCount); + for(int i = 0; i < golMenuCount && i < NGOL; i++) + { + Element_GOL_colour[i] = golMenuT[i].colour; + } + free(golMenuT); + } } + //#TPT-Directive ElementHeader Element_LIFE static int graphics(GRAPHICS_FUNC_ARGS) int Element_LIFE::graphics(GRAPHICS_FUNC_ARGS) @@ -94,7 +113,7 @@ int Element_LIFE::graphics(GRAPHICS_FUNC_ARGS) else pc = PIXRGB(255, 255, 0); } else { - pc = PIXRGB(255, 255, 0);//sim->gmenu[cpart->ctype].colour; + pc = Element_GOL_colour[cpart->ctype]; } *colr = PIXR(pc); *colg = PIXG(pc); -- cgit v0.9.2-21-gd62e From 4d961117bde4398ae4d72f2db96eef381371e2df Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 19 Jul 2012 17:49:40 +0100 Subject: Special ligh placement diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index d9c2d72..e4ee15b 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -61,7 +61,15 @@ GameModel::GameModel(): { if(sim->elements[i].MenuSection < 12 && sim->elements[i].Enabled && sim->elements[i].MenuVisible) { - Tool * tempTool = new ElementTool(i, sim->elements[i].Name, sim->elements[i].Description, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour)); + Tool * tempTool; + if(i == PT_LIGH) + { + tempTool = new Element_LIGH_Tool(i, sim->elements[i].Name, sim->elements[i].Description, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour)); + } + else + { + tempTool = new ElementTool(i, sim->elements[i].Name, sim->elements[i].Description, PIXR(sim->elements[i].Colour), PIXG(sim->elements[i].Colour), PIXB(sim->elements[i].Colour)); + } menuList[sim->elements[i].MenuSection]->AddTool(tempTool); } } @@ -88,7 +96,8 @@ GameModel::GameModel(): //Build menu for simtools for(int i = 0; i < sim->tools.size(); i++) { - Tool * tempTool = new Tool(i, sim->tools[i]->Name, sim->tools[i]->Description, PIXR(sim->tools[i]->Colour), PIXG(sim->tools[i]->Colour), PIXB(sim->tools[i]->Colour)); + Tool * tempTool; + tempTool = new Tool(i, sim->tools[i]->Name, sim->tools[i]->Description, PIXR(sim->tools[i]->Colour), PIXG(sim->tools[i]->Colour), PIXB(sim->tools[i]->Colour)); menuList[SC_TOOL]->AddTool(tempTool); } diff --git a/src/game/Tool.cpp b/src/game/Tool.cpp index 22d21ea..efe4831 100644 --- a/src/game/Tool.cpp +++ b/src/game/Tool.cpp @@ -92,5 +92,14 @@ void GolTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { sim->FloodParts(position.X, position.Y, PT_LIFE|(toolID<<8), -1, -1, 0); } - - +void Element_LIGH_Tool::Draw(Simulation * sim, Brush * brush, ui::Point position) +{ + int p = sim->create_part(-2, position.X, position.Y, toolID); + if (p != -1) + { + sim->parts[p].life = brush->GetRadius().X+brush->GetRadius().Y; + if (sim->parts[p].life > 55) + sim->parts[p].life = 55; + sim->parts[p].temp = sim->parts[p].life*150; // temperature of the lighting shows the power of the lighting + } +} \ No newline at end of file diff --git a/src/game/Tool.h b/src/game/Tool.h index 4172772..2cc33be 100644 --- a/src/game/Tool.h +++ b/src/game/Tool.h @@ -66,6 +66,21 @@ public: virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { } }; +class Element_LIGH_Tool: public Tool +{ +public: + Element_LIGH_Tool(int id, string name, string description, int r, int g, int b): + Tool(id, name, description, r, g, b) + { + } + virtual ~Element_LIGH_Tool() {} + virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); + virtual void Click(Simulation * sim, Brush * brush, ui::Point position) { } + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } + virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } + virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { } +}; + class ElementTool: public Tool { public: -- cgit v0.9.2-21-gd62e