Tweaked scripts for new api
parent
a49e1f61bd
commit
940ed863df
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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,6 +171,10 @@ fn init(state) {
|
|||
|
||||
scrollbox::add("outfit_list", scrollbox_rect);
|
||||
|
||||
let selected_outfit = false;
|
||||
|
||||
{
|
||||
// p cannot be saved in the global scope.
|
||||
let p = state.player_ship();
|
||||
if p.is_landed() {
|
||||
let s = "";
|
||||
|
@ -235,6 +238,7 @@ fn init(state) {
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue