95 lines
2.3 KiB
C++
95 lines
2.3 KiB
C++
#include "storyboard/ui.hpp"
|
|
#include "components.hpp"
|
|
#include "animation.hpp"
|
|
#include "sound.hpp"
|
|
|
|
namespace storyboard {
|
|
UI::UI() :
|
|
$view_texture({SCREEN_WIDTH, SCREEN_HEIGHT}),
|
|
$view_sprite($view_texture.getTexture()),
|
|
$audio(sound::get_sound_pair("ambient_1").sound)
|
|
{
|
|
$view_sprite.setPosition({0, 0});
|
|
$camera.style("pan");
|
|
sound::play("ambient_1", true);
|
|
}
|
|
|
|
void UI::init() {
|
|
$ui.position(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
|
|
$ui.set<guecs::Background>($ui.MAIN, {$ui.$parser, guecs::THEME.TRANSPARENT});
|
|
|
|
auto& background = $ui.get<guecs::Background>($ui.MAIN);
|
|
background.set_sprite("test_story", true);
|
|
|
|
$ui.layout(
|
|
"[a|b|c]"
|
|
"[*%(200,100)d|_|f]"
|
|
"[g|h|i]");
|
|
|
|
for(auto& [key, value] : $ui.$parser.cells) {
|
|
$cell_names.push_back(key);
|
|
}
|
|
}
|
|
|
|
void UI::render(sf::RenderWindow &window) {
|
|
track_audio();
|
|
$view_texture.clear();
|
|
|
|
$camera.render($view_texture);
|
|
$ui.render($view_texture);
|
|
$ui.debug_layout($view_texture);
|
|
|
|
$view_texture.display();
|
|
window.draw($view_sprite);
|
|
}
|
|
|
|
void UI::track_audio() {
|
|
int track_head = int($audio->getPlayingOffset().asSeconds());
|
|
|
|
if(track_head % 3 == 0) {
|
|
if($moving) return;
|
|
$moving = true; // prevent motion until next tick
|
|
|
|
// get the original zoom target as from
|
|
auto& cell = $ui.cell_for($zoom_target);
|
|
$camera.position(cell.mid_x, cell.mid_y);
|
|
|
|
// get the new target from the cell names
|
|
$zoom_target = $cell_names.at(track_head % $cell_names.size());
|
|
zoom($zoom_target);
|
|
$camera.play();
|
|
} else {
|
|
$moving = false;
|
|
}
|
|
}
|
|
|
|
bool UI::mouse(float x, float y, guecs::Modifiers mods) {
|
|
auto& cell = $ui.cell_for($zoom_target);
|
|
|
|
$zoom_target = *$ui.$parser.hit(x, y);
|
|
|
|
if($zoom_target == "a") {
|
|
reset();
|
|
} else {
|
|
$camera.position(cell.mid_x, cell.mid_y);
|
|
zoom($zoom_target);
|
|
$camera.play();
|
|
}
|
|
|
|
return $ui.mouse(x, y, mods);
|
|
}
|
|
|
|
void UI::zoom(const std::string &cell_name) {
|
|
auto& cell = $ui.cell_for(cell_name);
|
|
|
|
$camera.resize(float(cell.w), float(cell.h));
|
|
$camera.move(float(cell.mid_x), float(cell.mid_y));
|
|
}
|
|
|
|
void UI::reset() {
|
|
sf::FloatRect where{{0,0},{SCREEN_WIDTH, SCREEN_HEIGHT}};
|
|
sf::View view{where};
|
|
$view_texture.setView(view);
|
|
}
|
|
}
|