[Scummvm-cvs-logs] SF.net SVN: scummvm:[41622] tools/branches/gsoc2009-gui/gui
Remere at users.sourceforge.net
Remere at users.sourceforge.net
Thu Jun 18 03:55:51 CEST 2009
Revision: 41622
http://scummvm.svn.sourceforge.net/scummvm/?rev=41622&view=rev
Author: Remere
Date: 2009-06-18 01:55:51 +0000 (Thu, 18 Jun 2009)
Log Message:
-----------
*Added multi-page system, including storing options between pages, updating buttons and other bells & whistles.
*Added a to 'choose what game to compress for' page.
Modified Paths:
--------------
tools/branches/gsoc2009-gui/gui/main.cpp
tools/branches/gsoc2009-gui/gui/main.h
Added Paths:
-----------
tools/branches/gsoc2009-gui/gui/configuration.h
Added: tools/branches/gsoc2009-gui/gui/configuration.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/configuration.h (rev 0)
+++ tools/branches/gsoc2009-gui/gui/configuration.h 2009-06-18 01:55:51 UTC (rev 41622)
@@ -0,0 +1,25 @@
+#ifndef CONFIGURATION_H
+#define CONFIGURATION_H
+
+struct Configuration {
+ Configuration();
+
+ // While prepending with _ would be in line with the coding conventions
+ // this class is just a glorified map with different types, so it seems
+ // unnecessary.
+
+ bool compressing;
+ wxString selectedGame;
+ wxString selectedTool;
+};
+
+inline Configuration::Configuration() {
+ // Default values for all the settings
+
+ compressing = false;
+
+ selectedGame = wxT("");
+ selectedTool = wxT("");
+}
+
+#endif
Property changes on: tools/branches/gsoc2009-gui/gui/configuration.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: tools/branches/gsoc2009-gui/gui/main.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/main.cpp 2009-06-18 01:13:42 UTC (rev 41621)
+++ tools/branches/gsoc2009-gui/gui/main.cpp 2009-06-18 01:55:51 UTC (rev 41622)
@@ -97,46 +97,97 @@
// We create the intro page once the window is setup
wxSizer *panesizer = new wxBoxSizer(wxVERTICAL);
- panesizer->Add(new IntroPage(_wizardpane, _buttons), wxSizerFlags(1).Expand());
+ WizardPage *introPage = new IntroPage(_wizardpane);
+ panesizer->Add(introPage, wxSizerFlags(1).Expand());
_wizardpane->SetSizerAndFit(panesizer);
main->SetSizer(sizer);
+
+ // And reset the buttons to a standard state
+ _buttons->setPage(introPage);
}
-void ScummToolsFrame::SwitchPage(WizardPage *nextPage) {
-
+void ScummToolsFrame::SwitchPage(WizardPage *next) {
+ // Find the old page
+ WizardPage *old = dynamic_cast<WizardPage*>(_wizardpane->FindWindow(wxT("Wizard Page")));
+
+ wxASSERT_MSG(old, wxT("Expected the child 'Wizard Page' to be an actual Wizard Page window."));
+
+ old->save(configuration);
+
+ // Destroy the old page
+ old->Destroy();
+
+ next->load(configuration);
+
+ // Add the new page!
+ next->Reparent(_wizardpane);
+ _wizardpane->GetSizer()->Add(next, wxSizerFlags(1).Expand());
+
+ // Make sure it fits
+ _wizardpane->Fit();
+
+ // And reset the buttons to a standard state
+ _buttons->reset();
+ _buttons->setPage(next);
}
+BEGIN_EVENT_TABLE(WizardButtons, wxPanel)
+ EVT_BUTTON(ID_NEXT, WizardButtons::onClickNext)
+ EVT_BUTTON(ID_PREV, WizardButtons::onClickPrevious)
+ EVT_BUTTON(ID_CANCEL, WizardButtons::onClickCancel)
+END_EVENT_TABLE()
+
WizardButtons::WizardButtons(wxWindow *parent, wxStaticText *linetext)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxT("Wizard Button Panel")),
- _linetext(linetext)
+ _linetext(linetext),
+ _currentPage(NULL)
{
wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
- _prev = new wxButton(this, wxID_ANY, wxT("< Back"));
+ _prev = new wxButton(this, ID_PREV, wxT("< Back"));
_prev->SetSize(80, -1);
sizer->Add(_prev, wxSizerFlags().Center().ReserveSpaceEvenIfHidden());
- _next = new wxButton(this, wxID_ANY, wxT("Next >"));
+ _next = new wxButton(this, ID_NEXT, wxT("Next >"));
_next->SetSize(80, -1);
sizer->Add(_next, wxSizerFlags().Center().ReserveSpaceEvenIfHidden());
sizer->AddSpacer(10);
- _cancel = new wxButton(this, wxID_ANY, wxT("Cancel"));
+ _cancel = new wxButton(this, ID_CANCEL, wxT("Cancel"));
_cancel->SetSize(80, -1);
sizer->Add(_cancel, wxSizerFlags().Center().ReserveSpaceEvenIfHidden());
SetSizerAndFit(sizer);
+
+ reset();
}
+void WizardButtons::reset() {
+ enableNext(true);
+ enablePrevious(true);
+ showFinish(false);
+}
+
+void WizardButtons::setPage(WizardPage *current) {
+ _currentPage = current;
+ // We call onUpdateButtons, which sets the _buttons member of WizardPage
+ // to this, and in turn calls updateButtons on itself and sets up the buttons
+ // We cannot set this up in the constructor of the WizardPage, since it's impossible
+ // to call reset *before* the page is created from SwicthPage
+ current->onUpdateButtons(this);
+}
+
void WizardButtons::enableNext(bool enable) {
_next->Enable(enable);
}
void WizardButtons::enablePrevious(bool enable) {
- _next->Enable(enable);
+ if(enable)
+ showPrevious(true);
+ _prev->Enable(enable);
}
void WizardButtons::showFinish(bool show) {
@@ -153,6 +204,23 @@
_prev->Hide();
}
+// wx event handlers
+void WizardButtons::onClickNext(wxCommandEvent &e) {
+ wxASSERT(_currentPage);
+ _currentPage->Hide();
+ _currentPage->onNext();
+}
+
+void WizardButtons::onClickPrevious(wxCommandEvent &e) {
+ wxASSERT(_currentPage);
+ _currentPage->onPrevious();
+}
+
+void WizardButtons::onClickCancel(wxCommandEvent &e) {
+ wxASSERT(_currentPage);
+ _currentPage->onCancel();
+}
+
BEGIN_EVENT_TABLE(Header, wxPanel)
EVT_PAINT(Header::onPaint)
END_EVENT_TABLE()
@@ -208,15 +276,18 @@
dc.DrawText(wxT("Extraction & Compression Wizard"), 290, 70);
}
-
-WizardPage::WizardPage(wxWindow *parent, WizardButtons *buttons)
+WizardPage::WizardPage(wxWindow *parent)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxT("Wizard Page")),
_nextPage(NULL),
_prevPage(NULL),
- _buttons(buttons)
+ _buttons(NULL)
{
}
+void WizardPage::updateButtons() {
+ // Do nothing
+}
+
void WizardPage::SetAlignedSizer(wxSizer *sizer) {
wxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);
topsizer->AddSpacer(100);
@@ -224,8 +295,51 @@
SetSizer(topsizer);
}
-IntroPage::IntroPage(wxWindow *parent, WizardButtons *buttons)
- : WizardPage(parent, buttons)
+void WizardPage::SwitchPage(WizardPage *next) {
+ wxWindow *grandparent = GetParent();
+ while(grandparent->GetParent() != NULL)
+ grandparent = grandparent->GetParent();
+
+ if(grandparent) {
+ ScummToolsFrame *frame = dynamic_cast<ScummToolsFrame*>(grandparent);
+ frame->SwitchPage(next);
+ // We are probably dead now, make sure to do nothing
+ // involving member variabls after this point
+ }
+}
+
+// Our default handler for cancel
+void WizardPage::onCancel() {
+ wxMessageDialog dlg(this, wxT("Are you sure you want to abort the wizard?"), wxT("Abort"), wxYES | wxNO);
+ wxWindowID ret = dlg.ShowModal();
+ if(ret == wxID_YES) {
+ wxWindow *grandparent = GetParent();
+ while(grandparent->GetParent() != NULL)
+ grandparent = grandparent->GetParent();
+
+ grandparent->Close(true);
+ } else {
+ // Do nothing
+ }
+}
+
+void WizardPage::onUpdateButtons(WizardButtons *buttons) {
+ // We have this functions to avoid having to this in every child handler
+ _buttons = buttons;
+ updateButtons();
+}
+
+// Load/Save settings
+void WizardPage::load(Configuration &configuration) {
+}
+
+void WizardPage::save(Configuration &configuration) {
+}
+
+// Introduction page
+
+IntroPage::IntroPage(wxWindow *parent)
+ : WizardPage(parent)
{
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
@@ -246,8 +360,115 @@
_options->SetSelection(0);
SetAlignedSizer(sizer);
+}
+void IntroPage::updateButtons() {
_buttons->showPrevious(false);
_buttons->enableNext(true);
}
+void IntroPage::load(Configuration &config) {
+ if(config.compressing)
+ _options->SetSelection(1);
+}
+
+void IntroPage::save(Configuration &config) {
+ config.compressing = _options->GetStringSelection().Lower().Find(wxT("extract")) == wxNOT_FOUND;
+}
+
+void IntroPage::onNext() {
+ if(_options->GetStringSelection().Lower().Find(wxT("extract")) != wxNOT_FOUND) {
+ // extract
+ } else {
+ // compress
+ SwitchPage(new CompressionPage(this->GetParent()));
+ }
+}
+
+// Page to choose compression tool
+
+CompressionPage::CompressionPage(wxWindow *parent)
+ : WizardPage(parent)
+{
+ wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+ sizer->AddSpacer(15);
+
+ sizer->Add(new wxStaticText(this, wxID_ANY,
+ wxT("Please select for what game/engine you'd like to compress files.")));
+
+ // This list is most likely incomplete
+ wxArrayString choices;
+
+ // Many games use the same tool internally, and are grouped by tool used here
+ // the array is ordered before being displayed, though
+
+ // compress_agos
+ choices.Add(wxT("Feeble Files")),
+ choices.Add(wxT("Simon the Sorcerer I/II")),
+
+ // compress_gob
+ choices.Add(wxT("Gobliiins (all versions)")),
+
+ // compress_kyra
+ choices.Add(wxT("The Legend of Kyrandia")),
+ choices.Add(wxT("The Legend of Kyrandia: Hand of Fate")),
+ choices.Add(wxT("The Legend of Kyrandia: Malcolm's Revenge")),
+ choices.Add(wxT("Lands of Lore: The Throne of Chaos")),
+
+ // compress_queen
+ choices.Add(wxT("Flight of the Amazon Queen")),
+
+ // compress_saga
+ choices.Add(wxT("SAGA: Inherit The Earth")),
+ choices.Add(wxT("I Have No Mouth")),
+ choices.Add(wxT("I Must Scream")),
+
+ // compress_scumm_bun
+ choices.Add(wxT("The Secret of Monkey Island")),
+ choices.Add(wxT("Monkey Island 2: LeChuck's Revenge")),
+ choices.Add(wxT("The Curse of Monkey Island")),
+
+ // compress_scumm_san
+ // compress_scumm_sou
+ // Unsure of exact games...
+
+ // compress_sword1
+ choices.Add(wxT("Broken Sword 1")),
+
+ // compress_sword2
+ choices.Add(wxT("Broken Sword 2")),
+
+ // compress_touche
+ choices.Add(wxT("Touch\xE9: The Adventures of the Fifth Musketeer")),
+
+ // compress_tucker
+ choices.Add(wxT("Bud Tucker in Double Trouble")),
+
+
+ // Sort the array for display
+ choices.Sort();
+
+ _game = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
+ sizer->Add(_game);
+ _game->SetSelection(0);
+
+ SetAlignedSizer(sizer);
+}
+
+void CompressionPage::onPrevious() {
+ // It's kinda ugly that we must know the type here, would be better
+ // if we could infer previous page automatically, somehow, possibly
+ // templates + inheritence could solve this?
+ SwitchPage(new IntroPage(this->GetParent()));
+}
+
+
+// Load/Save settings
+void CompressionPage::load(Configuration &config) {
+ _game->SetStringSelection(config.selectedGame);
+}
+
+void CompressionPage::save(Configuration &config) {
+ config.selectedGame = _game->GetStringSelection();
+}
Modified: tools/branches/gsoc2009-gui/gui/main.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/main.h 2009-06-18 01:13:42 UTC (rev 41621)
+++ tools/branches/gsoc2009-gui/gui/main.h 2009-06-18 01:55:51 UTC (rev 41622)
@@ -25,9 +25,18 @@
#include <wx/wx.h>
+#include "configuration.h"
+
class WizardButtons;
class WizardPage;
+enum GUI_ID {
+ ID_FIRST = wxID_HIGHEST, // Ensure no collisions
+ ID_NEXT,
+ ID_PREV,
+ ID_CANCEL,
+};
+
// Application top window
class ScummToolsFrame : public wxFrame
@@ -39,6 +48,7 @@
void SwitchPage(WizardPage *nextPage);
private:
+ Configuration configuration;
wxPanel *_wizardpane;
WizardButtons *_buttons;
@@ -53,6 +63,14 @@
public:
WizardButtons(wxWindow *parent, wxStaticText *linetext);
+ // Set the buttons to the standard configuration
+ // (prev, next shown and enabled, finish disabled)
+ void reset();
+
+ // Set the current wizard page, done from SwitchPage required
+ // for the buttons to know where to drop their events
+ void setPage(WizardPage *current);
+
// Set the label of the line above the buttons, can display some useful info here
void setLineLabel(wxString label);
@@ -66,11 +84,20 @@
// Changes 'next' into 'finish'
void showFinish(bool show);
+ // wx event handlers
+ // overload the virtual functions below for the page-specific handlers
+ void onClickNext(wxCommandEvent &e);
+ void onClickPrevious(wxCommandEvent &e);
+ void onClickCancel(wxCommandEvent &e);
+
protected:
wxButton *_next;
wxButton *_prev;
wxButton *_cancel;
wxStaticText *_linetext;
+ WizardPage *_currentPage;
+
+ DECLARE_EVENT_TABLE()
};
// The header at the top of the window
@@ -98,12 +125,31 @@
class WizardPage : public wxPanel
{
public:
- WizardPage(wxWindow *parent, WizardButtons *buttons);
+ WizardPage(wxWindow *parent);
+ virtual void updateButtons();
// This adds an offset (about 100px) to the left of the sizer
// to center the text somewhat, before adding it to the panel
void SetAlignedSizer(wxSizer *sizer);
+ // This calls parent -> SwitchPage
+ // This page WILL BE DELETED
+ // You should return out of this class immedietly after calling this function
+ void SwitchPage(WizardPage *next);
+
+ // Load/Save configuration
+ virtual void load(Configuration &configuration);
+ virtual void save(Configuration &configuration);
+
+ // Event handlers
+ // overload these to handle prev/next/cancel clicks
+ virtual void onNext() {}
+ virtual void onPrevious() {}
+ virtual void onCancel(); // Default is to display 'Are you sure' and quit if you click 'Yes'
+
+ // Calls updateButtons
+ void onUpdateButtons(WizardButtons *buttons);
+
protected:
WizardPage *_nextPage;
WizardPage *_prevPage;
@@ -115,16 +161,30 @@
class IntroPage : public WizardPage
{
public:
- IntroPage(wxWindow *parent, WizardButtons *buttons);
+ IntroPage(wxWindow *parent);
+ virtual void updateButtons();
+ void load(Configuration &configuration);
+ void save(Configuration &configuration);
+
+ virtual void onNext();
+
protected:
wxRadioBox *_options;
};
-class TestPage : public WizardPage
+class CompressionPage : public WizardPage
{
public:
- TestPage(wxWindow *parent, WizardButtons *buttons);
+ CompressionPage(wxWindow *parent);
+
+ void load(Configuration &configuration);
+ void save(Configuration &configuration);
+
+ virtual void onPrevious();
+
+protected:
+ wxChoice *_game;
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list