Implement resource sprites and about page with third-party logos

This commit is contained in:
NaiJi ✨ 2022-03-10 20:45:19 +03:00
parent e580d45eef
commit b92bffb43e
34 changed files with 403 additions and 342 deletions

View File

@ -8,6 +8,7 @@
#include "core/rectangle.h"
#include "core/vector.h"
#include "core/line.h"
#include "core/sprite.h"
namespace kku
{
@ -20,6 +21,7 @@ public:
virtual std::shared_ptr<kku::Text> getText(kku::Font::Id id) const = 0;
virtual std::shared_ptr<kku::Rectangle> getRectangle() const = 0;
virtual std::shared_ptr<kku::Line> getLine() const = 0;
virtual std::shared_ptr<kku::Sprite> getSprite(kku::GUISprite::Id id) const = 0;
virtual kku::Vector2<std::size_t> getRenderSize() const = 0;
};

View File

@ -15,7 +15,7 @@ public:
_resources[id] = std::move(resource);
}
inline const std::shared_ptr<Resource>& get(Id id) const
inline std::shared_ptr<Resource> get(Id id) const
{
return _resources.find(id)->second;
}
@ -32,4 +32,21 @@ namespace Font
};
}
namespace Texture
{
enum class Id
{
GUI
};
}
namespace GUISprite
{
enum class Id
{
SFML_LOGO,
CRYPTOPP_LOGO
};
}
}

View File

@ -1,5 +1,7 @@
#pragma once
#include "core/area.h"
namespace kku
{
@ -7,7 +9,11 @@ class Sprite
{
public:
virtual ~Sprite() = default;
virtual void reset() = 0;
virtual void setPosition(const Point& position) = 0;
virtual Point getPosition() const = 0;
virtual void move(const kku::Vector2<float>& delta) = 0;
virtual void display() const = 0;
};

BIN
resources/gui-texture.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -0,0 +1,39 @@
#pragma once
#include "application/state.h"
#include "core/corefactory.h"
#include "core/functional.h"
class Group;
class PushButton;
namespace kku { class Sprite; class Text; }
class About : public GUIState
{
public:
struct Callbacks
{
kku::lambda onLeaveAboutState;
};
explicit About(const std::shared_ptr<kku::CoreFactory>& factory, Callbacks&& callbacks);
virtual void input(const kku::SystemEvent& event) override;
virtual void update(const kku::microsec& dt) override;
virtual void display() const override;
virtual void enter() override;
virtual void leave() override;
private:
const Callbacks _callbacks;
const std::shared_ptr<kku::CoreFactory> _core_factory;
const std::shared_ptr<kku::Sprite> _sfml_logo;
const std::shared_ptr<kku::Sprite> _cryptopp_logo;
const std::shared_ptr<kku::Text> _powered_by_text;
std::shared_ptr<Group> _buttons;
std::shared_ptr<PushButton> _exit_button;
};

View File

@ -14,6 +14,7 @@ public:
{
kku::lambda onAppendGameState;
kku::lambda onAppendEditorState;
kku::lambda onAppendAboutState;
};
explicit MainMenu(const std::shared_ptr<kku::CoreFactory>& factory, Callbacks&& callbacks);

View File

@ -19,6 +19,7 @@ public:
EDITOR_PICKER,
EDITOR,
SETTINGS,
ABOUT,
AMOUNT
};

View File

@ -0,0 +1,59 @@
#include "application/about.h"
#include "widgets/pushbutton.h"
#include "widgets/group.h"
About::About(const std::shared_ptr<kku::CoreFactory>& factory, About::Callbacks&& callbacks) :
_callbacks(std::move(callbacks)),
_core_factory(factory),
_sfml_logo(factory->getSprite(kku::GUISprite::Id::SFML_LOGO)),
_cryptopp_logo(factory->getSprite(kku::GUISprite::Id::CRYPTOPP_LOGO)),
_powered_by_text(factory->getText(kku::Font::Id::GUI)),
_buttons(std::make_shared<Group>())
{
_powered_by_text->setString("Powered by: ");
_powered_by_text->move(kku::Vector2<float>{0., 60});
_sfml_logo->move(kku::Vector2<float>{230., 60});
_cryptopp_logo->move(kku::Vector2<float>{250., 180});
}
void About::input(const kku::SystemEvent& event)
{
_buttons->input(event);
}
void About::update(const kku::microsec& dt)
{
_buttons->update(dt);
}
void About::display() const
{
_buttons->display();
_sfml_logo->display();
_cryptopp_logo->display();
_powered_by_text->display();
}
void About::enter()
{
const auto render_size = _core_factory->getRenderSize();
const float window_width = render_size.first;
const float window_height = render_size.second;
if (!_exit_button)
{
_exit_button = std::make_shared<PushButton>("Return", _core_factory, 48);
_exit_button->setCallback(_callbacks.onLeaveAboutState);
_buttons->addChild(_exit_button);
}
_exit_button->setRect(kku::Area<float>{window_width / 3.f, window_height / 7.f * 4,
window_width / 3.f, window_height / 7.f});
_buttons->setVisibility();
}
void About::leave()
{
_buttons->setVisibility(false);
}

View File

@ -5,6 +5,7 @@
#include "application/mainmenu.h"
#include "application/gamestate.h"
#include "application/editorstate.h"
#include "application/about.h"
#include "classicmode/classicfactory.h"
@ -16,18 +17,22 @@ bool Application::init()
MainMenu::Callbacks callbacks =
{
[&](){ pushState(GUIState::Tag::GAME); },
[&](){ pushState(GUIState::Tag::EDITOR); }
[&](){ pushState(GUIState::Tag::EDITOR); },
[&](){ pushState(GUIState::Tag::ABOUT); },
};
EditorState::Callbacks editor_callbacks = {[&](){ popState(); }};
About::Callbacks about_callbacks = {[&](){ popState(); }};
const auto main_menu = std::make_shared<MainMenu>(_core_factory, std::move(callbacks));
const auto game_state = std::make_shared<GameState>(_core_factory, classic::getGame(_core_factory), GameState::Callbacks());
const auto editor = std::make_shared<EditorState>(_core_factory, classic::getEditor(_core_factory), std::move(editor_callbacks));
const auto about = std::make_shared<About>(_core_factory, std::move(about_callbacks));
_states[GUIState::Tag::MAIN_MENU] = main_menu;
_states[GUIState::Tag::GAME] = game_state;
_states[GUIState::Tag::EDITOR] = editor;
_states[GUIState::Tag::ABOUT] = about;
pushState(GUIState::Tag::MAIN_MENU);

View File

@ -40,8 +40,14 @@ void MainMenu::enter()
window_width / 3.f, window_height / 7.f});
button_editor->setCallback(_callbacks.onAppendEditorState);
auto button_about = std::make_shared<PushButton>("About", _core_factory, 48);
button_about->setRect(kku::Area<float>{window_width / 3.f, window_height / 7.f * 5,
window_width / 3.f, window_height / 7.f});
button_about->setCallback(_callbacks.onAppendAboutState);
_buttons->addChild(button_start);
_buttons->addChild(button_editor);
_buttons->addChild(button_about);
_buttons->setVisibility();
}

View File

@ -4,13 +4,18 @@
#include "musicsfml.h"
#include "textsfml.h"
#include "linesfml.h"
#include "spritesfml.h"
CoreFactorySFML::CoreFactorySFML(sf::RenderTarget * const render_target) :
_render_target(render_target)
{
auto gui_font = std::make_unique<sf::Font>();
gui_font->loadFromFile("SourceCodePro-Regular.ttf");
gui_font->loadFromFile("resources/SourceCodePro-Regular.ttf");
_font_holder.load(kku::Font::Id::GUI, std::move(gui_font));
auto menu_texture = std::make_unique<sf::Texture>();
menu_texture->loadFromFile("resources/gui-texture.png");
_texture_holder.load(kku::Texture::Id::GUI, std::move(menu_texture));
}
std::shared_ptr<kku::Music> CoreFactorySFML::getMusic() const
@ -33,6 +38,27 @@ std::shared_ptr<kku::Rectangle> CoreFactorySFML::getRectangle() const
return std::make_unique<LineSFML>(_render_target);
}
std::shared_ptr<kku::Sprite> CoreFactorySFML::getSprite(kku::GUISprite::Id id) const
{
const auto texture = _texture_holder.get(kku::Texture::Id::GUI);
switch (id)
{
default:
return nullptr;
break;
case kku::GUISprite::Id::SFML_LOGO:
return std::make_unique<SpriteSFML>(_render_target, _texture_holder.get(kku::Texture::Id::GUI),
kku::Area<unsigned int>{0, 0, 252, 81});
break;
case kku::GUISprite::Id::CRYPTOPP_LOGO:
return std::make_unique<SpriteSFML>(_render_target, _texture_holder.get(kku::Texture::Id::GUI),
kku::Area<unsigned int>{252, 0, 135, 36});
break;
}
}
kku::Vector2<std::size_t> CoreFactorySFML::getRenderSize() const
{
const sf::Vector2u size = _render_target->getSize();

View File

@ -3,6 +3,8 @@
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Texture.hpp>
#include "core/corefactory.h"
@ -14,9 +16,11 @@ public:
virtual std::shared_ptr<kku::Text> getText(kku::Font::Id id) const override;
virtual std::shared_ptr<kku::Rectangle> getRectangle() const override;
virtual std::shared_ptr<kku::Line> getLine() const override;
virtual std::shared_ptr<kku::Sprite> getSprite(kku::GUISprite::Id id) const override;
virtual kku::Vector2<std::size_t> getRenderSize() const override;
private:
sf::RenderTarget * const _render_target;
kku::ResourceHolder<sf::Font, kku::Font::Id> _font_holder;
kku::ResourceHolder<sf::Texture, kku::Texture::Id> _texture_holder;
};

View File

@ -0,0 +1,33 @@
#include "spritesfml.h"
SpriteSFML::SpriteSFML(sf::RenderTarget * const render_target,
const std::shared_ptr<sf::Texture>& texture,
const kku::Area<unsigned int> &cropping) :
_render_target(render_target),
_sprite(*texture, sf::IntRect(cropping.left, cropping.top, cropping.width, cropping.height))
{}
void SpriteSFML::setPosition(const kku::Point& position)
{
_sprite.setPosition(position.x, position.y);
}
kku::Point SpriteSFML::getPosition() const
{
const auto& position = _sprite.getPosition();
return kku::Point
{
position.x,
position.y
};
}
void SpriteSFML::move(const kku::Vector2<float>& delta)
{
_sprite.move({delta.first, delta.second});
}
void SpriteSFML::display() const
{
_render_target->draw(_sprite);
}

View File

@ -0,0 +1,25 @@
#pragma once
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <memory>
#include "core/sprite.h"
class SpriteSFML : public kku::Sprite
{
public:
explicit SpriteSFML(sf::RenderTarget * const render_target,
const std::shared_ptr<sf::Texture> &texture,
const kku::Area<unsigned int>& cropping);
virtual void setPosition(const kku::Point& position) override;
virtual kku::Point getPosition() const override;
virtual void move(const kku::Vector2<float>& delta) override;
virtual void display() const override;
protected:
sf::RenderTarget * const _render_target;
sf::Sprite _sprite;
};

View File

@ -10,13 +10,13 @@
#include <array>
class ClassicAnimationScenario;
class ClassicSprite;
class ClassicSelection;
class ClassicNoteGraphics;
class ClassicSelectionGraphics;
struct MockElement
{
std::shared_ptr<ClassicSprite> sprite;
std::shared_ptr<ClassicSelection> selection;
std::shared_ptr<ClassicNoteGraphics> sprite;
std::shared_ptr<ClassicSelectionGraphics> selection;
bool selected;
std::array<std::shared_ptr<ClassicAnimationScenario>, 5> animations;

View File

@ -1,7 +1,7 @@
#include "selectionmanager.h"
#include "classicmocknote.h"
#include "mockelement.h"
#include "graphics/classicselection.h"
#include "graphics/classicselectiongraphics.h"
#include <algorithm>
SelectionManager::SelectionManager() :

View File

@ -9,12 +9,12 @@
#include <vector>
#include <array>
class ClassicSprite;
class ClassicNoteGraphics;
class ClassicAnimationScenario;
struct ArrowElement
{
std::shared_ptr<ClassicSprite> sprite;
std::shared_ptr<ClassicNoteGraphics> sprite;
std::array<std::shared_ptr<ClassicAnimationScenario>, 5> animations;
kku::SystemEvent::Key::Code pressed_as = kku::SystemEvent::Key::Code::Unknown;

View File

@ -4,19 +4,19 @@
#include <memory>
class ClassicSprite;
class ClassicNoteGraphics;
class ClassicAnimationScenario
{
public:
virtual ~ClassicAnimationScenario() = default;
virtual void launch(const std::shared_ptr<ClassicSprite> sprite, const kku::microsec& time_begin, const kku::microsec &time_end) = 0;
virtual void launch(const std::shared_ptr<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec &time_end) = 0;
virtual void update(const kku::microsec& music_offset) = 0;
virtual bool isDone() const = 0;
protected:
std::shared_ptr<ClassicSprite> _sprite;
std::shared_ptr<ClassicNoteGraphics> _sprite;
kku::microsec _time_begin;
kku::microsec _time_end;
};

View File

@ -1,7 +1,7 @@
#include "classicdyinganimationscenario.h"
#include "graphics/classicsprite.h"
#include "graphics/classicnotegraphics.h"
void ClassicDyingAnimationScenario::launch(const std::shared_ptr<ClassicSprite> sprite, const kku::microsec& time_begin, const kku::microsec &time_end)
void ClassicDyingAnimationScenario::launch(const std::shared_ptr<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec &time_end)
{
_sprite = sprite;
_time_begin = time_begin;

View File

@ -5,7 +5,7 @@
class ClassicDyingAnimationScenario : public ClassicAnimationScenario
{
public:
virtual void launch(const std::shared_ptr<ClassicSprite> sprite, const kku::microsec& time_begin, const kku::microsec& time_end) override;
virtual void launch(const std::shared_ptr<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec& time_end) override;
virtual void update(const kku::microsec& music_offset) override;
virtual bool isDone() const override;
};

View File

@ -1,7 +1,7 @@
#include "classicflyinganimationscenario.h"
#include "graphics/classicsprite.h"
#include "graphics/classicnotegraphics.h"
void ClassicFlyingAnimationScenario::launch(const std::shared_ptr<ClassicSprite> sprite, const kku::microsec& time_begin, const kku::microsec &time_end)
void ClassicFlyingAnimationScenario::launch(const std::shared_ptr<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec &time_end)
{
_sprite = sprite;
_time_begin = time_begin;

View File

@ -6,7 +6,7 @@
class ClassicFlyingAnimationScenario : public ClassicAnimationScenario
{
public:
virtual void launch(const std::shared_ptr<ClassicSprite> sprite, const kku::microsec& time_begin, const kku::microsec& time_end) override;
virtual void launch(const std::shared_ptr<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec& time_end) override;
virtual void update(const kku::microsec& music_offset) override;
virtual bool isDone() const override;

View File

@ -43,14 +43,14 @@ auto ClassicGraphicsFactory::generate(Type type) const -> SpriteData
return SpriteData{shape, trail, color};
}
std::shared_ptr<ClassicSprite> ClassicGraphicsFactory::createSprite(Type type) const
std::shared_ptr<ClassicNoteGraphics> ClassicGraphicsFactory::createSprite(Type type) const
{
const auto data = generate(type);
return std::make_shared<ClassicSprite>(ClassicSprite::Init{data.shape, data.trail, data.color});
return std::make_shared<ClassicNoteGraphics>(ClassicNoteGraphics::Init{data.shape, data.trail, data.color});
}
std::shared_ptr<ClassicSelection> ClassicGraphicsFactory::createSelection() const
std::shared_ptr<ClassicSelectionGraphics> ClassicGraphicsFactory::createSelection() const
{
const auto shape = _core_factory->getRectangle();
return std::make_shared<ClassicSelection>(ClassicSelection::Init{shape, kku::Color{51, 153, 255, 120}});
return std::make_shared<ClassicSelectionGraphics>(ClassicSelectionGraphics::Init{shape, kku::Color{51, 153, 255, 120}});
}

View File

@ -3,8 +3,8 @@
#include <memory>
#include "classicmode/classicactions.h"
#include "graphics/classicsprite.h"
#include "graphics/classicselection.h"
#include "graphics/classicnotegraphics.h"
#include "graphics/classicselectiongraphics.h"
#include "core/rectangle.h"
#include "core/corefactory.h"
@ -13,8 +13,8 @@ class ClassicGraphicsFactory
public:
explicit ClassicGraphicsFactory(const std::shared_ptr<kku::CoreFactory>& core_factory);
std::shared_ptr<ClassicSprite> createSprite(Type type) const;
std::shared_ptr<ClassicSelection> createSelection() const;
std::shared_ptr<ClassicNoteGraphics> createSprite(Type type) const;
std::shared_ptr<ClassicSelectionGraphics> createSelection() const;
private:
const std::shared_ptr<kku::CoreFactory> _core_factory;

View File

@ -0,0 +1,70 @@
#include "classicnotegraphics.h"
ClassicNoteGraphics::ClassicNoteGraphics(ClassicNoteGraphics::Init&& init) :
_reset_color(init.color),
_shape(init.shape),
_trail(init.trail)
{
_shape->setColor(init.color);
_trail->setColor(init.color);
}
void ClassicNoteGraphics::reset()
{
_shape->setPosition(kku::Point{0, 0});
_trail->setPosition(kku::Point{0, 0});
_shape->setColor(_reset_color);
_trail->setColor(_reset_color);
}
void ClassicNoteGraphics::setPosition(const kku::Point& position)
{
_shape->setPosition(position);
}
void ClassicNoteGraphics::setTrailPosition(const kku::Point &position)
{
_trail->setPosition(position);
}
kku::Point ClassicNoteGraphics::getPosition() const
{
return _shape->getPosition();
}
kku::Point ClassicNoteGraphics::getTrailPosition() const
{
return _trail->getPosition();
}
void ClassicNoteGraphics::setColor(const kku::Color& color)
{
_shape->setColor(color);
}
void ClassicNoteGraphics::setTrailColor(const kku::Color& color)
{
_trail->setColor(color);
}
kku::Color ClassicNoteGraphics::getColor() const
{
return _shape->getColor();
}
kku::Color ClassicNoteGraphics::getTrailColor() const
{
return _trail->getColor();
}
void ClassicNoteGraphics::display() const
{
_shape->display();
_trail->display();
}
std::shared_ptr<const kku::Rectangle> ClassicNoteGraphics::getRectangle() const
{
return _shape;
}

View File

@ -0,0 +1,41 @@
#pragma once
#include "core/sprite.h"
#include "core/point.h"
#include "core/color.h"
#include "core/rectangle.h"
#include <memory>
class ClassicNoteGraphics
{
public:
struct Init
{
std::shared_ptr<kku::Rectangle> shape;
std::shared_ptr<kku::Rectangle> trail;
kku::Color color;
};
ClassicNoteGraphics(ClassicNoteGraphics::Init&& init);
void reset();
void display() const;
void setPosition(const kku::Point &position);
void setTrailPosition(const kku::Point &position);
kku::Point getPosition() const;
kku::Point getTrailPosition() const;
void setColor(const kku::Color& color);
void setTrailColor(const kku::Color& color);
kku::Color getColor() const;
kku::Color getTrailColor() const;
std::shared_ptr<const kku::Rectangle> getRectangle() const;
protected:
kku::Color _reset_color;
std::shared_ptr<kku::Rectangle> _shape;
std::shared_ptr<kku::Rectangle> _trail;
};

View File

@ -48,7 +48,7 @@ public:
for (auto it = _first; it != _last; ++it)
{
display((*it)->getElements());
//display((*it)->getElements());
}
}
@ -139,8 +139,8 @@ public:
element.sprite->setPosition(element.position);
element.sprite->setTrailPosition(kku::Point( 0.f, 9.f ));
element.selection = _factory->createSelection();
element.selection->adjustTo(element.sprite);
//element.selection = _factory->createSelection();
//element.selection->adjustTo(element.sprite);
element.animations[ClassicNote::State::NONE] = nullptr;
element.animations[ClassicNote::State::FLYING] = std::make_shared<ClassicFlyingAnimationScenario>();
@ -165,7 +165,7 @@ public:
}
protected:
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicSprite> _sprite_container;
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container;
const std::shared_ptr<const ClassicGraphicsFactory> _factory;
typedef typename std::set<TNote*>::const_iterator Iterator;
@ -207,7 +207,7 @@ protected:
&& offset <= note->getPerfectOffset())
{
note->setState(ClassicNote::State::FLYING);
setGraphics(note, kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
//setGraphics(note, kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
}
}
else
@ -242,7 +242,7 @@ protected:
&& offset <= note->getPerfectOffset())
{
note->setState(ClassicNote::State::FLYING);
note->setGraphics(this, kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
//note->setGraphics(this, kku::TimeRange{note->getPerfectOffset() - _visibility_offset, note->getPerfectOffset()});
}
++note_iterator;

View File

@ -1,25 +0,0 @@
#include "classicselection.h"
#include "classicsprite.h"
ClassicSelection::ClassicSelection(ClassicSelection::Init&& init) :
_fill_color(init.color),
_shape(init.shape)
{
_shape->setColor(init.color);
}
void ClassicSelection::reset()
{
_shape->setPosition(kku::Point{0, 0});
_shape->setColor(kku::Color{51, 153, 255, 120});
}
void ClassicSelection::display() const
{
_shape->display();
}
void ClassicSelection::adjustTo(const std::shared_ptr<ClassicSprite>& sprite)
{
_shape->setRect(sprite->getRectangle()->getRect());
}

View File

@ -0,0 +1,25 @@
#include "classicselectiongraphics.h"
#include "classicnotegraphics.h"
ClassicSelectionGraphics::ClassicSelectionGraphics(ClassicSelectionGraphics::Init&& init) :
_fill_color(init.color),
_shape(init.shape)
{
_shape->setColor(init.color);
}
void ClassicSelectionGraphics::reset()
{
_shape->setPosition(kku::Point{0, 0});
_shape->setColor(kku::Color{51, 153, 255, 120});
}
void ClassicSelectionGraphics::display() const
{
_shape->display();
}
void ClassicSelectionGraphics::adjustTo(const std::shared_ptr<ClassicNoteGraphics>& sprite)
{
_shape->setRect(sprite->getRectangle()->getRect());
}

View File

@ -6,9 +6,9 @@
#include <memory>
class ClassicSprite;
class ClassicNoteGraphics;
class ClassicSelection : public kku::Sprite
class ClassicSelectionGraphics
{
public:
@ -18,11 +18,11 @@ public:
kku::Color color;
};
explicit ClassicSelection(ClassicSelection::Init&& init);
virtual void reset() override;
virtual void display() const override;
explicit ClassicSelectionGraphics(ClassicSelectionGraphics::Init&& init);
void reset();
void display() const;
void adjustTo(const std::shared_ptr<ClassicSprite>& sprite);
void adjustTo(const std::shared_ptr<ClassicNoteGraphics>& sprite);
protected:
kku::Color _fill_color;

View File

@ -1,70 +0,0 @@
#include "classicsprite.h"
ClassicSprite::ClassicSprite(ClassicSprite::Init&& init) :
_reset_color(init.color),
_shape(init.shape),
_trail(init.trail)
{
_shape->setColor(init.color);
_trail->setColor(init.color);
}
void ClassicSprite::reset()
{
_shape->setPosition(kku::Point{0, 0});
_trail->setPosition(kku::Point{0, 0});
_shape->setColor(_reset_color);
_trail->setColor(_reset_color);
}
void ClassicSprite::setPosition(const kku::Point& position)
{
_shape->setPosition(position);
}
void ClassicSprite::setTrailPosition(const kku::Point &position)
{
_trail->setPosition(position);
}
kku::Point ClassicSprite::getPosition() const
{
return _shape->getPosition();
}
kku::Point ClassicSprite::getTrailPosition() const
{
return _trail->getPosition();
}
void ClassicSprite::setColor(const kku::Color& color)
{
_shape->setColor(color);
}
void ClassicSprite::setTrailColor(const kku::Color& color)
{
_trail->setColor(color);
}
kku::Color ClassicSprite::getColor() const
{
return _shape->getColor();
}
kku::Color ClassicSprite::getTrailColor() const
{
return _trail->getColor();
}
void ClassicSprite::display() const
{
_shape->display();
_trail->display();
}
std::shared_ptr<const kku::Rectangle> ClassicSprite::getRectangle() const
{
return _shape;
}

View File

@ -1,41 +0,0 @@
#pragma once
#include "core/sprite.h"
#include "core/point.h"
#include "core/color.h"
#include "core/rectangle.h"
#include <memory>
class ClassicSprite : public kku::Sprite
{
public:
struct Init
{
std::shared_ptr<kku::Rectangle> shape;
std::shared_ptr<kku::Rectangle> trail;
kku::Color color;
};
explicit ClassicSprite(ClassicSprite::Init&& init);
virtual void reset() override;
virtual void display() const override;
virtual void setPosition(const kku::Point &position);
virtual void setTrailPosition(const kku::Point &position);
virtual kku::Point getPosition() const;
virtual kku::Point getTrailPosition() const;
virtual void setColor(const kku::Color& color);
virtual void setTrailColor(const kku::Color& color);
virtual kku::Color getColor() const;
virtual kku::Color getTrailColor() const;
std::shared_ptr<const kku::Rectangle> getRectangle() const;
protected:
kku::Color _reset_color;
std::shared_ptr<kku::Rectangle> _shape;
std::shared_ptr<kku::Rectangle> _trail;
};

View File

@ -1,121 +0,0 @@
#include "classictimelinegraphicsmanager.h"
#include "editor/mockelement.h"
#include "game/arrowelement.h"
ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicGraphicsFactory>& factory,
const kku::microsec& visibility_offset) :
ClassicGraphicsManager(visibility_offset),
_sprite_container({Type::UP, Type::DOWN,
Type::LEFT, Type::RIGHT},
factory),
_factory(factory),
_timeline(timeline)
{
}
void ClassicTimelineGraphicsManager::input(kku::GameEvent&& input)
{
(void)input;
}
void ClassicTimelineGraphicsManager::display() const
{
if (nothingToDraw())
return;
}
void ClassicTimelineGraphicsManager::update(const kku::microsec &offset)
{
fetchLastNote(offset);
fetchFirstNote(offset);
updateVisibleNotes(offset);
}
void ClassicTimelineGraphicsManager::display(const std::vector<ArrowElement>& elements) const
{
for (std::size_t i = 0; i < elements.size(); ++i)
{
const auto& sprite = elements[i].sprite;
if (i >= 1)
{
//const auto& neighbor_sprite = elements[i - 1].sprite;
//const auto c1 = neighbor_sprite->trailPosition();
//const auto c2 = sprite->trailPosition();
//_render_target->draw(makeLine(c1, c2));
}
sprite->display();
}
}
void ClassicTimelineGraphicsManager::setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange &&range)
{
(void)elements; (void)range;
}
void ClassicTimelineGraphicsManager::display(const std::vector<MockElement>& elements) const
{
for (std::size_t i = 0; i < elements.size(); ++i)
{
const auto& sprite = elements[i].sprite;
if (i >= 1)
{
//const auto& neighbor_sprite = elements[i - 1].sprite;
//const auto c1 = neighbor_sprite->trailPosition();
//const auto c2 = sprite->trailPosition();
//_render_target->draw(makeLine(c1, c2));
}
sprite->display();
}
}
void ClassicTimelineGraphicsManager::setGraphics(std::vector<MockElement>& elements, kku::TimeRange &&range)
{
(void)elements; (void)range;
}
/*sf::VertexArray ClassicSceneGraphicsSFML::makeLine(const kku::Point& c1, const kku::Point& c2) const
{
sf::VertexArray line(sf::LinesStrip, 2);
line[0].color = sf::Color::Yellow;
line[0].position = {c1.x + 10, c1.y};
line[1].color = sf::Color::Blue;
line[1].position = {c2.x + 10, c2.y};
return line;
}*/
void ClassicTimelineGraphicsManager::updateVisibleNotes(const kku::microsec &offset)
{
(void)offset;
}
void ClassicTimelineGraphicsManager::fetchFirstNote(const kku::microsec& offset)
{
(void)offset; // ????
}
void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& offset)
{
(void)offset; // ????
}
bool ClassicTimelineGraphicsManager::nothingToDraw() const noexcept
{
return true;
}
bool ClassicTimelineGraphicsManager::isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept
{
return note && music_offset;
}

View File

@ -1,42 +0,0 @@
#pragma once
#include "classicmode/classicnote.h"
#include "graphics/classicgraphicsmanager.h"
#include "graphics/classicgraphicsfactory.h"
#include "core/timeline.h"
#include "core/spritecontainer.h"
class ClassicSprite;
class ClassicTimelineGraphicsManager : public ClassicGraphicsManager
{
public:
explicit ClassicTimelineGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicGraphicsFactory>& factory,
const kku::microsec& visibility_offset);
virtual void input(kku::GameEvent&& input) override;
virtual void display() const override;
virtual void update(const kku::microsec& offset) override;
virtual void display(const std::vector<ArrowElement>& elements) const override;
virtual void setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange&& range) override;
virtual void display(const std::vector<MockElement>& elements) const override;
virtual void setGraphics(std::vector<MockElement>& elements, kku::TimeRange&& range) override;
protected:
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicSprite> _sprite_container;
const std::shared_ptr<const ClassicGraphicsFactory> _factory;
const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline;
inline bool nothingToDraw() const noexcept;
inline bool isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept;
//inline sf::VertexArray makeLine(const kku::Point& c1, const kku::Point& c2) const;
void fetchFirstNote(const kku::microsec& offset);
void fetchLastNote(const kku::microsec& offset);
void updateVisibleNotes(const kku::microsec& offset);
};