fn init(state) { conf::show_starfield(true); conf::show_phys(false); sprite::add( "se_box", "ui::outfitterbox", Rect( -1.0, -1.0, 202.345, 133.409, Anchor::SouthWest, Anchor::SouthWest ) ); textbox::add( "exit_text", 10.0, 10.0, Rect( 122.71, 48.0, 51.0, 12.0, Anchor::NorthWest, Anchor::SouthWest ), Color(1.0, 1.0, 1.0, 1.0) ); textbox::font_serif("exit_text"); textbox::align_center("exit_text"); textbox::set_text("exit_text", "Exit"); sprite::add( "exit_button", "ui::button", Rect( 113.35, 52.0, 69.8, 18.924, Anchor::NorthWest, Anchor::SouthWest ) ); sprite::add( "ship_bg", "ui::outfitter-ship-bg", Rect( 16.0, -16.0, 190.0, 353.0, Anchor::NorthWest, Anchor::NorthWest ) ); sprite::add( "ship_thumb", "icon::gypsum", Rect( 111.0, -95.45, 90.0, 90.0, Anchor::Center, Anchor::NorthWest ) ); sprite::preserve_aspect("ship_thumb", true); textbox::add( "ship_name", 10.0, 10.0, Rect( 111.0, -167.27, 145.0, 10.0, Anchor::Center, Anchor::NorthWest ), Color(1.0, 1.0, 1.0, 1.0) ); textbox::font_serif("ship_name"); textbox::align_center("ship_name"); textbox::set_text("ship_name", "Hyperion"); textbox::add( "ship_type", 7.0, 8.5, Rect( 111.0, -178.0, 145.0, 8.5, Anchor::Center, Anchor::NorthWest ), Color(0.7, 0.7, 0.7, 1.0) ); textbox::font_sans("ship_type"); textbox::align_center("ship_type"); if state.player_ship().is_some() { textbox::set_text("ship_type", state.player_ship().display_name()); } textbox::add( "ship_stats", 7.0, 8.5, Rect( 38.526, -192.332, 144.948, 154.5, Anchor::NorthWest, Anchor::NorthWest, ), Color(1.0, 1.0, 1.0, 1.0) ); textbox::font_mono("ship_stats"); textbox::set_text("ship_stats", "Earth"); sprite::add( "outfit_bg", "ui::outfitter-outfit-bg", Rect( -16.0, -16.0, 300.0, 480.0, Anchor::NorthEast, Anchor::NorthEast ) ); sprite::add( "outfit_thumb", "icon::engine", Rect( -166.0, -109.0, 90.0, 90.0, Anchor::Center, Anchor::NorthEast ) ); sprite::preserve_aspect("outfit_thumb", true); textbox::add( "outfit_name", 16.0, 16.0, Rect( -312.0, -20.0, 200.0, 16.0, Anchor::NorthWest, Anchor::NorthEast, ), Color(1.0, 1.0, 1.0, 1.0) ); textbox::font_serif("outfit_name"); textbox::weight_bold("outfit_name"); textbox::set_text("outfit_name", "Earth"); textbox::add( "outfit_desc", 7.0, 8.5, Rect( -166.0, -219.0, 260.0, 78.0, Anchor::Center, Anchor::NorthEast, ), Color(1.0, 1.0, 1.0, 1.0) ); textbox::font_serif("outfit_desc"); textbox::set_text("outfit_desc", "Earth"); textbox::add( "outfit_stats", 7.0, 8.5, Rect( -295.0, -271.0, 164.0, 216.0, Anchor::NorthWest, Anchor::NorthEast, ), Color(1.0, 1.0, 1.0, 1.0) ); 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 selected_outfit = false; { // 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"; 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); } } } fn event(state, event) { if type_of(event) == "MouseHoverEvent" { let element = event.element(); if element == "exit_button" { if event.is_enter() { sprite::jump_to("exit_button", "on:top", 0.1); } else { sprite::jump_to("exit_button", "off:top", 0.1); } } 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 PlayerDirective::None; } print(event.element()); let element = event.element(); if element == "exit_button" { ui::go_to_scene("landed"); 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 PlayerDirective::None; } }