Skip to content

Commit

Permalink
GameUI must use a singleton from now on to ensure we can add the UI t…
Browse files Browse the repository at this point in the history
…o a SubViewport

The SubViewport is used only for VR Mode and it will add optional VR nodes.
I successfully avoided needing to write a lot of await code with GameUI.instance.get method which is great
  • Loading branch information
RevoluPowered committed Jun 19, 2024
1 parent d9076ea commit 0c8a3f2
Show file tree
Hide file tree
Showing 122 changed files with 366 additions and 285 deletions.
1 change: 0 additions & 1 deletion mirror-godot-app/addons/gut/gui/editor_globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ static var user_prefs = _user_prefs :

static func create_temp_directory():
DirAccess.make_dir_recursive_absolute(temp_directory)

Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func _on_delete_dialog_confirmed():
Notify.error("Asset Delete Error", promise.get_error_message())
else:
Notify.info("Asset Deleted", "Asset deleted succesfully.")
GameUI.creator_ui.asset_browser.on_asset_deleted(true)
GameUI.instance.creator_ui.asset_browser.on_asset_deleted(true)
hide()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var _last_upload_directory: String = ""
@onready var _viewport: Viewport = get_viewport()
@onready var _file_search: FileDialog:
get:
return GameUI.file_search
return GameUI.instance.file_search

@onready var _sections := $VBoxContainer/Sections
@onready var _recents := _sections.get_node(^"Recents")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func _on_next_page_pressed():


func _on_focus_entered() -> void:
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)


func _on_focus_exited() -> void:
GameUI.release_input_lock(self)
GameUI.instance.release_input_lock(self)
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var _id_to_slot_map: Dictionary = {}

func _ready() -> void:
super()
await GameUI.ready
GameUI.login_ui.login_succeeded.connect(Net.asset_client.get_recent_assets)
await GameUI.instance.ready
GameUI.instance.login_ui.login_succeeded.connect(Net.asset_client.get_recent_assets)
Net.asset_client.asset_received.connect(_on_net_asset_received)
Net.asset_client.recent_assets_received.connect(_on_net_recent_assets_received)
Zone.client.disconnected.connect(_on_zone_disconnected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ func _slot_primary_action() -> void:

func _on_asset_slot_mouse_entered() -> void:
super()
GameUI.set_hover_tooltip_text(recent_script["name"], "Space Script")
GameUI.instance.set_hover_tooltip_text(recent_script["name"], "Space Script")
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func _on_line_edit_text_submitted(new_text: String) -> void:


func _on_focus_entered():
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)


func _on_focus_exited():
GameUI.release_input_lock(self)
GameUI.instance.release_input_lock(self)


func focus():
Expand Down
2 changes: 1 addition & 1 deletion mirror-godot-app/creator/common/asset_slot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ func _on_asset_slot_mouse_entered() -> void:
return
var hover_uri = asset_data.thirdparty_source_home_page_url
hover_uri = hover_uri.trim_prefix("https://").trim_prefix("http://")
GameUI.set_hover_tooltip_text(asset_data.asset_name, hover_uri)
GameUI.instance.set_hover_tooltip_text(asset_data.asset_name, hover_uri)
4 changes: 2 additions & 2 deletions mirror-godot-app/creator/common/base_asset_slot.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func _on_asset_slot_gui_input(input_event: InputEvent) -> void:
elif input_event.is_action_released(&"primary_action"):
slot_activated.emit(self, false)
elif input_event.is_action_released(&"secondary_action"):
GameUI.creator_ui.open_context_menu(self)
GameUI.instance.creator_ui.open_context_menu(self)


func _on_asset_slot_mouse_entered() -> void:
Expand All @@ -97,4 +97,4 @@ func _on_asset_slot_mouse_entered() -> void:
func _on_asset_slot_mouse_exited() -> void:
if not _is_selected:
_hover_state.hide()
GameUI.hide_hover_tooltip_text()
GameUI.instance.hide_hover_tooltip_text()
6 changes: 3 additions & 3 deletions mirror-godot-app/creator/creator_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func _selection_copy_paste_input(input_event: InputEvent) -> bool:
elif input_event.is_action_pressed(&"action_copy"):
object_selection.copy_selected_nodes()
elif input_event.is_action_pressed(&"action_paste")\
and not GameUI.is_mouse_hovering_any_control():
and not GameUI.instance.is_mouse_hovering_any_control():
object_selection.paste_copied_nodes()
else:
return false
Expand All @@ -159,7 +159,7 @@ func _selection_copy_paste_input(input_event: InputEvent) -> bool:

func _build_mode_camera_movement_input(input_event: InputEvent) -> bool:
_mouse_in_motion = input_event is InputEventMouseMotion and input_event.relative.length() > 0
if Input.is_action_pressed(&"build_mode_camera_movement") or GameUI.is_cinematic_mode_enabled():
if Input.is_action_pressed(&"build_mode_camera_movement") or GameUI.instance.is_cinematic_mode_enabled():
if _mouse_in_motion:
_mouse_used_for_build_mode_camera_movement = true
else:
Expand Down Expand Up @@ -337,7 +337,7 @@ func select_object(object: Node3D) -> void:


func raycast_hit_object(hit: Node3D) -> void:
if GameUI.is_cinematic_mode_enabled() or _current_game_mode == GameMode.Mode.NORMAL:
if GameUI.instance.is_cinematic_mode_enabled() or _current_game_mode == GameMode.Mode.NORMAL:
return
object_selection.raycast_hit_object(hit)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func popup_dialog(target_node: Node) -> void:
_add_script_menu.hide_add_script_filter_menu()
size = Vector2.ZERO
popup_centered()
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)
if GameplaySettings.script_quick_attach_existing:
title = "Create or Attach Script"
_add_script_menu.focus_add_script_filter_menu()
Expand Down
2 changes: 1 addition & 1 deletion mirror-godot-app/creator/selection/gizmo/gizmo.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func update_gizmo_visibility() -> void:
target.is_selection_empty()
or target.is_space_object_asset_type(Enums.ASSET_TYPE.MAP)
or target.is_any_object_not_allowed_to_edit()
or not GameUI.creator_ui.is_edit_mode(Enums.EDIT_MODE.Asset)
or not GameUI.instance.creator_ui.is_edit_mode(Enums.EDIT_MODE.Asset)
or PlayerData.game_mode.get_current_mode() == PlayerData.game_mode.Mode.NORMAL
):
_hide_all_gizmos()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func _on_toggle_button_pressed():
func _on_hoverable_button_mouse_entered() -> void:
if hover_tooltip_text == "":
return
GameUI.set_hover_tooltip_text(hover_tooltip_text)
GameUI.instance.set_hover_tooltip_text(hover_tooltip_text)


func _on_hoverable_button_mouse_exited() -> void:
GameUI.hide_hover_tooltip_text()
GameUI.instance.hide_hover_tooltip_text()


func _on_hoverable_button_pressed() -> void:
GameUI.hide_hover_tooltip_text()
GameUI.instance.hide_hover_tooltip_text()
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func _on_locked_value_changed(new_value: bool) -> void:


func _on_asset_asset_clicked(asset_data):
GameUI.creator_ui.asset_detail_window.request_info_popup(asset_data)
GameUI.instance.creator_ui.asset_detail_window.request_info_popup(asset_data)


func _on_description_value_changed(new_value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ func _select_new_team(value):


func _edit_teams_button_pressed():
GameUI.teams_handler.toggle_teams_editor()
GameUI.instance.teams_handler.toggle_teams_editor()
8 changes: 4 additions & 4 deletions mirror-godot-app/creator/selection/inspector/inspector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func _refresh_material_tabs(selected_nodes: Array[Node]):
idx = _surfaces_item_list.add_item(surface_name, _tab_materials_icon)
_surfaces_item_list.set_item_metadata(idx, [mi, x, space_obj])
space_obj_cnt += 1
if not is_instance_valid(GameUI.creator_ui):
if not is_instance_valid(GameUI.instance.creator_ui):
return
if idx > -1:
if previously_selected_idx != -1 and previously_selected_idx < idx:
Expand All @@ -141,7 +141,7 @@ func _refresh_material_tabs(selected_nodes: Array[Node]):
_surfaces_item_list.select(idx, true)
_surfaces_item_list.ensure_current_is_visible()
_on_surfaces_item_list_item_selected(idx, false)
var material_creator = GameUI.creator_ui.material_creator_window.material_creator
var material_creator = GameUI.instance.creator_ui.material_creator_window.material_creator
Util.safe_signal_connect(material_creator.on_surface_material_updated, _on_surface_material_updated)
Util.safe_signal_connect(_material_inspector.material_created, _on_material_created)

Expand Down Expand Up @@ -514,11 +514,11 @@ func _on_add_script_button_pressed() -> void:
func _on_material_creator_button_pressed() -> void:
var selected_surface = _surfaces_item_list.get_selected_items()
if selected_surface.size() != 1:
#GameUI.creator_ui.material_creator_window.edit_material_for_mesh()
#GameUI.instance.creator_ui.material_creator_window.edit_material_for_mesh()
return
var data = _surfaces_item_list.get_item_metadata(selected_surface[0])
# data contains [MeshInstance, surface_id, SpaceObject]
GameUI.creator_ui.material_creator_window.edit_material_for_mesh(data[2], data[0], data[1])
GameUI.instance.creator_ui.material_creator_window.edit_material_for_mesh(data[2], data[0], data[1])


func _on_surface_picked(data) -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ func _process_physics_shape_outlines() -> void:
var shape_size: Vector3 = _get_shape_size_vector_from_ext()
var shape_transform: Transform3D = target_node.scaled_model.global_transform.scaled_local(shape_size)
if shape_type == "box":
GameUI.object_outlines.draw_wireframe_box_transform(shape_transform, _OUTLINE_COLOR)
GameUI.instance.object_outlines.draw_wireframe_box_transform(shape_transform, _OUTLINE_COLOR)
elif shape_type == "sphere":
GameUI.object_outlines.draw_wireframe_sphere(shape_transform, _OUTLINE_COLOR)
GameUI.instance.object_outlines.draw_wireframe_sphere(shape_transform, _OUTLINE_COLOR)
else:
shape_transform = shape_transform.scaled_local(Vector3(1.0, shape_size.x / shape_size.y, 1.0))
if shape_type == "capsule":
var half_mid_height: float = (shape_size.y - shape_size.x) * 0.5
GameUI.object_outlines.draw_wireframe_capsule(shape_transform, half_mid_height, _OUTLINE_COLOR)
GameUI.instance.object_outlines.draw_wireframe_capsule(shape_transform, half_mid_height, _OUTLINE_COLOR)
if shape_type == "cylinder":
var half_height: float = shape_size.y * 0.5
GameUI.object_outlines.draw_wireframe_cylinder(shape_transform, half_height, _OUTLINE_COLOR)
GameUI.instance.object_outlines.draw_wireframe_cylinder(shape_transform, half_height, _OUTLINE_COLOR)


func _refresh_already_setup_inspectors() -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func _gui_input(input_event: InputEvent) -> void:
return
tree_item.select(0)
selected_node_name = tree_item.get_text(0)
GameUI.creator_ui.open_context_menu(self)
GameUI.instance.creator_ui.open_context_menu(self)
else:
super(input_event)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func _draw_lines() -> void:
_last_knee_position,
_last_foot_position,
]
var mi: MeshInstance3D = GameUI.object_outlines.draw_lines(lines, Color.SADDLE_BROWN)
var mi: MeshInstance3D = GameUI.instance.object_outlines.draw_lines(lines, Color.SADDLE_BROWN)
mi.transform = global_transform


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func cleanup_and_delete() -> void:
func _on_hoverable_inspector_item_mouse_entered() -> void:
if hover_tooltip_text == "":
return
GameUI.set_hover_tooltip_text(hover_tooltip_text)
GameUI.instance.set_hover_tooltip_text(hover_tooltip_text)


func _on_hoverable_inspector_item_mouse_exited() -> void:
GameUI.hide_hover_tooltip_text()
GameUI.instance.hide_hover_tooltip_text()
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func _on_focus_entered() -> void:
await get_tree().process_frame
# This is done declaratively by LineEdit.select_all_on_focus = true
# _line_edit_node.select_all()
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)


func _on_focus_exited() -> void:
GameUI.release_input_lock(self)
GameUI.instance.release_input_lock(self)


func _on_reset_button_pressed() -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func _on_file_dialog_file_selected(path):

func _upload_as_texture(path: String, param: String) -> void:
_loading_spinner.show()
var promise: Promise = await GameUI.creator_ui.asset_browser.create_asset_from_url(
var promise: Promise = await GameUI.instance.creator_ui.asset_browser.create_asset_from_url(
path,
Enums.ASSET_TYPE.TEXTURE,
{"textureImagePropertyAppliesTo": param}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func _on_reset_button_pressed() -> void:


func _on_material_selected():
var selected_slot = GameUI.creator_ui.material_window.material_browser.get_selected_slot()
var selected_slot = GameUI.instance.creator_ui.material_window.material_browser.get_selected_slot()
if selected_slot:
var is_instance = selected_slot is MaterialInstanceSlot
var material_type = Enums.MATERIAL_TYPE.INSTANCE if is_instance else Enums.MATERIAL_TYPE.ASSET
Expand All @@ -97,8 +97,8 @@ func _on_material_selected():


func _on_button_pressed():
GameUI.creator_ui.material_window.popup_centered()
GameUI.creator_ui.material_window.material_browser.selected_material_slot_changed.connect(_on_material_selected)
GameUI.instance.creator_ui.material_window.popup_centered()
GameUI.instance.creator_ui.material_window.material_browser.selected_material_slot_changed.connect(_on_material_selected)


func _clear() -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ func _on_spin_box_text_changed(new_text: String) -> void:

func _on_focus_entered() -> void:
_spin_box_node.value_changed.connect(_on_spin_box_value_changed, CONNECT_ONE_SHOT)
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)
await get_tree().process_frame
_line_edit_node.select_all()


func _on_focus_exited():
assert(not is_queued_for_deletion())
refresh_full()
GameUI.release_input_lock(self)
GameUI.instance.release_input_lock(self)


func _on_reset_button_pressed() -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ func set_enabled(in_is_enabled: bool):


func _on_focus_entered():
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)


func _on_focus_exited():
refresh()
GameUI.release_input_lock(self)
GameUI.instance.release_input_lock(self)


func _on_reset_button_pressed() -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ signal value_submitted()


func emit_value_submitted(_new_text = null) -> void:
GameUI.release_input_lock(self)
GameUI.instance.release_input_lock(self)
value_submitted.emit()


func _on_focus_entered() -> void:
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)


func _on_focus_exited() -> void:
if not get_viewport() is AcceptDialog:
GameUI.release_input_lock(self)
GameUI.instance.release_input_lock(self)
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ func _on_spin_box_text_changed(new_text: String) -> void:
func _on_key_focus_entered() -> void:
if not _spin_box_node.value_changed.is_connected(_on_spin_box_value_changed):
_spin_box_node.value_changed.connect(_on_spin_box_value_changed, CONNECT_ONE_SHOT)
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)
await get_tree().process_frame
_line_edit_node.select_all()


func _on_focus_exited():
refresh_full()
GameUI.release_input_lock(self)
GameUI.instance.release_input_lock(self)


func _on_gui_input(event: InputEvent):
Expand All @@ -103,7 +103,7 @@ func _on_gui_input(event: InputEvent):
else:
if _grabbing_spinner_attempt:
if _grabbing_spinner:
GameUI.creator_ui.ui_request_captured = false
GameUI.instance.creator_ui.ui_request_captured = false
# This is needed to avoid process frame issues race conditions
# free_camera.gd will try to handle CAPTURED before input
# handlin of mouse_capture.gd
Expand All @@ -124,7 +124,7 @@ func _on_gui_input(event: InputEvent):
diff_x *= 0.1
_grabbing_spinner_dist_cache += diff_x
if not _grabbing_spinner and absf(_grabbing_spinner_dist_cache) > 4 * GameplaySettings.ui_scale:
GameUI.creator_ui.ui_request_captured = true
GameUI.instance.creator_ui.ui_request_captured = true
_grabbing_spinner = true
if _grabbing_spinner:
# Don't make the user scroll all the way back to 'in range' if they went off the end.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ signal create_parameter(parameter_port_array: Array)
func _on_pressed() -> void:
_variable_creation_menu.clear_fields()
_add_input_dialog.popup_centered()
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)
_variable_creation_menu.focus_variable_editor_name_field()


Expand All @@ -24,8 +24,8 @@ func emit_create_parameter() -> void:


func _on_add_input_dialog_focus_entered() -> void:
GameUI.grab_input_lock(self)
GameUI.instance.grab_input_lock(self)


func _on_add_input_dialog_focus_exited() -> void:
GameUI.release_input_lock(self)
GameUI.instance.release_input_lock(self)
Loading

0 comments on commit 0c8a3f2

Please sign in to comment.