forked from mirror/openmw-tes3mp
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:
parent
5802930500
commit
07dd5e5631
5 changed files with 64 additions and 33 deletions
|
@ -13,7 +13,7 @@
|
|||
|
||||
using namespace MWGui;
|
||||
|
||||
RaceDialog::RaceDialog(MWWorld::Environment& environment, bool showNext)
|
||||
RaceDialog::RaceDialog(MWWorld::Environment& environment)
|
||||
: Layout("openmw_chargen_race_layout.xml")
|
||||
, environment(environment)
|
||||
, genderIndex(0)
|
||||
|
@ -78,20 +78,38 @@ RaceDialog::RaceDialog(MWWorld::Environment& environment, bool showNext)
|
|||
MyGUI::ButtonPtr okButton;
|
||||
getWidget(okButton, "OKButton");
|
||||
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();
|
||||
updateSkills();
|
||||
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)
|
||||
{
|
||||
currentRaceId = raceId;
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace MWGui
|
|||
class RaceDialog : public OEngine::GUI::Layout
|
||||
{
|
||||
public:
|
||||
RaceDialog(MWWorld::Environment& environment, bool showNext);
|
||||
RaceDialog(MWWorld::Environment& environment);
|
||||
|
||||
enum Gender
|
||||
{
|
||||
|
@ -44,6 +44,8 @@ namespace MWGui
|
|||
// setFace()
|
||||
// setHair()
|
||||
|
||||
void setNextButtonShow(bool shown);
|
||||
|
||||
// Events
|
||||
|
||||
/** Event : Back button clicked.\n
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
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")
|
||||
, environment(environment)
|
||||
{
|
||||
|
@ -14,27 +14,39 @@ TextInputDialog::TextInputDialog(MWWorld::Environment& environment, const std::s
|
|||
coord.top = (size.height - coord.height)/2;
|
||||
mMainWidget->setCoord(coord);
|
||||
|
||||
setText("LabelT", label);
|
||||
|
||||
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
|
||||
MyGUI::ButtonPtr okButton;
|
||||
getWidget(okButton, "OKButton");
|
||||
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
|
||||
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
|
||||
|
||||
void TextInputDialog::onOkClicked(MyGUI::Widget* _sender)
|
||||
|
|
|
@ -20,11 +20,14 @@ namespace MWGui
|
|||
class TextInputDialog : public OEngine::GUI::Layout
|
||||
{
|
||||
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() : ""; }
|
||||
void setTextInput(const std::string &text) { if (textEdit) textEdit->setOnlyText(text); }
|
||||
|
||||
void setNextButtonShow(bool shown);
|
||||
void setTextLabel(const std::string &label);
|
||||
|
||||
// Events
|
||||
|
||||
/** Event : Dialog finished, OK button clicked.\n
|
||||
|
|
|
@ -101,10 +101,11 @@ void WindowManager::updateVisible()
|
|||
if (mode == GM_Name)
|
||||
{
|
||||
if (!nameDialog)
|
||||
{
|
||||
nameDialog = new TextInputDialog(environment, gui->getViewSize());
|
||||
|
||||
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->setVisible(true);
|
||||
return;
|
||||
|
@ -113,7 +114,8 @@ void WindowManager::updateVisible()
|
|||
if (mode == GM_Race)
|
||||
{
|
||||
if (!raceDialog)
|
||||
raceDialog = new RaceDialog (environment, raceChosen);
|
||||
raceDialog = new RaceDialog(environment);
|
||||
nameDialog->setNextButtonShow(raceChosen);
|
||||
raceDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onRaceDialogDone);
|
||||
raceDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onRaceDialogBack);
|
||||
raceDialog->setVisible(true);
|
||||
|
@ -194,8 +196,6 @@ void WindowManager::onNameDialogDone()
|
|||
nameDialog->setVisible(false);
|
||||
environment.mMechanicsManager->setPlayerName(nameDialog->getTextInput());
|
||||
}
|
||||
delete nameDialog;
|
||||
nameDialog = nullptr;
|
||||
|
||||
updateCharacterGeneration();
|
||||
|
||||
|
@ -216,8 +216,6 @@ void WindowManager::onRaceDialogDone()
|
|||
raceDialog->setVisible(false);
|
||||
environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male);
|
||||
}
|
||||
delete raceDialog;
|
||||
raceDialog = nullptr;
|
||||
|
||||
updateCharacterGeneration();
|
||||
|
||||
|
@ -236,8 +234,6 @@ void WindowManager::onRaceDialogBack()
|
|||
raceDialog->setVisible(false);
|
||||
environment.mMechanicsManager->setPlayerRace(raceDialog->getRaceId(), raceDialog->getGender() == RaceDialog::GM_Male);
|
||||
}
|
||||
delete raceDialog;
|
||||
raceDialog = nullptr;
|
||||
|
||||
updateCharacterGeneration();
|
||||
|
||||
|
|
Loading…
Reference in a new issue