Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotate keybind #162

Merged
merged 14 commits into from
Dec 9, 2022
Merged
88 changes: 53 additions & 35 deletions game/Scenes/OptionsMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -761,160 +761,178 @@ size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_reset_piece"

[node name="Shuffle" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
[node name="RotatePiece" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 303.0
margin_right = 480.0
margin_bottom = 323.0
size_flags_horizontal = 3
text = "Shuffle"
text = "Rotate Piece"
align = 2

[node name="ShuffleButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
[node name="RotatePieceButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 300.0
margin_right = 964.0
margin_bottom = 326.0
hint_tooltip = "Rotates the the piece that is selected, or that the mouse is over."
size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_rotate_piece"

[node name="Shuffle" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 333.0
margin_right = 480.0
margin_bottom = 353.0
size_flags_horizontal = 3
text = "Shuffle"
align = 2

[node name="ShuffleButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 330.0
margin_right = 964.0
margin_bottom = 356.0
hint_tooltip = "Shuffle stacks of cards or tokens that are selected, or that the mouse is over."
size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_shuffle_stack"

[node name="LockPiece" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 333.0
margin_top = 363.0
margin_right = 480.0
margin_bottom = 353.0
margin_bottom = 383.0
size_flags_horizontal = 3
text = "Lock/Unlock Piece"
align = 2

[node name="LockPieceButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 330.0
margin_top = 360.0
margin_right = 964.0
margin_bottom = 356.0
margin_bottom = 386.0
hint_tooltip = "Toggles the lock on the selected piece, fixing its position and rotation."
size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_lock_piece"

[node name="DeletePiece" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 363.0
margin_top = 393.0
margin_right = 480.0
margin_bottom = 383.0
margin_bottom = 413.0
size_flags_horizontal = 3
text = "Delete Piece"
align = 2

[node name="DeletePieceButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 360.0
margin_top = 390.0
margin_right = 964.0
margin_bottom = 386.0
margin_bottom = 416.0
hint_tooltip = "Deletes the currently selected piece."
size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_delete_piece"

[node name="ToggleDebugInfo" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 393.0
margin_top = 423.0
margin_right = 480.0
margin_bottom = 413.0
margin_bottom = 443.0
size_flags_horizontal = 3
text = "Toggle Debug Info"
align = 2

[node name="ToggleDebugInfoButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 390.0
margin_top = 420.0
margin_right = 964.0
margin_bottom = 416.0
margin_bottom = 446.0
hint_tooltip = "Toggles whether debug information is displayed."
size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_toggle_debug_info"

[node name="Quicksave" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 423.0
margin_top = 453.0
margin_right = 480.0
margin_bottom = 443.0
margin_bottom = 473.0
size_flags_horizontal = 3
text = "Quicksave"
align = 2

[node name="QuicksaveButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 420.0
margin_top = 450.0
margin_right = 964.0
margin_bottom = 446.0
margin_bottom = 476.0
hint_tooltip = "Creates a quicksave file."
size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_quicksave"

[node name="Quickload" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 453.0
margin_top = 483.0
margin_right = 480.0
margin_bottom = 473.0
margin_bottom = 503.0
size_flags_horizontal = 3
text = "Quickload"
align = 2

[node name="QuickloadButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 450.0
margin_top = 480.0
margin_right = 964.0
margin_bottom = 476.0
margin_bottom = 506.0
hint_tooltip = "Loads the latest quicksave file."
size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_quickload"

[node name="ToggleUI" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 483.0
margin_top = 513.0
margin_right = 480.0
margin_bottom = 503.0
margin_bottom = 533.0
size_flags_horizontal = 3
text = "Toggle UI"
align = 2

[node name="ToggleUIButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 480.0
margin_top = 510.0
margin_right = 964.0
margin_bottom = 506.0
margin_bottom = 536.0
hint_tooltip = "Toggles whether the entire UI is displayed."
size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_toggle_ui"

[node name="TakeScreenshot" type="Label" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 513.0
margin_top = 543.0
margin_right = 480.0
margin_bottom = 533.0
margin_bottom = 563.0
size_flags_horizontal = 3
text = "Take Screenshot"
align = 2

[node name="TakeScreenshotButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 510.0
margin_top = 540.0
margin_right = 964.0
margin_bottom = 536.0
margin_bottom = 566.0
hint_tooltip = "Takes a screenshot of the game in its current state."
size_flags_horizontal = 3
script = ExtResource( 2 )
action = "game_take_screenshot"

[node name="ResetBindingsSpace" type="Control" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_top = 540.0
margin_top = 570.0
margin_right = 480.0
margin_bottom = 566.0
margin_bottom = 596.0

[node name="ResetBindingsButton" type="Button" parent="MarginContainer/VBoxContainer/TabContainer/Key Bindings/GridContainer"]
margin_left = 484.0
margin_top = 540.0
margin_top = 570.0
margin_right = 964.0
margin_bottom = 566.0
margin_bottom = 596.0
hint_tooltip = "Used to reset the key bindings to their default values."
text = "Reset Bindings"

Expand Down
46 changes: 41 additions & 5 deletions game/Scripts/Game/CameraController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,25 @@ func _unhandled_input(event):
piece.rpc_id(1, "request_flip_vertically")
else:
piece.rpc_id(1, "request_flip_vertically_on_ground")
elif event.is_action_pressed("game_rotate_piece"):
var amount = _piece_rotation_amount
if piece_rotate_invert:
amount *= -1
if _selected_pieces.empty():
if _piece_mouse_is_over != null:
if is_piece_allowed_modify(_piece_mouse_is_over, false):
if _piece_mouse_is_over.is_hovering():
_piece_mouse_is_over.rpc_id(1, "request_rotate_y", amount)
else:
_piece_mouse_is_over.rpc_id(1, "request_rotate_y_on_ground", amount)
else:
for piece in _selected_pieces:
if piece is Piece:
if is_piece_allowed_modify(piece, false):
if piece.is_hovering():
piece.rpc_id(1, "request_rotate_y", amount)
else:
piece.rpc_id(1, "request_rotate_y_on_ground", amount)
elif event.is_action_pressed("game_reset_piece"):
if _selected_pieces.empty():
if _piece_mouse_is_over != null:
Expand Down Expand Up @@ -856,14 +875,16 @@ func _unhandled_input(event):

# Checks if a piece is allowed to be modified by the current player.
# E.g. to rotate, flip etc
# piece: The piece to check
# in_hand: If the piece is allowed to be modified if in hand
# Returns true if piece can be modified by current player
func is_piece_allowed_modify( piece: Piece ) -> bool:
var can_modify = not piece is Card
func is_piece_allowed_modify( piece: Piece, in_hand: bool = true ) -> bool:
var can_modify = not bool(piece is Card)
if piece is Card:
if piece.over_hands.empty():
can_modify = true
else:
can_modify = piece.over_hands == [ get_tree().get_network_unique_id() ]
elif in_hand:
can_modify = bool(piece.over_hands == [ get_tree().get_network_unique_id() ])
return can_modify

# Calculate the hover position of a piece, given a mouse position on the screen.
Expand Down Expand Up @@ -1488,7 +1509,20 @@ func _set_control_hint_label() -> void:

text += _set_control_hint_label_row_actions(tr("Delete selected"),
["game_delete_piece"])


# Check if all pieces are in hand or if one piece is not in hand
for piece in _selected_pieces:
if piece is Card:
if piece.over_hands == [ get_tree().get_network_unique_id() ]:
is_card_in_hand = true
else:
is_card_in_hand = false
break
if is_card_in_hand:
text += _set_control_hint_label_row_actions(tr("Reset orientation"),
["game_reset_piece"])
text += _set_control_hint_label_row_actions(tr("Flip orientation"),
["game_flip_piece"])

elif _piece_mouse_is_over != null and _piece_mouse_is_over is Card:
if _piece_mouse_is_over.over_hands == [ get_tree().get_network_unique_id() ]:
Expand All @@ -1500,6 +1534,8 @@ func _set_control_hint_label() -> void:
is_card_in_hand = true

if (not _selected_pieces.empty() or _piece_mouse_is_over != null) and not is_card_in_hand:
text += _set_control_hint_label_row_actions(tr("Rotate Piece"),
["game_rotate_piece"])
text += _set_control_hint_label_row_actions(tr("Reset orientation"),
["game_reset_piece"])
text += _set_control_hint_label_row_actions(tr("Flip orientation"),
Expand Down
12 changes: 11 additions & 1 deletion game/Scripts/Game/Pieces/Piece.gd
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ master func request_reset_orientation_on_ground() -> void:
master func request_reset_orientation() -> void:
request_set_hover_basis(Basis.IDENTITY)

# If you are hovering the piece, rotate it on the y-axis.
# If you are hovering the piece, request the server to rotate it
# around the y-axis by the given rotation.
# rot: The amount to rotate it by in radians.
master func request_rotate_y(rot: float) -> void:
if rot == 0.0:
Expand All @@ -303,6 +304,15 @@ master func request_rotate_y(rot: float) -> void:

request_set_hover_basis(Basis(target_y_euler))

# If you are not hovering the piece, request the server to
# rotate it around the y-axis by the given rotation.
# rot: The amount to rotate it by in radians.
master func request_rotate_y_on_ground(rot: float) -> void:
var scaled_basis = Basis.IDENTITY.scaled(get_current_scale())
var current_basis = transform.basis * scaled_basis
var new_rotation = current_basis.rotated(transform.basis.y, rot)
request_set_transform(Transform(new_rotation, transform.origin))

# Request the server to set the material's albedo color.
# color: The new albedo color.
# unreliable: Should the server send the RPC unreliably?
Expand Down
5 changes: 5 additions & 0 deletions game/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ game_zoom_out={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":46,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
game_rotate_piece={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":84,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
game_shuffle_stack={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
Expand Down