Galactica/content/ui/outfitter.rhai

218 lines
3.9 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 22:19:06 -08:00
fn init(state) {
let se_box = SpriteBuilder(
"se_box",
"ui::outfitterbox",
Rect(
-1.0, -1.0, 202.345, 133.409,
SpriteAnchor::SouthWest,
SpriteAnchor::SouthWest
)
);
let exit_text = TextBoxBuilder(
2024-02-03 16:45:47 -08:00
"exit_text", 10.0, 10.0,
2024-02-02 22:19:06 -08:00
Rect(
122.71, 48.0, 51.0, 12.0,
SpriteAnchor::NorthWest,
SpriteAnchor::SouthWest
2024-02-03 16:21:21 -08:00
),
Color(1.0, 1.0, 1.0, 1.0)
2024-02-02 22:19:06 -08:00
);
2024-02-03 16:06:11 -08:00
exit_text.set_text("Exit");
2024-02-03 16:45:47 -08:00
exit_text.font_serif();
exit_text.align_center();
2024-02-02 22:19:06 -08:00
let exit_button = SpriteBuilder(
"exit_button",
"ui::button",
Rect(
113.35, 52.0, 69.8, 18.924,
SpriteAnchor::NorthWest,
SpriteAnchor::SouthWest
)
);
let ship_bg = SpriteBuilder(
"ship_bg",
"ui::outfitter-ship-bg",
Rect(
16.0, -16.0, 190.0, 353.0,
SpriteAnchor::NorthWest,
SpriteAnchor::NorthWest
)
);
let ship_thumb = SpriteBuilder(
"ship_thumb",
"icon::gypsum",
Rect(
111.0, -95.45, 90.0, 90.0,
SpriteAnchor::Center,
SpriteAnchor::NorthWest
)
);
let ship_name = TextBoxBuilder(
2024-02-03 16:45:47 -08:00
"ship_name", 10.0, 10.0,
2024-02-02 22:19:06 -08:00
Rect(
111.0, -167.27, 145.0, 10.0,
SpriteAnchor::Center,
SpriteAnchor::NorthWest
2024-02-03 16:21:21 -08:00
),
Color(1.0, 1.0, 1.0, 1.0)
2024-02-02 22:19:06 -08:00
);
2024-02-03 16:06:11 -08:00
ship_name.set_text("Hyperion");
2024-02-03 16:45:47 -08:00
ship_name.font_serif();
ship_name.align_center();
2024-02-02 22:19:06 -08:00
let ship_type = TextBoxBuilder(
2024-02-03 16:45:47 -08:00
"ship_type", 7.0, 8.5,
2024-02-02 22:19:06 -08:00
Rect(
111.0, -178.0, 145.0, 8.5,
SpriteAnchor::Center,
SpriteAnchor::NorthWest
2024-02-03 16:21:21 -08:00
),
Color(0.7, 0.7, 0.7, 1.0)
2024-02-02 22:19:06 -08:00
);
2024-02-03 16:06:11 -08:00
if state.player_ship().is_some() {
ship_type.set_text(state.player_ship().name());
} else {
ship_type.set_text("ERR: SHIP IS NONE");
}
2024-02-03 16:45:47 -08:00
ship_type.font_sansserif();
ship_type.align_center();
2024-02-02 22:19:06 -08:00
let ship_stats = TextBoxBuilder(
2024-02-03 16:45:47 -08:00
"ship_stats", 7.0, 8.5,
2024-02-02 22:19:06 -08:00
Rect(
38.526, -192.332, 144.948, 154.5,
SpriteAnchor::NorthWest,
SpriteAnchor::NorthWest,
2024-02-03 16:21:21 -08:00
),
Color(1.0, 1.0, 1.0, 1.0)
2024-02-02 22:19:06 -08:00
);
2024-02-03 11:24:17 -08:00
ship_stats.set_text("Earth");
2024-02-03 16:45:47 -08:00
ship_stats.font_monospace();
2024-02-02 22:19:06 -08:00
let outfit_bg = SpriteBuilder(
"outfit_bg",
"ui::outfitter-outfit-bg",
Rect(
-16.0, -16.0, 300.0, 480.0,
SpriteAnchor::NorthEast,
SpriteAnchor::NorthEast
)
);
let outfit_thumb = SpriteBuilder(
"outfit_thumb",
"icon::engine",
Rect(
-166.0, -109.0, 90.0, 90.0,
SpriteAnchor::Center,
SpriteAnchor::NorthEast
)
);
let outfit_name = TextBoxBuilder(
2024-02-03 16:45:47 -08:00
"outfit_name", 16.0, 16.0,
2024-02-02 22:19:06 -08:00
Rect(
-312.0, -20.0, 200.0, 16.0,
SpriteAnchor::NorthWest,
SpriteAnchor::NorthEast,
2024-02-03 16:21:21 -08:00
),
Color(1.0, 1.0, 1.0, 1.0)
2024-02-02 22:19:06 -08:00
);
2024-02-03 11:24:17 -08:00
outfit_name.set_text("Earth");
2024-02-03 16:45:47 -08:00
outfit_name.font_serif();
outfit_name.weight_bold();
2024-02-02 22:19:06 -08:00
let outfit_desc = TextBoxBuilder(
2024-02-03 16:45:47 -08:00
"outfit_desc", 7.0, 8.5,
2024-02-02 22:19:06 -08:00
Rect(
-166.0, -219.0, 260.0, 78.0,
SpriteAnchor::Center,
SpriteAnchor::NorthEast,
2024-02-03 16:21:21 -08:00
),
Color(1.0, 1.0, 1.0, 1.0)
2024-02-02 22:19:06 -08:00
);
2024-02-03 11:24:17 -08:00
outfit_desc.set_text("Earth");
2024-02-03 16:45:47 -08:00
outfit_desc.font_serif();
2024-02-02 22:19:06 -08:00
let outfit_stats = TextBoxBuilder(
2024-02-03 16:45:47 -08:00
"outfit_stats", 7.0, 8.5,
2024-02-02 22:19:06 -08:00
Rect(
-295.0, -271.0, 164.0, 216.0,
SpriteAnchor::NorthWest,
SpriteAnchor::NorthEast,
2024-02-03 16:21:21 -08:00
),
Color(1.0, 1.0, 1.0, 1.0)
2024-02-02 22:19:06 -08:00
);
2024-02-03 11:24:17 -08:00
outfit_stats.set_text("Earth");
2024-02-03 16:45:47 -08:00
ship_stats.font_monospace();
2024-02-02 22:19:06 -08:00
return [
ship_bg,
ship_thumb,
ship_name,
ship_type,
ship_stats,
outfit_bg,
outfit_thumb,
outfit_name,
outfit_desc,
outfit_stats,
se_box,
exit_button,
exit_text
];
}
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("exit_button") {
if event.is_enter() {
element.take_edge("on:top", 0.1);
} else {
element.take_edge("off:top", 0.1);
}
2024-02-02 22:19:06 -08:00
}
2024-02-03 11:24:17 -08:00
return;
2024-02-02 22:19:06 -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("exit_button") {
return SceneAction::GoTo("landed");
}
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
}
}