diff --git a/config.gd b/config.gd index 602a97f..652df9d 100644 --- a/config.gd +++ b/config.gd @@ -1,27 +1,36 @@ extends Node const PATH := "user://config.cfg" -const SECTION := "settings" +const SETTINGS_SECTION := "settings" +const JOYSTICK_SECTION := "joystick" +const BUTTONS_SECTION := "buttons" +const DEVICE_LABEL := "device_label" +const BACKGROUND_COLOR := "background_color" const JOYSTICK_LABELS := "joystick_labels" const TRACK_JOYSTICK_MOVEMENT := "track_joystick_movement" const TRACK_JOYSTICK_DRIFT := "track_joystick_drift" +const BUTTONS_LABELS := "buttons_labels" +const DEFAULT_COLOR := "default_color" +const ACTIVE_COLOR := "active_color" +const TEXT_COLOR := "text_color" var _config: ConfigFile +# Settings +static var device_label := ConfigOption.new(SETTINGS_SECTION, DEVICE_LABEL, true) +static var background_color := ConfigOption.new(SETTINGS_SECTION, BACKGROUND_COLOR, Color(0x4d4d4dff)) +static var default_color := ConfigOption.new(SETTINGS_SECTION, DEFAULT_COLOR, Color(0x2a2a2aff)) +static var active_color := ConfigOption.new(SETTINGS_SECTION, ACTIVE_COLOR, Color(0x4a8e53ff)) +static var text_color := ConfigOption.new(SETTINGS_SECTION, TEXT_COLOR, Color(0xffffffff)) + # Joystick -var joystick_labels: bool = true: - set(val): - joystick_labels = val - save_config() -var track_joystick_movement: bool = true: - set(val): - track_joystick_movement = val - save_config() -var track_joystick_drift: bool = true: - set(val): - track_joystick_drift = val - save_config() +static var joystick_labels := ConfigOption.new(JOYSTICK_SECTION, JOYSTICK_LABELS, true) +static var track_joystick_movement := ConfigOption.new(JOYSTICK_SECTION, TRACK_JOYSTICK_MOVEMENT, true) +static var track_joystick_drift := ConfigOption.new(JOYSTICK_SECTION, TRACK_JOYSTICK_DRIFT, true) + +# Buttons +static var buttons_labels := ConfigOption.new(BUTTONS_SECTION, BUTTONS_LABELS, true) func _ready() -> void: self._config = ConfigFile.new() @@ -30,14 +39,22 @@ func _ready() -> void: self.save_config() print_debug("Auto generated config file") - self.joystick_labels = self._config.get_value(SECTION, JOYSTICK_LABELS, true) - self.track_joystick_movement = self._config.get_value(SECTION, TRACK_JOYSTICK_MOVEMENT, true) - self.track_joystick_drift = self._config.get_value(SECTION, TRACK_JOYSTICK_DRIFT, true) + for opt in WyHelper.options: + opt.load(self._config) + + var bg_color: Color = self.background_color.value + + RenderingServer.set_default_clear_color(bg_color) + if bg_color.a > 0.0: + get_viewport().transparent_bg = false + +func _notification(what: int) -> void: + if what == NOTIFICATION_WM_CLOSE_REQUEST: + self.save_config() func save_config() -> void: - self._config.set_value(SECTION, JOYSTICK_LABELS, self.joystick_labels) - self._config.set_value(SECTION, TRACK_JOYSTICK_MOVEMENT, self.track_joystick_movement) - self._config.set_value(SECTION, TRACK_JOYSTICK_DRIFT, self.track_joystick_drift) + for opt in WyHelper.options: + opt.save(self._config) var err := self._config.save(PATH) if err != OK: diff --git a/config/config_option.gd b/config/config_option.gd new file mode 100644 index 0000000..ce2f990 --- /dev/null +++ b/config/config_option.gd @@ -0,0 +1,20 @@ +class_name ConfigOption +extends Resource + +var section: String +var key: String +var value: Variant +var default: Variant + +func _init(_section: String, _key: String, _value: Variant, _default: Variant = _value) -> void: + self.section = _section + self.key = _key + self.value = _value + self.default = _default + WyHelper.options.push_back(self) + +func save(config: ConfigFile) -> void: + config.set_value(self.section, self.key, self.value) + +func load(config: ConfigFile) -> void: + self.value = config.get_value(self.section, self.key, self.default) diff --git a/config/config_option.gd.uid b/config/config_option.gd.uid new file mode 100644 index 0000000..666294c --- /dev/null +++ b/config/config_option.gd.uid @@ -0,0 +1 @@ +uid://b16x8fmdgytc1 diff --git a/controller/button/controller_button.gd b/controller/button/controller_button.gd index 5004350..ad25eb7 100644 --- a/controller/button/controller_button.gd +++ b/controller/button/controller_button.gd @@ -12,6 +12,9 @@ extends ColorRect self.label_node.text = label func _ready() -> void: - self.label_node.text = self.label + if Config.buttons_labels.value: + self.label_node.text = self.label + else: + self.label_node.text = "" assert(self.input_code, "Missing input code for %s" % self.name) assert(InputMap.has_action(self.input_code), "Invalid input code for %s" % self.name) diff --git a/controller/controller.gd b/controller/controller.gd index f4f8fbd..c828a82 100644 --- a/controller/controller.gd +++ b/controller/controller.gd @@ -10,7 +10,7 @@ func _ready() -> void: self._buttons = self.get_tree().get_nodes_in_group("buttons") self._triggers = self.get_tree().get_nodes_in_group("triggers") if Input.get_connected_joypads().size() > 0: - self.device_name.text = Input.get_joy_name(0) + self.device_name.text = Input.get_joy_name(0) if Config.device_label.value else "" self._has_joy = true func _process(_delta: float) -> void: @@ -30,10 +30,10 @@ func _process(_delta: float) -> void: continue var cbtn := btn as ControllerButton - cbtn.color = WyHelper.DEFAULT_COLOR + cbtn.color = Config.default_color.value if cbtn.input_code && Input.is_action_pressed(cbtn.input_code): - cbtn.color = WyHelper.ACTIVE_COLOR + cbtn.color = Config.active_color.value for btn in self._triggers: if not btn is ControllerTrigger: diff --git a/controller/joystick/joystick.gd b/controller/joystick/joystick.gd index 530eccb..ec6908a 100644 --- a/controller/joystick/joystick.gd +++ b/controller/joystick/joystick.gd @@ -14,7 +14,10 @@ var _last_y := 0.0 func _ready() -> void: self._dot_style = box_theme.duplicate() self.pos.add_theme_stylebox_override("panel", self._dot_style) - self._dot_style.bg_color = WyHelper.DEFAULT_COLOR + self._dot_style.bg_color = Config.default_color.value + + var bg_color: Color = Config.default_color.value + (self.get_theme_stylebox("panel") as StyleBoxFlat).border_color = bg_color func _process(_delta: float) -> void: var x := Input.get_joy_axis(0, self.axis_x) @@ -31,14 +34,14 @@ func _process(_delta: float) -> void: var is_stuck: bool = (abs(x) > WyHelper.DRIFT_DEADZONE && abs(x) <= WyHelper.STUCK_DEADZONE) \ && (abs(y) > WyHelper.DRIFT_DEADZONE && abs(y) <= WyHelper.STUCK_DEADZONE) - if Config.track_joystick_movement && is_moving: - self._dot_style.bg_color = WyHelper.ACTIVE_COLOR - elif Config.track_joystick_drift && (is_drifting || is_stuck): + if Config.track_joystick_movement.value && is_moving: + self._dot_style.bg_color = Config.active_color.value + elif Config.track_joystick_drift.value && (is_drifting || is_stuck): self._dot_style.bg_color = WyHelper.ERROR_COLOR else: - self._dot_style.bg_color = WyHelper.DEFAULT_COLOR + self._dot_style.bg_color = Config.default_color.value - if Config.joystick_labels: + if Config.joystick_labels.value: self.label_node.text = "x:%0.2f y:%0.2f" % [x, y] self._last_x = x diff --git a/controller/trigger/trigger_button.gd b/controller/trigger/trigger_button.gd index bd0768e..5332f3d 100644 --- a/controller/trigger/trigger_button.gd +++ b/controller/trigger/trigger_button.gd @@ -13,7 +13,17 @@ extends ProgressBar self.label_node.text = label func _ready() -> void: - self.label_node.text = self.label + if Config.buttons_labels.value: + self.label_node.text = self.label + else: + self.label_node.text = "" + self.progress_label.text = "" + + var bg_color: Color = Config.default_color.value + var fill_color: Color = Config.active_color.value + (self.get_theme_stylebox("background") as StyleBoxFlat).border_color = bg_color + (self.get_theme_stylebox("fill") as StyleBoxFlat).bg_color = fill_color func _process(_delta: float) -> void: - self.progress_label.text = "%s%%" % str(self.value * 100.0) + if !Engine.is_editor_hint() && Config.buttons_labels.value: + self.progress_label.text = "%s%%" % str(self.value * 100.0) diff --git a/helper.gd b/helper.gd index ea6c542..294a724 100644 --- a/helper.gd +++ b/helper.gd @@ -6,6 +6,6 @@ const DRIFT_DEADZONE := 0.01; const REST_DEADZONE := 0.005; const STUCK_DEADZONE := 0.05; -const DEFAULT_COLOR := Color(0x2a2a2aff) -const ACTIVE_COLOR := Color(0x4a8e53ff) const ERROR_COLOR := Color(0xbe2037ff) + +static var options: Array[ConfigOption] = [] diff --git a/project.godot b/project.godot index a1332ea..95b6a23 100644 --- a/project.godot +++ b/project.godot @@ -38,8 +38,10 @@ gdscript/warnings/unsafe_call_argument=2 window/size/viewport_width=1280 window/size/viewport_height=720 window/size/borderless=true +window/size/transparent=true window/stretch/mode="canvas_items" window/stretch/aspect="expand" +window/per_pixel_transparency/allowed=true window/vsync/vsync_mode=false [global_group]