Tweaked scripts for new api

master
Mark 2024-02-08 20:41:04 -08:00
parent a49e1f61bd
commit 940ed863df
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
3 changed files with 113 additions and 86 deletions

View File

@ -39,6 +39,8 @@ fn init(state) {
let radar_size = 150.0;
let radar_range = 4000.0;
let hide_range = 0.85;
let shrink_distance = 20.0;
sprite::add(
"radar",
@ -78,9 +80,9 @@ fn event(state, event) {
if type_of(event) == "PlayerShipStateEvent" {
if state.player_ship().is_landed() {
ui::go_to_scene("landed");
return;
return PlayerDirective::None;
}
return;
return PlayerDirective::None;
}
if type_of(event) == "ScrollEvent" {
@ -106,6 +108,7 @@ fn event(state, event) {
if event.key() == "L" && event.is_down() {
return PlayerDirective::Land;
}
return PlayerDirective::None;
}
}
@ -121,10 +124,6 @@ fn step(state) {
// TODO: share variables with init();
let radar_size = 150.0;
let radar_range = 4000.0;
let hide_range = 0.85;
let shrink_distance = 20.0;
let p_pos = state.player_ship().get_pos();
// Radar arrow
@ -285,8 +284,8 @@ fn step(state) {
// Window frame
{
let dx = (((state.camera_zoom() / 2.0) * state.window_aspect()) / radar_range) * (radar_size / 2.0);
let dy = ((state.camera_zoom() / 2.0) / radar_range) * (radar_size / 2.0);
let dx = (((ui::get_camera_zoom() / 2.0) * state.window_aspect()) / radar_range) * (radar_size / 2.0);
let dy = ((ui::get_camera_zoom() / 2.0) / radar_range) * (radar_size / 2.0);
sprite::set_rect("radar.frame.ne",
Rect(
(radar_size / 2.0 + 5) - dx,

View File

@ -1,6 +1,4 @@
fn init(state) {
let player = state.player_ship();
conf::show_starfield(true);
conf::show_phys(false);
@ -17,8 +15,8 @@ fn init(state) {
sprite::add(
"landscape",
{
if player.is_landed() {
player.landed_on().image();
if state.player_ship().is_landed() {
state.player_ship().landed_on().image();
} else {
"";
}
@ -40,6 +38,9 @@ fn init(state) {
Anchor::Center
)
);
// If this is not set, the button will
// not receive events
sprite::set_disable_events("frame", true);
textbox::add(
@ -54,8 +55,8 @@ fn init(state) {
textbox::align_center("title");
textbox::font_serif("title");
textbox::weight_bold("title");
if player.is_landed() {
textbox::set_text("title", player.landed_on().display_name());
if state.player_ship().is_landed() {
textbox::set_text("title", state.player_ship().landed_on().display_name());
}
textbox::add(
@ -68,8 +69,8 @@ fn init(state) {
Color(1.0, 1.0, 1.0, 1.0)
);
textbox::font_sans("desc");
if player.is_landed() {
textbox::set_text("desc", player.landed_on().desc());
if state.player_ship().is_landed() {
textbox::set_text("desc", state.player_ship().landed_on().desc());
}
}
@ -83,19 +84,19 @@ fn event(state, event) {
sprite::jump_to("button", "off:top", 0.1);
}
}
return;
return PlayerDirective::None;
}
if type_of(event) == "MouseClickEvent" {
if !event.is_down() {
return;
return PlayerDirective::None;
}
let element = event.element();
if element == "button" {
ui::go_to_scene("outfitter");
return;
return PlayerDirective::None;
}
return;
}
@ -103,7 +104,7 @@ fn event(state, event) {
if type_of(event) == "KeyboardEvent" {
if !event.is_down() {
return;
return PlayerDirective::None;
}
if event.key() == "L" {
@ -112,15 +113,15 @@ fn event(state, event) {
if event.key() == "O" {
ui::go_to_scene("outfitter");
return;
return PlayerDirective::None;
}
}
if type_of(event) == "PlayerShipStateEvent" {
if !state.player_ship().is_landed() {
ui::go_to_scene("flying");
return;
return PlayerDirective::None;
}
return;
return PlayerDirective::None;
}
}

View File

@ -163,7 +163,6 @@ fn init(state) {
// width should be calculated as a fraction of screen width
let scrollbox_rect = Rect(
222.0, -16.0, 470.0, 480.0,
Anchor::NorthWest,
@ -172,68 +171,73 @@ fn init(state) {
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 selected_outfit = false;
let thumb_name = "outfit.thumb." + i.index() + xxx;
let backg_name = "outfit.backg." + i.index() + xxx;
let title_name = "outfit.title." + i.index() + xxx;
{
// p cannot be saved in the global scope.
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";
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);
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(
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);
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);
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;
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);
}
}
textbox::set_text("outfit_stats", s);
}
}
@ -248,28 +252,51 @@ fn event(state, event) {
sprite::jump_to("exit_button", "off:top", 0.1);
}
}
return;
if element.starts_with("outfit.backg.") && element != selected_outfit {
if event.is_enter() {
sprite::jump_to(element, "hover:top", 0.1);
} else {
sprite::jump_to(element, "off:top", 0.1);
}
}
return PlayerDirective::None;
}
// TODO: this occasionally breaks because of sprite ordering.
// Clicks go to se_box instead!
if type_of(event) == "MouseClickEvent" {
if !event.is_down() {
return;
return PlayerDirective::None;
}
print(event.element());
let element = event.element();
if element == "exit_button" {
ui::go_to_scene("landed");
return;
return PlayerDirective::None;
}
if element.starts_with("outfit.backg.") && element != selected_outfit {
if selected_outfit != false {
sprite::jump_to(selected_outfit, "off:top", 0.1);
}
sprite::jump_to(element, "selected:top", 0.1);
selected_outfit = element;
return PlayerDirective::None;
}
return;
}
if type_of(event) == "PlayerShipStateEvent" {
if !state.player_ship().is_landed() {
ui::go_to_scene("flying");
return;
}
return;
return PlayerDirective::None;
}
}