3 #include <BLIB/Audio/AudioSystem.hpp>
18 constexpr glm::vec2 MoveBoxPos(499.f, 463.f);
24 , state(State::Hidden)
25 , stateLoopGuard(false)
32 using namespace bl::menu;
34 actionMenu.create(engine,
35 engine.renderer().getObserver(),
36 bl::menu::ArrowSelector::create(12.f, sf::Color::Black));
37 actionMenu.addToScene(scene);
39 moveMenu.create(engine,
40 engine.renderer().getObserver(),
41 bl::menu::ArrowSelector::create(12.f, sf::Color::Black));
42 moveMenu.addToScene(scene);
45 fightItem->getSignal(Item::Activated).willAlwaysCall(std::bind(&PlayerMenu::fightChosen,
this));
47 bagItem->getSignal(Item::Activated).willAlwaysCall(std::bind(&PlayerMenu::itemChosen,
this));
49 switchItem->getSignal(Item::Activated)
50 .willAlwaysCall(std::bind(&PlayerMenu::switchChosen,
this));
52 runItem->getSignal(Item::Activated).willAlwaysCall(std::bind(&PlayerMenu::runChosen,
this));
54 actionMenu.setRootItem(fightItem);
55 actionMenu.addItem(bagItem, fightItem.get(), Item::Right);
56 actionMenu.addItem(switchItem, fightItem.get(), Item::Bottom);
58 actionMenu.addItem(runItem, bagItem.get(), Item::Bottom);
59 actionMenu.attachExisting(runItem.get(), switchItem.get(), Item::Right);
62 actionMenu.attachExisting(switchItem.get(), bagItem.get(), Item::Bottom,
false);
63 actionMenu.attachExisting(bagItem.get(), switchItem.get(), Item::Right,
false);
65 actionMenu.setPosition({513.f, 476.f});
66 actionMenu.setPadding({40.f, 17.f});
68 moveMenu.setPosition({16.f, 477.f});
69 moveMenu.setPadding({25.f, 20.f});
71 moveTxtr = engine.renderer().texturePool().getOrLoadTexture(
73 moveBox.create(engine, moveTxtr);
74 moveBox.getTransform().setPosition(MoveBoxPos);
75 moveBox.addToScene(scene, bl::rc::UpdateSpeed::Static);
78 movePwr.getTransform().setPosition(77.f, 20.f);
79 movePwr.setParent(moveBox);
80 movePwr.addToScene(scene, bl::rc::UpdateSpeed::Static);
83 moveAcc.getTransform().setPosition(77.f, 53.f);
84 moveAcc.setParent(moveBox);
85 moveAcc.addToScene(scene, bl::rc::UpdateSpeed::Static);
88 movePP.getTransform().setPosition(77.f, 87.f);
89 movePP.setParent(moveBox);
90 movePP.addToScene(scene, bl::rc::UpdateSpeed::Static);
94 using namespace bl::menu;
98 for (
int i = 0; i < 4; ++i) { moveItems[i].reset(); }
100 for (
int i = 0; i < 4; ++i) {
103 moveItems[i] = TextItem::create(
106 ->getSignal(Item::Activated)
107 .willAlwaysCall(std::bind(&PlayerMenu::moveChosen,
this, i));
109 ->getSignal(Item::Selected)
110 .willAlwaysCall(std::bind(&PlayerMenu::syncMove,
this, i));
111 if (i == 1) { moveItems[i]->overridePosition({240.f, 0.f}); }
114 moveMenu.setRootItem(moveItems[0]);
116 moveMenu.addItem(moveItems[1], moveItems[0].get(), Item::Right);
118 moveMenu.addItem(moveItems[2], moveItems[0].get(), Item::Bottom);
120 moveMenu.addItem(moveItems[3], moveItems[1].get(), Item::Bottom);
121 moveMenu.attachExisting(moveItems[3].get(), moveItems[2].get(), Item::Right);
124 moveMenu.attachExisting(
125 moveItems[2].get(), moveItems[1].get(), Item::Bottom,
false);
126 moveMenu.attachExisting(moveItems[1].get(), moveItems[2].get(), Item::Right,
false);
134 case State::PickingItem:
136 else if (stateLoopGuard) { stateLoopGuard =
false; }
137 else { state = State::PickingAction; }
139 case State::PickingPeoplemon:
140 if (chosenMoveOrPeoplemon != -1 && chosenMoveOrPeoplemon != currentPeoplemon) {
141 state = State::Hidden;
143 else if (stateLoopGuard) { stateLoopGuard =
false; }
145 state = State::PickingAction;
146 chosenMoveOrPeoplemon = -1;
155 state = State::PickingAction;
156 menuDriver.drive(&actionMenu);
160 state = State::PickingPeoplemon;
161 chosenMoveOrPeoplemon = -1;
162 stateLoopGuard =
true;
164 bl::event::Dispatcher::dispatch<event::OpenPeoplemonMenu>(
167 &chosenMoveOrPeoplemon});
169 else if (fromRevive) {
170 bl::event::Dispatcher::dispatch<event::OpenPeoplemonMenu>(
173 &chosenMoveOrPeoplemon});
176 bl::event::Dispatcher::dispatch<event::OpenPeoplemonMenu>(
179 &chosenMoveOrPeoplemon});
184 state = State::ChoosingMoveToForget;
185 menuDriver.drive(&moveMenu);
199 menuDriver.sendControl(cmd, fromEvent);
201 if (state == State::PickingMove) {
202 state = State::PickingAction;
203 menuDriver.drive(&actionMenu);
206 else if (state == State::ChoosingMoveToForget) {
214 if (state == State::PickingAction) { actionMenu.draw(ctx); }
215 else if (state == State::PickingMove || state == State::ChoosingMoveToForget) {
224 void PlayerMenu::fightChosen() {
225 state = State::PickingMove;
228 bool useFlail =
true;
229 for (
int i = 0; i < 4; ++i) {
236 state = State::Hidden;
237 chosenMoveOrPeoplemon = -1;
240 menuDriver.drive(&moveMenu);
241 for (
int i = 0; i < 4; ++i) {
242 if (moveMenu.getSelectedItem() == moveItems[i].get()) {
250 void PlayerMenu::switchChosen() {
251 state = State::PickingPeoplemon;
253 chosenMoveOrPeoplemon = -1;
254 stateLoopGuard =
true;
255 bl::event::Dispatcher::dispatch<event::OpenPeoplemonMenu>(
258 &chosenMoveOrPeoplemon});
261 void PlayerMenu::itemChosen() {
262 state = State::PickingItem;
264 stateLoopGuard =
true;
269 &chosenMoveOrPeoplemon});
272 void PlayerMenu::runChosen() {
274 state = State::Hidden;
277 void PlayerMenu::moveChosen(
int i) {
278 chosenMoveOrPeoplemon = i;
279 state = State::Hidden;
282 void PlayerMenu::syncMove(
int i) {
283 movePP.getSection().setString(std::to_string(moves[i].curPP) +
"/" +
284 std::to_string(moves[i].maxPP));
Id
Represents an item in its simplist form.
Core classes and functionality for both the editor and game.
TurnAction
Represents an action that a battler may take on their turn.
std::underlying_type_t< Control::EntityControl > EntityControl
Helper typedef to avoid too much casting boilerplate.
void handleInput(input::EntityControl input, bool ignoreDebounce)
Processes player input to update the menu state.
TurnAction selectedAction() const
The selected turn action.
void chooseMoveToForget()
Initiates the process of choosing the move to forget.
int selectedPeoplemon() const
Returns the selected peoplemon index.
PlayerMenu(bl::engine::Engine &engine, bool canRun)
Construct a new Player Menu.
void setPeoplemon(int i, const pplmn::BattlePeoplemon &ppl)
Updates the menu for the given peoplemon.
void render(bl::rc::scene::CodeScene::RenderContext &ctx)
Renders the menu.
void choosePeoplemonMidTurn(bool fromFaint, bool fromRevive)
Opens the menu to select a peoplemon to send out.
item::Id selectedItem() const
Returns the selected item.
void beginTurn()
Resets the menu to the turn start state.
int selectedMove() const
Returns the selected move index.
void init(bl::rc::scene::CodeScene *scene)
Creates UI elements and adds them to the scene.
void refresh()
Polls state from opened peoplemon or bag menu.
bool ready() const
Returns true when the player's choice has been made.
Represents a Peoplemon in battle. Stores some extra state that only exists in battle....
OwnedPeoplemon & base()
Returns the wrapped peoplemon.
static int damage(MoveId move)
Returns the damage of the given move.
static int accuracy(MoveId move)
Returns the accuracy of the given move.
static const std::string & name(MoveId move)
Returns the name of the given move.
const OwnedMove * knownMoves() const
Returns the moves known by this Peoplemon.
static const sf::VulkanFont & MenuFont()
static bl::audio::AudioSystem::Handle MenuBackSound()
static const std::string & ImagePath()