1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
use map_gui::tools::{open_browser, PopupMsg}; use widgetry::{ Btn, DrawBaselayer, EventCtx, GfxCtx, Key, Line, Outcome, Panel, State, Text, Widget, }; use crate::{App, Transition}; pub struct TitleScreen { panel: Panel, } impl TitleScreen { pub fn new(ctx: &mut EventCtx, app: &App) -> Box<dyn State<App>> { let mut level_buttons = Vec::new(); for (idx, level) in app.session.levels.iter().enumerate() { if idx < app.session.levels_unlocked { level_buttons.push(Btn::text_bg2(&level.title).build_def(ctx, None)); } else { level_buttons.push(Btn::text_bg2(&level.title).inactive(ctx)); } } let upgrades = Text::from_multiline(vec![ Line(format!( "Vehicles unlocked: {}", app.session.vehicles_unlocked.join(", "), )), Line(format!( "Upzones unlocked: {}", app.session.upzones_unlocked )), ]); Box::new(TitleScreen { panel: Panel::new( Widget::col(vec![ Btn::svg_def("system/assets/pregame/quit.svg") .build(ctx, "quit", Key::Escape) .align_left(), { let mut txt = Text::from(Line("15 minute Santa").display_title()); txt.add(Line("Created by Dustin Carlino, Yuwen Li, & Michael Kirk")); txt.draw(ctx).centered_horiz() }, Btn::text_bg1("Santa character created by @parallaxcreativedesign").build( ctx, "open https://www.instagram.com/parallaxcreativedesign/", None, ), Btn::text_bg2("Instructions").build_def(ctx, None), Widget::row(level_buttons), upgrades.draw(ctx), ]) .evenly_spaced(), ) .exact_size_percent(90, 85) .build_custom(ctx), }) } } impl State<App> for TitleScreen { fn event(&mut self, ctx: &mut EventCtx, app: &mut App) -> Transition { match self.panel.event(ctx) { Outcome::Clicked(x) => match x.as_ref() { "quit" => { std::process::exit(0); } "Instructions" => { return Transition::Push(PopupMsg::new( ctx, "Instructions", vec![ "It's Christmas Eve, so it's time for Santa to deliver presents in \ Seattle.", "2020 has thoroughly squashed any remaining magic out of the world, \ so your sleigh can only hold so many presents at a time.", "Deliver presents as fast as you can. When you run out, refill from a \ yellow-colored store.", "It's faster to deliver to buildings with multiple families inside.", ], )); } x => { if let Some(url) = x.strip_prefix("open ") { open_browser(url.to_string()); return Transition::Keep; } for level in &app.session.levels { if x == level.title { return Transition::Push(crate::before_level::Picker::new( ctx, app, level.clone(), )); } } panic!("Unknown action {}", x); } }, _ => {} } Transition::Keep } fn draw_baselayer(&self) -> DrawBaselayer { DrawBaselayer::Custom } fn draw(&self, g: &mut GfxCtx, app: &App) { g.clear(app.cs.dialog_bg); self.panel.draw(g); } }