Icons now work way better and don't have the the 'Rayview cuts icons' bug. It actually was a bug in the lel-guecs Sprite class that was using the TextureRect from the source sprite. Now its initialized with the framesize from the .json. This also uses the new guecs::Icon, but I have to fix that as it doesn't scale correctly. Closes #2.

This commit is contained in:
Zed A. Shaw 2025-07-22 15:03:37 -04:00
parent b311713064
commit ff7111b006
22 changed files with 81 additions and 64 deletions

View file

@ -35,7 +35,7 @@ namespace gui {
$animation = $world->get<components::Animation>($boss_id);
$animation.frame_width = $sprite_config.width;
$boss_image = textures::get($sprite_config.name);
$boss_image = textures::get_sprite($sprite_config.name);
sf::IntRect frame_rect{{0,0},{$sprite_config.width,$sprite_config.height}};
$boss_image.sprite->setTextureRect(frame_rect);
$boss_image.sprite->setScale({$sprite_config.scale, $sprite_config.scale});
@ -52,13 +52,13 @@ namespace gui {
void BossFightUI::configure_background() {
auto& boss = $world->get<components::BossFight>($boss_id);
$boss_background = textures::get(boss.background);
$boss_background = textures::get_sprite(boss.background);
$boss_background.sprite->setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
$status.set<Background>($status.MAIN, {$status.$parser});
if(boss.stage) {
$boss_has_stage = true;
$boss_stage = textures::get(*boss.stage);
$boss_stage = textures::get_sprite(*boss.stage);
$boss_stage.sprite->setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
}
}

View file

@ -347,7 +347,6 @@ namespace gui {
if(!sound::playing("ambient_1")) sound::play("ambient_1", true);
$debug_ui.debug();
shaders::reload();
$map_ui.save_map($main_ui.$compass_dir);
break;
case KEY::O:
autowalking = true;

View file

@ -21,11 +21,9 @@ namespace guecs {
}
void GrabSource::setSprite(guecs::UI& gui, guecs::Entity gui_id) {
dbc::check(gui.has<guecs::Sprite>(gui_id), "GrabSource given sprite gui_id that doesn't exist");
dbc::check(gui.has<guecs::Icon>(gui_id), "GrabSource given sprite gui_id that doesn't exist");
fmt::println("> Grabsource Set sprite entity {}", world_entity);
auto& sp = gui.get<guecs::Sprite>(gui_id);
auto& sp = gui.get<guecs::Icon>(gui_id);
sprite = sp.sprite;
}

View file

@ -75,7 +75,7 @@ namespace gui {
dbc::check($level.world->has<components::Sprite>(item),
"item in inventory UI doesn't exist in world. New level?");
auto& sprite = $level.world->get<components::Sprite>(item);
$gui.set_init<guecs::Sprite>(id, {fmt::format("{}_ICON", sprite.name)});
$gui.set_init<guecs::Icon>(id, {sprite.name});
guecs::GrabSource grabber{
item, [&, id]() { return remove_slot(id); }};
@ -84,7 +84,7 @@ namespace gui {
} else {
// BUG: fix remove so it's safe to call on empty
if($gui.has<guecs::GrabSource>(id)) {
$gui.remove<guecs::Sprite>(id);
$gui.remove<guecs::Icon>(id);
$gui.remove<guecs::GrabSource>(id);
}

View file

@ -49,15 +49,6 @@ namespace gui {
$gui.init();
}
void MapViewUI::save_map(int compass_dir) {
(void)compass_dir;
// confirm we get two different maps
auto out_img = $map_render->getTexture().copyToImage();
bool worked = out_img.saveToFile("tmp/map_render.png");
dbc::check(worked, "failed to render map");
}
void MapViewUI::render(sf::RenderWindow &window, int compass_dir) {
$gui.render(window);
System::draw_map($level, $map_tiles, $entity_map);

View file

@ -24,6 +24,5 @@ namespace gui {
void update_level(GameLevel &level);
void log(std::wstring msg);
void update();
void save_map(int compass_dir);
};
}

View file

@ -44,7 +44,7 @@ namespace gui {
}
void UI::START(Event) {
$ritual_ui = textures::get("ritual_crafting_area");
$ritual_ui = textures::get_sprite("ritual_crafting_area");
$ritual_ui.sprite->setPosition($gui.get_position());
$ritual_ui.sprite->setTextureRect($ritual_closed_rect);
$ritual_anim = animation::load("ritual_blanket");

View file

@ -80,7 +80,7 @@ namespace gui {
auto gui_id = $gui.entity(slot);
auto& sprite = $level.world->get<components::Sprite>(world_entity);
$gui.set_init<guecs::Sprite>(gui_id, {fmt::format("{}_ICON", sprite.name)});
$gui.set_init<guecs::Icon>(gui_id, {sprite.name});
guecs::GrabSource grabber{ world_entity,
[&, gui_id]() { return remove_slot(gui_id); }};
grabber.setSprite($gui, gui_id);
@ -136,7 +136,7 @@ namespace gui {
inventory.remove(world_entity);
$gui.remove<guecs::GrabSource>(slot_id);
$gui.remove<guecs::Sprite>(slot_id);
$gui.remove<guecs::Icon>(slot_id);
}
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {