2021-08-12 21:10:52 +02:00
|
|
|
#include "editor.h"
|
|
|
|
#include "widgets/button.h"
|
|
|
|
#include "widgets/group.h"
|
2021-08-16 20:54:03 +02:00
|
|
|
#include "widgets/menubar.h"
|
2021-08-27 19:40:48 +02:00
|
|
|
#include "widgets/bpmcalculatorwidget.h"
|
2021-08-12 21:10:52 +02:00
|
|
|
#include "tools/bpmcalculator.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2021-08-26 19:41:16 +02:00
|
|
|
Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music, const FontHolder& font_holder) :
|
2021-08-12 21:10:52 +02:00
|
|
|
_game_window(game_window),
|
|
|
|
_music(std::move(music)),
|
2021-08-27 19:40:48 +02:00
|
|
|
_bpm_calculator(std::make_shared<BPMCalculator>(_music)),
|
|
|
|
_bpm_widget(std::make_shared<BPMCalculatorWidget>(_bpm_calculator, font_holder.get(Fonts::Id::GUI)))
|
2021-08-12 21:10:52 +02:00
|
|
|
{
|
|
|
|
(void)callbacks;
|
|
|
|
const float window_width = game_window.getSize().x;
|
2021-08-16 20:54:03 +02:00
|
|
|
//const float window_height = game_window.getSize().y;
|
2021-08-12 21:10:52 +02:00
|
|
|
|
2021-08-26 19:41:16 +02:00
|
|
|
_menu_bar = std::make_shared<MenuBar>(font_holder.get(Fonts::Id::GUI));
|
|
|
|
|
|
|
|
auto bpm_button = std::make_shared<PushButton>("Play song :)", font_holder.get(Fonts::Id::GUI));
|
2021-08-26 18:54:30 +02:00
|
|
|
bpm_button->setCallback([&]()
|
|
|
|
{
|
2021-08-27 19:40:48 +02:00
|
|
|
_bpm_widget->setVisibility(true);
|
2021-08-26 18:54:30 +02:00
|
|
|
});
|
|
|
|
|
2021-08-27 19:40:48 +02:00
|
|
|
_bpm_widget->setRect(sf::FloatRect(_game_window.getSize().x / 3, _game_window.getSize().y / 3, _game_window.getSize().x / 3, _game_window.getSize().y / 3));
|
|
|
|
_bpm_widget->setVisibility(false);
|
|
|
|
|
2021-08-26 20:22:19 +02:00
|
|
|
auto test_menu_2 = std::make_shared<MenuDrop>();
|
|
|
|
test_menu_2->setRect(sf::FloatRect{0, 0, 200, 27 * 5});
|
|
|
|
|
2021-08-27 19:40:48 +02:00
|
|
|
auto test_menu_3 = std::make_shared<MenuDrop>();
|
|
|
|
test_menu_3->setRect(sf::FloatRect{0, 0, 200, 27 * 5});
|
|
|
|
|
2021-08-26 20:22:19 +02:00
|
|
|
auto test_cascade_button = std::make_shared<CascadeMenuButton>("Show submenu", font_holder.get(Fonts::Id::GUI));
|
|
|
|
|
2021-08-27 19:40:48 +02:00
|
|
|
auto test_cascade_button_2 = std::make_shared<CascadeMenuButton>("Show submenu 2", font_holder.get(Fonts::Id::GUI));
|
|
|
|
|
2021-08-26 19:41:16 +02:00
|
|
|
auto quit_button = std::make_shared<PushButton>("Quit", font_holder.get(Fonts::Id::GUI));
|
2021-08-26 18:54:30 +02:00
|
|
|
quit_button->setCallback(callbacks.onLeaveEditorState);
|
|
|
|
|
|
|
|
auto test_menu = std::make_shared<MenuDrop>();
|
2021-08-26 20:22:19 +02:00
|
|
|
test_menu->setRect(sf::FloatRect{0, 0, 200, 27 * 3});
|
2021-08-26 18:54:30 +02:00
|
|
|
|
2021-08-16 20:54:03 +02:00
|
|
|
_menu_bar->setRect(sf::FloatRect(0, 0, window_width, 27));
|
2021-08-26 18:54:30 +02:00
|
|
|
_menu_bar->addSubMenu("test", test_menu);
|
|
|
|
|
2021-08-26 20:22:19 +02:00
|
|
|
test_cascade_button->setSubmenu(test_menu_2);
|
|
|
|
|
2021-08-26 18:54:30 +02:00
|
|
|
test_menu->addPushButton(bpm_button);
|
2021-08-26 20:22:19 +02:00
|
|
|
test_menu->addCascadeButton(test_cascade_button);
|
2021-08-26 18:54:30 +02:00
|
|
|
test_menu->addPushButton(quit_button);
|
|
|
|
|
2021-08-26 20:51:49 +02:00
|
|
|
test_cascade_button->resetRect();
|
2021-08-26 20:22:19 +02:00
|
|
|
|
2021-08-27 19:40:48 +02:00
|
|
|
test_cascade_button_2->setSubmenu(test_menu_3);
|
|
|
|
test_menu_2->addCascadeButton(test_cascade_button_2);
|
|
|
|
test_cascade_button_2->resetRect();
|
|
|
|
|
2021-08-26 18:54:30 +02:00
|
|
|
_music->openFromFile("Uta-test.flac");
|
|
|
|
_music->setVolume(5);
|
2021-08-12 21:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Editor::input(const sf::Event& event)
|
|
|
|
{
|
2021-08-16 20:54:03 +02:00
|
|
|
_menu_bar->input(event);
|
2021-08-12 21:10:52 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 19:40:48 +02:00
|
|
|
void Editor::update(const sf::Time& dt)
|
2021-08-12 21:10:52 +02:00
|
|
|
{
|
2021-08-27 19:40:48 +02:00
|
|
|
_menu_bar->update(dt);
|
|
|
|
_bpm_widget->update(dt);
|
2021-08-12 21:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Editor::draw() const
|
|
|
|
{
|
2021-08-16 20:54:03 +02:00
|
|
|
_game_window.draw(*_menu_bar);
|
2021-08-27 19:40:48 +02:00
|
|
|
_game_window.draw(*_bpm_widget);
|
2021-08-12 21:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Editor::enter()
|
|
|
|
{
|
2021-08-16 20:54:03 +02:00
|
|
|
_menu_bar->setVisibility();
|
2021-08-12 21:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Editor::leave()
|
|
|
|
{
|
2021-08-16 20:54:03 +02:00
|
|
|
_menu_bar->setVisibility(false);
|
2021-08-12 21:10:52 +02:00
|
|
|
}
|
|
|
|
|