working updates
This commit is contained in:
@@ -7,9 +7,9 @@ signal clicked(card_visual: CardVisual)
|
||||
signal hovered(card_visual: CardVisual)
|
||||
signal unhovered(card_visual: CardVisual)
|
||||
|
||||
# Card dimensions (standard card ratio ~2.5:3.5)
|
||||
const CARD_WIDTH: float = 0.63
|
||||
const CARD_HEIGHT: float = 0.88
|
||||
# Card dimensions (doubled for readability, standard card ratio ~2.5:3.5)
|
||||
const CARD_WIDTH: float = 1.26
|
||||
const CARD_HEIGHT: float = 1.76
|
||||
const CARD_THICKNESS: float = 0.02
|
||||
|
||||
# Associated card instance
|
||||
@@ -23,8 +23,10 @@ var is_hovered: bool = false
|
||||
# Animation
|
||||
var target_position: Vector3 = Vector3.ZERO
|
||||
var target_rotation: Vector3 = Vector3.ZERO
|
||||
var base_position: Vector3 = Vector3.ZERO # Position set by zone arrangement (before hover offset)
|
||||
var move_speed: float = 10.0
|
||||
var is_animating: bool = false
|
||||
const HOVER_LIFT: float = 0.15
|
||||
|
||||
# Components
|
||||
var mesh_instance: MeshInstance3D
|
||||
@@ -46,14 +48,21 @@ func _create_card_mesh() -> void:
|
||||
mesh_instance = MeshInstance3D.new()
|
||||
add_child(mesh_instance)
|
||||
|
||||
# Create box mesh for card
|
||||
var box = BoxMesh.new()
|
||||
box.size = Vector3(CARD_WIDTH, CARD_THICKNESS, CARD_HEIGHT)
|
||||
mesh_instance.mesh = box
|
||||
# Create a quad mesh for the card face (more appropriate for card textures)
|
||||
var quad = QuadMesh.new()
|
||||
quad.size = Vector2(CARD_WIDTH, CARD_HEIGHT)
|
||||
mesh_instance.mesh = quad
|
||||
|
||||
# Rotate to lay flat on table (facing up)
|
||||
mesh_instance.rotation_degrees.x = -90
|
||||
|
||||
# Slight offset up so it's above the table
|
||||
mesh_instance.position.y = CARD_THICKNESS / 2
|
||||
|
||||
# Create material
|
||||
material = StandardMaterial3D.new()
|
||||
material.albedo_color = Color.WHITE
|
||||
material.cull_mode = BaseMaterial3D.CULL_DISABLED # Show both sides
|
||||
mesh_instance.material_override = material
|
||||
|
||||
func _setup_collision() -> void:
|
||||
@@ -99,8 +108,10 @@ func _load_card_texture() -> void:
|
||||
var texture = CardDatabase.get_card_texture(card_instance.card_data)
|
||||
if texture:
|
||||
material.albedo_texture = texture
|
||||
material.albedo_color = Color.WHITE # Reset to white so texture shows properly
|
||||
else:
|
||||
# Use element color as fallback
|
||||
# Use element color as fallback when no texture
|
||||
material.albedo_texture = null
|
||||
var element_color = Enums.element_to_color(card_instance.get_element())
|
||||
material.albedo_color = element_color
|
||||
|
||||
@@ -109,18 +120,22 @@ func _update_visual_state() -> void:
|
||||
if not material:
|
||||
return
|
||||
|
||||
var color = normal_color
|
||||
# Only apply color tints if we don't have a texture, or for highlight/dull effects
|
||||
var has_texture = material.albedo_texture != null
|
||||
var base_color = Color.WHITE if has_texture else normal_color
|
||||
|
||||
if is_selected:
|
||||
color = selected_color
|
||||
# Slight green tint for selection
|
||||
base_color = base_color * Color(0.9, 1.1, 0.9)
|
||||
elif is_highlighted:
|
||||
color = highlight_color
|
||||
# Slight yellow tint for highlight
|
||||
base_color = base_color * Color(1.1, 1.1, 0.9)
|
||||
|
||||
# Apply dull tint
|
||||
# Apply dull tint (darkening)
|
||||
if card_instance and card_instance.is_dull():
|
||||
color = color * dull_tint
|
||||
base_color = base_color * dull_tint
|
||||
|
||||
material.albedo_color = color
|
||||
material.albedo_color = base_color
|
||||
|
||||
## Set card as highlighted
|
||||
func set_highlighted(highlighted: bool) -> void:
|
||||
@@ -134,12 +149,16 @@ func set_selected(selected: bool) -> void:
|
||||
|
||||
## Move card to position with animation
|
||||
func move_to(pos: Vector3, rot: Vector3 = Vector3.ZERO) -> void:
|
||||
base_position = pos
|
||||
target_position = pos
|
||||
if is_hovered:
|
||||
target_position.y = pos.y + HOVER_LIFT
|
||||
target_rotation = rot
|
||||
is_animating = true
|
||||
|
||||
## Move card instantly
|
||||
func set_position_instant(pos: Vector3, rot: Vector3 = Vector3.ZERO) -> void:
|
||||
base_position = pos
|
||||
position = pos
|
||||
rotation = rot
|
||||
target_position = pos
|
||||
@@ -163,18 +182,16 @@ func _on_input_event(_camera: Node, event: InputEvent, _position: Vector3, _norm
|
||||
func _on_mouse_entered() -> void:
|
||||
is_hovered = true
|
||||
hovered.emit(self)
|
||||
# Slight raise on hover
|
||||
if not is_animating:
|
||||
target_position.y = position.y + 0.1
|
||||
is_animating = true
|
||||
# Raise card above base position on hover
|
||||
target_position.y = base_position.y + HOVER_LIFT
|
||||
is_animating = true
|
||||
|
||||
func _on_mouse_exited() -> void:
|
||||
is_hovered = false
|
||||
unhovered.emit(self)
|
||||
# Return to normal height
|
||||
if not is_animating and card_instance:
|
||||
target_position.y = position.y - 0.1
|
||||
is_animating = true
|
||||
# Return to base height
|
||||
target_position.y = base_position.y
|
||||
is_animating = true
|
||||
|
||||
## Get display info for UI
|
||||
func get_card_info() -> Dictionary:
|
||||
|
||||
Reference in New Issue
Block a user