mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-13 11:54:04 +02:00
Merge branch 'master' of github.com:FacialTurd/PowderToypp
This commit is contained in:
@@ -6,24 +6,30 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ConfirmPrompt.h"
|
#include "ConfirmPrompt.h"
|
||||||
#include "interface/Label.h"
|
#include "interface/Textblock.h"
|
||||||
#include "interface/Button.h"
|
#include "interface/Button.h"
|
||||||
|
|
||||||
ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDialogueCallback * callback_):
|
ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDialogueCallback * callback_):
|
||||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 75)),
|
ui::Window(ui::Point(-1, -1), ui::Point(200, 50)),
|
||||||
callback(callback_)
|
callback(callback_)
|
||||||
{
|
{
|
||||||
ui::Label * titleLabel = new ui::Label(ui::Point(2, 1), ui::Point(Size.X-4, 16), title);
|
int width, height;
|
||||||
|
ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 15), title);
|
||||||
titleLabel->SetTextColour(ui::Colour(220, 220, 50));
|
titleLabel->SetTextColour(ui::Colour(220, 220, 50));
|
||||||
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
AddComponent(titleLabel);
|
AddComponent(titleLabel);
|
||||||
|
|
||||||
ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), message);
|
|
||||||
|
ui::Textblock * messageLabel = new ui::Textblock(ui::Point(4, 25), ui::Point(Size.X-8, 60), message);
|
||||||
|
Graphics::textsize(messageLabel->GetDisplayText().c_str(), width, height);
|
||||||
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||||
AddComponent(messageLabel);
|
AddComponent(messageLabel);
|
||||||
|
|
||||||
|
Size.Y += height;
|
||||||
|
Position.Y = (ui::Engine::Ref().GetHeight()-Size.Y)/2;
|
||||||
|
|
||||||
class CloseAction: public ui::ButtonAction
|
class CloseAction: public ui::ButtonAction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -34,21 +40,21 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial
|
|||||||
{
|
{
|
||||||
ui::Engine::Ref().CloseWindow();
|
ui::Engine::Ref().CloseWindow();
|
||||||
prompt->callback->ConfirmCallback(result);
|
prompt->callback->ConfirmCallback(result);
|
||||||
prompt->SelfDestruct(); //TODO: Fix component disposal
|
prompt->SelfDestruct();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X-50, 16), "Cancel");
|
ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X-50, 16), "Cancel");
|
||||||
cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
|
cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
|
||||||
cancelButton->SetActionCallback(new CloseAction(this, ResultCancel));
|
cancelButton->SetActionCallback(new CloseAction(this, ResultCancel));
|
||||||
AddComponent(cancelButton);
|
AddComponent(cancelButton);
|
||||||
|
|
||||||
ui::Button * okayButton = new ui::Button(ui::Point(Size.X-50, Size.Y-16), ui::Point(50, 16), "Continue");
|
ui::Button * okayButton = new ui::Button(ui::Point(Size.X-76, Size.Y-16), ui::Point(76, 16), "Continue");
|
||||||
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
okayButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
okayButton->Appearance.TextInactive = ui::Colour(220, 220, 50);
|
okayButton->Appearance.TextInactive = ui::Colour(220, 220, 50);
|
||||||
okayButton->SetActionCallback(new CloseAction(this, ResultOkay));
|
okayButton->SetActionCallback(new CloseAction(this, ResultOkay));
|
||||||
AddComponent(okayButton);
|
AddComponent(okayButton);
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include "login/LoginController.h"
|
#include "login/LoginController.h"
|
||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
#include "dialogues/ErrorMessage.h"
|
#include "dialogues/ErrorMessage.h"
|
||||||
|
#include "dialogues/ConfirmPrompt.h"
|
||||||
#include "GameModelException.h"
|
#include "GameModelException.h"
|
||||||
#include "simulation/Air.h"
|
#include "simulation/Air.h"
|
||||||
#include "Notification.h"
|
#include "Notification.h"
|
||||||
@@ -121,7 +122,8 @@ GameController::GameController():
|
|||||||
ssave(NULL),
|
ssave(NULL),
|
||||||
console(NULL),
|
console(NULL),
|
||||||
tagsWindow(NULL),
|
tagsWindow(NULL),
|
||||||
options(NULL)
|
options(NULL),
|
||||||
|
HasDone(false)
|
||||||
{
|
{
|
||||||
gameView = new GameView();
|
gameView = new GameView();
|
||||||
gameModel = new GameModel();
|
gameModel = new GameModel();
|
||||||
@@ -391,6 +393,13 @@ void GameController::Tick()
|
|||||||
commandInterface->OnTick();
|
commandInterface->OnTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::Exit()
|
||||||
|
{
|
||||||
|
if(ui::Engine::Ref().GetWindow() == gameView)
|
||||||
|
ui::Engine::Ref().CloseWindow();
|
||||||
|
HasDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::Update()
|
void GameController::Update()
|
||||||
{
|
{
|
||||||
ui::Point pos = gameView->GetMousePosition();
|
ui::Point pos = gameView->GetMousePosition();
|
||||||
@@ -629,6 +638,19 @@ std::string GameController::ElementResolve(int type)
|
|||||||
|
|
||||||
void GameController::NotifyUpdateAvailable(Client * sender)
|
void GameController::NotifyUpdateAvailable(Client * sender)
|
||||||
{
|
{
|
||||||
|
class UpdateConfirmation: public ConfirmDialogueCallback {
|
||||||
|
public:
|
||||||
|
GameController * c;
|
||||||
|
UpdateConfirmation(GameController * c_) { c = c_; }
|
||||||
|
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
|
||||||
|
if (result == ConfirmPrompt::ResultOkay)
|
||||||
|
{
|
||||||
|
c->RunUpdater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
virtual ~UpdateConfirmation() { }
|
||||||
|
};
|
||||||
|
|
||||||
class UpdateNotification : public Notification
|
class UpdateNotification : public Notification
|
||||||
{
|
{
|
||||||
GameController * c;
|
GameController * c;
|
||||||
@@ -638,7 +660,7 @@ void GameController::NotifyUpdateAvailable(Client * sender)
|
|||||||
|
|
||||||
virtual void Action()
|
virtual void Action()
|
||||||
{
|
{
|
||||||
c->RemoveNotification(this);
|
new ConfirmPrompt("Run Updater", "Are you sure you want to run the updater, please save any changes before updating", new UpdateConfirmation(c));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -650,3 +672,8 @@ void GameController::RemoveNotification(Notification * notification)
|
|||||||
gameModel->RemoveNotification(notification);
|
gameModel->RemoveNotification(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::RunUpdater()
|
||||||
|
{
|
||||||
|
Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -42,6 +42,7 @@ private:
|
|||||||
OptionsController * options;
|
OptionsController * options;
|
||||||
CommandInterface * commandInterface;
|
CommandInterface * commandInterface;
|
||||||
public:
|
public:
|
||||||
|
bool HasDone;
|
||||||
class LoginCallback;
|
class LoginCallback;
|
||||||
class SearchCallback;
|
class SearchCallback;
|
||||||
class RenderCallback;
|
class RenderCallback;
|
||||||
@@ -60,6 +61,7 @@ public:
|
|||||||
bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
bool KeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
bool KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
bool KeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
void Tick();
|
void Tick();
|
||||||
|
void Exit();
|
||||||
|
|
||||||
void SetZoomEnabled(bool zoomEnable);
|
void SetZoomEnabled(bool zoomEnable);
|
||||||
void SetZoomPosition(ui::Point position);
|
void SetZoomPosition(ui::Point position);
|
||||||
@@ -107,6 +109,7 @@ public:
|
|||||||
void RemoveNotification(Notification * notification);
|
void RemoveNotification(Notification * notification);
|
||||||
|
|
||||||
virtual void NotifyUpdateAvailable(Client * sender);
|
virtual void NotifyUpdateAvailable(Client * sender);
|
||||||
|
void RunUpdater();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GAMECONTROLLER_H
|
#endif // GAMECONTROLLER_H
|
||||||
|
@@ -25,6 +25,7 @@ public:
|
|||||||
Textblock(Point position, Point size, std::string textboxText);
|
Textblock(Point position, Point size, std::string textboxText);
|
||||||
virtual void TextPosition() {}
|
virtual void TextPosition() {}
|
||||||
virtual void SetText(std::string text);
|
virtual void SetText(std::string text);
|
||||||
|
virtual std::string GetDisplayText() { return textLines; }
|
||||||
virtual void Draw(const Point& screenPos);
|
virtual void Draw(const Point& screenPos);
|
||||||
virtual ~Textblock();
|
virtual ~Textblock();
|
||||||
};
|
};
|
||||||
|
@@ -17,6 +17,8 @@ void Task::SetTaskListener(TaskListener * listener)
|
|||||||
|
|
||||||
void Task::Start()
|
void Task::Start()
|
||||||
{
|
{
|
||||||
|
pthread_mutex_init (&taskMutex, NULL);
|
||||||
|
pthread_cond_init(&taskCond, NULL);
|
||||||
pthread_create(&doWorkThread, 0, &Task::doWork_helper, this);
|
pthread_create(&doWorkThread, 0, &Task::doWork_helper, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +37,42 @@ bool Task::GetDone()
|
|||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Task::Poll()
|
||||||
|
{
|
||||||
|
int newProgress;
|
||||||
|
bool newDone;
|
||||||
|
std::string newStatus;
|
||||||
|
pthread_mutex_lock(&taskMutex);
|
||||||
|
newProgress = thProgress;
|
||||||
|
newDone = thDone;
|
||||||
|
newStatus = std::string(thStatus);
|
||||||
|
pthread_cond_signal(&taskCond);
|
||||||
|
pthread_mutex_unlock(&taskMutex);
|
||||||
|
|
||||||
|
if(newProgress!=progress) {
|
||||||
|
progress = newProgress;
|
||||||
|
if(listener)
|
||||||
|
listener->NotifyProgress(this);
|
||||||
|
}
|
||||||
|
if(newStatus!=status) {
|
||||||
|
status = newStatus;
|
||||||
|
if(listener)
|
||||||
|
listener->NotifyStatus(this);
|
||||||
|
}
|
||||||
|
if(newDone!=done)
|
||||||
|
{
|
||||||
|
done = newDone;
|
||||||
|
if(listener)
|
||||||
|
listener->NotifyDone(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(done)
|
||||||
|
{
|
||||||
|
pthread_join(doWorkThread, NULL);
|
||||||
|
pthread_mutex_destroy(&taskMutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Task::~Task()
|
Task::~Task()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -59,26 +97,24 @@ void * Task::doWork_helper(void * ref)
|
|||||||
|
|
||||||
void Task::notifyProgress(int progress)
|
void Task::notifyProgress(int progress)
|
||||||
{
|
{
|
||||||
if(this->progress!=progress) {
|
pthread_mutex_lock(&taskMutex);
|
||||||
this->progress = progress;
|
pthread_cond_wait(&taskCond, &taskMutex);
|
||||||
if(listener)
|
thProgress = progress;
|
||||||
listener->NotifyProgress(this);
|
pthread_mutex_unlock(&taskMutex);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Task::notifyStatus(std::string status)
|
void Task::notifyStatus(std::string status)
|
||||||
{
|
{
|
||||||
if(this->status!=status) {
|
pthread_mutex_lock(&taskMutex);
|
||||||
this->status = status;
|
pthread_cond_wait(&taskCond, &taskMutex);
|
||||||
if(listener)
|
thStatus = status;
|
||||||
listener->NotifyStatus(this);
|
pthread_mutex_unlock(&taskMutex);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Task::notifyDone()
|
void Task::notifyDone()
|
||||||
{
|
{
|
||||||
if(listener)
|
pthread_mutex_lock(&taskMutex);
|
||||||
{
|
pthread_cond_wait(&taskCond, &taskMutex);
|
||||||
done = true; listener->NotifyDone(this);
|
thDone = true;
|
||||||
}
|
pthread_mutex_unlock(&taskMutex);
|
||||||
}
|
}
|
||||||
|
@@ -20,16 +20,26 @@ public:
|
|||||||
int GetProgress();
|
int GetProgress();
|
||||||
bool GetDone();
|
bool GetDone();
|
||||||
std::string GetStatus();
|
std::string GetStatus();
|
||||||
|
void Poll();
|
||||||
Task() {}
|
Task() {}
|
||||||
virtual ~Task();
|
virtual ~Task();
|
||||||
protected:
|
protected:
|
||||||
int progress;
|
int progress;
|
||||||
bool done;
|
bool done;
|
||||||
std::string status;
|
std::string status;
|
||||||
|
|
||||||
|
int thProgress;
|
||||||
|
bool thDone;
|
||||||
|
std::string thStatus;
|
||||||
|
|
||||||
TaskListener * listener;
|
TaskListener * listener;
|
||||||
pthread_t doWorkThread;
|
pthread_t doWorkThread;
|
||||||
|
pthread_mutex_t taskMutex;
|
||||||
|
pthread_cond_t taskCond;
|
||||||
|
|
||||||
virtual void doWork();
|
virtual void doWork();
|
||||||
static void * doWork_helper(void * ref);
|
static void * doWork_helper(void * ref);
|
||||||
|
|
||||||
void notifyProgress(int progress);
|
void notifyProgress(int progress);
|
||||||
void notifyStatus(std::string status);
|
void notifyStatus(std::string status);
|
||||||
void notifyDone();
|
void notifyDone();
|
||||||
|
@@ -48,6 +48,11 @@ void TaskWindow::NotifyProgress(Task * task)
|
|||||||
progress = task->GetProgress();
|
progress = task->GetProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TaskWindow::OnTick(float dt)
|
||||||
|
{
|
||||||
|
task->Poll();
|
||||||
|
}
|
||||||
|
|
||||||
void TaskWindow::OnDraw()
|
void TaskWindow::OnDraw()
|
||||||
{
|
{
|
||||||
Graphics * g = ui::Engine::Ref().g;
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
@@ -25,6 +25,7 @@ public:
|
|||||||
virtual void NotifyStatus(Task * task);
|
virtual void NotifyStatus(Task * task);
|
||||||
virtual void NotifyDone(Task * task);
|
virtual void NotifyDone(Task * task);
|
||||||
virtual void NotifyProgress(Task * task);
|
virtual void NotifyProgress(Task * task);
|
||||||
|
virtual void OnTick(float dt);
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
virtual ~TaskWindow();
|
virtual ~TaskWindow();
|
||||||
};
|
};
|
||||||
|
28
src/update/UpdateActivity.cpp
Normal file
28
src/update/UpdateActivity.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* UpdateActivity.cpp
|
||||||
|
*
|
||||||
|
* Created on: Jun 20, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "UpdateActivity.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
|
class UpdateDownloadTask : public Task
|
||||||
|
{
|
||||||
|
UpdateDownloadTask() {};
|
||||||
|
/*virtual void doWork()
|
||||||
|
{
|
||||||
|
while(1)
|
||||||
|
}*/
|
||||||
|
};
|
||||||
|
|
||||||
|
UpdateActivity::UpdateActivity() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateActivity::~UpdateActivity() {
|
||||||
|
// TODO Auto-generated destructor stub
|
||||||
|
}
|
||||||
|
|
22
src/update/UpdateActivity.h
Normal file
22
src/update/UpdateActivity.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* UpdateActivity.h
|
||||||
|
*
|
||||||
|
* Created on: Jun 20, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UPDATEACTIVITY_H_
|
||||||
|
#define UPDATEACTIVITY_H_
|
||||||
|
|
||||||
|
#include "interface/Window.h"
|
||||||
|
#include "tasks/TaskWindow.h"
|
||||||
|
|
||||||
|
class UpdateActivity {
|
||||||
|
Task * updateDownloadTask;
|
||||||
|
TaskWindow * updateWindow;
|
||||||
|
public:
|
||||||
|
UpdateActivity();
|
||||||
|
virtual ~UpdateActivity();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* UPDATEACTIVITY_H_ */
|
Reference in New Issue
Block a user