Improve style in many demos (#1263)

This commit is contained in:
Aaron Franke
2025-10-11 05:03:59 -07:00
committed by GitHub
parent 0ae09b7e5a
commit 520b4a7870
197 changed files with 904 additions and 766 deletions

View File

@@ -6,7 +6,7 @@ const TEST_ITEM_SKU = "my_in_app_purchase_sku"
@onready var label: Label = $Label
var payment: Object = null
var test_item_purchase_token := ""
var test_item_purchase_token: String = ""
func _ready() -> void:

View File

@@ -3,10 +3,10 @@ extends Control
@export var target: NodePath
@export var min_scale := 0.1
@export var max_scale := 3.0
@export var one_finger_rot_x := true
@export var one_finger_rot_y := true
@export var two_fingers_rot_z := true
@export var two_fingers_zoom := true
@export var one_finger_rot_x: bool = true
@export var one_finger_rot_y: bool = true
@export var two_fingers_rot_z: bool = true
@export var two_fingers_zoom: bool = true
var base_state := {}
var curr_state := {}
@@ -16,69 +16,70 @@ var base_xform: Transform3D
@onready var target_node: Node = get_node(target)
func _gui_input(event: InputEvent) -> void:
func _gui_input(input_event: InputEvent) -> void:
# We must start touching inside, but we can drag or unpress outside.
# if not (event is InputEventScreenDrag or
# (event is InputEventScreenTouch and (not event.pressed or get_global_rect().has_point(event.position)))):
# if not (input_event is InputEventScreenDrag or
# (input_event is InputEventScreenTouch and (not input_event.pressed or get_global_rect().has_point(input_event.position)))):
# return
var finger_count := base_state.size()
if finger_count == 0:
# No fingers => Accept press.
if event is InputEventScreenTouch:
if event.pressed:
if input_event is InputEventScreenTouch:
if input_event.pressed:
# A finger started touching.
base_state = {
event.index: event.position,
input_event.index: input_event.position,
}
elif finger_count == 1:
# One finger => For rotating around X and Y.
# Accept one more press, unpress, or drag.
if event is InputEventScreenTouch:
if event.pressed:
if input_event is InputEventScreenTouch:
if input_event.pressed:
# One more finger started touching.
# Reset the base state to the only current and the new fingers.
base_state = {
curr_state.keys()[0]: curr_state.values()[0],
event.index: event.position,
input_event.index: input_event.position,
}
else:
if base_state.has(event.index):
if base_state.has(input_event.index):
# Only touching finger released.
base_state.clear()
elif event is InputEventScreenDrag:
if curr_state.has(event.index):
elif input_event is InputEventScreenDrag:
if curr_state.has(input_event.index):
# Touching finger dragged.
var unit_drag := _px2unit(base_state[base_state.keys()[0]] - event.position)
var unit_drag := _px2unit(base_state[base_state.keys()[0]] - input_event.position)
if one_finger_rot_x:
target_node.global_rotate(Vector3.UP, deg_to_rad(180.0 * unit_drag.x))
if one_finger_rot_y:
target_node.global_rotate(Vector3.RIGHT, deg_to_rad(180.0 * unit_drag.y))
# Since rotating around two axes, we have to reset the base constantly.
curr_state[event.index] = event.position
base_state[event.index] = event.position
curr_state[input_event.index] = input_event.position
base_state[input_event.index] = input_event.position
base_xform = target_node.get_transform()
elif finger_count == 2:
# Two fingers => To pinch-zoom and rotate around Z.
# Accept unpress or drag.
if event is InputEventScreenTouch:
if not event.pressed and base_state.has(event.index):
if input_event is InputEventScreenTouch:
if not input_event.pressed and base_state.has(input_event.index):
# Some known touching finger released.
# Clear the base state
base_state.clear()
elif event is InputEventScreenDrag:
if curr_state.has(event.index):
elif input_event is InputEventScreenDrag:
if curr_state.has(input_event.index):
# Some known touching finger dragged.
curr_state[event.index] = event.position
curr_state[input_event.index] = input_event.position
# Compute base and current inter-finger vectors.
var base_segment: Vector3 = base_state[base_state.keys()[0]] - base_state[base_state.keys()[1]]

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=3 format=3 uid="uid://584orsojewxv"]
[ext_resource type="Script" uid="uid://dsefg6y34mer7" path="res://GestureArea.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://cv4h5vfwnpj63" path="res://CubeScene.tscn" id="2"]
[ext_resource type="Script" uid="uid://dsefg6y34mer7" path="res://gesture_area.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://cv4h5vfwnpj63" path="res://cube_scene.tscn" id="2"]
[node name="VBoxContainer" type="VBoxContainer"]
anchors_preset = 15

View File

@@ -10,10 +10,10 @@ config_version=5
[application]
config/name="Multitouch Cubes Demo "
config/name="Multitouch Cubes Demo"
config/description="Demo of multitouch input and different gestures using the touch API. This demo is meant to be used with a touch-enabled device such as a phone or tablet."
config/tags=PackedStringArray("demo", "input", "mobile", "official")
run/main_scene="res://Main.tscn"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.5")
config/icon="res://icon.webp"

View File

@@ -1,5 +1,6 @@
extends Node2D
func _process(_delta: float) -> void:
# Keep redrawing on every frame.
queue_redraw()

View File

@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://cdlf0y2e26ru7"]
[ext_resource type="Script" uid="uid://hgkdjcvnp704" path="res://Main.gd" id="1"]
[ext_resource type="Script" uid="uid://hgkdjcvnp704" path="res://main.gd" id="1_ig7tw"]
[node name="Main" type="Node2D"]
script = ExtResource("1")
script = ExtResource("1_ig7tw")

View File

@@ -13,13 +13,13 @@ config_version=5
config/name="Multitouch View"
config/description="Simple debugger for multitouch input. Shows red dots everywhere you press."
config/tags=PackedStringArray("demo", "input", "mobile", "official")
run/main_scene="res://Main.tscn"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.5")
config/icon="res://icon.webp"
[autoload]
TouchHelper="*res://TouchHelper.gd"
TouchHelper="*res://touch_helper.gd"
[debug]

View File

@@ -1,23 +1,25 @@
extends Node
# This will track the position of every pointer in its public `state` property, which is a
# Dictionary, in which each key is a pointer index (integer) and each value its position (Vector2).
# It works by listening to input events not handled by other means.
# It also remaps the pointer indices coming from the OS to the lowest available to be friendlier.
# It can be conveniently setup as a singleton.
extends Node
var state := {}
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventScreenTouch:
if event.pressed:
var state: Dictionary[int, Vector2] = {}
func _unhandled_input(input_event: InputEvent) -> void:
if input_event is InputEventScreenTouch:
if input_event.pressed:
# Down.
state[event.index] = event.position
state[input_event.index] = input_event.position
else:
# Up.
state.erase(event.index)
state.erase(input_event.index)
get_viewport().set_input_as_handled()
elif event is InputEventScreenDrag:
elif input_event is InputEventScreenDrag:
# Movement.
state[event.index] = event.position
state[input_event.index] = input_event.position
get_viewport().set_input_as_handled()

View File

@@ -103,7 +103,7 @@ func _process(delta: float) -> void:
var gyro := Input.get_gyroscope()
# Show our base values.
var format := "%.05f"
var format: String = "%.05f"
%AccX.text = format % acc.x
%AccY.text = format % acc.y