use nightshade_api::prelude::*;
struct Scene {
cube: Entity,
red_button: Entity,
blue_button: Entity,
burst_button: Entity,
status: Entity,
}
fn main() {
run(setup, update).unwrap();
}
fn setup(world: &mut World) -> Scene {
set_window_title(world, "World-space UI");
set_background(world, Background::Space);
show_grid(world, true);
point_light(world, vec3(2.0, 4.0, 4.0), [1.0, 0.9, 0.7], 8.0);
spawn_floor(world, 10.0);
let cube = spawn_cube(world, vec3(0.0, 0.6, 2.5));
set_color(world, cube, GRAY);
let panel = spawn_world_panel(
world,
vec3(0.0, 2.2, 0.0),
3.2,
1.8,
rgba(0.05, 0.06, 0.1, 0.9),
);
set_rotation(world, panel, Vec3::y(), 0.35);
let title = world_panel_label(world, panel, "Cube control", -1.3, 0.6);
set_text_color(world, title, WHITE);
let red_button = world_panel_button(world, panel, -0.9, 0.0, 0.7, 0.4, RED);
world_panel_label(world, panel, "Red", -1.05, 0.0);
let blue_button = world_panel_button(world, panel, 0.0, 0.0, 0.7, 0.4, BLUE);
world_panel_label(world, panel, "Blue", -0.15, 0.0);
let burst_button = world_panel_button(world, panel, 0.9, 0.0, 0.7, 0.4, GOLD);
world_panel_label(world, panel, "Burst", 0.72, 0.0);
let status = spawn_text(
world,
"Click a button in the scene",
ScreenAnchor::BottomCenter,
);
set_text_color(world, status, WHITE);
Scene {
cube,
red_button,
blue_button,
burst_button,
status,
}
}
fn update(world: &mut World, scene: &mut Scene) {
if world_button_hovered(world, scene.burst_button) {
set_text(world, scene.status, "Burst ready");
}
if world_button_clicked(world, scene.red_button) {
set_color(world, scene.cube, RED);
set_text(world, scene.status, "Cube set to red");
}
if world_button_clicked(world, scene.blue_button) {
set_color(world, scene.cube, BLUE);
set_text(world, scene.status, "Cube set to blue");
}
if world_button_clicked(world, scene.burst_button) {
let at = position(world, scene.cube);
emit_burst(world, at + vec3(0.0, 0.5, 0.0), GOLD, 48);
set_text(world, scene.status, "Burst!");
}
}