Add Editor interface
This commit is contained in:
parent
8579dc5507
commit
c097ac0da5
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "tools/mathutils.h"
|
||||
|
||||
struct BPMSection
|
||||
{
|
||||
int bpm = 0;
|
||||
int fraction = 1;
|
||||
microsec offset_start = 0;
|
||||
|
||||
inline bool operator<(const BPMSection& right)
|
||||
{
|
||||
return offset_start < right.offset_start;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,55 @@
|
|||
#pragma once
|
||||
|
||||
#include <set>
|
||||
#include "core/inputtype.h"
|
||||
#include "core/bpmsection.h"
|
||||
|
||||
class Editor
|
||||
{
|
||||
public:
|
||||
virtual ~Editor() = default;
|
||||
|
||||
virtual void input(PlayerInput&& inputdata) = 0;
|
||||
virtual void update() = 0;
|
||||
virtual void draw() const = 0;
|
||||
|
||||
inline void setBPMSections(const std::set<BPMSection>& sections)
|
||||
{
|
||||
_bpm_sections = sections;
|
||||
}
|
||||
|
||||
inline void setBPMSections(std::set<BPMSection>&& sections)
|
||||
{
|
||||
_bpm_sections = std::move(sections);
|
||||
}
|
||||
|
||||
inline void insertBPMSection(const BPMSection& section)
|
||||
{
|
||||
_bpm_sections.insert(section);
|
||||
}
|
||||
|
||||
inline void insertBPMSection(BPMSection&& section)
|
||||
{
|
||||
_bpm_sections.insert(std::move(section));
|
||||
}
|
||||
|
||||
void removeBPMSectionAt(const microsec& offset)
|
||||
{
|
||||
const auto section_it = std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(),
|
||||
[offset](const auto& section)
|
||||
{
|
||||
return section.start_offset < offset;
|
||||
});
|
||||
|
||||
if (section_it != _bpm_sections.rend())
|
||||
_bpm_sections.erase((section_it + 1).base());
|
||||
}
|
||||
|
||||
inline void clearBPMSections()
|
||||
{
|
||||
_bpm_sections.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::set<BPMSection> _bpm_sections;
|
||||
};
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
#pragma once
|
||||
|
||||
#include "core/inputtype.h"
|
||||
|
||||
|
@ -14,5 +13,3 @@ public:
|
|||
virtual void update() = 0;
|
||||
virtual void draw() const = 0;
|
||||
};
|
||||
|
||||
#endif // GAME_H
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#include "classiceditor.h"
|
||||
|
||||
ClassicEditor::ClassicEditor()
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#include "classiceditor.h"
|
||||
|
||||
ClassicEditor::ClassicEditor(std::shared_ptr<ClassicGraphicsManager>&& manager)
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/editor.h"
|
||||
|
||||
class ClassicEditor : public Editor
|
||||
{
|
||||
public:
|
||||
explicit ClassicEditor();
|
||||
|
||||
virtual void input(PlayerInput&& inputdata) = 0;
|
||||
virtual void update() = 0;
|
||||
virtual void draw() const = 0;
|
||||
};
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "mainmenu.h"
|
||||
#include "gamestate.h"
|
||||
#include "editor.h"
|
||||
#include "editorstate.h"
|
||||
|
||||
#include "tools/music.h"
|
||||
#include "classicmode/classicfactory.h"
|
||||
|
@ -30,11 +30,11 @@ Application::Application() :
|
|||
[&](){ pushState(GUIState::Tag::EDITOR); }
|
||||
};
|
||||
|
||||
Editor::Callbacks editor_callbacks = {[&](){ popState(); }};
|
||||
EditorState::Callbacks editor_callbacks = {[&](){ popState(); }};
|
||||
|
||||
const auto main_menu = std::make_shared<MainMenu>(_game_window, std::move(callbacks), _font_holder);
|
||||
const auto game_state = std::make_shared<GameState>(_game_window, _game, GameState::Callbacks());
|
||||
const auto editor = std::make_shared<Editor>(_game_window, std::move(editor_callbacks), std::make_unique<Music>(), _font_holder);
|
||||
const auto editor = std::make_shared<EditorState>(_game_window, std::move(editor_callbacks), std::make_unique<Music>(), _font_holder);
|
||||
|
||||
_states[GUIState::Tag::MAIN_MENU] = main_menu;
|
||||
_states[GUIState::Tag::GAME] = game_state;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "editor.h"
|
||||
#include "editorstate.h"
|
||||
#include "widgets/button.h"
|
||||
#include "widgets/group.h"
|
||||
#include "widgets/menubar.h"
|
||||
|
@ -8,29 +8,29 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
Editor::Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music, const FontHolder& font_holder) :
|
||||
EditorState::EditorState(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music, const FontHolder& font_holder) :
|
||||
_font(font_holder.get(Fonts::Id::GUI)),
|
||||
_game_window(game_window),
|
||||
_callbacks(std::move(callbacks)),
|
||||
_music(std::move(music))
|
||||
{}
|
||||
|
||||
void Editor::input(const sf::Event& event)
|
||||
void EditorState::input(const sf::Event& event)
|
||||
{
|
||||
_group->input(event);
|
||||
}
|
||||
|
||||
void Editor::update(const sf::Time& dt)
|
||||
void EditorState::update(const sf::Time& dt)
|
||||
{
|
||||
_group->update(dt);
|
||||
}
|
||||
|
||||
void Editor::draw() const
|
||||
void EditorState::draw() const
|
||||
{
|
||||
_game_window.draw(*_group);
|
||||
}
|
||||
|
||||
void Editor::enter()
|
||||
void EditorState::enter()
|
||||
{
|
||||
auto& group = _group;
|
||||
auto& music = _music;
|
||||
|
@ -103,7 +103,7 @@ void Editor::enter()
|
|||
_group->addChild(bpm_widget);
|
||||
}
|
||||
|
||||
void Editor::leave()
|
||||
void EditorState::leave()
|
||||
{
|
||||
_group.reset();
|
||||
_bpm_calculator.reset();
|
|
@ -8,7 +8,7 @@
|
|||
class BPMCalculator;
|
||||
class Group;
|
||||
|
||||
class Editor : public GUIState
|
||||
class EditorState : public GUIState
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -17,7 +17,7 @@ public:
|
|||
std::function<void(void)> onLeaveEditorState;
|
||||
};
|
||||
|
||||
explicit Editor(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music, const FontHolder& font_holder);
|
||||
explicit EditorState(sf::RenderWindow& game_window, Callbacks&& callbacks, std::unique_ptr<Music>&& music, const FontHolder& font_holder);
|
||||
virtual void input(const sf::Event& event) override;
|
||||
virtual void update(const sf::Time& dt) override;
|
||||
virtual void draw() const override;
|
|
@ -0,0 +1,50 @@
|
|||
#include "editorwidget.h"
|
||||
|
||||
EditorWidget::EditorWidget(const std::shared_ptr<Editor>& editor) :
|
||||
_editor(editor)
|
||||
{}
|
||||
|
||||
void EditorWidget::input(const sf::Event& event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditorWidget::update(const sf::Time& dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditorWidget::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditorWidget::move(const sf::Vector2f& delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool EditorWidget::isUnderMouse(int mouse_x, int mouse_y) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditorWidget::setRect(const sf::FloatRect& rect)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
sf::FloatRect EditorWidget::rect() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EditorWidget::setPosition(const sf::Vector2f& position)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
sf::Vector2f EditorWidget::position() const
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "widget.h"
|
||||
|
||||
class Editor;
|
||||
|
||||
class EditorWidget : public Widget
|
||||
{
|
||||
public:
|
||||
explicit EditorWidget(const std::shared_ptr<Editor>& editor);
|
||||
|
||||
virtual void input(const sf::Event& event) override;
|
||||
virtual void update(const sf::Time& dt) override;
|
||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
virtual void move(const sf::Vector2f& delta) override;
|
||||
virtual bool isUnderMouse(int mouse_x, int mouse_y) const override;
|
||||
|
||||
virtual void setRect(const sf::FloatRect& rect) override;
|
||||
virtual sf::FloatRect rect() const override;
|
||||
|
||||
virtual void setPosition(const sf::Vector2f& position) override;
|
||||
virtual sf::Vector2f position() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Editor> _editor;
|
||||
};
|
||||
|
Loading…
Reference in New Issue