Galactica/content/ui/landed.rhai

123 lines
2.1 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) {
2024-02-03 16:06:11 -08:00
let player = state.player_ship();
2024-02-02 16:45:23 -08:00
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 16:06:11 -08:00
{
if player.is_landed() {
player.landed_on().image();
} else {
"";
}
},
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(
2024-02-03 16:45:47 -08:00
"title", 10.0, 10.0,
2024-02-02 16:45:23 -08:00
Rect(
-70.79, 138.0, 59.867, 10.0,
SpriteAnchor::NorthWest,
SpriteAnchor::Center
2024-02-03 16:21:21 -08:00
),
Color(1.0, 1.0, 1.0, 1.0)
2024-02-02 16:45:23 -08:00
);
2024-02-03 16:06:11 -08:00
if player.is_landed() {
title.set_text(player.landed_on().name());
} else {
title.set_text("");
}
2024-02-03 16:45:47 -08:00
title.align_center();
title.font_serif();
title.weight_bold();
2024-02-03 16:06:11 -08:00
let desc = TextBoxBuilder(
2024-02-03 16:45:47 -08:00
"desc", 7.5, 8.0,
2024-02-03 16:06:11 -08:00
Rect(
-178.92, -20.3, 343.0, 81.467,
SpriteAnchor::NorthWest,
SpriteAnchor::Center
2024-02-03 16:21:21 -08:00
),
Color(1.0, 1.0, 1.0, 1.0)
2024-02-03 16:06:11 -08:00
);
if player.is_landed() {
desc.set_text(player.landed_on().desc());
} else {
desc.set_text("");
}
2024-02-03 16:45:47 -08:00
desc.font_sansserif();
2024-02-02 16:45:23 -08:00
return [
button,
landscape,
frame,
title,
2024-02-03 16:06:11 -08:00
desc,
2024-02-02 16:45:23 -08:00
];
}
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
}
}