extends SceneTree const COLORS = preload("res://themes/palette.gd") func _initialize() -> void: for high_contrast in [false, true]: var palette: Dictionary = COLORS.HIGH_CONTRAST if high_contrast else COLORS.SOFT var path := "res://themes/theme_highcontrast.tres" if high_contrast else "res://themes/theme.tres" var error := ResourceSaver.save(_build_theme(palette, high_contrast), path) if error != OK: push_error("Could not save %s: %s" % [path, error_string(error)]) quit(error) return var material := StandardMaterial3D.new() material.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA material.cull_mode = BaseMaterial3D.CULL_DISABLED material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED material.albedo_color = COLORS.COMPASS_TEST material.albedo_texture = load("res://assets/vector/dial.svg") var material_error := ResourceSaver.save(material, "res://themes/compass_material.tres") if material_error != OK: push_error("Could not save compass material: " + error_string(material_error)) quit(material_error) return var config := ConfigFile.new() var config_error := config.load("res://project.godot") if config_error == OK and config.get_value("rendering", "environment/defaults/default_clear_color") != COLORS.VIEWPORT_BACKGROUND: config.set_value("rendering", "environment/defaults/default_clear_color", COLORS.VIEWPORT_BACKGROUND) config_error = config.save("res://project.godot") if config_error != OK: push_error("Could not update viewport background: " + error_string(config_error)) quit(config_error) return quit() func _build_theme(palette: Dictionary, high_contrast: bool) -> Theme: var theme := ThemeDB.get_default_theme().duplicate(true) as Theme theme.default_font_size = 18 for type in theme.get_type_list(): for name in theme.get_font_size_list(type): theme.set_font_size(name, type, 18) for type in theme.get_type_list(): for name in theme.get_color_list(type): var color: Color = palette.text if "disabled" in name or "placeholder" in name or "readonly" in name: color = palette.muted_text elif "selection" in name: color = COLORS.SECONDARY elif name in ["font_pressed_color", "font_hover_pressed_color"] and type in ["Button", "OptionButton", "MenuButton"]: color = palette.active_text elif name == "font_selected_color" and type == "TabContainer": color = palette.active_text elif name == "font_color" and type == "ProgressBar": color = palette.fill_text elif "background" in name: color = COLORS.CLEAR elif "caret" in name or "accent" in name: color = COLORS.ACCENT elif "shadow" in name or "outline" in name: color = COLORS.CLEAR theme.set_color(name, type, color) for name in theme.get_stylebox_list(type): var original := theme.get_stylebox(name, type) if original is StyleBoxEmpty: continue var style := StyleBoxFlat.new() for side in range(4): style.set_content_margin(side, maxf(original.get_content_margin(side), 4.0)) style.bg_color = palette.surface style.border_color = palette.border style.set_border_width_all(1 if high_contrast else 0) if "hover" in name: style.bg_color = palette.hover style.border_color = palette.focus if "pressed" in name or ("selected" in name and "unselected" not in name) or name == "fill" or name.begins_with("grabber"): style.bg_color = palette.pressed if not high_contrast: style.border_width_bottom = 1 style.border_color = palette.focus if name == "fill" or name.begins_with("grabber"): style.bg_color = palette.fill if not high_contrast: style.set_border_width_all(0) if "disabled" in name or "read_only" in name: style.bg_color = palette.disabled style.border_color = palette.disabled_border if "focus" in name: style.draw_center = false style.border_color = palette.focus style.set_border_width_all(2 if high_contrast else 1) if type in ["LineEdit", "TextEdit", "CodeEdit", "Tree", "ItemList"] and name == "normal": style.bg_color = palette.input if type in ["Panel", "PanelContainer", "PopupPanel", "PopupMenu", "Window", "AcceptDialog"]: style.bg_color = palette.panel if type in ["HSeparator", "VSeparator"]: style.bg_color = palette.separator style.border_color = palette.separator theme.set_stylebox(name, type, style) for type in ["HSlider", "VSlider"]: for name in ["grabber", "grabber_highlight", "grabber_disabled"]: var bitmap := Image.create(14, 18, false, Image.FORMAT_RGBA8) bitmap.fill(COLORS.ACCENT if name == "grabber_highlight" else palette.thumb) theme.set_icon(name, type, ImageTexture.create_from_image(bitmap)) var panel := theme.get_stylebox("panel", "PanelContainer").duplicate() as StyleBoxFlat theme.set_stylebox("panel_inactive", "SurfaceSide", panel) var active := panel.duplicate() as StyleBoxFlat active.border_color = palette.focus active.set_border_width_all(2 if high_contrast else 0) if not high_contrast: active.border_width_top = 2 theme.set_stylebox("panel_active", "SurfaceSide", active) theme.set_color("accent", "SurfaceSide", COLORS.ACCENT) theme.set_color("secondary", "SurfaceSide", COLORS.SECONDARY) _add_instrument_theme(theme, palette) for role in COLORS.STATUS: theme.set_color(role, "SurfaceSide", COLORS.STATUS[role]) theme.set_type_variation("VehicleWarningText", "Label") theme.set_color("font_color", "VehicleWarningText", COLORS.STATUS.status_ink) theme.set_type_variation("VehicleFaultText", "Label") theme.set_color("font_color", "VehicleFaultText", COLORS.WHITE) theme.set_type_variation("VehicleBackground", "PanelContainer") var vehicle_background := StyleBoxFlat.new() vehicle_background.bg_color = palette.panel vehicle_background.border_color = palette.border vehicle_background.set_border_width_all(1 if high_contrast else 0) theme.set_stylebox("panel", "VehicleBackground", vehicle_background) theme.set_type_variation("LayoutItemBackground", "Panel") theme.set_stylebox("panel", "LayoutItemBackground", vehicle_background) theme.set_type_variation("LayoutLibraryList", "ItemList") theme.set_color("guide_color", "LayoutLibraryList", COLORS.SECONDARY if high_contrast else COLORS.CLEAR) theme.set_constant("v_separation", "LayoutLibraryList", 8) for variant in ["LinkRateNormal", "LinkRateWarning", "LinkRateFault", "LinkMuted"]: theme.set_type_variation(variant, "Label") theme.set_color("font_color", "LinkRateNormal", COLORS.INSTRUMENT.instrument_accent) theme.set_color("font_color", "LinkRateWarning", COLORS.WARNING) theme.set_color("font_color", "LinkRateFault", COLORS.FAULT) theme.set_color("font_color", "LinkMuted", palette.muted_text) for variant in ["InstrumentWarning", "InstrumentFault", "InstrumentMuted"]: theme.set_type_variation(variant, "Label") theme.set_color("font_color", "InstrumentWarning", COLORS.WARNING) theme.set_color("font_color", "InstrumentFault", COLORS.FAULT) theme.set_color("font_color", "InstrumentMuted", palette.muted_text) return theme func _add_instrument_theme(theme: Theme, palette: Dictionary) -> void: for role in COLORS.INSTRUMENT: theme.set_color(role, "SurfaceSide", COLORS.INSTRUMENT[role]) theme.set_color("instrument_empty", "SurfaceSide", palette.input) theme.set_color("instrument_axis", "SurfaceSide", palette.muted_text) theme.set_type_variation("MotionBackground", "Panel") var background := StyleBoxFlat.new() background.bg_color = palette.panel theme.set_stylebox("panel", "MotionBackground", background) for vertical in [false, true]: var type := "MotionVSeparator" if vertical else "MotionHSeparator" theme.set_type_variation(type, "VSeparator" if vertical else "HSeparator") var separator := StyleBoxLine.new() separator.color = COLORS.INSTRUMENT.instrument_grid separator.thickness = 1 separator.vertical = vertical theme.set_stylebox("separator", type, separator) theme.set_type_variation("MotionAlertPanel", "PanelContainer") var alert := StyleBoxFlat.new() alert.bg_color = COLORS.INSTRUMENT.alert_background alert.content_margin_top = 7 alert.content_margin_bottom = 7 theme.set_stylebox("panel", "MotionAlertPanel", alert) theme.set_type_variation("MotionAlertText", "Label") theme.set_color("font_color", "MotionAlertText", COLORS.INSTRUMENT.alert_text) theme.set_type_variation("MotionWarning", "Label") theme.set_color("font_color", "MotionWarning", COLORS.INSTRUMENT.instrument_accent)