Extract an abstract EntityList base for the HUD lists #146
Labels
No labels
assets
bug
duplicate
enhancement
help wanted
invalid
question
testing
ui
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
liamjd/UntitledColonyBuilder#146
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of milestone #6 (Selection and inspection). Depends on #140 and #141 being merged.
PawnList(#140) andBuildingList(#141) are near-copies, in both the scripts and the scenes. The only real differences are whichGameStatesignals add and remove rows, and which card scene a row is built from. Pull the shared behaviour into an abstract base class and a shared base scene, so the next list (or a fix to the expand/collapse animation) is made once.This is a refactor. Neither list should behave any differently afterwards: all the rules in #140 and #141 (select on click, NONE mode only, dimmed outside NONE, catches the mouse, follows the selection back) still apply.
Design
Script:
ui/lists/entity_list.gd,@abstract class_name EntityList extends MarginContainer. It uses the same@abstractannotation asEntity._cardsby the entity, not its id:Dictionary[Entity, Button]. The base class then never needs an id._on_selection_changedchecks_cards.has(new)in place ofnew is Pawn/new is Building, so the type check goes away._entity_selected(toggled: bool, entity: Entity)replaces_pawn_selectedand_building_selected._toggle_expanded,_resize_list_container, the tween), interaction-mode handling, and add/remove all move into the base class.@abstract func _connect_entity_signals() -> void: connect the spawn/remove signals to_add_entity/_remove_entity. Called from the base_ready.@abstract func _make_card(entity: Entity) -> Button: instantiate and populate the card. It isn't in the tree yet, so its@onreadyvars are unset.PawnListandBuildingListbecomeextends EntityList, holding onlyCARD_SCENEand the two hooks._remove_entitymustremove_childthe card beforequeue_free(), then resize.queue_freeis deferred, so a card that is only queued still counts towardsget_combined_minimum_size(), and the list ends up one row too tall (found during #141).Scenes: script inheritance doesn't share the
.tscnlayout, so use scene inheritance.ui/lists/entity_list.tscnholds the full layout (header button, arrow label, title label, clipper, row container) with neutral unique names, e.g.%ListContainer.pawn_list.tscnandbuilding_list.tscnare recreated as inherited scenes (Scene > New Inherited Scene). Each attaches its concrete script to the root and sets the title text.uid=values forpawn_list.tscn/building_list.tscnif possible.game.tscnreferences them.Out of scope: a shared
EntityCardbase forPawnCard/BuildingCard. They share only the toggle-button shape, and each_processreads different fields. Revisit if a third list appears.Acceptance criteria
EntityListexists, is@abstract, and holds all shared list behaviour.PawnListandBuildingListextend it and implement only_connect_entity_signalsand_make_card(plusCARD_SCENE).entity_list.tscnis the only place the list layout is defined. Both list scenes inherit it.class_name EntityList, and the GUT suite is green.