forked from NaiJi/project-kyoku
Add editor state
parent
befd7e5cf9
commit
7e97510f31
@ -0,0 +1,61 @@
|
||||
#include "editor.h"
|
||||
#include "widgets/button.h"
|
||||
#include "widgets/group.h"
|
||||
#include "tools/bpmcalculator.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music) :
|
||||
_buttons(std::make_shared<Group>()),
|
||||
_game_window(game_window),
|
||||
_music(std::move(music)),
|
||||
_bpm_calculator(std::make_unique<BPMCalculator>(_music))
|
||||
{
|
||||
(void)callbacks;
|
||||
const float window_width = game_window.getSize().x;
|
||||
const float window_height = game_window.getSize().y;
|
||||
|
||||
_music->openFromFile("Uta-test.flac");
|
||||
_music->setVolume(20);
|
||||
|
||||
std::shared_ptr<Button> button_start = std::make_shared<Button>("Start");
|
||||
button_start->setRect(sf::FloatRect(window_width / 3., window_height / 7. * 2, window_width / 3., window_height / 7.));
|
||||
button_start->setCallback([&]()
|
||||
{
|
||||
_bpm_calculator->startListening(0);
|
||||
});
|
||||
|
||||
_buttons->addChild(button_start);
|
||||
}
|
||||
|
||||
void Editor::input(const sf::Event& event)
|
||||
{
|
||||
_buttons->input(event);
|
||||
|
||||
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
|
||||
{
|
||||
_bpm_calculator->click();
|
||||
std::cout << _bpm_calculator->getCurrentApproximation() << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::update()
|
||||
{
|
||||
_buttons->update();
|
||||
}
|
||||
|
||||
void Editor::draw() const
|
||||
{
|
||||
_game_window.draw(*_buttons);
|
||||
}
|
||||
|
||||
void Editor::enter()
|
||||
{
|
||||
_buttons->setVisibility();
|
||||
}
|
||||
|
||||
void Editor::leave()
|
||||
{
|
||||
_buttons->setVisibility(false);
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "gui/state.h"
|
||||
#include "tools/music.h"
|
||||
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
|
||||
class Group;
|
||||
class BPMCalculator;
|
||||
|
||||
class Editor : public GUIState
|
||||
{
|
||||
public:
|
||||
|
||||
struct Callbacks
|
||||
{
|
||||
std::function<void(void)> onAppendGameState;
|
||||
};
|
||||
|
||||
explicit Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music);
|
||||
virtual void input(const sf::Event& event) override;
|
||||
virtual void update() override;
|
||||
virtual void draw() const override;
|
||||
|
||||
virtual void enter() override;
|
||||
virtual void leave() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Group> _buttons;
|
||||
sf::RenderWindow& _game_window;
|
||||
|
||||
std::shared_ptr<Music> _music;
|
||||
std::shared_ptr<BPMCalculator> _bpm_calculator;
|
||||
};
|
||||
|
Loading…
Reference in New Issue