fix: separate wall and floor decor placement
This commit is contained in:
@@ -23,8 +23,8 @@ const DECOR_TEXTURE_FILTER: int = CanvasItem.TEXTURE_FILTER_LINEAR
|
|||||||
const DECOR_COLLISION_LAYER: int = 1
|
const DECOR_COLLISION_LAYER: int = 1
|
||||||
const DECOR_COLLISION_MASK: int = 1
|
const DECOR_COLLISION_MASK: int = 1
|
||||||
const ROOM_GRID_SIZE: float = 16.0
|
const ROOM_GRID_SIZE: float = 16.0
|
||||||
const FLOOR_PLACE_BOUNDS: Rect2 = Rect2(-426.0, -186.0, 852.0, 398.0)
|
const FLOOR_PLACE_BOUNDS: Rect2 = Rect2(-426.0, -176.0, 852.0, 388.0)
|
||||||
const WALL_PLACE_BOUNDS: Rect2 = Rect2(-378.0, -258.0, 756.0, 72.0)
|
const WALL_PLACE_BOUNDS: Rect2 = Rect2(-378.0, -258.0, 756.0, 66.0)
|
||||||
|
|
||||||
@onready var player: PlayerController = $YSortWorld/Characters/Players/Player
|
@onready var player: PlayerController = $YSortWorld/Characters/Players/Player
|
||||||
@onready var playerCamera: Camera2D = $YSortWorld/Characters/Players/Player/Camera2D
|
@onready var playerCamera: Camera2D = $YSortWorld/Characters/Players/Player/Camera2D
|
||||||
@@ -204,8 +204,14 @@ func _build_placement_grid() -> void:
|
|||||||
_gridOverlay.visible = false
|
_gridOverlay.visible = false
|
||||||
ySortWorld.add_child(_gridOverlay)
|
ySortWorld.add_child(_gridOverlay)
|
||||||
ySortWorld.move_child(_gridOverlay, 0)
|
ySortWorld.move_child(_gridOverlay, 0)
|
||||||
_add_grid_zone(FLOOR_PLACE_BOUNDS, Color(0.050, 0.560, 0.900, 0.20), Color(0.050, 0.560, 0.900, 0.62))
|
_rebuild_placement_grid()
|
||||||
_add_grid_zone(WALL_PLACE_BOUNDS, Color(0.620, 0.330, 0.860, 0.20), Color(0.620, 0.330, 0.860, 0.62))
|
|
||||||
|
func _rebuild_placement_grid() -> void:
|
||||||
|
if _gridOverlay == null:
|
||||||
|
return
|
||||||
|
_clear_children(_gridOverlay)
|
||||||
|
_add_grid_zone(_placement_bounds_for_surface("floor"), Color(0.050, 0.560, 0.900, 0.20), Color(0.050, 0.560, 0.900, 0.62))
|
||||||
|
_add_grid_zone(_placement_bounds_for_surface("wall"), Color(0.620, 0.330, 0.860, 0.20), Color(0.620, 0.330, 0.860, 0.62))
|
||||||
|
|
||||||
func _add_grid_zone(bounds: Rect2, line_color: Color, edge_color: Color) -> void:
|
func _add_grid_zone(bounds: Rect2, line_color: Color, edge_color: Color) -> void:
|
||||||
if _gridOverlay == null:
|
if _gridOverlay == null:
|
||||||
@@ -617,6 +623,7 @@ func _apply_remote_decor_definitions(definitionsVariant: Variant) -> void:
|
|||||||
_to_float(position.get("y", 0.0), 0.0)
|
_to_float(position.get("y", 0.0), 0.0)
|
||||||
)
|
)
|
||||||
_remoteDecorDefinitions[decorId] = definition
|
_remoteDecorDefinitions[decorId] = definition
|
||||||
|
_rebuild_placement_grid()
|
||||||
|
|
||||||
func _render_inventory_list() -> void:
|
func _render_inventory_list() -> void:
|
||||||
if _visitorMode:
|
if _visitorMode:
|
||||||
@@ -679,7 +686,8 @@ func _create_inventory_card(decorId: String) -> Button:
|
|||||||
|
|
||||||
var status := Label.new()
|
var status := Label.new()
|
||||||
status.custom_minimum_size = Vector2(0, 22)
|
status.custom_minimum_size = Vector2(0, 22)
|
||||||
status.text = "已摆放" if bool(item.get("placed", false)) else "未摆放"
|
var surface_label := "墙面挂饰" if str(item.get("placement_surface", "floor")) == "wall" else "地面家具"
|
||||||
|
status.text = "%s · %s" % [surface_label, "已摆放" if bool(item.get("placed", false)) else "未摆放"]
|
||||||
status.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
status.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
||||||
status.add_theme_font_size_override("font_size", 14)
|
status.add_theme_font_size_override("font_size", 14)
|
||||||
status.add_theme_color_override("font_color", ACCENT_COLOR if bool(item.get("placed", false)) else MUTED_COLOR)
|
status.add_theme_color_override("font_color", ACCENT_COLOR if bool(item.get("placed", false)) else MUTED_COLOR)
|
||||||
@@ -1355,7 +1363,29 @@ func _leave_visited_room() -> void:
|
|||||||
SceneManager.change_scene("square")
|
SceneManager.change_scene("square")
|
||||||
|
|
||||||
func _placement_bounds_for_item(item: Dictionary) -> Rect2:
|
func _placement_bounds_for_item(item: Dictionary) -> Rect2:
|
||||||
return WALL_PLACE_BOUNDS if str(item.get("placement_surface", "floor")) == "wall" else FLOOR_PLACE_BOUNDS
|
var surface := str(item.get("placement_surface", "floor"))
|
||||||
|
return _placement_bounds_from_variant(item.get("placement_bounds", null), WALL_PLACE_BOUNDS if surface == "wall" else FLOOR_PLACE_BOUNDS)
|
||||||
|
|
||||||
|
func _placement_bounds_for_surface(surface: String) -> Rect2:
|
||||||
|
for definition_variant in _remoteDecorDefinitions.values():
|
||||||
|
if not (definition_variant is Dictionary):
|
||||||
|
continue
|
||||||
|
var definition: Dictionary = definition_variant as Dictionary
|
||||||
|
if str(definition.get("placement_surface", "floor")) == surface:
|
||||||
|
return _placement_bounds_from_variant(definition.get("placement_bounds", null), WALL_PLACE_BOUNDS if surface == "wall" else FLOOR_PLACE_BOUNDS)
|
||||||
|
return WALL_PLACE_BOUNDS if surface == "wall" else FLOOR_PLACE_BOUNDS
|
||||||
|
|
||||||
|
func _placement_bounds_from_variant(value: Variant, fallback: Rect2) -> Rect2:
|
||||||
|
if not (value is Dictionary):
|
||||||
|
return fallback
|
||||||
|
var bounds: Dictionary = value as Dictionary
|
||||||
|
var min_x := _to_float(bounds.get("min_x", fallback.position.x), fallback.position.x)
|
||||||
|
var max_x := _to_float(bounds.get("max_x", fallback.end.x), fallback.end.x)
|
||||||
|
var min_y := _to_float(bounds.get("min_y", fallback.position.y), fallback.position.y)
|
||||||
|
var max_y := _to_float(bounds.get("max_y", fallback.end.y), fallback.end.y)
|
||||||
|
if min_x >= max_x or min_y >= max_y:
|
||||||
|
return fallback
|
||||||
|
return Rect2(min_x, min_y, max_x - min_x, max_y - min_y)
|
||||||
|
|
||||||
func _constrain_room_position(position: Vector2, item: Dictionary) -> Vector2:
|
func _constrain_room_position(position: Vector2, item: Dictionary) -> Vector2:
|
||||||
var bounds := _placement_bounds_for_item(item)
|
var bounds := _placement_bounds_for_item(item)
|
||||||
|
|||||||
Reference in New Issue
Block a user