refactor: changing focus naming convention to stage based metaphor
This commit is contained in:
parent
67cde4ca17
commit
8f53ed664d
|
|
@ -1,6 +1,6 @@
|
|||
extends Area3D
|
||||
|
||||
@onready var focus_forward = $UiWrapper/UiSprite/SubViewport/Collectable_ui
|
||||
@onready var pass_to_actor = $UiWrapper/UiSprite/SubViewport/Collectable_ui
|
||||
var has_mouse: bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ var current_mode: int = Modes.FREEZE:
|
|||
func start():
|
||||
$light_animation.play("light_up")
|
||||
$AudioPlayer.play("intro")
|
||||
State.pass_focus_to($PlayerController)
|
||||
State.pass_stage_to($PlayerController)
|
||||
current_mode = Modes.WALKING
|
||||
|
||||
func _update_scene(new_mode) -> int:
|
||||
|
|
@ -35,4 +35,4 @@ func _unhandled_input(event):
|
|||
if event is InputEventMouseButton:
|
||||
if event.pressed:
|
||||
print("passed")
|
||||
#State.pass_focus_to($PlayerController)
|
||||
#State.pass_stage_to($PlayerController)
|
||||
|
|
|
|||
|
|
@ -1050,8 +1050,8 @@ light_energy = 0.5
|
|||
light_size = 0.499
|
||||
light_specular = 0.0
|
||||
shadow_enabled = true
|
||||
shadow_bias = 0.0
|
||||
shadow_normal_bias = 6.753
|
||||
shadow_bias = 0.01
|
||||
shadow_normal_bias = 5.78
|
||||
shadow_blur = 0.5
|
||||
omni_attenuation = 1.51572
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ extends PanelContainer
|
|||
var area_dict = {}
|
||||
enum ui_context {DROPZONE, POST_IT_LIST, ASSIGN_POST_IT}
|
||||
|
||||
var has_focus = false:
|
||||
var has_stage = false:
|
||||
set(focus):
|
||||
if focus != has_focus:
|
||||
if focus != has_stage:
|
||||
if focus:
|
||||
has_focus = true
|
||||
has_stage = true
|
||||
self.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
else:
|
||||
has_focus = false
|
||||
has_stage = false
|
||||
self.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
||||
@onready var dropzone = $HBoxContainer/dropzone
|
||||
|
|
@ -41,7 +41,7 @@ func _ready():
|
|||
func _process(delta):
|
||||
# Reset information about Areas being dragged, if the mouse is not longer pressed.
|
||||
# Needed because otherwise it can happen that the areas don't register it if you stop clicking on them.
|
||||
if has_focus and !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged:
|
||||
if has_stage and !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and is_area_dragged:
|
||||
currently_dragged_area.is_dragged = false
|
||||
is_area_dragged = false
|
||||
currently_dragged_area = null
|
||||
|
|
@ -200,7 +200,7 @@ func reorder_areas(reorder: String):
|
|||
# Takes the inputs for control inputs
|
||||
func _input(event):
|
||||
# Return, if the input is a mouse event (mouse events are handled separately)
|
||||
if event is InputEventMouse or !has_focus: return
|
||||
if event is InputEventMouse or !has_stage: return
|
||||
|
||||
if event.is_action_pressed("ui_up"): # up to select an element above
|
||||
match active_context:
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ enum {
|
|||
|
||||
@onready var debug_board:Control = $"board of devs"
|
||||
|
||||
var has_focus = false:
|
||||
var has_stage = false:
|
||||
set(focus):
|
||||
if not focus == has_focus:
|
||||
if not focus == has_stage:
|
||||
if focus:
|
||||
for player in anim_players: player.play("reveal")
|
||||
selection_state = CARDS # fixme
|
||||
|
|
@ -21,9 +21,9 @@ var has_focus = false:
|
|||
self.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
else:
|
||||
self.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
has_focus = focus
|
||||
has_stage = focus
|
||||
|
||||
visible = has_focus
|
||||
visible = has_stage
|
||||
|
||||
var selection_state = INI
|
||||
var input_locked = true
|
||||
|
|
@ -76,7 +76,7 @@ func fill_post_slots():
|
|||
options[i].replace_with(post_its[i])
|
||||
|
||||
func _unhandled_input(event):
|
||||
if has_focus and not input_locked:
|
||||
if has_stage and not input_locked:
|
||||
if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_left") or event.is_action_pressed("ui_focus_next"):
|
||||
curr_selection_id -= 1
|
||||
elif event.is_action_pressed("ui_down") or event.is_action_pressed("ui_right") or event.is_action_pressed("ui_focus_prev"):
|
||||
|
|
@ -141,7 +141,7 @@ func pick(id: int):
|
|||
for card in output:
|
||||
out_str.append(card.name)
|
||||
emit_signal("cards_picked", out_str)
|
||||
State.drop_focus(self)
|
||||
State.leave_stage(self)
|
||||
|
||||
func handle_hover(new_highlight):
|
||||
if not input_locked:
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@ class_name Collectable_Ui
|
|||
collapsed = collapse
|
||||
|
||||
@export var is_story: bool = false
|
||||
@export var has_focus: bool = false:
|
||||
@export var has_stage: bool = false:
|
||||
set(focused):
|
||||
print("set focus of card to ", focused)
|
||||
|
||||
if has_focus == focused: return
|
||||
if has_stage == focused: return
|
||||
|
||||
if focused:
|
||||
has_focus = true
|
||||
has_stage = true
|
||||
print(visible)
|
||||
if not visible: show()
|
||||
collapsed = false
|
||||
|
|
@ -33,8 +33,8 @@ class_name Collectable_Ui
|
|||
$Panel/Content/Buttons/VBoxContainer/put_back.grab_focus()
|
||||
else:
|
||||
$Panel/Content/Buttons/VBoxContainer/collect_or_listen.grab_focus()
|
||||
elif has_focus:
|
||||
has_focus = false
|
||||
elif has_stage:
|
||||
has_stage = false
|
||||
get_viewport().gui_release_focus()
|
||||
#hide()
|
||||
|
||||
|
|
@ -111,11 +111,11 @@ func show():
|
|||
|
||||
func _yoink_focus():
|
||||
return # fixme
|
||||
if not has_focus:
|
||||
State.request_focus_for(self, true)
|
||||
if not has_stage:
|
||||
State.take_stage(self, true)
|
||||
|
||||
func _on_pick_button_pressed():
|
||||
hide()
|
||||
print("card collected!")
|
||||
emit_signal("card_collected")
|
||||
State.drop_focus(self)
|
||||
State.leave_stage(self)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
extends Panel
|
||||
|
||||
@onready var has_focus = true:
|
||||
@onready var has_stage = true:
|
||||
set(focus):
|
||||
if focus:
|
||||
has_focus = State.request_focus(self)
|
||||
has_stage = State.request_focus(self)
|
||||
else:
|
||||
has_focus = false
|
||||
has_stage = false
|
||||
State.drop_own_focus(self)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
extends RigidBody3D
|
||||
|
||||
var has_focus: bool = false:
|
||||
var has_stage: bool = false:
|
||||
set(focused):
|
||||
if has_focus != focused:
|
||||
if has_stage != focused:
|
||||
if focused:
|
||||
has_focus = true
|
||||
has_stage = true
|
||||
if is_inside_tree():
|
||||
camera.make_current()
|
||||
get_viewport().gui_release_focus()
|
||||
|
|
@ -12,20 +12,20 @@ var has_focus: bool = false:
|
|||
var jitter_tween: Tween = create_tween()
|
||||
jitter_tween.tween_property(self, "jitter_strength", 1, 1)
|
||||
if has_entered: emit_signal("ui_entered")
|
||||
elif has_focus:
|
||||
elif has_stage:
|
||||
camera.current = true
|
||||
jitter_strength = 1
|
||||
else:
|
||||
if is_inside_tree() and has_focus:
|
||||
if is_inside_tree() and has_stage:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
var jitter_tween: Tween = create_tween()
|
||||
jitter_tween.tween_property(self, "jitter_strength", 0, 0.5)
|
||||
if has_entered: emit_signal("ui_exited")
|
||||
else:
|
||||
jitter_strength = 0
|
||||
has_focus = false
|
||||
has_stage = false
|
||||
|
||||
sleeping = has_focus
|
||||
sleeping = has_stage
|
||||
|
||||
@export_range (0, 10) var max_speed: float = 3
|
||||
@export_range (0, 10) var max_acceleration: float = 5
|
||||
|
|
@ -76,10 +76,10 @@ func _process(_delta):
|
|||
emit_signal("ui_exited")
|
||||
has_entered = false
|
||||
if Input.is_action_just_pressed("ui_accept"):
|
||||
State.pass_focus_to(focus_ray.get_collider())
|
||||
State.pass_stage_to(focus_ray.get_collider())
|
||||
|
||||
func _physics_process(delta:float):
|
||||
if has_focus:
|
||||
if has_stage:
|
||||
_handle_movement(delta)
|
||||
_handle_rotation(delta)
|
||||
if jitter_strength > 0: _handle_jitter(delta)
|
||||
|
|
@ -144,7 +144,7 @@ func _handle_mouse_input(event:InputEventMouseMotion):
|
|||
current_mouse_rotation = event.relative
|
||||
|
||||
func _input(event:InputEvent):
|
||||
if has_focus:
|
||||
if has_stage:
|
||||
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
_handle_mouse_input(event)
|
||||
get_viewport().set_input_as_handled()
|
||||
|
|
@ -152,11 +152,11 @@ func _input(event:InputEvent):
|
|||
State.free_focus()
|
||||
get_viewport().set_input_as_handled()
|
||||
#if event.is_action_pressed("ui_accept"):
|
||||
# State.pass_focus_to(focus_ray.get_collider())
|
||||
# State.pass_stage_to(focus_ray.get_collider())
|
||||
# get_viewport().set_input_as_handled()
|
||||
|
||||
func _on_empty_click():
|
||||
State.request_focus_for(self, true)
|
||||
State.take_stage(self, true)
|
||||
|
||||
func _on_bed_enter(_body):
|
||||
if not (crouched or on_crouch_cooldown):
|
||||
|
|
|
|||
|
|
@ -9,65 +9,67 @@ var show_content_notes: bool = false
|
|||
var provide_summaries: bool = false
|
||||
var allow_skipping: bool = false
|
||||
|
||||
var focus_list:Array = []
|
||||
var stage_list:Array = []
|
||||
var lock_focus: bool = false
|
||||
|
||||
func _ready():
|
||||
for child in get_parent().get_children():
|
||||
if "has_focus" in child:
|
||||
pass_focus_to(child)
|
||||
if "has_stage" in child:
|
||||
pass_stage_to(child)
|
||||
|
||||
# Intented for use when me wants focus for itself, can reclaim focus, thus dropping the stack that focused.
|
||||
func request_focus_for(me: Object, reclaim: bool = false) -> bool:
|
||||
# Meta: due to conflicting names with the internal focus handling of godot, a "stage-based" Metaphor is being used to refer to focus handling.
|
||||
|
||||
# Intented for use when an actor wants focus for itself, can reclaim focus, thus dropping the stack that focused.
|
||||
func take_stage(actor: Object, reclaim: bool = false) -> bool:
|
||||
if reclaim:
|
||||
focus_list.front().has_focus = false
|
||||
if focus_list.has(me):
|
||||
while focus_list.pop_front() != me: break
|
||||
me.has_focus = true
|
||||
return me.has_focus
|
||||
push_warning(me, " wanted to reclaim focus, but was not on list.")
|
||||
return pass_focus_to(me)
|
||||
stage_list.front().has_stage = false
|
||||
if stage_list.has(actor):
|
||||
while stage_list.pop_front() != actor: break
|
||||
actor.has_stage = true
|
||||
return actor.has_stage
|
||||
push_warning(actor, " wanted to reclaim focus, but was not on list.")
|
||||
return pass_stage_to(actor)
|
||||
|
||||
# Element no longer wants focus, if Element itself is also dropped, this option can be chosen aswell.
|
||||
func drop_focus(of:Object, dropObject: bool = false) -> bool:
|
||||
func leave_stage(actor:Object, dropObject: bool = false) -> bool:
|
||||
if lock_focus or get_tree().paused:
|
||||
push_error(of, " wanted to drop focus while it was locked or tree is paused.")
|
||||
push_error(actor, " wanted to drop focus while it was locked or tree is paused.")
|
||||
|
||||
if not dropObject: of.has_focus = false
|
||||
if not dropObject: actor.has_stage = false
|
||||
|
||||
focus_list.erase(of)
|
||||
stage_list.erase(actor)
|
||||
|
||||
focus_list.front().has_focus = true
|
||||
stage_list.front().has_stage = true
|
||||
|
||||
return false
|
||||
|
||||
func get_current_focus(): return focus_list.front()
|
||||
func get_current_actor(): return stage_list.front()
|
||||
|
||||
# Used to put a new target on top of the Focus Stack.
|
||||
func pass_focus_to(target:Object) -> bool:
|
||||
if "focus_forward" in target:
|
||||
pass_focus_to(target.focus_forward)
|
||||
func pass_stage_to(target:Object) -> bool:
|
||||
if "pass_to_actor" in target:
|
||||
pass_stage_to(target.pass_to_actor)
|
||||
if lock_focus or get_tree().paused:
|
||||
push_error(target, " requested focus while it was locked or tree is paused.")
|
||||
elif !is_instance_valid(target):
|
||||
push_error("Focus instance not valid")
|
||||
elif !"has_focus" in target:
|
||||
elif !"has_stage" in target:
|
||||
push_error(target, " has no has focus method.")
|
||||
if focus_list.size() > 0:
|
||||
if focus_list.front() == target:
|
||||
if stage_list.size() > 0:
|
||||
if stage_list.front() == target:
|
||||
push_warning(target, " is already target. Abort passing focus.")
|
||||
else:
|
||||
if not focus_list.size() == 0: focus_list.front().has_focus = false
|
||||
target.has_focus = true
|
||||
if target.has_focus:
|
||||
focus_list.push_front(target)
|
||||
assert(focus_list.size() < 100)
|
||||
if not stage_list.size() == 0: stage_list.front().has_stage = false
|
||||
target.has_stage = true
|
||||
if target.has_stage:
|
||||
stage_list.push_front(target)
|
||||
assert(stage_list.size() < 100)
|
||||
return true
|
||||
return false
|
||||
|
||||
# Currently focused element loses focus, but remains in stack.
|
||||
func free_focus():
|
||||
if not focus_list.front() == null: focus_list.front().has_focus = false
|
||||
if not stage_list.front() == null: stage_list.front().has_stage = false
|
||||
|
||||
func queue_for_focus(target: Object, index: int):
|
||||
focus_list.insert(index, target)
|
||||
func queue_for_stage(target: Object, index: int):
|
||||
stage_list.insert(index, target)
|
||||
|
|
|
|||
Loading…
Reference in New Issue