Skip to content

Commit

Permalink
feat(Library): add option and menu to hide items in library
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Jun 4, 2024
1 parent f221c0c commit b026738
Show file tree
Hide file tree
Showing 19 changed files with 359 additions and 87 deletions.
8 changes: 8 additions & 0 deletions assets/state/states/game_settings_library.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="State" load_steps=2 format=3 uid="uid://bnw36g1l7shcy"]

[ext_resource type="Script" path="res://core/systems/state/state.gd" id="1_ds0g8"]

[resource]
script = ExtResource("1_ds0g8")
name = "library"
data = {}
8 changes: 8 additions & 0 deletions assets/state/states/settings_library.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="State" load_steps=2 format=3 uid="uid://blcfrofi5oawd"]

[ext_resource type="Script" path="res://core/systems/state/state.gd" id="1_728sf"]

[resource]
script = ExtResource("1_728sf")
name = "library"
data = {}
15 changes: 15 additions & 0 deletions core/global/library_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ signal library_loaded(library_id: String)
signal library_item_added(item: LibraryItem)
## Emitted when a [LibraryItem] is removed from the library
signal library_item_removed(item: LibraryItem)
## Emitted when a [LibraryItem] is hidden from the library
signal library_item_hidden(item: LibraryItem)
## Emitted when a [LibraryItem] is unhidden from the library
signal library_item_unhidden(item: LibraryItem)
## Emitted when a [LibraryLaunchItem] is added to a [LibraryItem]
signal library_launch_item_added(item: LibraryLaunchItem)
## Emitted when a [LibraryLaunchItem] is removed from a [LibraryItem]
signal library_launch_item_removed(item: LibraryLaunchItem)

var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager

# Dictionary of registered library providers
# The dictionary is in the form of:
# {
Expand Down Expand Up @@ -106,6 +112,12 @@ func filter_by_library(apps: Array[LibraryItem], library_id: String) -> Array[Li
return apps.filter(filter)


## Filters the given array of apps by hidden
func filter_by_hidden(apps: Array[LibraryItem]) -> Array[LibraryItem]:
var filter := func(item: LibraryItem): return item.is_hidden
return apps.filter(filter)


## Returns an dictionary of all available apps
func get_available() -> Dictionary:
return _available_apps.duplicate()
Expand Down Expand Up @@ -135,6 +147,9 @@ func add_library_launch_item(library_id: String, item: LibraryLaunchItem) -> voi
library_item = LibraryItem.new_from_launch_item(item)
_available_apps[item.name] = library_item
is_new = true
var is_hidden := settings_manager.get_library_value(library_item, "hidden", false) as bool
if is_hidden:
library_item.is_hidden = is_hidden

# Update the provider fields on the library item
item._provider_id = library_id
Expand Down
6 changes: 6 additions & 0 deletions core/systems/debug/logger.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ func error(message: Variant, xtra2: Variant = null, xtra3: Variant = null, xtra4
var msg := _stringify(message, xtra2, xtra3, xtra4, xtra5, xtra6)
push_error(prefix, msg)
print_rich("[color=red]", prefix, "[/color]", msg)


func deprecated(message: Variant) -> void:
var prefix := _format_prefix("DEPRECATED", _get_caller())
var msg := str(message)
print_rich("[color=pink]", prefix, "[/color]", msg)
12 changes: 12 additions & 0 deletions core/systems/library/library_item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ signal installed(launch_item: LibraryLaunchItem)
signal uninstalled(launch_item: LibraryLaunchItem)
## Emitted when the [InstallManager] has updated this library item
signal upgraded(launch_item: LibraryLaunchItem)
## Emitted when this library item is hidden from the library
signal hidden
## Emitted when this library item is unhidden from the library
signal unhidden

## The unique ID of the library item
@export var _id: String
Expand All @@ -31,6 +35,14 @@ signal upgraded(launch_item: LibraryLaunchItem)
@export var tags: PackedStringArray
## An array of categories the game belongs to
@export var categories: PackedStringArray
## Whether or not this library item should be hidden in the library
var is_hidden: bool:
set(_is_hidden):
is_hidden = _is_hidden
if is_hidden:
hidden.emit()
else:
unhidden.emit()


## Creates a new library item from the given library launch item
Expand Down
13 changes: 12 additions & 1 deletion core/ui/card_ui/launch/game_settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ var library_item: LibraryItem
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
game_settings_state.state_entered.connect(_on_state_entered)
game_settings_state.state_exited.connect(_on_state_exited)
settings_state_machine.state_changed.connect(_on_settings_state_changed)


func _on_state_entered(_from: State) -> void:
if "item" in game_settings_state.data:
if game_settings_state.has_meta("item"):
library_item = game_settings_state.get_meta("item") as LibraryItem
elif "item" in game_settings_state.data:
library_item = game_settings_state.data["item"] as LibraryItem

# Set the selected game's name
Expand All @@ -33,7 +36,15 @@ func _on_state_entered(_from: State) -> void:
break


func _on_state_exited(_to: State) -> void:
settings_state_machine.pop_state()
game_settings_state.data.erase("item")
game_settings_state.remove_meta("item")


func _on_settings_state_changed(_from: State, to: State) -> void:
if not to:
return
var text := to.name
text = text.capitalize()
text = text.replace("_", " ")
Expand Down
23 changes: 22 additions & 1 deletion core/ui/card_ui/launch/game_settings.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=3 uid="uid://58qlqqbh58im"]
[gd_scene load_steps=26 format=3 uid="uid://58qlqqbh58im"]

[ext_resource type="Script" path="res://core/ui/card_ui/launch/game_settings.gd" id="1_vrr6s"]
[ext_resource type="PackedScene" uid="uid://orey8uxm7v6v" path="res://core/systems/state/visibility_manager.tscn" id="2_pga6u"]
Expand All @@ -19,7 +19,9 @@
[ext_resource type="Resource" uid="uid://1dnelmxp0tuq" path="res://assets/state/state_machines/game_settings_state_machine.tres" id="20_cokg3"]
[ext_resource type="Resource" uid="uid://d3rbp3ws1ejal" path="res://assets/state/states/game_settings_launch.tres" id="21_tdepl"]
[ext_resource type="PackedScene" uid="uid://dl3lxwakvk7l2" path="res://core/ui/common/launch/game_boxart_settings.tscn" id="24_4afdc"]
[ext_resource type="Resource" uid="uid://bnw36g1l7shcy" path="res://assets/state/states/game_settings_library.tres" id="24_um3vy"]
[ext_resource type="Resource" uid="uid://bn8ih6qafytvi" path="res://assets/state/states/game_settings_boxart.tres" id="25_3xebk"]
[ext_resource type="PackedScene" uid="uid://bvdasrjrvyp11" path="res://core/ui/card_ui/launch/game_settings_library.tscn" id="25_c26mp"]
[ext_resource type="PackedScene" uid="uid://dithv38oqgy58" path="res://core/ui/components/section_label.tscn" id="27_06vpr"]
[ext_resource type="PackedScene" uid="uid://bo077a5mwi7xl" path="res://core/ui/components/transition_fade_in.tscn" id="29_voua8"]
[ext_resource type="Script" path="res://core/ui/components/transition_container.gd" id="34_j5cnx"]
Expand Down Expand Up @@ -150,6 +152,20 @@ on_signal = "focus_entered"
target = NodePath("../../../../../../../../../ContentContainer/VBoxContainer/ContentContainer/MarginContainer/BoxArtSettings/MarginContainer/VBoxContainer/FocusGroup")
on_signal = "pressed"

[node name="LibraryButton" parent="MarginContainer/HBoxContainer/MenuContainer/VBoxContainer/ButtonContainer/MarginContainer/ScrollContainer/MarginContainer/ButtonsContainer" instance=ExtResource("19_1erbu")]
layout_mode = 2
text = "Library"

[node name="StateUpdater" parent="MarginContainer/HBoxContainer/MenuContainer/VBoxContainer/ButtonContainer/MarginContainer/ScrollContainer/MarginContainer/ButtonsContainer/LibraryButton" instance=ExtResource("15_lmmqq")]
state_machine = ExtResource("20_cokg3")
state = ExtResource("24_um3vy")
action = 3
on_signal = "focus_entered"

[node name="FocusGroupSetter" parent="MarginContainer/HBoxContainer/MenuContainer/VBoxContainer/ButtonContainer/MarginContainer/ScrollContainer/MarginContainer/ButtonsContainer/LibraryButton" node_paths=PackedStringArray("target") instance=ExtResource("18_qwki4")]
target = NodePath("../../../../../../../../../ContentContainer/VBoxContainer/ContentContainer/MarginContainer/LibrarySettings/MarginContainer/VBoxContainer/FocusGroup")
on_signal = "pressed"

[node name="ContentContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
Expand Down Expand Up @@ -216,5 +232,10 @@ script = ExtResource("34_j5cnx")

[node name="TransitionFadeIn" parent="MarginContainer/HBoxContainer/ContentContainer/VBoxContainer/ContentContainer/MarginContainer/BoxArtSettings/TransitionContainer" instance=ExtResource("29_voua8")]

[node name="LibrarySettings" parent="MarginContainer/HBoxContainer/ContentContainer/VBoxContainer/ContentContainer/MarginContainer" instance=ExtResource("25_c26mp")]
visible = false
layout_mode = 2

[editable path="MarginContainer/HBoxContainer/ContentContainer/VBoxContainer/ContentContainer/MarginContainer/LaunchSettings"]
[editable path="MarginContainer/HBoxContainer/ContentContainer/VBoxContainer/ContentContainer/MarginContainer/BoxArtSettings"]
[editable path="MarginContainer/HBoxContainer/ContentContainer/VBoxContainer/ContentContainer/MarginContainer/LibrarySettings"]
48 changes: 48 additions & 0 deletions core/ui/card_ui/launch/game_settings_library.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
extends ScrollContainer

var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
var library_manager := load("res://core/global/library_manager.tres") as LibraryManager
var library_state := load("res://assets/state/states/game_settings_library.tres") as State
var game_settings_state := load("res://assets/state/states/game_settings.tres") as State
var library_item: LibraryItem
var logger := Log.get_logger("GameSettingsLibrary")

@onready var hide_toggle := $%HideToggle as Toggle


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
library_state.state_entered.connect(_on_state_entered)
library_state.state_exited.connect(_on_state_exited)

# When the hide button is toggled, update the settings for this library item
var on_hide_toggled := func(is_hidden: bool):
if not library_item:
return
settings_manager.set_library_value(library_item, "hidden", is_hidden)
library_item.is_hidden = is_hidden
if is_hidden:
library_manager.library_item_hidden.emit(library_item)
else:
library_manager.library_item_unhidden.emit(library_item)
hide_toggle.toggled.connect(on_hide_toggled)


func _on_state_entered(_from: State) -> void:
# Get the current library item
if game_settings_state.has_meta("item"):
library_item = game_settings_state.get_meta("item") as LibraryItem
elif "item" in game_settings_state.data:
library_item = game_settings_state.data["item"] as LibraryItem

if not library_item:
logger.warn("No library item set in game settings state to configure")
return

# Find the settings
var is_hidden := settings_manager.get_library_value(library_item, "hidden", false) as bool
hide_toggle.button_pressed = is_hidden


func _on_state_exited(_to: State) -> void:
library_item = null
52 changes: 52 additions & 0 deletions core/ui/card_ui/launch/game_settings_library.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[gd_scene load_steps=8 format=3 uid="uid://bvdasrjrvyp11"]

[ext_resource type="Script" path="res://core/ui/card_ui/launch/game_settings_library.gd" id="1_f1pex"]
[ext_resource type="PackedScene" uid="uid://shvyhrv5sx3v" path="res://core/systems/state/state_watcher.tscn" id="1_mk47q"]
[ext_resource type="Resource" uid="uid://bnw36g1l7shcy" path="res://assets/state/states/game_settings_library.tres" id="2_j1lqu"]
[ext_resource type="PackedScene" uid="uid://bw8113ocotx2r" path="res://core/systems/effects/fade_effect.tscn" id="3_tkmdj"]
[ext_resource type="PackedScene" uid="uid://8m20p2s0v5gb" path="res://core/systems/input/focus_group.tscn" id="4_qj1l3"]
[ext_resource type="Resource" uid="uid://cc6i4i264dmqd" path="res://core/ui/card_ui/launch/game_settings_focus.tres" id="5_7h7mk"]
[ext_resource type="PackedScene" uid="uid://d1qb7euwlu7bh" path="res://core/ui/components/toggle.tscn" id="6_e3kvo"]

[node name="LibrarySettings" type="ScrollContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
follow_focus = true
script = ExtResource("1_f1pex")

[node name="StateWatcher" parent="." instance=ExtResource("1_mk47q")]
state = ExtResource("2_j1lqu")

[node name="FadeEffect" parent="StateWatcher" node_paths=PackedStringArray("target") instance=ExtResource("3_tkmdj")]
target = NodePath("../..")
on_signal = "state_entered"
fade_out_signal = "state_exited"
on_signal = "state_entered"

[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/margin_left = 4
theme_override_constants/margin_top = 4
theme_override_constants/margin_right = 4
theme_override_constants/margin_bottom = 4

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2

[node name="FocusGroup" parent="MarginContainer/VBoxContainer" node_paths=PackedStringArray("current_focus") instance=ExtResource("4_qj1l3")]
current_focus = NodePath("../HideToggle")
focus_stack = ExtResource("5_7h7mk")

[node name="HideToggle" parent="MarginContainer/VBoxContainer" instance=ExtResource("6_e3kvo")]
unique_name_in_owner = true
layout_mode = 2
text = "Hidden in library"
description = "Prevent this item from showing up in your library"
button_pressed = false
45 changes: 26 additions & 19 deletions core/ui/card_ui/library/library_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ extends Control

signal refresh_completed

var BoxArtManager := load("res://core/global/boxart_manager.tres") as BoxArtManager
var LibraryManager := load("res://core/global/library_manager.tres") as LibraryManager
var InstallManager := preload("res://core/global/install_manager.tres")
var state_machine := preload("res://assets/state/state_machines/global_state_machine.tres") as StateMachine
var library_state := preload("res://assets/state/states/library.tres") as State
var launcher_state := preload("res://assets/state/states/game_launcher.tres") as State
var osk_state := preload("res://assets/state/states/osk.tres") as State
var card_scene := preload("res://core/ui/components/card.tscn") as PackedScene
var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
var library_manager := load("res://core/global/library_manager.tres") as LibraryManager
var install_manager := load("res://core/global/install_manager.tres") as InstallManager
var state_machine := load("res://assets/state/state_machines/global_state_machine.tres") as StateMachine
var library_state := load("res://assets/state/states/library.tres") as State
var launcher_state := load("res://assets/state/states/game_launcher.tres") as State
var osk_state := load("res://assets/state/states/osk.tres") as State
var card_scene := load("res://core/ui/components/card.tscn") as PackedScene

var tween: Tween
var refresh_requested := false
Expand Down Expand Up @@ -39,15 +39,16 @@ func _ready() -> void:
tabs_state.tab_changed.connect(_on_tab_container_tab_changed)

# Listen for library changes
var on_library_changed := func(item: LibraryItem):
var on_library_changed := func(_item: LibraryItem):
queue_refresh()
LibraryManager.library_item_added.connect(on_library_changed)
LibraryManager.library_item_removed.connect(on_library_changed)
library_manager.library_item_added.connect(on_library_changed)
library_manager.library_item_removed.connect(on_library_changed)
library_manager.library_item_unhidden.connect(on_library_changed)

# Listen for app install/uninstall changes
InstallManager.install_queued.connect(_on_install_queued)
InstallManager.install_completed.connect(_on_installed)
InstallManager.uninstall_completed.connect(_on_uninstalled)
install_manager.install_queued.connect(_on_install_queued)
install_manager.install_completed.connect(_on_installed)
install_manager.uninstall_completed.connect(_on_uninstalled)
if global_search != null:
global_search.search_submitted.connect(_on_search)

Expand Down Expand Up @@ -110,15 +111,15 @@ func _reload_library() -> void:
const available_tab_idx := 1

# Load our library entries and add them to all games
var available := LibraryManager.get_library_items()
var available := library_manager.get_library_items()

# If the library has been loaded before, check for removed items
if _library.size() > 0:
var card_names := _library[available_tab_idx].keys() as Array

# Delete any library cards that no longer exist in the library
for card_name in card_names:
if LibraryManager.has_app(card_name):
if library_manager.has_app(card_name):
continue
var card := _library[available_tab_idx][card_name] as Control
_library[available_tab_idx].erase(card_name)
Expand All @@ -134,10 +135,10 @@ func _reload_library() -> void:

# Populate the installed games grid
var modifiers: Array[Callable] = [
LibraryManager.filter_installed,
LibraryManager.sort_by_name,
library_manager.filter_installed,
library_manager.sort_by_name,
]
var installed := LibraryManager.get_library_items(modifiers)
var installed := library_manager.get_library_items(modifiers)
await _populate_grid(installed_games_grid, installed, installed_tab_idx)


Expand All @@ -161,6 +162,11 @@ func _populate_grid(grid: HFlowContainer, library_items: Array, tab_num: int):
for i in range(library_items.size()):
var item: LibraryItem = library_items[i]

# Check to see if this library item should be hidden
var is_hidden := settings_manager.get_library_value(item, "hidden", false) as bool
if is_hidden:
continue

# If the card node already exists, move it to the correct place
if tab_num in _library and item.name in _library[tab_num]:
var card := _library[tab_num][item.name] as GameCard
Expand All @@ -178,6 +184,7 @@ func _populate_grid(grid: HFlowContainer, library_items: Array, tab_num: int):
var on_removed := func():
_library[tab_num].erase(item.name)
item.removed_from_library.connect(on_removed)
item.hidden.connect(on_removed)

# Add the card to the grid
grid.add_child(card)
Expand Down
Loading

0 comments on commit b026738

Please sign in to comment.