Tried to get camera to have a reset but couldn't figure out.
This commit is contained in:
parent
29409c54ce
commit
de7f9f3445
4 changed files with 37 additions and 34 deletions
|
|
@ -75,11 +75,7 @@ namespace boss {
|
||||||
void UI::zoom(const std::string &cell_name) {
|
void UI::zoom(const std::string &cell_name) {
|
||||||
auto& cell = $arena.$ui.cell_for(cell_name);
|
auto& cell = $arena.$ui.cell_for(cell_name);
|
||||||
|
|
||||||
$camera.resize({BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2});
|
$camera.resize(BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2);
|
||||||
$camera.move($view_texture,
|
$camera.move(float(cell.mid_x), float(cell.mid_y));
|
||||||
{float(cell.x/2), float(cell.y/2)});
|
|
||||||
|
|
||||||
// BUG: do I need this?
|
|
||||||
// $view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
29
camera.cpp
29
camera.cpp
|
|
@ -32,32 +32,35 @@ namespace cinematic {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::resize(sf::Vector2f to) {
|
void Camera::resize(float width, float height) {
|
||||||
size = to;
|
size = {width, height};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::style(const std::string &name) {
|
void Camera::style(const std::string &name) {
|
||||||
anim = MGR.animations.at(name);
|
anim = MGR.animations.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::focus(float x, float y) {
|
void Camera::position(float x, float y) {
|
||||||
position.x = x;
|
aimed_at = {x, y};
|
||||||
position.y = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) {
|
void Camera::move(float x, float y) {
|
||||||
sf::View zoom;
|
going_to = {x, y};
|
||||||
|
|
||||||
// BUG: annoying special case
|
// BUG: annoying special case
|
||||||
if(anim.motion == ease::SLIDE) {
|
if(anim.motion == ease::SLIDE) {
|
||||||
anim.min_x = position.x;
|
anim.min_x = aimed_at.x;
|
||||||
anim.min_y = position.y;
|
anim.min_y = aimed_at.y;
|
||||||
anim.max_x = pos.x;
|
anim.max_x = going_to.x;
|
||||||
anim.max_y = pos.y;
|
anim.max_y = going_to.y;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
anim.apply(zoom, pos, size);
|
void Camera::render(sf::RenderTexture& target) {
|
||||||
target.setView(zoom);
|
if(anim.playing) {
|
||||||
|
anim.apply(view, going_to, size);
|
||||||
|
target.setView(view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Camera::playing() {
|
bool Camera::playing() {
|
||||||
|
|
|
||||||
12
camera.hpp
12
camera.hpp
|
|
@ -6,16 +6,18 @@ namespace cinematic {
|
||||||
struct Camera {
|
struct Camera {
|
||||||
components::Animation anim;
|
components::Animation anim;
|
||||||
sf::View view;
|
sf::View view;
|
||||||
sf::Vector2f size;
|
sf::Vector2f size{SCREEN_WIDTH, SCREEN_WIDTH};
|
||||||
sf::Vector2f position;
|
sf::Vector2f aimed_at{0,0};
|
||||||
|
sf::Vector2f going_to{0,0};
|
||||||
|
|
||||||
Camera();
|
Camera();
|
||||||
|
|
||||||
void resize(sf::Vector2f size);
|
void resize(float width, float height);
|
||||||
void move(sf::RenderTexture& target, sf::Vector2f pos);
|
void position(float x, float y);
|
||||||
|
void move(float x, float y);
|
||||||
bool playing();
|
bool playing();
|
||||||
|
void render(sf::RenderTexture& target);
|
||||||
void play();
|
void play();
|
||||||
void focus(float x, float y);
|
|
||||||
void style(const std::string &name);
|
void style(const std::string &name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,25 +26,28 @@ namespace storyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::render(sf::RenderWindow &window) {
|
void UI::render(sf::RenderWindow &window) {
|
||||||
if($camera.playing()) {
|
|
||||||
zoom($zoom_target);
|
|
||||||
}
|
|
||||||
|
|
||||||
$view_texture.clear();
|
$view_texture.clear();
|
||||||
|
|
||||||
|
$camera.render($view_texture);
|
||||||
$ui.render($view_texture);
|
$ui.render($view_texture);
|
||||||
$ui.debug_layout($view_texture);
|
$ui.debug_layout($view_texture);
|
||||||
|
|
||||||
$view_texture.display();
|
$view_texture.display();
|
||||||
window.draw($view_sprite);
|
window.draw($view_sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UI::mouse(float x, float y, guecs::Modifiers mods) {
|
bool UI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||||
auto& cell = $ui.cell_for($zoom_target);
|
auto& cell = $ui.cell_for($zoom_target);
|
||||||
$camera.focus(cell.mid_x, cell.mid_y);
|
|
||||||
|
|
||||||
$zoom_target = *$ui.$parser.hit(x, y);
|
$zoom_target = *$ui.$parser.hit(x, y);
|
||||||
|
|
||||||
zoom($zoom_target);
|
if($zoom_target == "a") {
|
||||||
$camera.play();
|
reset();
|
||||||
|
} else {
|
||||||
|
$camera.position(cell.mid_x, cell.mid_y);
|
||||||
|
zoom($zoom_target);
|
||||||
|
$camera.play();
|
||||||
|
}
|
||||||
|
|
||||||
return $ui.mouse(x, y, mods);
|
return $ui.mouse(x, y, mods);
|
||||||
}
|
}
|
||||||
|
|
@ -52,9 +55,8 @@ namespace storyboard {
|
||||||
void UI::zoom(const std::string &cell_name) {
|
void UI::zoom(const std::string &cell_name) {
|
||||||
auto& cell = $ui.cell_for(cell_name);
|
auto& cell = $ui.cell_for(cell_name);
|
||||||
|
|
||||||
$camera.resize({float(cell.w), float(cell.h)});
|
$camera.resize(float(cell.w), float(cell.h));
|
||||||
$camera.move($view_texture,
|
$camera.move(float(cell.mid_x), float(cell.mid_y));
|
||||||
{float(cell.mid_x), float(cell.mid_y)});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::reset() {
|
void UI::reset() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue