Fast quit option (disable to make "X" act like in tpt)

This commit is contained in:
jacob1 2012-10-03 18:55:19 -04:00 committed by Simon Robertshaw
parent 71db872e64
commit 97cea273e5
9 changed files with 62 additions and 4 deletions

View File

@ -309,7 +309,8 @@ void EngineProcess()
switch (event.type)
{
case SDL_QUIT:
engine->Exit();
if (engine->GetFastQuit() || engine->CloseWindow())
engine->Exit();
break;
case SDL_KEYDOWN:
engine->onKeyPress(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KEY_MOD_LSHIFT, event.key.keysym.mod&KEY_MOD_LCONTROL, event.key.keysym.mod&KEY_MOD_LALT);
@ -491,6 +492,7 @@ int main(int argc, char * argv[])
engine = &ui::Engine::Ref();
engine->SetMaxSize(desktopWidth, desktopHeight);
engine->Begin(XRES+BARSIZE, YRES+MENUSIZE);
engine->SetFastQuit(Client::Ref().GetPrefBool("FastQuit", true));
GameController * gameController = new GameController();
engine->ShowWindow(gameController->GetView());

View File

@ -30,6 +30,7 @@ Engine::Engine():
FrameIndex(0),
Fullscreen(false),
Scale(1),
FastQuit(1),
break_(false),
lastTick(0)
{
@ -109,7 +110,7 @@ void Engine::ShowWindow(Window * window)
}
void Engine::CloseWindow()
int Engine::CloseWindow()
{
if(!windows.empty())
{
@ -139,10 +140,12 @@ void Engine::CloseWindow()
mousexp_ = mousex_;
mouseyp_ = mousey_;
}
return 0;
}
else
{
state_ = NULL;
return 1;
}
}

View File

@ -22,7 +22,7 @@ namespace ui
~Engine();
void ShowWindow(Window * window);
void CloseWindow();
int CloseWindow();
void onMouseMove(int x, int y);
void onMouseClick(int x, int y, unsigned button);
@ -46,6 +46,8 @@ namespace ui
inline bool GetFullscreen() { return Fullscreen; }
void SetScale(int scale) { Scale = scale; }
inline int GetScale() { return Scale; }
void SetFastQuit(bool fastquit) { FastQuit = fastquit; }
inline bool GetFastQuit() {return FastQuit; }
void Tick();
void Draw();
@ -88,6 +90,7 @@ namespace ui
bool running_;
bool break_;
bool FastQuit;
int lastTick;
int mouseb_;

View File

@ -78,6 +78,11 @@ void OptionsController::SetScale(bool scale)
}
void OptionsController::SetFastQuit(bool fastquit)
{
model->SetFastQuit(fastquit);
}
OptionsView * OptionsController::GetView()
{
return view;

View File

@ -33,6 +33,7 @@ public:
void SetEdgeMode(int airMode);
void SetFullscreen(bool fullscreen);
void SetScale(bool scale);
void SetFastQuit(bool fastquit);
void Exit();
OptionsView * GetView();
virtual ~OptionsController();

View File

@ -120,6 +120,17 @@ void OptionsModel::SetFullscreen(bool fullscreen)
notifySettingsChanged();
}
bool OptionsModel::GetFastQuit()
{
return ui::Engine::Ref().GetFastQuit();
}
void OptionsModel::SetFastQuit(bool fastquit)
{
ui::Engine::Ref().SetFastQuit(fastquit);
Client::Ref().SetPref("FastQuit", bool(fastquit));
notifySettingsChanged();
}
void OptionsModel::notifySettingsChanged()
{
for(int i = 0; i < observers.size(); i++)

View File

@ -38,6 +38,8 @@ public:
void SetGravityMode(int gravityMode);
bool GetFullscreen();
void SetFullscreen(bool fullscreen);
bool GetFastQuit();
void SetFastQuit(bool fastquit);
bool GetScale();
void SetScale(bool scale);
virtual ~OptionsModel();

View File

@ -12,7 +12,7 @@
#include "interface/DropDown.h"
OptionsView::OptionsView():
ui::Window(ui::Point(-1, -1), ui::Point(300, 270)){
ui::Window(ui::Point(-1, -1), ui::Point(300, 290)){
ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options");
tempLabel->SetTextColour(style::Colour::InformationTitle);
@ -146,8 +146,12 @@ OptionsView::OptionsView():
scale = new ui::Checkbox(ui::Point(8, 210), ui::Point(Size.X-6, 16), "Large screen", "");
scale->SetActionCallback(new ScaleAction(this));
tempLabel = new ui::Label(ui::Point(scale->Position.X+Graphics::textwidth(scale->GetText().c_str())+20, scale->Position.Y), ui::Point(Size.X-28, 16), "\bg- Double window size for smaller screen");
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(tempLabel);
AddComponent(scale);
class FullscreenAction: public ui::CheckboxAction
{
OptionsView * v;
@ -158,8 +162,27 @@ OptionsView::OptionsView():
fullscreen = new ui::Checkbox(ui::Point(8, 230), ui::Point(Size.X-6, 16), "Fullscreen", "");
fullscreen->SetActionCallback(new FullscreenAction(this));
tempLabel = new ui::Label(ui::Point(fullscreen->Position.X+Graphics::textwidth(fullscreen->GetText().c_str())+20, fullscreen->Position.Y), ui::Point(Size.X-28, 16), "\bg- Use the entire screen");
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(tempLabel);
AddComponent(fullscreen);
class FastQuitAction: public ui::CheckboxAction
{
OptionsView * v;
public:
FastQuitAction(OptionsView * v_){ v = v_; }
virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetFastQuit(sender->GetChecked()); }
};
fastquit = new ui::Checkbox(ui::Point(8, 250), ui::Point(Size.X-6, 16), "Fast Quit", "");
fastquit->SetActionCallback(new FastQuitAction(this));
tempLabel = new ui::Label(ui::Point(fastquit->Position.X+Graphics::textwidth(fastquit->GetText().c_str())+20, fastquit->Position.Y), ui::Point(Size.X-28, 16), "\bg- Always exit completely when hitting close");
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(tempLabel);
AddComponent(fastquit);
class CloseAction: public ui::ButtonAction
{
public:
@ -189,6 +212,7 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
edgeMode->SetOption(sender->GetEdgeMode());
scale->SetChecked(sender->GetScale());
fullscreen->SetChecked(sender->GetFullscreen());
fastquit->SetChecked(sender->GetFastQuit());
}
void OptionsView::AttachController(OptionsController * c_)
@ -204,6 +228,11 @@ void OptionsView::OnDraw()
g->draw_line(Position.X+1, Position.Y+scale->Position.Y-4, Position.X+Size.X-1, Position.Y+scale->Position.Y-4, 255, 255, 255, 180);
}
void OptionsView::OnTryExit(ExitMethod method)
{
c->Exit();
}
OptionsView::~OptionsView() {
// TODO Auto-generated destructor stub

View File

@ -27,11 +27,13 @@ class OptionsView: public ui::Window {
ui::DropDown * edgeMode;
ui::Checkbox * scale;
ui::Checkbox * fullscreen;
ui::Checkbox * fastquit;
public:
OptionsView();
void NotifySettingsChanged(OptionsModel * sender);
void AttachController(OptionsController * c_);
void OnDraw();
void OnTryExit(ExitMethod method);
virtual ~OptionsView();
};