8000 Added drag source filtering to DropArea. · BraindeadBZH/godot_card_engine@85390e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Added drag source filtering to DropArea.
Browse files Browse the repository at this point in the history
  • Loading branch information
BraindeadBZH committed Jan 8, 2021
1 parent 204e97f commit 85390e4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion addons/cardengine/card/abstract_card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func _on_Transitions_tween_all_completed() -> void:


func _on_MouseArea_drag_started() -> void:
CardEngine.general().start_drag(_inst)
CardEngine.general().start_drag(_inst, _container)
_is_dragged = true

if _follow_mouse:
Expand Down
6 changes: 6 additions & 0 deletions addons/cardengine/core/drop_area.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ extends Control

signal dropped(card)

export(Array) var source_filter: Array = []

var _filter: Query = null


Expand All @@ -12,6 +14,10 @@ func set_filter(filter: Query) -> void:

func can_drop_data(_position: Vector2, data) -> bool:
if data == "card_engine:drag":
var source = CardEngine.general().get_drag_source()
if not source_filter.empty() and not source_filter.has(source):
return false

if _filter != null:
var card := CardEngine.general().get_dragged_card()
return _filter.match_card(card.data())
Expand Down
9 changes: 8 additions & 1 deletion addons/cardengine/core/general_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ signal drag_stopped()

var _drag_started: bool = false
var _dragged_card: CardInstance = null
var _drag_source: String = ""


func validate_form(form_name: String, form: Dictionary) -> Array:
Expand All @@ -19,9 +20,10 @@ func validate_form(form_name: String, form: Dictionary) -> Array:
return errors


func start_drag(card: CardInstance) -> void:
func start_drag(card: CardInstance, source: String) -> void:
_drag_started = true
_dragged_card = card
_drag_source = source
emit_signal("drag_started")


Expand All @@ -33,7 +35,12 @@ func get_dragged_card() -> CardInstance:
return _dragged_card


func get_drag_source() -> String:
return _drag_source


func stop_drag() -> void:
_drag_started = false
_dragged_card = null
_drag_source = ""
emit_signal("drag_stopped")
1 change: 1 addition & 0 deletions screens/game/game_screen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ script = ExtResource( 4 )
__meta__ = {
"_edit_use_anchors_": false
}
source_filter = [ "hand" ]

[node name="ManaBar" type="HBoxContainer" parent="."]
anchor_left = 0.5
Expand Down

0 comments on commit 85390e4

Please sign in to comment.
0