Bored state

This commit is contained in:
Rekku 2024-09-17 21:05:57 +01:00
parent 27d150d466
commit 96965a704a
2 changed files with 37 additions and 25 deletions

View file

@ -3,62 +3,72 @@ extends MarginContainer
var press_time: float = 0.0 var press_time: float = 0.0
var is_state_pressed: bool = false var is_state_pressed: bool = false
var PRESS_DURATION: float = 3.0 var PRESS_DURATION: float = 3.0
var current_button: Button = null
var current_progress: ProgressBar = null
var current_state: String = ""
func _ready(): func _ready():
_connect_signals() _connect_signals()
func _process(delta: float) -> void: func _process(delta: float) -> void:
update_progress(delta, %ask_to_exit_progress, %ask_to_exit_button, class_functions.ask_to_exit_state) if current_button != null:
update_progress(delta, %border_progress, %border_button, class_functions.border_state) update_progress(delta, current_progress)
update_progress(delta, %widescreen_progress, %widescreen_button, class_functions.widescreen_state)
update_progress(delta, %quick_rewind_progress, %quick_rewind_button, class_functions.quick_rewind_state)
func update_progress(delta: float, progress: ProgressBar, button: Button, state: String) -> void: func update_progress(delta: float, progress: ProgressBar) -> void:
if press_time >= PRESS_DURATION: if press_time >= PRESS_DURATION:
#_do_complete(button) _do_complete(current_button)
print ("Progress Bar: %s Button: %s" % [progress.name, button.name]) print ("Progress Bar: %s Button: %s" % [progress.name, current_button.name])
press_time = 0.0 elif is_state_pressed and current_state == "mixed":
is_state_pressed = false
progress.value = 0.0
elif is_state_pressed and state == "mixed":
press_time += delta press_time += delta
progress.value = press_time / PRESS_DURATION * 100.0 progress.value = press_time / PRESS_DURATION * 100.0
func _connect_signals(): func _connect_signals():
%quick_resume_button.pressed.connect(class_functions.run_function.bind(%quick_resume_button, "quick_resume")) %quick_resume_button.pressed.connect(class_functions.run_function.bind(%quick_resume_button, "quick_resume"))
%button_swap_button.button_down.connect(_do_action.bind(%button_swap_progress)) %button_swap_button.button_down.connect(_do_action.bind(%button_swap_progress, %button_swap_button))
%button_swap_button.button_up.connect(_on_button_released.bind(%button_swap_progress)) %button_swap_button.button_up.connect(_on_button_released.bind(%button_swap_progress))
%button_swap_button.pressed.connect(class_functions.run_function.bind(%button_swap_button, "abxy_button_swap")) %button_swap_button.pressed.connect(class_functions.run_function.bind(%button_swap_button, "abxy_button_swap"))
%ask_to_exit_button.button_down.connect(_do_action.bind(%ask_to_exit_progress)) %ask_to_exit_button.button_down.connect(_do_action.bind(%ask_to_exit_progress, %ask_to_exit_button))
%ask_to_exit_button.button_up.connect(_on_button_released.bind(%ask_to_exit_progress)) %ask_to_exit_button.button_up.connect(_on_button_released.bind(%ask_to_exit_progress))
%ask_to_exit_button.pressed.connect(class_functions.run_function.bind(%ask_to_exit_button, "ask_to_exit")) %ask_to_exit_button.pressed.connect(class_functions.run_function.bind(%ask_to_exit_button, "ask_to_exit"))
%border_button.button_down.connect(_do_action.bind(%border_progress)) %border_button.button_down.connect(_do_action.bind(%border_progress, %border_button))
%border_button.button_up.connect(_on_button_released.bind(%border_progress)) %border_button.button_up.connect(_on_button_released.bind(%border_progress))
%border_button.pressed.connect(class_functions.run_function.bind(%border_button, "borders")) %border_button.pressed.connect(class_functions.run_function.bind(%border_button, "borders"))
%widescreen_button.button_down.connect(_do_action.bind(%widescreen_progress)) %widescreen_button.button_down.connect(_do_action.bind(%widescreen_progress, %widescreen_button))
%widescreen_button.button_up.connect(_on_button_released.bind(%widescreen_progress)) %widescreen_button.button_up.connect(_on_button_released.bind(%widescreen_progress))
%widescreen_button.pressed.connect(class_functions.run_function.bind(%widescreen_button, "widescreen")) %widescreen_button.pressed.connect(class_functions.run_function.bind(%widescreen_button, "widescreen"))
%quick_rewind_button.button_down.connect(_do_action.bind(%quick_rewind_progress)) %quick_rewind_button.button_down.connect(_do_action.bind(%quick_rewind_progress, %quick_rewind_button))
%quick_rewind_button.button_up.connect(_on_button_released.bind(%quick_rewind_progress)) %quick_rewind_button.button_up.connect(_on_button_released.bind(%quick_rewind_progress))
%quick_rewind_button.pressed.connect(class_functions.run_function.bind(%quick_rewind_button, "rewind")) %quick_rewind_button.pressed.connect(class_functions.run_function.bind(%quick_rewind_button, "rewind"))
func _on_button_released(progress: ProgressBar) -> void: func _on_button_released(progress: ProgressBar) -> void:
print ("Release " + progress.name)
is_state_pressed = false is_state_pressed = false
progress.visible = false progress.visible = false
press_time = 0.0 press_time = 0.0
progress.value = 0.0 progress.value = 0.0
current_button = null
current_progress = null
current_state == null
func _do_action(progress: ProgressBar) -> void: func _do_action(progress: ProgressBar, button: Button) -> void:
print ("Action " + progress.name) match progress.name:
match class_functions.button_list: "button_swap_progress":
class_functions.button_list: current_state = class_functions.abxy_state
is_state_pressed = true "ask_to_exit_progress":
progress.visible = true current_state = class_functions.ask_to_exit_state
"quick_rewind_progress":
current_state = class_functions.quick_rewind_state
"widescreen_progress":
current_state = class_functions.widescreen_state
"border_progress":
current_state = class_functions.border_state
current_button = button
current_progress = progress
current_progress.visible = true
is_state_pressed = true
func _do_complete(button: Button) ->void: func _do_complete(button: Button) ->void:
#TODO use object for state #TODO use object for state
if is_state_pressed: if is_state_pressed and button == current_button:
match button.name: match button.name:
"button_swap_button": "button_swap_button":
class_functions.abxy_state = "false" class_functions.abxy_state = "false"

View file

@ -289,6 +289,8 @@ func update_global(button: Button, preset: String, state: bool) -> void:
border_state = str(state) border_state = str(state)
result = data_handler.change_all_cfg_values(config_file_path, config_section, preset, str(state)) result = data_handler.change_all_cfg_values(config_file_path, config_section, preset, str(state))
change_global(result, "build_preset_config", button, border_state) change_global(result, "build_preset_config", button, border_state)
#if widescreen_state == "true" or widescreen_state == "mixed":
#print ("What's up")
"widescreen_button": "widescreen_button":
if widescreen_state != "mixed": if widescreen_state != "mixed":
widescreen_state = str(state) widescreen_state = str(state)