From ffd347b4d098ec31ccc21ec3c0ee3c58f3319b3c Mon Sep 17 00:00:00 2001 From: elmodor Date: Fri, 2 Dec 2022 00:14:07 +0100 Subject: [PATCH 01/11] Mouseover actions for flipping and reset orientation --- game/Scripts/Game/CameraController.gd | 28 +++++++++++++++++++-------- game/Scripts/Game/Pieces/Piece.gd | 24 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/game/Scripts/Game/CameraController.gd b/game/Scripts/Game/CameraController.gd index 522287db..df2e237d 100644 --- a/game/Scripts/Game/CameraController.gd +++ b/game/Scripts/Game/CameraController.gd @@ -756,24 +756,36 @@ func _unhandled_input(event): _lock_selected_pieces() elif event.is_action_pressed("game_flip_piece"): if _selected_pieces.empty(): - if _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() ]: - if not _piece_mouse_is_over.is_collisions_on(): + if _piece_mouse_is_over != null: + if (_piece_mouse_is_over is Card and (_piece_mouse_is_over.over_hands.empty() or _piece_mouse_is_over.over_hands == [ get_tree().get_network_unique_id() ])) \ + or not _piece_mouse_is_over is Card: + if _piece_mouse_is_over.is_hovering(): _piece_mouse_is_over.rpc_id(1, "request_flip_vertically") + else: + _piece_mouse_is_over.rpc_id(1, "request_flip_vertically_on_ground") else: for piece in _selected_pieces: if piece is Piece: - piece.rpc_id(1, "request_flip_vertically") + if piece.is_hovering(): + piece.rpc_id(1, "request_flip_vertically") + else: + piece.rpc_id(1, "request_flip_vertically_on_ground") elif event.is_action_pressed("game_reset_piece"): if _selected_pieces.empty(): - if _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() ]: - if not _piece_mouse_is_over.is_collisions_on(): + if _piece_mouse_is_over != null: + if (_piece_mouse_is_over is Card and (_piece_mouse_is_over.over_hands.empty() or _piece_mouse_is_over.over_hands == [ get_tree().get_network_unique_id() ])) \ + or not _piece_mouse_is_over is Card: + if _piece_mouse_is_over.is_hovering(): _piece_mouse_is_over.rpc_id(1, "request_reset_orientation") + else: + _piece_mouse_is_over.rpc_id(1, "request_reset_orientation_on_ground") else: for piece in _selected_pieces: if piece is Piece: - piece.rpc_id(1, "request_reset_orientation") + if piece.is_hovering(): + piece.rpc_id(1, "request_reset_orientation") + else: + _piece_mouse_is_over.rpc_id(1, "request_reset_orientation_on_ground") elif event.is_action_pressed("game_toggle_debug_info"): _debug_info_label.visible = not _debug_info_label.visible elif event.is_action_pressed("game_toggle_ui"): diff --git a/game/Scripts/Game/Pieces/Piece.gd b/game/Scripts/Game/Pieces/Piece.gd index b684be89..d3eedc17 100644 --- a/game/Scripts/Game/Pieces/Piece.gd +++ b/game/Scripts/Game/Pieces/Piece.gd @@ -84,6 +84,8 @@ var _expose_albedo_color = true var _original_shape_scales = [] var _original_shape_scales_saved = false +var _timer_stop_hover = Timer.new() + # Apply a texture to the piece. # texture: The texture to apply. # surface: The index of the surface to apply the texture to. @@ -250,6 +252,13 @@ func play_effect(sound: AudioStream) -> void: effect_player.stream = sound effect_player.play() +# If you are not hovering this piece, ask the server to lift the piece up and flip the piece vertically. +master func request_flip_vertically_on_ground() -> void: + request_start_hovering(transform.origin, Vector3(0, 5, 0) ) + request_flip_vertically() + _timer_stop_hover.connect("timeout", self, "rpc_id", [1, "request_stop_hovering"], 4) + _timer_stop_hover.start() + # If you are hovering this piece, ask the server to flip the piece vertically. master func request_flip_vertically() -> void: request_set_hover_basis(hover_basis.rotated(hover_basis.z, PI)) @@ -265,6 +274,18 @@ master func request_impulse(position: Vector3, impulse: Vector3) -> void: master func request_lock() -> void: srv_lock() +# If you are not hovering the piece, ask the server to lift the piece up and reset the +# orientation of the piece. +master func request_reset_orientation_on_ground() -> void: + # Basis.is_equal_approx discards the epsilon. So here we go using the length instead + if (Basis.IDENTITY.get_euler() - transform.basis.get_euler()).length() < 0.01: + return + + request_start_hovering(transform.origin, Vector3(0,1,0) ) + request_reset_orientation() + _timer_stop_hover.connect("timeout", self, "rpc_id", [1, "request_stop_hovering"], 4) + _timer_stop_hover.start() + # If you are hovering the piece, ask the server to reset the orientation of the # piece. master func request_reset_orientation() -> void: @@ -563,6 +584,9 @@ func _ready(): connect("body_entered", self, "_on_body_entered") connect("tree_entered", self, "_on_tree_entered") + _timer_stop_hover.set_wait_time(0.15) + _timer_stop_hover.set_one_shot(true) + add_child(_timer_stop_hover) func _process(delta): _last_slow_table_collision += delta From 58916eda5c3353e49b8ffd7a3390367aa6ae78c5 Mon Sep 17 00:00:00 2001 From: elmodor Date: Fri, 2 Dec 2022 23:35:16 +0100 Subject: [PATCH 02/11] Removed animation --- game/Scripts/Game/CameraController.gd | 34 ++++++++++++++++----------- game/Scripts/Game/Pieces/Piece.gd | 23 ++++-------------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/game/Scripts/Game/CameraController.gd b/game/Scripts/Game/CameraController.gd index df2e237d..03959746 100644 --- a/game/Scripts/Game/CameraController.gd +++ b/game/Scripts/Game/CameraController.gd @@ -766,10 +766,12 @@ func _unhandled_input(event): else: for piece in _selected_pieces: if piece is Piece: - if piece.is_hovering(): - piece.rpc_id(1, "request_flip_vertically") - else: - piece.rpc_id(1, "request_flip_vertically_on_ground") + if (piece is Card and (piece.over_hands.empty() or piece.over_hands == [ get_tree().get_network_unique_id() ])) \ + or not piece is Card: + if piece.is_hovering(): + piece.rpc_id(1, "request_flip_vertically") + else: + piece.rpc_id(1, "request_flip_vertically_on_ground") elif event.is_action_pressed("game_reset_piece"): if _selected_pieces.empty(): if _piece_mouse_is_over != null: @@ -782,10 +784,12 @@ func _unhandled_input(event): else: for piece in _selected_pieces: if piece is Piece: - if piece.is_hovering(): - piece.rpc_id(1, "request_reset_orientation") - else: - _piece_mouse_is_over.rpc_id(1, "request_reset_orientation_on_ground") + if (piece is Card and (piece.over_hands.empty() or piece.over_hands == [ get_tree().get_network_unique_id() ])) \ + or not piece is Card: + if piece.is_hovering(): + piece.rpc_id(1, "request_reset_orientation") + else: + piece.rpc_id(1, "request_reset_orientation_on_ground") elif event.is_action_pressed("game_toggle_debug_info"): _debug_info_label.visible = not _debug_info_label.visible elif event.is_action_pressed("game_toggle_ui"): @@ -1442,14 +1446,9 @@ func _set_control_hint_label() -> void: ######### # OTHER # ######### - + var is_card_in_hand = false if not _selected_pieces.empty(): if _is_hovering_selected: - text += _set_control_hint_label_row_actions(tr("Flip orientation"), - ["game_flip_piece"]) - text += _set_control_hint_label_row_actions(tr("Reset orientation"), - ["game_reset_piece"]) - var ctrl_mod = cmd if OS.get_name() == "OSX" else ctrl var alt_mod = ctrl if OS.get_name() == "OSX" else alt @@ -1477,6 +1476,13 @@ func _set_control_hint_label() -> void: ["game_flip_piece"]) text += _set_control_hint_label_row_actions(tr("Face card up"), ["game_reset_piece"]) + 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("Reset orientation"), + ["game_reset_piece"]) + text += _set_control_hint_label_row_actions(tr("Flip orientation"), + ["game_flip_piece"]) text += _set_control_hint_label_row_actions(tr("Reset camera"), ["game_reset_camera"]) diff --git a/game/Scripts/Game/Pieces/Piece.gd b/game/Scripts/Game/Pieces/Piece.gd index d3eedc17..1cc3c4a2 100644 --- a/game/Scripts/Game/Pieces/Piece.gd +++ b/game/Scripts/Game/Pieces/Piece.gd @@ -84,8 +84,6 @@ var _expose_albedo_color = true var _original_shape_scales = [] var _original_shape_scales_saved = false -var _timer_stop_hover = Timer.new() - # Apply a texture to the piece. # texture: The texture to apply. # surface: The index of the surface to apply the texture to. @@ -252,12 +250,9 @@ func play_effect(sound: AudioStream) -> void: effect_player.stream = sound effect_player.play() -# If you are not hovering this piece, ask the server to lift the piece up and flip the piece vertically. +# If you are not hovering this piece, ask the server to flip the piece vertically. master func request_flip_vertically_on_ground() -> void: - request_start_hovering(transform.origin, Vector3(0, 5, 0) ) - request_flip_vertically() - _timer_stop_hover.connect("timeout", self, "rpc_id", [1, "request_stop_hovering"], 4) - _timer_stop_hover.start() + request_set_transform(Transform(transform.basis.rotated(transform.basis.z, PI), transform.origin)) # If you are hovering this piece, ask the server to flip the piece vertically. master func request_flip_vertically() -> void: @@ -274,17 +269,10 @@ master func request_impulse(position: Vector3, impulse: Vector3) -> void: master func request_lock() -> void: srv_lock() -# If you are not hovering the piece, ask the server to lift the piece up and reset the +# If you are not hovering the piece, ask the server to reset the # orientation of the piece. master func request_reset_orientation_on_ground() -> void: - # Basis.is_equal_approx discards the epsilon. So here we go using the length instead - if (Basis.IDENTITY.get_euler() - transform.basis.get_euler()).length() < 0.01: - return - - request_start_hovering(transform.origin, Vector3(0,1,0) ) - request_reset_orientation() - _timer_stop_hover.connect("timeout", self, "rpc_id", [1, "request_stop_hovering"], 4) - _timer_stop_hover.start() + request_set_transform(Transform(Basis.IDENTITY, transform.origin)) # If you are hovering the piece, ask the server to reset the orientation of the # piece. @@ -584,9 +572,6 @@ func _ready(): connect("body_entered", self, "_on_body_entered") connect("tree_entered", self, "_on_tree_entered") - _timer_stop_hover.set_wait_time(0.15) - _timer_stop_hover.set_one_shot(true) - add_child(_timer_stop_hover) func _process(delta): _last_slow_table_collision += delta From 76a049a37cc9d2e055dbd063ac6840ec8b8083c2 Mon Sep 17 00:00:00 2001 From: elmodor Date: Sat, 3 Dec 2022 15:24:10 +0100 Subject: [PATCH 03/11] Modified keybinding description --- game/Scenes/OptionsMenu.tscn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/Scenes/OptionsMenu.tscn b/game/Scenes/OptionsMenu.tscn index cd29e1f0..5e557051 100644 --- a/game/Scenes/OptionsMenu.tscn +++ b/game/Scenes/OptionsMenu.tscn @@ -738,7 +738,7 @@ margin_left = 484.0 margin_top = 240.0 margin_right = 964.0 margin_bottom = 266.0 -hint_tooltip = "Flip the selected piece on the horizontal axis." +hint_tooltip = "Flip the selected or mouseovered piece on the horizontal axis." size_flags_horizontal = 3 script = ExtResource( 2 ) action = "game_flip_piece" @@ -756,7 +756,7 @@ margin_left = 484.0 margin_top = 270.0 margin_right = 964.0 margin_bottom = 296.0 -hint_tooltip = "Resets the selected piece to its default orientation." +hint_tooltip = "Resets the selected or mouseovered piece to its default orientation." size_flags_horizontal = 3 script = ExtResource( 2 ) action = "game_reset_piece" From fbc2f04276d0a34cfc732b74dd2351cd7117cc37 Mon Sep 17 00:00:00 2001 From: elmodor Date: Sat, 3 Dec 2022 17:03:34 +0100 Subject: [PATCH 04/11] Added keybind to rotate a piece (selected/mouseover) --- game/Scenes/OptionsMenu.tscn | 88 ++++++++++++++++----------- game/Scripts/Game/CameraController.gd | 21 +++++++ game/Scripts/Game/Pieces/Piece.gd | 17 ++++-- game/project.godot | 5 ++ 4 files changed, 91 insertions(+), 40 deletions(-) diff --git a/game/Scenes/OptionsMenu.tscn b/game/Scenes/OptionsMenu.tscn index 5e557051..1011ec99 100644 --- a/game/Scenes/OptionsMenu.tscn +++ b/game/Scenes/OptionsMenu.tscn @@ -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" diff --git a/game/Scripts/Game/CameraController.gd b/game/Scripts/Game/CameraController.gd index dfcd6dda..013cd6f4 100644 --- a/game/Scripts/Game/CameraController.gd +++ b/game/Scripts/Game/CameraController.gd @@ -772,6 +772,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 (_piece_mouse_is_over is Card and _piece_mouse_is_over.over_hands.empty()) or not _piece_mouse_is_over is Card: + 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 (piece is Card and piece.over_hands.empty()) or not piece is Card: + 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: @@ -1492,6 +1511,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"), diff --git a/game/Scripts/Game/Pieces/Piece.gd b/game/Scripts/Game/Pieces/Piece.gd index 1cc3c4a2..fa4121f4 100644 --- a/game/Scripts/Game/Pieces/Piece.gd +++ b/game/Scripts/Game/Pieces/Piece.gd @@ -250,11 +250,11 @@ func play_effect(sound: AudioStream) -> void: effect_player.stream = sound effect_player.play() -# If you are not hovering this piece, ask the server to flip the piece vertically. +# If you are not hovering this piece, request the server to flip the piece vertically. master func request_flip_vertically_on_ground() -> void: request_set_transform(Transform(transform.basis.rotated(transform.basis.z, PI), transform.origin)) -# If you are hovering this piece, ask the server to flip the piece vertically. +# If you are hovering this piece, request the server to flip the piece vertically. master func request_flip_vertically() -> void: request_set_hover_basis(hover_basis.rotated(hover_basis.z, PI)) @@ -269,17 +269,18 @@ master func request_impulse(position: Vector3, impulse: Vector3) -> void: master func request_lock() -> void: srv_lock() -# If you are not hovering the piece, ask the server to reset the +# If you are not hovering the piece, request the server to reset the # orientation of the piece. master func request_reset_orientation_on_ground() -> void: request_set_transform(Transform(Basis.IDENTITY, transform.origin)) -# If you are hovering the piece, ask the server to reset the orientation of the +# If you are hovering the piece, request the server to reset the orientation of the # piece. 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: @@ -299,6 +300,12 @@ 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: + request_set_transform(Transform(transform.basis.rotated(transform.basis.y, rot), 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? diff --git a/game/project.godot b/game/project.godot index 5e254a7a..823f28bb 100644 --- a/game/project.godot +++ b/game/project.godot @@ -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) From e6fdb4281faa1b6f8f195d9bc083efd65b1ba1a0 Mon Sep 17 00:00:00 2001 From: elmodor Date: Sun, 4 Dec 2022 12:50:58 +0100 Subject: [PATCH 05/11] Refacted check if piece is allowed to be modified --- game/Scenes/OptionsMenu.tscn | 4 ++-- game/Scripts/Game/CameraController.gd | 24 ++++++++++++++++-------- game/Scripts/Game/Pieces/Piece.gd | 3 ++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/game/Scenes/OptionsMenu.tscn b/game/Scenes/OptionsMenu.tscn index 5e557051..d936d0e1 100644 --- a/game/Scenes/OptionsMenu.tscn +++ b/game/Scenes/OptionsMenu.tscn @@ -738,7 +738,7 @@ margin_left = 484.0 margin_top = 240.0 margin_right = 964.0 margin_bottom = 266.0 -hint_tooltip = "Flip the selected or mouseovered piece on the horizontal axis." +hint_tooltip = "Flip the selected piece or the piece the mouse is over on the horizontal axis." size_flags_horizontal = 3 script = ExtResource( 2 ) action = "game_flip_piece" @@ -756,7 +756,7 @@ margin_left = 484.0 margin_top = 270.0 margin_right = 964.0 margin_bottom = 296.0 -hint_tooltip = "Resets the selected or mouseovered piece to its default orientation." +hint_tooltip = "Resets the selected piece or the piece the mouse is over to its default orientation." size_flags_horizontal = 3 script = ExtResource( 2 ) action = "game_reset_piece" diff --git a/game/Scripts/Game/CameraController.gd b/game/Scripts/Game/CameraController.gd index dfcd6dda..bbc30ae3 100644 --- a/game/Scripts/Game/CameraController.gd +++ b/game/Scripts/Game/CameraController.gd @@ -757,8 +757,7 @@ func _unhandled_input(event): elif event.is_action_pressed("game_flip_piece"): if _selected_pieces.empty(): if _piece_mouse_is_over != null: - if (_piece_mouse_is_over is Card and (_piece_mouse_is_over.over_hands.empty() or _piece_mouse_is_over.over_hands == [ get_tree().get_network_unique_id() ])) \ - or not _piece_mouse_is_over is Card: + if is_piece_allowed_modify(_piece_mouse_is_over): if _piece_mouse_is_over.is_hovering(): _piece_mouse_is_over.rpc_id(1, "request_flip_vertically") else: @@ -766,8 +765,7 @@ func _unhandled_input(event): else: for piece in _selected_pieces: if piece is Piece: - if (piece is Card and (piece.over_hands.empty() or piece.over_hands == [ get_tree().get_network_unique_id() ])) \ - or not piece is Card: + if is_piece_allowed_modify(piece): if piece.is_hovering(): piece.rpc_id(1, "request_flip_vertically") else: @@ -775,8 +773,7 @@ func _unhandled_input(event): elif event.is_action_pressed("game_reset_piece"): if _selected_pieces.empty(): if _piece_mouse_is_over != null: - if (_piece_mouse_is_over is Card and (_piece_mouse_is_over.over_hands.empty() or _piece_mouse_is_over.over_hands == [ get_tree().get_network_unique_id() ])) \ - or not _piece_mouse_is_over is Card: + if is_piece_allowed_modify(_piece_mouse_is_over): if _piece_mouse_is_over.is_hovering(): _piece_mouse_is_over.rpc_id(1, "request_reset_orientation") else: @@ -784,8 +781,7 @@ func _unhandled_input(event): else: for piece in _selected_pieces: if piece is Piece: - if (piece is Card and (piece.over_hands.empty() or piece.over_hands == [ get_tree().get_network_unique_id() ])) \ - or not piece is Card: + if is_piece_allowed_modify(piece): if piece.is_hovering(): piece.rpc_id(1, "request_reset_orientation") else: @@ -858,6 +854,18 @@ func _unhandled_input(event): # NOTE: Mouse events are caught by the MouseGrab node, see # _on_MouseGrab_gui_input(). +# Checks if a piece is allowed to be modified by the current player. +# E.g. to rotate, flip etc +# 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 + if piece is Card: + if piece.over_hands.empty(): + can_modify = true + else: + can_modify = 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. # Returns: The hover position of a piece, based on the given mouse position. # mouse_position: The mouse position on the screen. diff --git a/game/Scripts/Game/Pieces/Piece.gd b/game/Scripts/Game/Pieces/Piece.gd index 1cc3c4a2..ca9426e1 100644 --- a/game/Scripts/Game/Pieces/Piece.gd +++ b/game/Scripts/Game/Pieces/Piece.gd @@ -252,7 +252,8 @@ func play_effect(sound: AudioStream) -> void: # If you are not hovering this piece, ask the server to flip the piece vertically. master func request_flip_vertically_on_ground() -> void: - request_set_transform(Transform(transform.basis.rotated(transform.basis.z, PI), transform.origin)) + var flipped_rotation = transform.basis.rotated(transform.basis.z, PI) + request_set_transform(Transform(flipped_rotation, transform.origin)) # If you are hovering this piece, ask the server to flip the piece vertically. master func request_flip_vertically() -> void: From 9ed84d4a5d5c225e02859fdcc84492ece9daf58b Mon Sep 17 00:00:00 2001 From: elmodor Date: Sun, 4 Dec 2022 12:56:56 +0100 Subject: [PATCH 06/11] Adapted check if piece is allowed to be modified --- game/Scripts/Game/CameraController.gd | 4 ++-- game/Scripts/Game/Pieces/Piece.gd | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/game/Scripts/Game/CameraController.gd b/game/Scripts/Game/CameraController.gd index 9b6d3b7a..c1027e32 100644 --- a/game/Scripts/Game/CameraController.gd +++ b/game/Scripts/Game/CameraController.gd @@ -776,7 +776,7 @@ func _unhandled_input(event): amount *= -1 if _selected_pieces.empty(): if _piece_mouse_is_over != null: - if (_piece_mouse_is_over is Card and _piece_mouse_is_over.over_hands.empty()) or not _piece_mouse_is_over is Card: + if is_piece_allowed_modify(_piece_mouse_is_over) and _piece_mouse_is_over.over_hands.empty(): if _piece_mouse_is_over.is_hovering(): _piece_mouse_is_over.rpc_id(1, "request_rotate_y", amount) else: @@ -784,7 +784,7 @@ func _unhandled_input(event): else: for piece in _selected_pieces: if piece is Piece: - if (piece is Card and piece.over_hands.empty()) or not piece is Card: + if is_piece_allowed_modify(piece) and piece.over_hands.empty(): if piece.is_hovering(): piece.rpc_id(1, "request_rotate_y", amount) else: diff --git a/game/Scripts/Game/Pieces/Piece.gd b/game/Scripts/Game/Pieces/Piece.gd index f165a099..0d9765d5 100644 --- a/game/Scripts/Game/Pieces/Piece.gd +++ b/game/Scripts/Game/Pieces/Piece.gd @@ -305,7 +305,8 @@ master func request_rotate_y(rot: float) -> void: # 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: - request_set_transform(Transform(transform.basis.rotated(transform.basis.y, rot), transform.origin)) + var new_rotation = transform.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. From 39803508dde8510e416aeba9069369b418c7ff93 Mon Sep 17 00:00:00 2001 From: elmodor Date: Thu, 8 Dec 2022 11:56:28 +0100 Subject: [PATCH 07/11] Explicit bool casting --- game/Scripts/Game/CameraController.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/Scripts/Game/CameraController.gd b/game/Scripts/Game/CameraController.gd index c1027e32..488f6840 100644 --- a/game/Scripts/Game/CameraController.gd +++ b/game/Scripts/Game/CameraController.gd @@ -877,12 +877,12 @@ func _unhandled_input(event): # E.g. to rotate, flip etc # 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 + 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() ] + 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. From 23f221009fcd13e41b0b07c9703e13dc416eaa57 Mon Sep 17 00:00:00 2001 From: elmodor Date: Thu, 8 Dec 2022 12:07:55 +0100 Subject: [PATCH 08/11] Expanded is_piece_allowed_modify with not_in_hand parameter --- game/Scripts/Game/CameraController.gd | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/game/Scripts/Game/CameraController.gd b/game/Scripts/Game/CameraController.gd index 488f6840..515b647f 100644 --- a/game/Scripts/Game/CameraController.gd +++ b/game/Scripts/Game/CameraController.gd @@ -776,7 +776,7 @@ func _unhandled_input(event): amount *= -1 if _selected_pieces.empty(): if _piece_mouse_is_over != null: - if is_piece_allowed_modify(_piece_mouse_is_over) and _piece_mouse_is_over.over_hands.empty(): + if is_piece_allowed_modify(_piece_mouse_is_over, true): if _piece_mouse_is_over.is_hovering(): _piece_mouse_is_over.rpc_id(1, "request_rotate_y", amount) else: @@ -784,7 +784,7 @@ func _unhandled_input(event): else: for piece in _selected_pieces: if piece is Piece: - if is_piece_allowed_modify(piece) and piece.over_hands.empty(): + if is_piece_allowed_modify(piece, true): if piece.is_hovering(): piece.rpc_id(1, "request_rotate_y", amount) else: @@ -875,13 +875,15 @@ 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 +# not_in_hand: If the piece is only allowed to be modified if not in hand # Returns true if piece can be modified by current player -func is_piece_allowed_modify( piece: Piece ) -> bool: +func is_piece_allowed_modify( piece: Piece, not_in_hand: bool = false ) -> bool: var can_modify = not bool(piece is Card) if piece is Card: if piece.over_hands.empty(): can_modify = true - else: + elif not not_in_hand: can_modify = bool(piece.over_hands == [ get_tree().get_network_unique_id() ]) return can_modify From 27167e2ef18af65daa9b83eb0caede68f48b1b00 Mon Sep 17 00:00:00 2001 From: elmodor Date: Fri, 9 Dec 2022 15:06:16 +0100 Subject: [PATCH 09/11] Fixed scale --- game/Scripts/Game/Pieces/Piece.gd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/game/Scripts/Game/Pieces/Piece.gd b/game/Scripts/Game/Pieces/Piece.gd index 344de86c..f9b9e718 100644 --- a/game/Scripts/Game/Pieces/Piece.gd +++ b/game/Scripts/Game/Pieces/Piece.gd @@ -308,7 +308,9 @@ master func request_rotate_y(rot: float) -> void: # 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 new_rotation = transform.basis.rotated(transform.basis.y, rot) + 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. From ef76b9500a0fd499ad9b63314aeee122a84aca6b Mon Sep 17 00:00:00 2001 From: elmodor Date: Fri, 9 Dec 2022 15:10:39 +0100 Subject: [PATCH 10/11] Removed double negation in if statement --- game/Scripts/Game/CameraController.gd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/game/Scripts/Game/CameraController.gd b/game/Scripts/Game/CameraController.gd index 8cc927fd..7a408577 100644 --- a/game/Scripts/Game/CameraController.gd +++ b/game/Scripts/Game/CameraController.gd @@ -776,7 +776,7 @@ func _unhandled_input(event): amount *= -1 if _selected_pieces.empty(): if _piece_mouse_is_over != null: - if is_piece_allowed_modify(_piece_mouse_is_over, true): + 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: @@ -784,7 +784,7 @@ func _unhandled_input(event): else: for piece in _selected_pieces: if piece is Piece: - if is_piece_allowed_modify(piece, true): + if is_piece_allowed_modify(piece, false): if piece.is_hovering(): piece.rpc_id(1, "request_rotate_y", amount) else: @@ -876,14 +876,14 @@ 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 -# not_in_hand: If the piece is only allowed to be modified if not in hand +# 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, not_in_hand: bool = false ) -> bool: +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 - elif not not_in_hand: + elif in_hand: can_modify = bool(piece.over_hands == [ get_tree().get_network_unique_id() ]) return can_modify From 545f71f8082364401bc1e91c84da29a5a1e15154 Mon Sep 17 00:00:00 2001 From: elmodor Date: Fri, 9 Dec 2022 15:24:46 +0100 Subject: [PATCH 11/11] Fixed tooltips --- game/Scripts/Game/CameraController.gd | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/game/Scripts/Game/CameraController.gd b/game/Scripts/Game/CameraController.gd index 7a408577..5e19c230 100644 --- a/game/Scripts/Game/CameraController.gd +++ b/game/Scripts/Game/CameraController.gd @@ -1509,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() ]: