feat: card zoom

This commit is contained in:
Kenshia 2025-01-26 11:49:25 +07:00
parent cd9f7c7679
commit 83df3047f7
3 changed files with 33 additions and 18 deletions

View file

@ -22,6 +22,7 @@ var match_manager: MatchManager
var show_buttons: bool var show_buttons: bool
var signal_connected: bool var signal_connected: bool
var selected_card: Control var selected_card: Control
var focused_card: Control
var hovering_cards_this_frame: Array[Control] = [] var hovering_cards_this_frame: Array[Control] = []
var hovering_cards_duration: Dictionary = {} var hovering_cards_duration: Dictionary = {}
@ -128,6 +129,8 @@ func _on_update(transition):
_pop_this_card(monster_card) _pop_this_card(monster_card)
play_card.emit(card)) play_card.emit(card))
monster_card.hovering.connect(func (delta): _do_hover(monster_card, delta)) monster_card.hovering.connect(func (delta): _do_hover(monster_card, delta))
monster_card.right_clicked.connect(func(): _do_zoom(monster_card))
monster_card.un_right_clicked.connect(_do_unzoom)
deck.add_child(monster_card) deck.add_child(monster_card)
elif card is SupportCard and card.type == "red": elif card is SupportCard and card.type == "red":
@ -144,12 +147,28 @@ func _on_update(transition):
_pop_this_card(btn) _pop_this_card(btn)
play_card.emit(card)) play_card.emit(card))
btn.hovering.connect(func (delta): _do_hover(btn, delta)) btn.hovering.connect(func (delta): _do_hover(btn, delta))
btn.right_clicked.connect(func(): _do_zoom(btn))
btn.un_right_clicked.connect(_do_unzoom)
if rps_button_container: if rps_button_container:
rps_button_container.visible = match_manager.phase == Match.Phase.RPS rps_button_container.visible = match_manager.phase == Match.Phase.RPS
for button: TextureButton in rps_button_container.get_children(): for button: TextureButton in rps_button_container.get_children():
button.modulate = rps_grayed_color button.modulate = rps_grayed_color
func _do_zoom(card: Control):
if focused_card:
_do_unzoom()
var new_card: Control = card.duplicate()
get_parent().add_child(new_card)
new_card.set_anchors_and_offsets_preset(Control.PRESET_CENTER)
new_card.scale = Vector2(2,2)
focused_card = new_card
func _do_unzoom():
if focused_card:
focused_card.queue_free()
focused_card = null
func _pop_this_card(control: Control): func _pop_this_card(control: Control):
if selected_card: if selected_card:

View file

@ -3,6 +3,7 @@ class_name CardBase
signal left_clicked signal left_clicked
signal right_clicked signal right_clicked
signal un_right_clicked
signal hovering(delta: float) signal hovering(delta: float)
@export var card_name_label: Label @export var card_name_label: Label
@ -25,20 +26,17 @@ func _update(card: SupportCard):
func _process(delta): func _process(delta):
var mouse_position = get_global_mouse_position() var mouse_position = get_global_mouse_position()
var rect = get_global_rect() var rect = get_global_rect()
if rect.has_point(mouse_position): if rect.has_point(mouse_position) and get_window().has_focus():
hovering.emit(delta) hovering.emit(delta)
func _input(event): func _input(event):
if event is InputEventMouseButton: if event is InputEventMouseButton:
if !event.is_pressed():
return
var mouse_position = get_global_mouse_position() var mouse_position = get_global_mouse_position()
var rect = get_global_rect() var rect = get_global_rect()
if not rect.has_point(mouse_position):
return
if event.button_index == MOUSE_BUTTON_LEFT: if rect.has_point(mouse_position) and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() and get_window().has_focus():
left_clicked.emit() left_clicked.emit()
elif event.button_index == MOUSE_BUTTON_RIGHT: elif rect.has_point(mouse_position) and event.button_index == MOUSE_BUTTON_RIGHT and event.is_pressed() and get_window().has_focus():
right_clicked.emit() right_clicked.emit()
elif event.button_index == MOUSE_BUTTON_RIGHT and !event.is_pressed():
un_right_clicked.emit()

View file

@ -3,6 +3,7 @@ class_name MonsterCardUI
signal left_clicked signal left_clicked
signal right_clicked signal right_clicked
signal un_right_clicked
signal hovering(delta: float) signal hovering(delta: float)
@export var name_label : Label @export var name_label : Label
@ -37,20 +38,17 @@ func show_monster(monster: MatchMonster):
func _process(delta): func _process(delta):
var mouse_position = get_global_mouse_position() var mouse_position = get_global_mouse_position()
var rect = get_global_rect() var rect = get_global_rect()
if rect.has_point(mouse_position): if rect.has_point(mouse_position) and get_window().has_focus():
hovering.emit(delta) hovering.emit(delta)
func _input(event): func _input(event):
if event is InputEventMouseButton: if event is InputEventMouseButton:
if !event.is_pressed():
return
var mouse_position = get_global_mouse_position() var mouse_position = get_global_mouse_position()
var rect = get_global_rect() var rect = get_global_rect()
if not rect.has_point(mouse_position):
return
if event.button_index == MOUSE_BUTTON_LEFT: if rect.has_point(mouse_position) and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() and get_window().has_focus():
left_clicked.emit() left_clicked.emit()
elif event.button_index == MOUSE_BUTTON_RIGHT: elif rect.has_point(mouse_position) and event.button_index == MOUSE_BUTTON_RIGHT and event.is_pressed() and get_window().has_focus():
right_clicked.emit() right_clicked.emit()
elif event.button_index == MOUSE_BUTTON_RIGHT and !event.is_pressed():
un_right_clicked.emit()