Tweaked scripts for new api
parent
a49e1f61bd
commit
940ed863df
|
@ -39,6 +39,8 @@ fn init(state) {
|
||||||
|
|
||||||
let radar_size = 150.0;
|
let radar_size = 150.0;
|
||||||
let radar_range = 4000.0;
|
let radar_range = 4000.0;
|
||||||
|
let hide_range = 0.85;
|
||||||
|
let shrink_distance = 20.0;
|
||||||
|
|
||||||
sprite::add(
|
sprite::add(
|
||||||
"radar",
|
"radar",
|
||||||
|
@ -78,9 +80,9 @@ fn event(state, event) {
|
||||||
if type_of(event) == "PlayerShipStateEvent" {
|
if type_of(event) == "PlayerShipStateEvent" {
|
||||||
if state.player_ship().is_landed() {
|
if state.player_ship().is_landed() {
|
||||||
ui::go_to_scene("landed");
|
ui::go_to_scene("landed");
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if type_of(event) == "ScrollEvent" {
|
if type_of(event) == "ScrollEvent" {
|
||||||
|
@ -106,6 +108,7 @@ fn event(state, event) {
|
||||||
if event.key() == "L" && event.is_down() {
|
if event.key() == "L" && event.is_down() {
|
||||||
return PlayerDirective::Land;
|
return PlayerDirective::Land;
|
||||||
}
|
}
|
||||||
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,10 +124,6 @@ fn step(state) {
|
||||||
|
|
||||||
|
|
||||||
// TODO: share variables with init();
|
// 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();
|
let p_pos = state.player_ship().get_pos();
|
||||||
|
|
||||||
// Radar arrow
|
// Radar arrow
|
||||||
|
@ -285,8 +284,8 @@ fn step(state) {
|
||||||
|
|
||||||
// Window frame
|
// Window frame
|
||||||
{
|
{
|
||||||
let dx = (((state.camera_zoom() / 2.0) * state.window_aspect()) / 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 = ((state.camera_zoom() / 2.0) / 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",
|
sprite::set_rect("radar.frame.ne",
|
||||||
Rect(
|
Rect(
|
||||||
(radar_size / 2.0 + 5) - dx,
|
(radar_size / 2.0 + 5) - dx,
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
fn init(state) {
|
fn init(state) {
|
||||||
let player = state.player_ship();
|
|
||||||
|
|
||||||
conf::show_starfield(true);
|
conf::show_starfield(true);
|
||||||
conf::show_phys(false);
|
conf::show_phys(false);
|
||||||
|
|
||||||
|
@ -17,8 +15,8 @@ fn init(state) {
|
||||||
sprite::add(
|
sprite::add(
|
||||||
"landscape",
|
"landscape",
|
||||||
{
|
{
|
||||||
if player.is_landed() {
|
if state.player_ship().is_landed() {
|
||||||
player.landed_on().image();
|
state.player_ship().landed_on().image();
|
||||||
} else {
|
} else {
|
||||||
"";
|
"";
|
||||||
}
|
}
|
||||||
|
@ -40,6 +38,9 @@ fn init(state) {
|
||||||
Anchor::Center
|
Anchor::Center
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
// If this is not set, the button will
|
||||||
|
// not receive events
|
||||||
|
sprite::set_disable_events("frame", true);
|
||||||
|
|
||||||
|
|
||||||
textbox::add(
|
textbox::add(
|
||||||
|
@ -54,8 +55,8 @@ fn init(state) {
|
||||||
textbox::align_center("title");
|
textbox::align_center("title");
|
||||||
textbox::font_serif("title");
|
textbox::font_serif("title");
|
||||||
textbox::weight_bold("title");
|
textbox::weight_bold("title");
|
||||||
if player.is_landed() {
|
if state.player_ship().is_landed() {
|
||||||
textbox::set_text("title", player.landed_on().display_name());
|
textbox::set_text("title", state.player_ship().landed_on().display_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
textbox::add(
|
textbox::add(
|
||||||
|
@ -68,8 +69,8 @@ fn init(state) {
|
||||||
Color(1.0, 1.0, 1.0, 1.0)
|
Color(1.0, 1.0, 1.0, 1.0)
|
||||||
);
|
);
|
||||||
textbox::font_sans("desc");
|
textbox::font_sans("desc");
|
||||||
if player.is_landed() {
|
if state.player_ship().is_landed() {
|
||||||
textbox::set_text("desc", player.landed_on().desc());
|
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);
|
sprite::jump_to("button", "off:top", 0.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if type_of(event) == "MouseClickEvent" {
|
if type_of(event) == "MouseClickEvent" {
|
||||||
if !event.is_down() {
|
if !event.is_down() {
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let element = event.element();
|
let element = event.element();
|
||||||
if element == "button" {
|
if element == "button" {
|
||||||
ui::go_to_scene("outfitter");
|
ui::go_to_scene("outfitter");
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +104,7 @@ fn event(state, event) {
|
||||||
|
|
||||||
if type_of(event) == "KeyboardEvent" {
|
if type_of(event) == "KeyboardEvent" {
|
||||||
if !event.is_down() {
|
if !event.is_down() {
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if event.key() == "L" {
|
if event.key() == "L" {
|
||||||
|
@ -112,15 +113,15 @@ fn event(state, event) {
|
||||||
|
|
||||||
if event.key() == "O" {
|
if event.key() == "O" {
|
||||||
ui::go_to_scene("outfitter");
|
ui::go_to_scene("outfitter");
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if type_of(event) == "PlayerShipStateEvent" {
|
if type_of(event) == "PlayerShipStateEvent" {
|
||||||
if !state.player_ship().is_landed() {
|
if !state.player_ship().is_landed() {
|
||||||
ui::go_to_scene("flying");
|
ui::go_to_scene("flying");
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -163,7 +163,6 @@ fn init(state) {
|
||||||
|
|
||||||
|
|
||||||
// width should be calculated as a fraction of screen width
|
// width should be calculated as a fraction of screen width
|
||||||
|
|
||||||
let scrollbox_rect = Rect(
|
let scrollbox_rect = Rect(
|
||||||
222.0, -16.0, 470.0, 480.0,
|
222.0, -16.0, 470.0, 480.0,
|
||||||
Anchor::NorthWest,
|
Anchor::NorthWest,
|
||||||
|
@ -172,68 +171,73 @@ fn init(state) {
|
||||||
|
|
||||||
scrollbox::add("outfit_list", scrollbox_rect);
|
scrollbox::add("outfit_list", scrollbox_rect);
|
||||||
|
|
||||||
let p = state.player_ship();
|
let selected_outfit = false;
|
||||||
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;
|
// p cannot be saved in the global scope.
|
||||||
let title_name = "outfit.title." + i.index() + xxx;
|
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(
|
let thumb_name = "outfit.thumb." + i.index() + xxx;
|
||||||
backg_name,
|
let backg_name = "outfit.backg." + i.index() + xxx;
|
||||||
"ui::outfitbg",
|
let title_name = "outfit.title." + i.index() + xxx;
|
||||||
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(
|
sprite::add(
|
||||||
thumb_name,
|
backg_name,
|
||||||
i.thumbnail(),
|
"ui::outfitbg",
|
||||||
Rect(
|
Rect(
|
||||||
x, y, 75.0, 75.0,
|
x, y, 90.0, 90.0,
|
||||||
Anchor::Center,
|
Anchor::Center,
|
||||||
Anchor::NorthWest
|
Anchor::NorthWest
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
sprite::preserve_aspect(thumb_name, true);
|
sprite::preserve_aspect(backg_name, true);
|
||||||
scrollbox::add_element("outfit_list", thumb_name);
|
scrollbox::add_element("outfit_list", backg_name);
|
||||||
|
|
||||||
textbox::add(
|
sprite::add(
|
||||||
title_name,
|
thumb_name,
|
||||||
10.0, 10.0,
|
i.thumbnail(),
|
||||||
Rect(
|
Rect(
|
||||||
x, y - 50.0, 90.0, 10.0,
|
x, y, 75.0, 75.0,
|
||||||
Anchor::Center,
|
Anchor::Center,
|
||||||
Anchor::NorthWest,
|
Anchor::NorthWest
|
||||||
),
|
)
|
||||||
Color(1.0, 1.0, 1.0, 1.0)
|
);
|
||||||
);
|
sprite::preserve_aspect(thumb_name, true);
|
||||||
textbox::font_sans(title_name);
|
scrollbox::add_element("outfit_list", thumb_name);
|
||||||
textbox::align_center(title_name);
|
|
||||||
textbox::set_text(title_name, i.display_name());
|
textbox::add(
|
||||||
scrollbox::add_element("outfit_list", title_name);
|
title_name,
|
||||||
|
10.0, 10.0,
|
||||||
x = x + 120.0;
|
Rect(
|
||||||
if x > (
|
x, y - 50.0, 90.0, 10.0,
|
||||||
scrollbox_rect.pos().x() + scrollbox_rect.dim().x() - 45.0
|
Anchor::Center,
|
||||||
) {
|
Anchor::NorthWest,
|
||||||
x = scrollbox_rect.pos().x() + 45.0;
|
),
|
||||||
y = y - 120.0;
|
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);
|
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 type_of(event) == "MouseClickEvent" {
|
||||||
if !event.is_down() {
|
if !event.is_down() {
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print(event.element());
|
||||||
|
|
||||||
|
|
||||||
let element = event.element();
|
let element = event.element();
|
||||||
if element == "exit_button" {
|
if element == "exit_button" {
|
||||||
ui::go_to_scene("landed");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if type_of(event) == "PlayerShipStateEvent" {
|
if type_of(event) == "PlayerShipStateEvent" {
|
||||||
if !state.player_ship().is_landed() {
|
if !state.player_ship().is_landed() {
|
||||||
ui::go_to_scene("flying");
|
ui::go_to_scene("flying");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
return;
|
return PlayerDirective::None;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue