UI script updates

master
Mark 2024-02-07 15:58:48 -08:00
parent c8f2001426
commit bb269285bb
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
3 changed files with 120 additions and 5 deletions

View File

@ -82,6 +82,31 @@ fn event(state, event) {
}
return;
}
if type_of(event) == "ScrollEvent" {
return ui::set_camera_zoom(
ui::get_camera_zoom()
- (5.0 * event.val())
);
}
if type_of(event) == "KeyboardEvent" {
if event.key() == "up" {
return PlayerDirective::Engine(event.is_down());
}
if event.key() == "left" {
return PlayerDirective::TurnLeft(event.is_down());
}
if event.key() == "right" {
return PlayerDirective::TurnRight(event.is_down());
}
if event.key() == "space" {
return PlayerDirective::Guns(event.is_down());
}
if event.key() == "L" && event.is_down() {
return PlayerDirective::Land;
}
}
}
fn step(state) {
@ -298,5 +323,5 @@ fn step(state) {
Anchor::NorthWest
)
);
}
}
}

View File

@ -78,9 +78,9 @@ fn event(state, event) {
let element = event.element();
if element == "button" {
if event.is_enter() {
sprite::take_edge("button", "on:top", 0.1);
sprite::jump_to("button", "on:top", 0.1);
} else {
sprite::take_edge("button", "off:top", 0.1);
sprite::jump_to("button", "off:top", 0.1);
}
}
return;
@ -100,6 +100,22 @@ fn event(state, event) {
return;
}
if type_of(event) == "KeyboardEvent" {
if !event.is_down() {
return;
}
if event.key() == "L" {
return PlayerDirective::UnLand;
}
if event.key() == "O" {
ui::go_to_scene("outfitter");
return;
}
}
if type_of(event) == "PlayerShipStateEvent" {
if !state.player_ship().is_landed() {
ui::go_to_scene("flying");

View File

@ -161,6 +161,80 @@ fn init(state) {
textbox::font_mono("outfit_stats");
textbox::set_text("outfit_stats", "Earth");
// width should be calculated as a fraction of screen width
let scrollbox_rect = Rect(
222.0, -16.0, 470.0, 480.0,
Anchor::NorthWest,
Anchor::NorthWest,
);
scrollbox::add("outfit_list", scrollbox_rect);
let p = state.player_ship();
if p.is_landed() {
let s = "";
let x = scrollbox_rect.pos().x() + 45.0;
let y = scrollbox_rect.pos().y() - 45.0;
for xxx in ["1","2","3"] {
for i in p.landed_on().outfitter() {
s = s + i.display_name() + "\n";
let thumb_name = "outfit.thumb." + i.index() + xxx;
let backg_name = "outfit.backg." + i.index() + xxx;
let title_name = "outfit.title." + i.index() + xxx;
sprite::add(
backg_name,
"ui::outfitbg",
Rect(
x, y, 90.0, 90.0,
Anchor::Center,
Anchor::NorthWest
)
);
sprite::preserve_aspect(backg_name, true);
scrollbox::add_element("outfit_list", backg_name);
sprite::add(
thumb_name,
i.thumbnail(),
Rect(
x, y, 75.0, 75.0,
Anchor::Center,
Anchor::NorthWest
)
);
sprite::preserve_aspect(thumb_name, true);
scrollbox::add_element("outfit_list", thumb_name);
textbox::add(
title_name,
10.0, 10.0,
Rect(
x, y - 50.0, 90.0, 10.0,
Anchor::Center,
Anchor::NorthWest,
),
Color(1.0, 1.0, 1.0, 1.0)
);
textbox::font_sans(title_name);
textbox::align_center(title_name);
textbox::set_text(title_name, i.display_name());
scrollbox::add_element("outfit_list", title_name);
x = x + 120.0;
if x > (
scrollbox_rect.pos().x() + scrollbox_rect.dim().x() - 45.0
) {
x = scrollbox_rect.pos().x() + 45.0;
y = y - 120.0;
}
}
}
textbox::set_text("outfit_stats", s);
}
}
@ -169,9 +243,9 @@ fn event(state, event) {
let element = event.element();
if element == "exit_button" {
if event.is_enter() {
sprite::take_edge("exit_button", "on:top", 0.1);
sprite::jump_to("exit_button", "on:top", 0.1);
} else {
sprite::take_edge("exit_button", "off:top", 0.1);
sprite::jump_to("exit_button", "off:top", 0.1);
}
}
return;