Race and name dialog are now kept in memory after ok/next is clicked, this avoids a crash where MyGUI would call into the dialog widgets after being destroyed.

This commit is contained in:
Jan Borsodi 2010-09-15 19:37:06 +02:00
parent 5802930500
commit 07dd5e5631
5 changed files with 64 additions and 33 deletions

View file

@ -13,7 +13,7 @@
using namespace MWGui; using namespace MWGui;
RaceDialog::RaceDialog(MWWorld::Environment& environment, bool showNext) RaceDialog::RaceDialog(MWWorld::Environment& environment)
: Layout("openmw_chargen_race_layout.xml") : Layout("openmw_chargen_race_layout.xml")
, environment(environment) , environment(environment)
, genderIndex(0) , genderIndex(0)
@ -78,20 +78,38 @@ RaceDialog::RaceDialog(MWWorld::Environment& environment, bool showNext)
MyGUI::ButtonPtr okButton; MyGUI::ButtonPtr okButton;
getWidget(okButton, "OKButton"); getWidget(okButton, "OKButton");
okButton->eventMouseButtonClick = MyGUI::newDelegate(this, &RaceDialog::onOkClicked); okButton->eventMouseButtonClick = MyGUI::newDelegate(this, &RaceDialog::onOkClicked);
if (showNext)
{
okButton->setCaption("Next");
// Adjust back button when next is shown
backButton->setCoord(backButton->getCoord() - MyGUI::IntPoint(18, 0));
okButton->setCoord(okButton->getCoord() + MyGUI::IntCoord(-18, 0, 18, 0));
}
updateRaces(); updateRaces();
updateSkills(); updateSkills();
updateSpellPowers(); updateSpellPowers();
} }
void RaceDialog::setNextButtonShow(bool shown)
{
MyGUI::ButtonPtr backButton;
getWidget(backButton, "BackButton");
MyGUI::ButtonPtr okButton;
getWidget(okButton, "OKButton");
// TODO: All hardcoded coords for buttons are temporary, will be replaced with a dynamic system.
if (shown)
{
okButton->setCaption("Next");
// Adjust back button when next is shown
backButton->setCoord(MyGUI::IntCoord(471 - 18, 397, 53, 23));
okButton->setCoord(MyGUI::IntCoord(532 - 18, 397 + 18, 42, 23));
}
else
{
okButton->setCaption("ok");
backButton->setCoord(MyGUI::IntCoord(471, 397, 53, 23));
okButton->setCoord(MyGUI::IntCoord(532, 397, 42, 23));
}
}
void RaceDialog::setRaceId(const std::string &raceId) void RaceDialog::setRaceId(const std::string &raceId)
{ {
currentRaceId = raceId; currentRaceId = raceId;

View file

@ -26,7 +26,7 @@ namespace MWGui
class RaceDialog : public OEngine::GUI::Layout class RaceDialog : public OEngine::GUI::Layout
{ {
public: public:
RaceDialog(MWWorld::Environment& environment, bool showNext); RaceDialog(MWWorld::Environment& environment);
enum Gender enum Gender
{ {
@ -44,6 +44,8 @@ namespace MWGui
// setFace() // setFace()
// setHair() // setHair()
void setNextButtonShow(bool shown);
// Events // Events
/** Event : Back button clicked.\n /** Event : Back button clicked.\n

View file

@ -4,7 +4,7 @@
using namespace MWGui; using namespace MWGui;
TextInputDialog::TextInputDialog(MWWorld::Environment& environment, const std::string &label, bool showNext, MyGUI::IntSize size) TextInputDialog::TextInputDialog(MWWorld::Environment& environment, MyGUI::IntSize size)
: Layout("openmw_text_input_layout.xml") : Layout("openmw_text_input_layout.xml")
, environment(environment) , environment(environment)
{ {
@ -14,27 +14,39 @@ TextInputDialog::TextInputDialog(MWWorld::Environment& environment, const std::s
coord.top = (size.height - coord.height)/2; coord.top = (size.height - coord.height)/2;
mMainWidget->setCoord(coord); mMainWidget->setCoord(coord);
setText("LabelT", label);
getWidget(textEdit, "TextEdit"); getWidget(textEdit, "TextEdit");
// textEdit->eventEditSelectAccept = newDelegate(this, &TextInputDialog::onTextAccepted); textEdit->eventEditSelectAccept = newDelegate(this, &TextInputDialog::onTextAccepted);
// TODO: These buttons should be managed by a Dialog class // TODO: These buttons should be managed by a Dialog class
MyGUI::ButtonPtr okButton; MyGUI::ButtonPtr okButton;
getWidget(okButton, "OKButton"); getWidget(okButton, "OKButton");
okButton->eventMouseButtonClick = MyGUI::newDelegate(this, &TextInputDialog::onOkClicked); okButton->eventMouseButtonClick = MyGUI::newDelegate(this, &TextInputDialog::onOkClicked);
if (showNext)
{
okButton->setCaption("Next");
// Adjust back button when next is shown
okButton->setCoord(okButton->getCoord() + MyGUI::IntCoord(-18, 0, 18, 0));
}
// Make sure the edit box has focus // Make sure the edit box has focus
MyGUI::InputManager::getInstance().setKeyFocusWidget(textEdit); MyGUI::InputManager::getInstance().setKeyFocusWidget(textEdit);
} }
void TextInputDialog::setNextButtonShow(bool shown)
{
MyGUI::ButtonPtr okButton;
getWidget(okButton, "OKButton");
if (shown)
{
okButton->setCaption("Next");
okButton->setCoord(MyGUI::IntCoord(264 - 18, 60, 42 + 18, 23));
}
else
{
okButton->setCaption("OK");
okButton->setCoord(MyGUI::IntCoord(264, 60, 42, 23));
}
}
void TextInputDialog::setTextLabel(const std::string &label)
{
setText("LabelT", label);
}
// widget controls // widget controls
void TextInputDialog::onOkClicked(MyGUI::Widget* _sender) void TextInputDialog::onOkClicked(MyGUI::Widget* _sender)

View file

@ -20,11 +20,14 @@ namespace MWGui
class TextInputDialog : public OEngine::GUI::Layout class TextInputDialog : public OEngine::GUI::Layout
{ {
public: public:
TextInputDialog(MWWorld::Environment& environment, const std::string &label, bool showNext, MyGUI::IntSize size); TextInputDialog(MWWorld::Environment& environment, MyGUI::IntSize size);
std::string getTextInput() const { return textEdit ? textEdit->getOnlyText() : ""; } std::string getTextInput() const { return textEdit ? textEdit->getOnlyText() : ""; }
void setTextInput(const std::string &text) { if (textEdit) textEdit->setOnlyText(text); } void setTextInput(const std::string &text) { if (textEdit) textEdit->setOnlyText(text); }
void setNextButtonShow(bool shown);
void setTextLabel(const std::string &label);
// Events // Events
/** Event : Dialog finished, OK button clicked.\n /** Event : Dialog finished, OK button clicked.\n

View file

@ -101,10 +101,11 @@ void WindowManager::updateVisible()
if (mode == GM_Name) if (mode == GM_Name)
{ {
if (!nameDialog) if (!nameDialog)
{ nameDialog = new TextInputDialog(environment, gui->getViewSize());
std::string sName = getGameSettingString("sName", "Name"); std::string sName = getGameSettingString("sName", "Name");
nameDialog = new TextInputDialog(environment, sName, nameChosen, gui->getViewSize()); nameDialog->setTextLabel(sName);
} nameDialog->setNextButtonShow(nameChosen);
nameDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onNameDialogDone); nameDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onNameDialogDone);
nameDialog->setVisible(true); nameDialog->setVisible(true);
return; return;
@ -113,7 +114,8 @@ void WindowManager::updateVisible()
if (mode == GM_Race) if (mode == GM_Race)
{ {
if (!raceDialog) if (!raceDialog)
raceDialog = new RaceDialog (environment, raceChosen); raceDialog = new RaceDialog(environment);
nameDialog->setNextButtonShow(raceChosen);
raceDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onRaceDialogDone); raceDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onRaceDialogDone);
raceDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onRaceDialogBack); raceDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onRaceDialogBack);
raceDialog->setVisible(true); raceDialog->setVisible(true);
@ -194,8 +196,6 @@ void WindowManager::onNameDialogDone()
nameDialog->setVisible(false); nameDialog->setVisible(false);
environment.mMechanicsManager->setPlayerName(nameDialog->getTextInput()); environment.mMechanicsManager->setPlayerName(nameDialog->getTextInput());
} }
delete nameDialog;
nameDialog = nullptr;
updateCharacterGeneration(); updateCharacterGeneration();
@ -216,8 +216,6 @@ void WindowManager::onRaceDialogDone()
raceDialog->setVisible(false); raceDialog->setVisible(false);
environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male); environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male);
} }
delete raceDialog;
raceDialog = nullptr;
updateCharacterGeneration(); updateCharacterGeneration();
@ -236,8 +234,6 @@ void WindowManager::onRaceDialogBack()
raceDialog->setVisible(false); raceDialog->setVisible(false);
environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male); environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male);
} }
delete raceDialog;
raceDialog = nullptr;
updateCharacterGeneration(); updateCharacterGeneration();