Implement note decorators

This commit is contained in:
NaiJi ✨ 2022-08-07 09:26:55 +03:00
parent 4b91146c33
commit 03d1b39331
20 changed files with 172 additions and 84 deletions

View File

@ -139,7 +139,7 @@ void EditorState::enter()
test_menu->addPushButton(bpm_button);
test_menu->addCascadeButton(test_cascade_button);
test_menu->addPushButton(quit_button);
//test_menu->addPushButton(quit_button);
test_cascade_button->resetRect();

View File

@ -2,7 +2,7 @@
#include "game/classicarrownote.h"
#include "graphics/animations/classicanimationscenario.h"
#include "graphics/classicgraphicsmanager.h"
#include "graphics/classicnotegraphics.h"
#include "graphics/notegraphics/notegraphics.h"
EditorContext::EditorContext(const std::shared_ptr<SelectionManager<ClassicNote>>& selection_manager,
std::vector<std::shared_ptr<ClassicGraphicsManager>>&& graphics_managers) :

View File

@ -60,12 +60,6 @@ public:
return _multiselection_enabled;
}
void apply(const std::function<void(T*)>& function)
{
for (auto& thing : _selected_things)
function(thing);
}
private:
std::vector<T*> _selected_things;
bool _multiselection_enabled;

View File

@ -3,18 +3,18 @@
#include "classicmode/classicactions.h"
#include "core/gameevent.h"
#include "core/point.h"
#include "core/point.h"
#include <memory>
#include <vector>
#include <array>
class ClassicNoteGraphics;
class NoteGraphics;
class ClassicAnimationScenario;
struct ArrowElement
{
std::shared_ptr<ClassicNoteGraphics> sprite;
std::shared_ptr<NoteGraphics> 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 ClassicNoteGraphics;
class NoteGraphics;
class ClassicAnimationScenario
{
public:
virtual ~ClassicAnimationScenario() = default;
virtual void launch(const std::shared_ptr<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec &time_end) = 0;
virtual void launch(const std::shared_ptr<NoteGraphics> 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<ClassicNoteGraphics> _sprite;
std::shared_ptr<NoteGraphics> _sprite;
kku::microsec _time_begin;
kku::microsec _time_end;
};

View File

@ -1,7 +1,7 @@
#include "classicdyinganimationscenario.h"
#include "graphics/classicnotegraphics.h"
#include "graphics/notegraphics/notegraphics.h"
void ClassicDyingAnimationScenario::launch(const std::shared_ptr<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec &time_end)
void ClassicDyingAnimationScenario::launch(const std::shared_ptr<NoteGraphics> 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<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec& time_end) override;
virtual void launch(const std::shared_ptr<NoteGraphics> 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/classicnotegraphics.h"
#include "graphics/notegraphics/notegraphics.h"
void ClassicFlyingAnimationScenario::launch(const std::shared_ptr<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec &time_end)
void ClassicFlyingAnimationScenario::launch(const std::shared_ptr<NoteGraphics> 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<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec& time_end) override;
virtual void launch(const std::shared_ptr<NoteGraphics> 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

@ -41,10 +41,10 @@ auto ClassicGraphicsFactory::generate(Type type) const -> SpriteData
return SpriteData{shape, trail, color};
}
std::shared_ptr<ClassicNoteGraphics> ClassicGraphicsFactory::createSprite(Type type) const
std::shared_ptr<NoteGraphics> ClassicGraphicsFactory::createSprite(Type type) const
{
const auto data = generate(type);
return std::make_shared<ClassicNoteGraphics>(ClassicNoteGraphics::Init{data.shape, data.trail, data.color});
return std::make_shared<ClassicContentGraphics>(NoteGraphics::Init{data.shape, data.trail, data.color});
}
std::shared_ptr<ClassicSelectionGraphics> ClassicGraphicsFactory::createSelection() const

View File

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

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 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

@ -30,7 +30,7 @@ public:
protected:
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container;
kku::SpriteContainer<Type, ClassicGraphicsFactory, NoteGraphics> _sprite_container;
const std::shared_ptr<const ClassicGraphicsFactory> _factory;
typedef typename std::set<ClassicNote*>::const_iterator Iterator;

View File

@ -1,5 +1,5 @@
#include "classicselectiongraphics.h"
#include "classicnotegraphics.h"
#include "graphics/notegraphics/notegraphics.h"
ClassicSelectionGraphics::ClassicSelectionGraphics(ClassicSelectionGraphics::Init&& init) :
_fill_color(init.color),
@ -19,7 +19,7 @@ void ClassicSelectionGraphics::display() const
_shape->display();
}
void ClassicSelectionGraphics::adjustTo(const std::shared_ptr<ClassicNoteGraphics>& sprite)
void ClassicSelectionGraphics::adjustTo(const std::shared_ptr<NoteGraphics>& sprite)
{
_shape->setRect(sprite->getRectangle()->getRect());
}

View File

@ -6,7 +6,7 @@
#include <memory>
class ClassicNoteGraphics;
class NoteGraphics;
class ClassicSelectionGraphics
{
@ -22,7 +22,7 @@ public:
void reset();
void display() const;
void adjustTo(const std::shared_ptr<ClassicNoteGraphics>& sprite);
void adjustTo(const std::shared_ptr<NoteGraphics> &sprite);
protected:
kku::Color _fill_color;

View File

@ -26,7 +26,7 @@ public:
virtual void draw(const ClassicArrowNote * const note) const override;
protected:
kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container;
kku::SpriteContainer<Type, ClassicGraphicsFactory, NoteGraphics> _sprite_container;
const std::shared_ptr<const ClassicGraphicsFactory> _factory;
typedef typename std::set<ClassicNote*>::const_iterator Iterator;

View File

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

View File

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

View File

@ -0,0 +1,71 @@
#pragma once
#include "notegraphics.h"
#include <memory>
class NoteDecoratorGraphics : public NoteGraphics
{
public:
virtual ~NoteDecoratorGraphics() override = 0;
explicit NoteDecoratorGraphics(const std::shared_ptr<NoteGraphics>& decorated_graphics)
: _decorated_graphics(decorated_graphics)
{}
virtual void reset() override
{
_decorated_graphics->reset();
}
virtual void display() const override
{
_decorated_graphics->display();
}
virtual void setPosition(const kku::Point &position) override
{
_decorated_graphics->setPosition(position);
}
virtual void setTrailPosition(const kku::Point &position) override
{
_decorated_graphics->setTrailPosition(position);
}
virtual kku::Point getPosition() const override
{
return _decorated_graphics->getPosition();
}
virtual kku::Point getTrailPosition() const override
{
return _decorated_graphics->getTrailPosition();
}
virtual void setColor(const kku::Color& color) override
{
_decorated_graphics->setColor(color);
}
virtual void setTrailColor(const kku::Color& color) override
{
_decorated_graphics->setTrailColor(color);
}
virtual kku::Color getColor() const override
{
return _decorated_graphics->getColor();
}
virtual kku::Color getTrailColor() const override
{
return _decorated_graphics->getTrailColor();
}
virtual std::shared_ptr<const kku::Rectangle> getRectangle() const override
{
return _decorated_graphics->getRectangle();
}
private:
const std::shared_ptr<NoteGraphics> _decorated_graphics;
};

View File

@ -0,0 +1,27 @@
#pragma once
#include "core/point.h"
#include "core/color.h"
#include "core/rectangle.h"
#include <memory>
class NoteGraphics
{
public:
virtual ~NoteGraphics() = default;
virtual void reset() = 0;
virtual void display() const = 0;
virtual void setPosition(const kku::Point& position) = 0;
virtual void setTrailPosition(const kku::Point& position) = 0;
virtual kku::Point getPosition() const = 0;
virtual kku::Point getTrailPosition() const = 0;
virtual void setColor(const kku::Color& color) = 0;
virtual void setTrailColor(const kku::Color& color) = 0;
virtual kku::Color getColor() const = 0;
virtual kku::Color getTrailColor() const = 0;
virtual std::shared_ptr<const kku::Rectangle> getRectangle() const = 0;
};