Skip to content

Commit

Permalink
JADE: Add character generation name menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius committed Jul 21, 2019
1 parent f14f853 commit 9d8f7a0
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
117 changes: 117 additions & 0 deletions src/engines/jade/gui/chargen/charactername.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* xoreos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Character generation name menu.
*/

#include "src/aurora/talkman.h"

#include "src/events/events.h"

#include "src/engines/jade/gui/chargen/charactername.h"

#include "src/engines/odyssey/widget.h"

namespace Engines {

namespace Jade {

CharacterName::CharacterName(CharacterGeneration &chargen, CharacterInfo &charInfo) :
CharacterGenerationBase(chargen, charInfo) {
load("keyboard");

_labelText = getLabel("LabelText");
}

void CharacterName::callbackActive(Widget &widget) {
if (widget.getTag() == "ButtonDefault") {
_charInfo.setName(_charInfo.getDefaultName());
updateName();
return;
}

if (widget.getTag() == "ButtonBack") {
_charInfo.setName(_charInfo.getDefaultName());
_chargen.showSelection();

EventMan.enableTextInput(false);
EventMan.enableKeyRepeat(false);

return;
}

if (widget.getTag() == "ButtonDone") {
_chargen.showSummary();

EventMan.enableTextInput(false);
EventMan.enableKeyRepeat(false);

return;
}

if (widget.getTag() == "bClear") {
_charInfo.setName("");
updateName();

return;
}
}

void CharacterName::initWidget(Widget &widget) {
if (widget.getTag() == "TitleLabel")
reinterpret_cast<Odyssey::WidgetLabel &>(widget).setText(TalkMan.getString(301));
}

void CharacterName::updateName() {
_labelText->setText(_charInfo.getName() + "_");
}

void CharacterName::show() {
updateName();

EventMan.enableTextInput(true);
EventMan.enableKeyRepeat(true);

GUI::show();
}

void CharacterName::callbackTextInput(const Common::UString &text) {
if (_charInfo.getName().size() >= 20)
return;

_charInfo.setName(_charInfo.getName() + text);
updateName();
}

void CharacterName::callbackKeyInput(const Events::Key &key, const Events::EventType &type) {
if (key == Events::kKeyBackspace && type == Events::kEventKeyDown) {
Common::UString name = _charInfo.getName();
if (!name.empty()) {
name.erase(--name.end());
_charInfo.setName(name);
updateName();
}
}
}

} // End of namespace Jade

} // End of namespace Engines
60 changes: 60 additions & 0 deletions src/engines/jade/gui/chargen/charactername.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* xoreos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Character generation name menu.
*/

#ifndef ENGINES_JADE_GUI_CHARGEN_CHARACTERNAME_H
#define ENGINES_JADE_GUI_CHARGEN_CHARACTERNAME_H

#include "src/engines/jade/gui/gui.h"
#include "src/engines/jade/gui/chargen/charactergenerationbase.h"

#include "src/engines/odyssey/label.h"

namespace Engines {

namespace Jade {

class CharacterName : public CharacterGenerationBase {
public:
CharacterName(CharacterGeneration &chargen, CharacterInfo &charInfo);

void show() override;

protected:
void callbackActive(Widget &widget) override;
void callbackTextInput(const Common::UString &text) override;
void callbackKeyInput(const Events::Key &key, const Events::EventType &type) override;

void initWidget(Widget &widget) override;

private:
void updateName();

Odyssey::WidgetLabel *_labelText;
};

} // End of namespace Jade

} // End of namespace Engines

#endif // ENGINES_JADE_GUI_CHARGEN_CHARACTERNAME_H
2 changes: 2 additions & 0 deletions src/engines/jade/gui/chargen/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
src_engines_jade_libjade_la_SOURCES += \
src/engines/jade/gui/chargen/charactergenerationbase.h \
src/engines/jade/gui/chargen/characterinfo.h \
src/engines/jade/gui/chargen/charactername.h \
$(EMPTY)

src_engines_jade_libjade_la_SOURCES += \
src/engines/jade/gui/chargen/charactergenerationbase.cpp \
src/engines/jade/gui/chargen/characterinfo.cpp \
src/engines/jade/gui/chargen/charactername.cpp \
$(EMPTY)

0 comments on commit 9d8f7a0

Please sign in to comment.