Add multiplayer fish showcases

This commit is contained in:
Alexander Sellite 2026-08-01 17:12:29 -04:00
parent 3f4392fdd3
commit 904a9c2d9e
23 changed files with 966 additions and 46 deletions

View file

@ -10,6 +10,8 @@ const ItemCatalogType = preload("res://items/item_catalog.gd")
const ItemDataType = preload("res://items/item_data.gd")
const PlayerBagType = preload("res://inventory/player_bag.gd")
const PlayerHotbarType = preload("res://inventory/player_hotbar.gd")
const FishInventoryType = preload("res://inventory/fish_inventory.gd")
const FishCatchType = preload("res://fish/fish_catch.gd")
const SELECTED_SCALE: float = 1.12
const HOVER_SCALE: float = 1.025
@ -41,6 +43,7 @@ const DEFORMATION_Y_AMPLITUDE: float = 0.007
var _hotbar: PlayerHotbarType
var _bag: PlayerBagType
var _catalog: ItemCatalogType
var _fish_inventory: FishInventoryType
var _drag_enabled: bool = false
var _drag_in_progress: bool = false
var _selected: bool = false
@ -69,10 +72,12 @@ func setup(
hotbar: PlayerHotbarType,
bag: PlayerBagType,
catalog: ItemCatalogType,
fish_inventory: FishInventoryType,
) -> void:
_hotbar = hotbar
_bag = bag
_catalog = catalog
_fish_inventory = fish_inventory
refresh()
@ -144,12 +149,22 @@ func refresh() -> void:
if _hotbar == null:
return
var item_id: StringName = _hotbar.get_item_id(slot_index)
var catch_id: StringName = _hotbar.get_fish_catch_id(slot_index)
var item: ItemDataType = (
_catalog.get_item_by_id(item_id)
if _catalog != null and not item_id.is_empty()
else null
)
_item_icon.texture = item.icon if item != null else null
var fish_catch: FishCatchType = (
_fish_inventory.get_catch_by_id(catch_id)
if _fish_inventory != null and not catch_id.is_empty()
else null
)
_item_icon.texture = (
fish_catch.fish.display_texture
if fish_catch != null
else item.icon if item != null else null
)
var quantity: int = (
_bag.get_quantity(item_id)
if _bag != null and not item_id.is_empty()
@ -163,12 +178,17 @@ func refresh() -> void:
_quantity_label.text = quantity_text
_quantity_label.visible = not quantity_text.is_empty()
tooltip_text = (
item.display_name if item != null else "empty hotbar slot"
"%s · %.1f lb" % [
fish_catch.fish.display_name,
fish_catch.weight_lb,
]
if fish_catch != null
else item.display_name if item != null else "empty hotbar slot"
)
var was_selected: bool = _selected
var was_empty: bool = _empty
_selected = slot_index == _hotbar.get_selected_slot()
_empty = item == null
_empty = item == null and fish_catch == null
if was_selected != _selected or was_empty != _empty:
_apply_style()
@ -283,12 +303,22 @@ func _get_drag_data(_at_position: Vector2) -> Variant:
if not _drag_enabled or _hotbar == null:
return null
var item_id: StringName = _hotbar.get_item_id(slot_index)
if item_id.is_empty():
var catch_id: StringName = _hotbar.get_fish_catch_id(slot_index)
if item_id.is_empty() and catch_id.is_empty():
return null
var item: ItemDataType = _catalog.get_item_by_id(item_id)
var fish_catch: FishCatchType = (
_fish_inventory.get_catch_by_id(catch_id)
if _fish_inventory != null and not catch_id.is_empty()
else null
)
var preview := TextureRect.new()
preview.custom_minimum_size = Vector2(44.0, 44.0)
preview.texture = item.icon if item != null else null
preview.texture = (
fish_catch.fish.display_texture
if fish_catch != null
else item.icon if item != null else null
)
preview.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
preview.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
preview.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
@ -299,7 +329,6 @@ func _get_drag_data(_at_position: Vector2) -> Variant:
return {
"kind": "hotbar_slot",
"slot_index": slot_index,
"item_id": String(item_id),
}
@ -315,13 +344,19 @@ func _can_drop_data(_at_position: Vector2, data: Variant) -> bool:
and source_index < PlayerHotbarType.SLOT_COUNT
and source_index != slot_index
)
if kind != "bag_item":
return false
var item_id: StringName = StringName(str(payload.get("item_id", "")))
if _bag == null or not _bag.owns_item(item_id) or _catalog == null:
return false
var item: ItemDataType = _catalog.get_item_by_id(item_id)
return item != null and item.is_valid() and item.hotbar_allowed
if kind == "bag_item":
var item_id: StringName = StringName(str(payload.get("item_id", "")))
if _bag == null or not _bag.owns_item(item_id) or _catalog == null:
return false
var item: ItemDataType = _catalog.get_item_by_id(item_id)
return item != null and item.is_valid() and item.hotbar_allowed
if kind == "cooler_fish":
var catch_id: StringName = StringName(str(payload.get("catch_id", "")))
return (
_fish_inventory != null
and _fish_inventory.contains_catch_id(catch_id)
)
return false
func _drop_data(_at_position: Vector2, data: Variant) -> void:
@ -330,6 +365,11 @@ func _drop_data(_at_position: Vector2, data: Variant) -> void:
var payload: Dictionary = data
if str(payload.get("kind", "")) == "hotbar_slot":
_hotbar.swap_slots(int(payload["slot_index"]), slot_index)
elif str(payload.get("kind", "")) == "cooler_fish":
_hotbar.assign_fish(
slot_index,
StringName(str(payload["catch_id"])),
)
else:
_hotbar.assign_item(
slot_index,
@ -346,7 +386,10 @@ func _select_slot() -> void:
func _on_mouse_entered() -> void:
_hovered = true
if _hotbar != null:
item_hovered.emit(slot_index, _hotbar.get_item_id(slot_index))
var identity: StringName = _hotbar.get_item_id(slot_index)
if identity.is_empty():
identity = _hotbar.get_fish_catch_id(slot_index)
item_hovered.emit(slot_index, identity)
func _on_mouse_exited() -> void:

View file

@ -7,6 +7,7 @@ extends Button
@onready var _favorite_marker: Label = %FavoriteMarker
var catch_id: StringName
var _display_name: String = ""
var _neutral_position := Vector2.ZERO
var _target_position := Vector2.ZERO
var _motion_phase: float = 0.0
@ -35,18 +36,48 @@ func _ready() -> void:
func configure(
identity: StringName,
display_name: String,
texture: Texture2D,
phase: float,
depth_scale: float,
rarity_color: Color,
) -> void:
catch_id = identity
_display_name = display_name
_fish_texture.texture = texture
_fish_shadow.texture = texture
_motion_phase = phase
_depth_scale = depth_scale
_rarity_color = rarity_color
_refresh_style()
tooltip_text = "%s · drag to a hotbar slot" % _display_name
func _get_drag_data(_at_position: Vector2) -> Variant:
if catch_id.is_empty() or disabled or _fish_texture.texture == null:
return null
var preview := VBoxContainer.new()
preview.mouse_filter = Control.MOUSE_FILTER_IGNORE
preview.add_theme_constant_override("separation", 2)
var texture := TextureRect.new()
texture.custom_minimum_size = Vector2(72.0, 52.0)
texture.texture = _fish_texture.texture
texture.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
texture.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
texture.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
texture.mouse_filter = Control.MOUSE_FILTER_IGNORE
preview.add_child(texture)
var label := Label.new()
label.text = _display_name
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
label.add_theme_font_size_override("font_size", 12)
preview.add_child(label)
set_drag_preview(preview)
return {
"kind": "cooler_fish",
"catch_id": String(catch_id),
}
func set_target_position(target: Vector2, immediate: bool = false) -> void:

View file

@ -183,7 +183,7 @@ func setup(
network_profile_service,
network_player_list,
)
_hotbar_ui.setup(hotbar, bag, item_catalog, fishing_spot)
_hotbar_ui.setup(hotbar, bag, item_catalog, fishing_spot, inventory)
_fishing_shop.setup(
player,
wallet,

View file

@ -6,6 +6,8 @@ signal presentation_transition_finished(is_visible: bool)
const ItemCatalogType = preload("res://items/item_catalog.gd")
const PlayerBagType = preload("res://inventory/player_bag.gd")
const PlayerHotbarType = preload("res://inventory/player_hotbar.gd")
const FishInventoryType = preload("res://inventory/fish_inventory.gd")
const FishCatchType = preload("res://fish/fish_catch.gd")
const BubbleHotbarSlotType = preload(
"res://ui/components/bubble_hotbar/bubble_hotbar_slot.gd"
)
@ -28,6 +30,7 @@ const HOTBAR_MENU_Z_INDEX: int = 90
var _hotbar: PlayerHotbarType
var _bag: PlayerBagType
var _catalog: ItemCatalogType
var _fish_inventory: FishInventoryType
var _fishing_spot: FishingSpotType
var _slots: Array[BubbleHotbarSlotType] = []
var _gameplay_input_enabled: bool = false
@ -59,11 +62,13 @@ func setup(
bag: PlayerBagType,
catalog: ItemCatalogType,
fishing_spot: FishingSpotType,
fish_inventory: FishInventoryType,
) -> void:
_hotbar = hotbar
_bag = bag
_catalog = catalog
_fishing_spot = fishing_spot
_fish_inventory = fish_inventory
if not _hotbar.slots_changed.is_connected(_refresh):
_hotbar.slots_changed.connect(_refresh)
if not _hotbar.selected_slot_changed.is_connected(
@ -72,8 +77,10 @@ func setup(
_hotbar.selected_slot_changed.connect(_on_selected_slot_changed)
if not _bag.contents_changed.is_connected(_refresh):
_bag.contents_changed.connect(_refresh)
if not _fish_inventory.catches_changed.is_connected(_refresh):
_fish_inventory.catches_changed.connect(_refresh)
for slot: BubbleHotbarSlotType in _slots:
slot.setup(_hotbar, _bag, _catalog)
slot.setup(_hotbar, _bag, _catalog, _fish_inventory)
slot.set_drag_enabled(_drag_enabled)
_refresh()
@ -274,7 +281,7 @@ func _on_slot_item_hovered(
return
_hovered_slot_index = slot_index
_item_name_timer.stop()
_show_item_name(item_id)
_show_assignment_name(slot_index, item_id)
func _on_slot_item_hover_ended(slot_index: int) -> void:
@ -297,16 +304,31 @@ func _show_selected_item_briefly() -> void:
if _item_name_suppressed or _hotbar == null:
_hide_item_name()
return
_show_item_name(_hotbar.get_selected_item_id())
var selected_slot: int = _hotbar.get_selected_slot()
var identity: StringName = _hotbar.get_selected_item_id()
if identity.is_empty():
identity = _hotbar.get_selected_fish_catch_id()
_show_assignment_name(selected_slot, identity)
if _selected_item_label.visible:
_item_name_timer.start()
func _show_item_name(item_id: StringName) -> void:
if item_id.is_empty() or _catalog == null:
func _show_assignment_name(slot_index: int, identity: StringName) -> void:
if identity.is_empty() or _hotbar == null:
_hide_item_name()
return
var item := _catalog.get_item_by_id(item_id)
var catch_id: StringName = _hotbar.get_fish_catch_id(slot_index)
if not catch_id.is_empty() and _fish_inventory != null:
var fish_catch: FishCatchType = _fish_inventory.get_catch_by_id(catch_id)
if fish_catch != null:
_selected_item_label.text = fish_catch.fish.display_name
_selected_item_label.visible = true
return
var item = (
_catalog.get_item_by_id(identity)
if _catalog != null
else null
)
if item == null:
_hide_item_name()
return

View file

@ -2609,6 +2609,7 @@ func _sync_cooler_fish_nodes(catches: Array[FishCatchType]) -> void:
var identity_hash: int = absi(String(fish_catch.catch_id).hash())
fish_node.configure(
fish_catch.catch_id,
fish_catch.fish.display_name,
fish_catch.fish.display_texture,
float(identity_hash % 628) / 100.0,
0.96 + float(identity_hash % 9) * 0.01,

View file

@ -1215,7 +1215,7 @@ theme_override_constants/separation = 7
[node name="BagHint" type="Label" parent="ResponsivePlayerMenuStage/PlayerMenuPresentationScaleRoot/MenuPanel/Margin/Layout/Content/BagSection"]
layout_mode = 2
text = "drag hotbar-compatible items onto a slot below. right-click a slot to clear it."
text = "drag fish or hotbar-compatible items onto a slot below. right-click a slot to clear it."
horizontal_alignment = 1
autowrap_mode = 2