More refactoring of the gui. Now most things are out of the FSM and MainUI is responsible for the rayvew and its overlay.

This commit is contained in:
Zed A. Shaw 2025-02-21 00:50:54 -05:00
parent 23ed1594f2
commit dd4f77a106
6 changed files with 89 additions and 45 deletions

View file

@ -19,8 +19,7 @@ namespace gui {
$map_ui($level),
$combat_ui($level),
$status_ui($level),
$font{FONT_FILE_NAME},
$rayview($textures, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT)
$font{FONT_FILE_NAME}
{
$textures.load_tiles();
$textures.load_sprites();
@ -41,13 +40,11 @@ namespace gui {
}
void FSM::START(Event ) {
generate_map();
$main_ui.generate_map();
$level.world->set_the<Debug>({});
$rayview.init_shaders();
$rayview.set_position(RAY_VIEW_X, RAY_VIEW_Y);
$rayview.position_camera($player.x + 0.5, $player.y + 0.5);
$main_ui.render();
$main_ui.init();
$combat_ui.render($textures);
$status_ui.render($textures);
$status_ui.log("Welcome to the game!");
@ -79,8 +76,9 @@ namespace gui {
}
void FSM::MOVING(Event ) {
if($camera.play_move($rayview)) {
System::plan_motion(*$level.world, {size_t($camera.target_x), size_t($camera.target_y)});
// this should be an optional that returns a point
if($main_ui.play_move()) {
System::plan_motion(*$level.world, {size_t($main_ui.$camera.target_x), size_t($main_ui.$camera.target_y)});
run_systems();
state(State::IDLE);
}
@ -107,13 +105,13 @@ namespace gui {
}
void FSM::ROTATING(Event ) {
if($camera.play_rotate($rayview)) {
if($main_ui.play_rotate()) {
state(State::IDLE);
}
}
void FSM::COMBAT_ROTATE(Event ) {
if($camera.play_rotate($rayview)) {
if($main_ui.play_rotate()) {
state(State::IN_COMBAT);
}
}
@ -139,11 +137,11 @@ namespace gui {
try_move(-1, true);
break;
case ROTATE_LEFT:
$camera.plan_rotate($rayview, 1);
$main_ui.plan_rotate(1);
state(State::ROTATING);
break;
case ROTATE_RIGHT:
$camera.plan_rotate($rayview, -1);
$main_ui.plan_rotate(-1);
state(State::ROTATING);
break;
case MAP_OPEN:
@ -179,11 +177,11 @@ namespace gui {
state(State::ATTACKING);
break;
case ROTATE_LEFT:
$camera.plan_rotate($rayview, 1);
$main_ui.plan_rotate(1);
state(State::COMBAT_ROTATE);
break;
case ROTATE_RIGHT:
$camera.plan_rotate($rayview, -1);
$main_ui.plan_rotate(-1);
state(State::COMBAT_ROTATE);
break;
case STOP_COMBAT:
@ -202,13 +200,13 @@ namespace gui {
void FSM::try_move(int dir, bool strafe) {
using enum State;
// prevent moving into occupied space
Point move_to = $camera.plan_move($rayview, dir, strafe);
Point move_to = $main_ui.plan_move(dir, strafe);
if($level.map->can_move(move_to) && !$level.collision->occupied(move_to)) {
state(MOVING);
} else {
state(IDLE);
$camera.abort_plan($rayview);
$main_ui.abort_plan();
}
}
@ -262,7 +260,6 @@ namespace gui {
}
}
void FSM::draw_gui() {
$status_ui.draw($window);
$combat_ui.draw($window);
@ -275,14 +272,7 @@ namespace gui {
$map_ui.render();
$renderer.draw($map_ui);
} else {
auto start = std::chrono::high_resolution_clock::now();
$rayview.draw($window);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration<double>(end - start);
$main_ui.$stats.sample(1/elapsed.count());
draw_gui();
$main_ui.draw_blood();
}
$window.display();
@ -293,17 +283,10 @@ namespace gui {
sf::Vector2f pos = $window.mapPixelToCoords(sf::Mouse::getPosition($window));
$combat_ui.$gui.mouse(pos.x, pos.y);
$status_ui.$gui.mouse(pos.x, pos.y);
$main_ui.mouse(pos.x, pos.y);
}
}
void FSM::generate_map() {
// ZED: this should eventually go away now that level manager is in play
auto& player = $level.world->get_the<Player>();
auto& player_position = $level.world->get<Position>(player.entity);
$player = player_position.location;
$rayview.set_level($level);
}
void FSM::run_systems() {
System::enemy_pathing($level);
System::collision($level);
@ -361,8 +344,7 @@ namespace gui {
break;
case eGUI::DEATH: {
if(entity != player.entity) {
auto &sprite = $level.world->get<Sprite>(entity);
$rayview.update_sprite(entity, sprite);
$main_ui.dead_entity(entity);
}
} break;
case eGUI::NOOP: