Better exiting from windows (Escape and Enter) and 'q' for exit, fixes #35 and #60

This commit is contained in:
Simon Robertshaw 2012-08-04 16:39:24 +01:00
parent 0558322709
commit f2f4278932
15 changed files with 62 additions and 12 deletions

View File

@ -35,6 +35,7 @@ void ConsoleView::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, b
{
switch(key)
{
case KEY_ESCAPE:
case '`':
c->CloseConsole();
break;

View File

@ -52,6 +52,7 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial
cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
cancelButton->SetActionCallback(new CloseAction(this, ResultCancel));
AddComponent(cancelButton);
SetCancelButton(cancelButton);
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;
@ -59,6 +60,7 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial
okayButton->Appearance.TextInactive = style::Colour::WarningTitle;
okayButton->SetActionCallback(new CloseAction(this, ResultOkay));
AddComponent(okayButton);
SetOkayButton(okayButton);
ui::Engine::Ref().ShowWindow(this);
}

View File

@ -42,6 +42,9 @@ ErrorMessage::ErrorMessage(std::string title, std::string message):
okayButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
okayButton->SetActionCallback(new DismissAction(this));
AddComponent(okayButton);
SetOkayButton(okayButton);
SetCancelButton(okayButton);
ui::Engine::Ref().ShowWindow(this);
}

View File

@ -60,6 +60,7 @@ TextPrompt::TextPrompt(std::string title, std::string message, bool multiline, T
cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
cancelButton->SetActionCallback(new CloseAction(this, ResultCancel));
AddComponent(cancelButton);
SetCancelButton(cancelButton);
ui::Button * okayButton = new ui::Button(ui::Point(Size.X/2, Size.Y-16), ui::Point(Size.X/2, 16), "Okay");
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
@ -67,6 +68,7 @@ TextPrompt::TextPrompt(std::string title, std::string message, bool multiline, T
okayButton->Appearance.TextInactive = style::Colour::WarningTitle;
okayButton->SetActionCallback(new CloseAction(this, ResultOkay));
AddComponent(okayButton);
SetOkayButton(okayButton);
ui::Engine::Ref().ShowWindow(this);
}

View File

@ -12,6 +12,7 @@
#include "interface/Slider.h"
#include "search/Thumbnail.h"
#include "simulation/SaveRenderer.h"
#include "dialogues/ConfirmPrompt.h"
#include "Format.h"
#include "QuickOption.h"
@ -888,6 +889,22 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
}
}
void GameView::ExitPrompt()
{
class ExitConfirmation: public ConfirmDialogueCallback {
public:
ExitConfirmation() {}
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
if (result == ConfirmPrompt::ResultOkay)
{
ui::Engine::Ref().Exit();
}
}
virtual ~ExitConfirmation() { }
};
new ConfirmPrompt("You are about to quit", "Are you sure you want to exit the game?", new ExitConfirmation());
}
void GameView::ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip)
{
this->toolTip = toolTip;
@ -1024,6 +1041,10 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
case 'y':
c->SwitchAir();
break;
case KEY_ESCAPE:
case 'q':
ExitPrompt();
break;
case 'u':
c->ToggleAHeat();
break;

View File

@ -142,6 +142,8 @@ public:
void NotifyInfoTipChanged(GameModel * sender);
void NotifyQuickOptionsChanged(GameModel * sender);
void ExitPrompt();
virtual void ToolTip(ui::Component * sender, ui::Point mousePosition, std::string toolTip);
virtual void OnMouseMove(int x, int y, int dx, int dy);

View File

@ -84,7 +84,7 @@ void Window::RemoveComponent(Component* c)
void Window::OnTryExit(ExitMethod method)
{
if(cancelButton)
if(cancelButton && method != MouseOutside)
cancelButton->DoAction();
}

View File

@ -48,11 +48,13 @@ LoginView::LoginView():
AddComponent(infoLabel);
AddComponent(loginButton);
SetOkayButton(loginButton);
loginButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
loginButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
loginButton->Appearance.TextInactive = style::Colour::ConfirmButton;
loginButton->SetActionCallback(new LoginAction(this));
AddComponent(cancelButton);
SetCancelButton(cancelButton);
cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
cancelButton->SetActionCallback(new CancelAction(this));
@ -78,11 +80,6 @@ void LoginView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, boo
else
FocusComponent(usernameField);
break;
case KEY_ENTER:
case KEY_RETURN:
if(IsFocused(passwordField))
loginButton->DoAction();
break;
}
}

View File

@ -133,6 +133,8 @@ OptionsView::OptionsView():
ui::Button * tempButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "OK");
tempButton->SetActionCallback(new CloseAction(this));
AddComponent(tempButton);
SetCancelButton(tempButton);
SetOkayButton(tempButton);
}
void OptionsView::NotifySettingsChanged(OptionsModel * sender)

View File

@ -75,6 +75,7 @@ PreviewView::PreviewView():
openButton->SetIcon(IconOpen);
openButton->SetActionCallback(new OpenAction(this));
AddComponent(openButton);
SetOkayButton(openButton);
class FavAction: public ui::ButtonAction
{
@ -291,9 +292,8 @@ void PreviewView::OnTick(float dt)
c->Update();
}
void PreviewView::OnMouseDown(int x, int y, unsigned button)
void PreviewView::OnTryExit(ExitMethod method)
{
if(!(x > Position.X && y > Position.Y && y < Position.Y+Size.Y && x < Position.X+Size.X)) //Clicked outside window
c->Exit();
}

View File

@ -68,7 +68,7 @@ public:
virtual void OnDraw();
virtual void DoDraw();
virtual void OnTick(float dt);
virtual void OnMouseDown(int x, int y, unsigned button);
virtual void OnTryExit(ExitMethod method);
virtual void OnMouseWheel(int x, int y, int d);
virtual ~PreviewView();
};

View File

@ -53,6 +53,7 @@ LocalSaveActivity::LocalSaveActivity(SaveFile save) :
cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
cancelButton->SetActionCallback(new CancelAction(this));
AddComponent(cancelButton);
SetCancelButton(cancelButton);
ui::Button * okayButton = new ui::Button(ui::Point(Size.X-76, Size.Y-16), ui::Point(76, 16), "Save");
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
@ -60,6 +61,7 @@ LocalSaveActivity::LocalSaveActivity(SaveFile save) :
okayButton->Appearance.TextInactive = style::Colour::InformationTitle;
okayButton->SetActionCallback(new SaveAction(this));
AddComponent(okayButton);
SetOkayButton(okayButton);
if(save.GetGameSave())
ThumbnailBroker::Ref().RenderThumbnail(save.GetGameSave(), Size.X-16, -1, this);

View File

@ -80,6 +80,7 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUp
cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
cancelButton->SetActionCallback(new CancelAction(this));
AddComponent(cancelButton);
SetCancelButton(cancelButton);
ui::Button * okayButton = new ui::Button(ui::Point((Size.X/2)-76, Size.Y-16), ui::Point(76, 16), "Save");
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
@ -87,6 +88,7 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUp
okayButton->Appearance.TextInactive = style::Colour::InformationTitle;
okayButton->SetActionCallback(new SaveAction(this));
AddComponent(okayButton);
SetOkayButton(okayButton);
if(save.GetGameSave())
ThumbnailBroker::Ref().RenderThumbnail(save.GetGameSave(), (Size.X/2)-16, -1, this);

View File

@ -20,8 +20,13 @@ public:
{
if(cc->activePreview->GetDoOpen() && cc->activePreview->GetSave())
{
cc->searchModel->SetLoadedSave(new SaveInfo(*(cc->activePreview->GetSave())));
cc->searchModel->SetLoadedSave(cc->activePreview->GetSave());
}
else
{
cc->searchModel->SetLoadedSave(NULL);
}
}
};
@ -161,6 +166,8 @@ void SearchController::Selected(int saveID, bool selected)
void SearchController::OpenSave(int saveID)
{
if(activePreview)
delete activePreview;
activePreview = new PreviewController(saveID, new OpenCallback(this));
ui::Engine::Ref().ShowWindow(activePreview->GetView());
}

View File

@ -57,7 +57,16 @@ void SearchModel::UpdateSaveList(int pageNumber, std::string query)
void SearchModel::SetLoadedSave(SaveInfo * save)
{
loadedSave = save;
if(loadedSave != save && loadedSave)
delete loadedSave;
if(save)
{
loadedSave = new SaveInfo(*save);
}
else
{
loadedSave = NULL;
}
}
SaveInfo * SearchModel::GetLoadedSave(){