Galactica/content/ui/landed.rhai

91 lines
1.6 KiB
Plaintext
Raw Normal View History

2024-02-03 11:24:17 -08:00
fn config() {
let config = SceneConfig();
config.show_starfield(true);
config.show_phys(false);
return config
}
2024-02-02 16:45:23 -08:00
fn init(state) {
let frame = SpriteBuilder(
"frame",
"ui::planet",
Rect(
0.0, 0.0, 400.0, 297.866,
SpriteAnchor::Center,
SpriteAnchor::Center
)
);
let landscape = SpriteBuilder(
"landscape",
2024-02-03 11:24:17 -08:00
"ui::landscape::test",
2024-02-02 16:45:23 -08:00
Rect(
-180.0, 142.0, 274.0, 135.0,
SpriteAnchor::NorthWest,
SpriteAnchor::Center
)
);
landscape.set_mask("ui::landscapemask");
let button = SpriteBuilder(
"button",
"ui::planet::button",
Rect(
99.0, 128.0, 73.898, 18.708,
SpriteAnchor::NorthWest,
SpriteAnchor::Center
)
);
let title = TextBoxBuilder(
"title",
10.0, 10.0, TextBoxFont::Serif, TextBoxJustify::Center,
Rect(
-70.79, 138.0, 59.867, 10.0,
SpriteAnchor::NorthWest,
SpriteAnchor::Center
)
);
2024-02-03 11:24:17 -08:00
title.set_text("Title");
2024-02-02 16:45:23 -08:00
return [
button,
landscape,
frame,
title,
];
}
2024-02-03 11:24:17 -08:00
fn event(state, event) {
if type_of(event) == "MouseHoverEvent" {
let element = event.element();
if element.has_name("button") {
if event.is_enter() {
element.take_edge("on:top", 0.1);
} else {
element.take_edge("off:top", 0.1);
}
2024-02-02 16:45:23 -08:00
}
2024-02-03 11:24:17 -08:00
return;
2024-02-02 16:45:23 -08:00
}
2024-02-03 11:24:17 -08:00
if type_of(event) == "MouseClickEvent" {
if !event.is_down() {
return SceneAction::None;
}
let element = event.element();
if element.has_name("button") {
return SceneAction::GoTo("outfitter");
}
return;
2024-02-02 22:19:06 -08:00
}
2024-02-03 11:24:17 -08:00
if type_of(event) == "PlayerShipStateEvent" {
if !state.player_ship().is_landed() {
return SceneAction::GoTo("flying");
}
return;
2024-02-02 22:19:06 -08:00
}
}