mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
toggle color scheme in options panel
This commit is contained in:
parent
3fc4684fec
commit
71854bc959
@ -124,10 +124,6 @@ pub fn path_ab_test_save(map_name: &str, test_name: &str, time: String) -> Strin
|
||||
)
|
||||
}
|
||||
|
||||
pub fn path_color_scheme() -> String {
|
||||
format!("../data/color_scheme.json")
|
||||
}
|
||||
|
||||
pub fn path_popdat() -> String {
|
||||
format!("../data/shapes/popdat.bin")
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::options::Options;
|
||||
use crate::pregame::TitleScreen;
|
||||
use crate::render::DrawOptions;
|
||||
use crate::sandbox::{GameplayMode, SandboxMode};
|
||||
@ -20,7 +21,7 @@ impl Game {
|
||||
let title = !flags.dev
|
||||
&& !flags.sim_flags.load.contains("data/save")
|
||||
&& !flags.sim_flags.load.contains("data/scenarios");
|
||||
let mut ui = UI::new(flags, ctx, title);
|
||||
let mut ui = UI::new(flags, Options::default(), ctx, title);
|
||||
let states: Vec<Box<dyn State>> = if title {
|
||||
vec![Box::new(TitleScreen::new(ctx, &ui))]
|
||||
} else {
|
||||
|
@ -78,6 +78,8 @@ pub struct ColorScheme {
|
||||
|
||||
// A subset of map
|
||||
modified: ModifiedColors,
|
||||
|
||||
path: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@ -86,18 +88,22 @@ struct ModifiedColors {
|
||||
}
|
||||
|
||||
impl ColorScheme {
|
||||
pub fn load() -> ColorScheme {
|
||||
let modified: ModifiedColors =
|
||||
abstutil::read_json(abstutil::path_color_scheme(), &mut Timer::throwaway());
|
||||
// TODO When we quit with this, it'll save and overwrite it... remember the name too
|
||||
pub fn load(path: String) -> ColorScheme {
|
||||
let modified: ModifiedColors = abstutil::read_json(path.clone(), &mut Timer::throwaway());
|
||||
let mut map: HashMap<String, Color> = default_colors();
|
||||
for (name, c) in &modified.map {
|
||||
map.insert(name.clone(), *c);
|
||||
}
|
||||
ColorScheme { map, modified }
|
||||
ColorScheme {
|
||||
map,
|
||||
modified,
|
||||
path,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save(&self) {
|
||||
abstutil::write_json(abstutil::path_color_scheme(), &self.modified);
|
||||
abstutil::write_json(self.path.clone(), &self.modified);
|
||||
}
|
||||
|
||||
// Get, but specify the default inline. The default is extracted before compilation by a script
|
||||
|
@ -1,14 +1,18 @@
|
||||
use crate::game::{State, Transition, WizardState};
|
||||
use ezgui::Choice;
|
||||
|
||||
// TODO SimOptions stuff too
|
||||
#[derive(Clone)]
|
||||
pub struct Options {
|
||||
pub traffic_signal_style: TrafficSignalStyle,
|
||||
pub color_scheme: String,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
pub fn default() -> Options {
|
||||
Options {
|
||||
traffic_signal_style: TrafficSignalStyle::GroupArrows,
|
||||
color_scheme: "../data/color_scheme.json".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,6 +45,23 @@ pub fn open_panel() -> Box<dyn State> {
|
||||
),
|
||||
]
|
||||
})?;
|
||||
let (_, color_scheme) = wizard.choose("What color scheme?", || {
|
||||
vec![
|
||||
Choice::new("default", "../data/color_scheme.json".to_string()),
|
||||
Choice::new("night mode", "../data/night_colors.json".to_string()),
|
||||
]
|
||||
})?;
|
||||
|
||||
if ui.opts.color_scheme != color_scheme {
|
||||
wizard.acknowledge("Changing color scheme", || {
|
||||
vec![
|
||||
"Changing color scheme will reset the simulation",
|
||||
"Also, some colors don't completely change immediately",
|
||||
"Please file a bug if you notice anything weird",
|
||||
]
|
||||
})?;
|
||||
}
|
||||
|
||||
if ui.opts.traffic_signal_style != traffic_signal_style {
|
||||
ui.opts.traffic_signal_style = traffic_signal_style;
|
||||
println!("Rerendering traffic signals...");
|
||||
@ -48,6 +69,13 @@ pub fn open_panel() -> Box<dyn State> {
|
||||
*i.draw_traffic_signal.borrow_mut() = None;
|
||||
}
|
||||
}
|
||||
|
||||
if ui.opts.color_scheme != color_scheme {
|
||||
ui.opts.color_scheme = color_scheme.clone();
|
||||
let map_name = ui.primary.map.get_name().clone();
|
||||
ui.switch_map(ctx, &map_name);
|
||||
}
|
||||
|
||||
Some(Transition::Pop)
|
||||
}))
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ pub struct UI {
|
||||
}
|
||||
|
||||
impl UI {
|
||||
pub fn new(flags: Flags, ctx: &mut EventCtx, splash: bool) -> UI {
|
||||
let cs = ColorScheme::load();
|
||||
pub fn new(flags: Flags, opts: Options, ctx: &mut EventCtx, splash: bool) -> UI {
|
||||
let cs = ColorScheme::load(opts.color_scheme.clone());
|
||||
let (primary, prebaked) = ctx.loading_screen("load map", |ctx, mut timer| {
|
||||
// Always load some small icons.
|
||||
let mut textures = vec![
|
||||
@ -122,7 +122,7 @@ impl UI {
|
||||
cs,
|
||||
agent_cs: AgentColorScheme::VehicleTypes,
|
||||
prebaked,
|
||||
opts: Options::default(),
|
||||
opts,
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ impl UI {
|
||||
ctx.canvas.save_camera_state(self.primary.map.get_name());
|
||||
let mut flags = self.primary.current_flags.clone();
|
||||
flags.sim_flags.load = abstutil::path_map(name);
|
||||
*self = UI::new(flags, ctx, false);
|
||||
*self = UI::new(flags, self.opts.clone(), ctx, false);
|
||||
}
|
||||
|
||||
pub fn draw_ctx(&self) -> DrawCtx<'_> {
|
||||
|
Loading…
Reference in New Issue
Block a user