forked from NaiJi/project-kyoku
parent
e580d45eef
commit
b92bffb43e
After Width: | Height: | Size: 24 KiB |
@ -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; |
||||
}; |
||||
|
@ -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); |
||||
} |
||||
|
@ -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); |
||||
} |
@ -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; |
||||
}; |
@ -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; |
||||
} |
@ -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; |
||||
}; |
@ -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()); |
||||
} |
@ -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()); |
||||
} |
@ -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; |
||||
} |
@ -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; |
||||
}; |
@ -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; |
||||
} |
@ -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); |
||||
}; |
Loading…
Reference in new issue