summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-20 12:40:18 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-20 12:40:18 (GMT)
commit2be9c925088c16beb144dd9932202416d00ff581 (patch)
tree51f8ccbf2b0b051890c5f5d12fa28a67635c06c2 /src/game
parent9769239af69695e9a7f8cf103a197695ecf691e0 (diff)
downloadpowder-2be9c925088c16beb144dd9932202416d00ff581.zip
powder-2be9c925088c16beb144dd9932202416d00ff581.tar.gz
OpenGL canvas for Windows, Notifications for main Game, Update checker in Client (+ other client triggered events)
Diffstat (limited to 'src/game')
-rw-r--r--src/game/EllipseBrush.h2
-rw-r--r--src/game/GameController.cpp25
-rw-r--r--src/game/GameController.h8
-rw-r--r--src/game/GameModel.cpp33
-rw-r--r--src/game/GameModel.h7
-rw-r--r--src/game/GameView.cpp52
-rw-r--r--src/game/GameView.h2
-rw-r--r--src/game/Notification.h23
8 files changed, 150 insertions, 2 deletions
diff --git a/src/game/EllipseBrush.h b/src/game/EllipseBrush.h
index 8a1dc9a..a02516e 100644
--- a/src/game/EllipseBrush.h
+++ b/src/game/EllipseBrush.h
@@ -17,7 +17,7 @@ public:
EllipseBrush(ui::Point size_):
Brush(size_)
{
-
+ SetRadius(size_);
};
virtual void GenerateBitmap()
{
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 3031fb6..dfbd935 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -12,6 +12,7 @@
#include "dialogues/ErrorMessage.h"
#include "GameModelException.h"
#include "simulation/Air.h"
+#include "Notification.h"
using namespace std;
@@ -132,6 +133,7 @@ GameController::GameController():
//commandInterface->AttachGameModel(gameModel);
//sim = new Simulation();
+ Client::Ref().AddListener(this);
}
GameController::~GameController()
@@ -624,3 +626,26 @@ std::string GameController::ElementResolve(int type)
return "";
}
+void GameController::NotifyUpdateAvailable(Client * sender)
+{
+ class UpdateNotification : public Notification
+ {
+ GameController * c;
+ public:
+ UpdateNotification(GameController * c, std::string message) : c(c), Notification(message) {}
+ virtual ~UpdateNotification() {}
+
+ virtual void Action()
+ {
+ c->RemoveNotification(this);
+ }
+ };
+
+ gameModel->AddNotification(new UpdateNotification(this, "An Update is available"));
+}
+
+void GameController::RemoveNotification(Notification * notification)
+{
+ gameModel->RemoveNotification(notification);
+}
+
diff --git a/src/game/GameController.h b/src/game/GameController.h
index ecbe9b3..269cdf5 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -16,15 +16,17 @@
//#include "cat/TPTScriptInterface.h"
#include "cat/LuaScriptInterface.h"
#include "options/OptionsController.h"
+#include "client/ClientListener.h"
#include "Menu.h"
using namespace std;
+class Notification;
class GameModel;
class GameView;
class CommandInterface;
class ConsoleController;
-class GameController
+class GameController: public ClientListener
{
private:
//Simulation * sim;
@@ -101,6 +103,10 @@ public:
void LoadClipboard();
void LoadStamp();
+
+ void RemoveNotification(Notification * notification);
+
+ virtual void NotifyUpdateAvailable(Client * sender);
};
#endif // GAMECONTROLLER_H
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 5c9344d..054a415 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -513,6 +513,39 @@ deque<string> GameModel::GetLog()
return consoleLog;
}
+std::vector<Notification*> GameModel::GetNotifications()
+{
+ return notifications;
+}
+
+void GameModel::AddNotification(Notification * notification)
+{
+ notifications.push_back(notification);
+ notifyNotificationsChanged();
+}
+
+void GameModel::RemoveNotification(Notification * notification)
+{
+ for(std::vector<Notification*>::iterator iter = notifications.begin(); iter != notifications.end(); ++iter)
+ {
+ if(*iter == notification)
+ {
+ notifications.erase(iter);
+ delete *iter;
+ break;
+ }
+ }
+ notifyNotificationsChanged();
+}
+
+void GameModel::notifyNotificationsChanged()
+{
+ for(std::vector<GameView*>::iterator iter = observers.begin(); iter != observers.end(); ++iter)
+ {
+ (*iter)->NotifyNotificationsChanged(this);
+ }
+}
+
void GameModel::notifyColourSelectorColourChanged()
{
for(int i = 0; i < observers.size(); i++)
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index 9faf5fc..48364a7 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -10,6 +10,7 @@
#include "GameView.h"
#include "Brush.h"
#include "client/User.h"
+#include "Notification.h"
#include "Tool.h"
#include "Menu.h"
@@ -32,6 +33,7 @@ public:
class GameModel
{
private:
+ vector<Notification*> notifications;
//int clipboardSize;
//unsigned char * clipboardData;
GameSave * stamp;
@@ -67,6 +69,7 @@ private:
void notifyPlaceSaveChanged();
void notifyColourSelectorColourChanged();
void notifyColourSelectorVisibilityChanged();
+ void notifyNotificationsChanged();
void notifyLogChanged(string entry);
public:
GameModel();
@@ -120,6 +123,10 @@ public:
GameSave * GetClipboard();
GameSave * GetStamp();
GameSave * GetPlaceSave();
+
+ std::vector<Notification*> GetNotifications();
+ void AddNotification(Notification * notification);
+ void RemoveNotification(Notification * notification);
};
#endif // GAMEMODEL_H
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 8abcca6..4900603 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -846,6 +846,58 @@ void GameView::DoDraw()
c->Tick();
}
+void GameView::NotifyNotificationsChanged(GameModel * sender)
+{
+ class NotificationButtonAction : public ui::ButtonAction
+ {
+ GameView * v;
+ Notification * notification;
+ public:
+ NotificationButtonAction(GameView * v, Notification * notification) : v(v), notification(notification) { }
+ void ActionCallback(ui::Button * sender)
+ {
+ notification->Action();
+ //v->c->RemoveNotification(notification);
+ }
+ };
+ class CloseNotificationButtonAction : public ui::ButtonAction
+ {
+ GameView * v;
+ Notification * notification;
+ public:
+ CloseNotificationButtonAction(GameView * v, Notification * notification) : v(v), notification(notification) { }
+ void ActionCallback(ui::Button * sender)
+ {
+ v->c->RemoveNotification(notification);
+ }
+ };
+
+ for(std::vector<ui::Component*>::iterator iter = notificationComponents.begin(); iter != notificationComponents.end(); ++iter) {
+ RemoveComponent(*iter);
+ delete *iter;
+ }
+ notificationComponents.clear();
+
+ std::vector<Notification*> notifications = sender->GetNotifications();
+
+ int currentY = YRES-17;
+ for(std::vector<Notification*>::iterator iter = notifications.begin(); iter != notifications.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);
+ tempButton->SetActionCallback(new NotificationButtonAction(this, *iter));
+ AddComponent(tempButton);
+ notificationComponents.push_back(tempButton);
+
+ tempButton = new ui::Button(ui::Point(XRES-20, currentY), ui::Point(15, 15));
+ tempButton->SetIcon(IconDelete);
+ tempButton->SetActionCallback(new CloseNotificationButtonAction(this, *iter));
+ AddComponent(tempButton);
+ notificationComponents.push_back(tempButton);
+
+ currentY -= 17;
+ }
+}
void GameView::NotifyZoomChanged(GameModel * sender)
{
diff --git a/src/game/GameView.h b/src/game/GameView.h
index b7c6989..55b9dc3 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -43,6 +43,7 @@ private:
//UI Elements
vector<ui::Button*> menuButtons;
vector<ToolButton*> toolButtons;
+ vector<ui::Component*> notificationComponents;
deque<string> logEntries;
float lastLogEntry;
ui::Button * searchButton;
@@ -99,6 +100,7 @@ public:
void NotifyColourSelectorVisibilityChanged(GameModel * sender);
void NotifyColourSelectorColourChanged(GameModel * sender);
void NotifyPlaceSaveChanged(GameModel * sender);
+ void NotifyNotificationsChanged(GameModel * sender);
void NotifyLogChanged(GameModel * sender, string entry);
virtual void OnMouseMove(int x, int y, int dx, int dy);
virtual void OnMouseDown(int x, int y, unsigned button);
diff --git a/src/game/Notification.h b/src/game/Notification.h
new file mode 100644
index 0000000..4c64dea
--- /dev/null
+++ b/src/game/Notification.h
@@ -0,0 +1,23 @@
+/*
+ * Notification.h
+ *
+ * Created on: Jun 20, 2012
+ * Author: Simon
+ */
+
+#ifndef NOTIFICATION_H_
+#define NOTIFICATION_H_
+
+#include <string>
+
+class Notification
+{
+public:
+ Notification(std::string message) : Message(message) {}
+ virtual ~Notification() {};
+ std::string Message;
+
+ virtual void Action() { }
+};
+
+#endif /* NOTIFICATION_H_ */