First commit 🎉

This commit is contained in:
Tony Bark 2025-07-17 01:49:18 -04:00
commit 43ea213f9b
728 changed files with 37080 additions and 0 deletions

View file

@ -0,0 +1,168 @@
class_name PopochiuCursor
extends CanvasLayer
# TODO: Deprecate this? I'll leave it here while we merge the refactor for the
# creation popups because in those the Cursor.Type enum is used.
enum Type {
NONE,
ACTIVE,
DOWN,
IDLE,
LEFT,
LOOK,
RIGHT,
SEARCH,
TALK,
UP,
USE,
WAIT,
}
@export var is_pixel_perfect := false
var is_blocked := false
@onready var main_cursor: AnimatedSprite2D = $MainCursor
@onready var secondary_cursor: Sprite2D = $SecondaryCursor
#region Godot ######################################################################################
func _init() -> void:
Engine.register_singleton(&"Cursor", self)
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
# Connect to autoload signals
PopochiuUtils.e.ready.connect(show_cursor)
func _process(delta):
var texture_size := (main_cursor.sprite_frames.get_frame_texture(
main_cursor.animation,
main_cursor.frame
) as Texture2D).get_size()
var mouse_position: Vector2 = main_cursor.get_global_mouse_position()
if is_pixel_perfect:
# Thanks to @whyshchuck
main_cursor.position = Vector2i(mouse_position)
secondary_cursor.position = Vector2i(mouse_position)
else:
main_cursor.position = mouse_position
secondary_cursor.position = mouse_position
if main_cursor.position.x < 1.0:
main_cursor.position.x = 1.0
elif main_cursor.position.x > PopochiuUtils.e.width - 2.0:
main_cursor.position.x = PopochiuUtils.e.width - 2.0
if main_cursor.position.y < 1.0:
main_cursor.position.y = 1.0
elif main_cursor.position.y > PopochiuUtils.e.height - 2.0:
main_cursor.position.y = PopochiuUtils.e.height - 2.0
#endregion
#region Public #####################################################################################
func show_cursor(anim_name := "normal", ignore_block := false) -> void:
if not ignore_block and is_blocked: return
if (
not anim_name.is_empty()
and not main_cursor.sprite_frames.has_animation(anim_name)
):
PopochiuUtils.print_error("Cursor has no animation: %s" % anim_name)
return
main_cursor.play(anim_name)
main_cursor.show()
secondary_cursor.hide()
func set_secondary_cursor_texture(texture: Texture2D, ignore_block := false) -> void:
if not ignore_block and is_blocked: return
secondary_cursor.texture = texture
if PopochiuUtils.e.settings.scale_gui:
# Scale the cursor based the relation of the texture size compared to the main cursor
# texture size
secondary_cursor.scale = Vector2.ONE * ceil(
float(texture.get_height()) / float(get_cursor_height())
)
secondary_cursor.show()
func remove_secondary_cursor_texture() -> void:
secondary_cursor.texture = null
if PopochiuUtils.e.settings.scale_gui:
secondary_cursor.scale = PopochiuUtils.e.scale
secondary_cursor.hide()
func toggle_visibility(is_visible: bool) -> void:
main_cursor.visible = is_visible
secondary_cursor.visible = is_visible
func block() -> void:
is_blocked = true
func unblock() -> void:
is_blocked = false
func scale_cursor(factor: Vector2) -> void:
secondary_cursor.scale = factor
main_cursor.scale = factor
func get_position() -> Vector2:
return secondary_cursor.position
func replace_frames(new_node: AnimatedSprite2D) -> void:
main_cursor.sprite_frames = new_node.sprite_frames
main_cursor.offset = new_node.offset
func hide_main_cursor() -> void:
main_cursor.hide()
func show_main_cursor() -> void:
main_cursor.show()
func hide_secondary_cursor() -> void:
secondary_cursor.hide()
func show_secondary_cursor() -> void:
secondary_cursor.show()
func get_type_name(idx: int) -> String:
return Type.keys()[idx].to_snake_case()
func get_cursor_height() -> int:
var height := 0
if main_cursor.visible:
height = main_cursor.sprite_frames.get_frame_texture(main_cursor.animation, 0).get_height()
elif secondary_cursor.visible:
height = secondary_cursor.texture.get_height()
return height
#endregion

View file

@ -0,0 +1 @@
uid://cus5ystyu850m

View file

@ -0,0 +1,211 @@
[gd_scene load_steps=22 format=3 uid="uid://c2pqh7ajiuiy0"]
[ext_resource type="Texture2D" uid="uid://bl3ecai6lvat1" path="res://addons/popochiu/engine/cursor/sprites/cursor.png" id="1"]
[ext_resource type="Script" path="res://addons/popochiu/engine/cursor/cursor.gd" id="1_n3epl"]
[sub_resource type="AtlasTexture" id="10"]
atlas = ExtResource("1")
region = Rect2(0, 0, 32, 32)
[sub_resource type="AtlasTexture" id="11"]
atlas = ExtResource("1")
region = Rect2(32, 0, 32, 32)
[sub_resource type="AtlasTexture" id="12"]
atlas = ExtResource("1")
region = Rect2(64, 0, 32, 32)
[sub_resource type="AtlasTexture" id="15"]
atlas = ExtResource("1")
region = Rect2(96, 0, 32, 32)
[sub_resource type="AtlasTexture" id="16"]
atlas = ExtResource("1")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="4"]
atlas = ExtResource("1")
region = Rect2(192, 0, 32, 32)
[sub_resource type="AtlasTexture" id="5"]
atlas = ExtResource("1")
region = Rect2(224, 0, 32, 32)
[sub_resource type="AtlasTexture" id="18"]
atlas = ExtResource("1")
region = Rect2(256, 0, 32, 32)
[sub_resource type="AtlasTexture" id="17"]
atlas = ExtResource("1")
region = Rect2(288, 0, 32, 32)
[sub_resource type="AtlasTexture" id="9"]
atlas = ExtResource("1")
region = Rect2(160, 0, 32, 32)
[sub_resource type="AtlasTexture" id="2"]
atlas = ExtResource("1")
region = Rect2(320, 0, 32, 32)
[sub_resource type="AtlasTexture" id="3"]
atlas = ExtResource("1")
region = Rect2(352, 0, 32, 32)
[sub_resource type="AtlasTexture" id="14"]
atlas = ExtResource("1")
region = Rect2(384, 0, 32, 32)
[sub_resource type="AtlasTexture" id="19"]
atlas = ExtResource("1")
region = Rect2(416, 0, 32, 32)
[sub_resource type="AtlasTexture" id="6"]
atlas = ExtResource("1")
region = Rect2(448, 0, 32, 32)
[sub_resource type="AtlasTexture" id="7"]
atlas = ExtResource("1")
region = Rect2(480, 0, 32, 32)
[sub_resource type="AtlasTexture" id="13"]
atlas = ExtResource("1")
region = Rect2(512, 0, 32, 32)
[sub_resource type="AtlasTexture" id="8"]
atlas = ExtResource("1")
region = Rect2(544, 0, 32, 32)
[sub_resource type="SpriteFrames" id="1"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("10")
}, {
"duration": 1.0,
"texture": SubResource("11")
}, {
"duration": 1.0,
"texture": SubResource("12")
}, {
"duration": 1.0,
"texture": SubResource("12")
}, {
"duration": 1.0,
"texture": SubResource("11")
}],
"loop": true,
"name": &"active",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("15")
}, {
"duration": 1.0,
"texture": SubResource("16")
}],
"loop": true,
"name": &"down",
"speed": 4.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("4")
}, {
"duration": 1.0,
"texture": SubResource("5")
}],
"loop": true,
"name": &"left",
"speed": 4.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("18")
}],
"loop": false,
"name": &"look",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("17")
}],
"loop": false,
"name": &"none",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("9")
}],
"loop": false,
"name": &"normal",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("2")
}, {
"duration": 1.0,
"texture": SubResource("3")
}],
"loop": true,
"name": &"right",
"speed": 4.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("14")
}],
"loop": false,
"name": &"search",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("19")
}],
"loop": false,
"name": &"talk",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("6")
}, {
"duration": 1.0,
"texture": SubResource("7")
}],
"loop": true,
"name": &"up",
"speed": 4.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("13")
}],
"loop": false,
"name": &"use",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("8")
}],
"loop": false,
"name": &"wait",
"speed": 5.0
}]
[node name="CursorLayer" type="CanvasLayer"]
layer = 100
script = ExtResource("1_n3epl")
[node name="MainCursor" type="AnimatedSprite2D" parent="."]
texture_filter = 1
sprite_frames = SubResource("1")
animation = &"normal"
[node name="SecondaryCursor" type="Sprite2D" parent="."]
texture_filter = 1

View file

@ -0,0 +1,211 @@
[gd_resource type="SpriteFrames" load_steps=22 format=3 uid="uid://d0ny3mket72mf"]
[ext_resource type="Texture2D" uid="uid://bl3ecai6lvat1" path="res://addons/popochiu/engine/cursor/sprites/cursor.png" id="1_qk45r"]
[ext_resource type="Texture2D" uid="uid://bocign602kxhh" path="res://addons/popochiu/engine/objects/gui/templates/simple_click/images/simple_click_cursor.png" id="2_05hav"]
[sub_resource type="AtlasTexture" id="10"]
atlas = ExtResource("1_qk45r")
region = Rect2(0, 0, 32, 32)
[sub_resource type="AtlasTexture" id="11"]
atlas = ExtResource("1_qk45r")
region = Rect2(32, 0, 32, 32)
[sub_resource type="AtlasTexture" id="12"]
atlas = ExtResource("1_qk45r")
region = Rect2(64, 0, 32, 32)
[sub_resource type="AtlasTexture" id="15"]
atlas = ExtResource("1_qk45r")
region = Rect2(96, 0, 32, 32)
[sub_resource type="AtlasTexture" id="16"]
atlas = ExtResource("1_qk45r")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_t3qtx"]
atlas = ExtResource("2_05hav")
region = Rect2(576, 0, 32, 32)
[sub_resource type="AtlasTexture" id="4"]
atlas = ExtResource("1_qk45r")
region = Rect2(192, 0, 32, 32)
[sub_resource type="AtlasTexture" id="5"]
atlas = ExtResource("1_qk45r")
region = Rect2(224, 0, 32, 32)
[sub_resource type="AtlasTexture" id="18"]
atlas = ExtResource("1_qk45r")
region = Rect2(256, 0, 32, 32)
[sub_resource type="AtlasTexture" id="17"]
atlas = ExtResource("1_qk45r")
region = Rect2(288, 0, 32, 32)
[sub_resource type="AtlasTexture" id="9"]
atlas = ExtResource("1_qk45r")
region = Rect2(160, 0, 32, 32)
[sub_resource type="AtlasTexture" id="2"]
atlas = ExtResource("1_qk45r")
region = Rect2(320, 0, 32, 32)
[sub_resource type="AtlasTexture" id="3"]
atlas = ExtResource("1_qk45r")
region = Rect2(352, 0, 32, 32)
[sub_resource type="AtlasTexture" id="14"]
atlas = ExtResource("1_qk45r")
region = Rect2(384, 0, 32, 32)
[sub_resource type="AtlasTexture" id="19"]
atlas = ExtResource("1_qk45r")
region = Rect2(416, 0, 32, 32)
[sub_resource type="AtlasTexture" id="6"]
atlas = ExtResource("1_qk45r")
region = Rect2(448, 0, 32, 32)
[sub_resource type="AtlasTexture" id="7"]
atlas = ExtResource("1_qk45r")
region = Rect2(480, 0, 32, 32)
[sub_resource type="AtlasTexture" id="13"]
atlas = ExtResource("1_qk45r")
region = Rect2(512, 0, 32, 32)
[sub_resource type="AtlasTexture" id="8"]
atlas = ExtResource("1_qk45r")
region = Rect2(544, 0, 32, 32)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("10")
}, {
"duration": 1.0,
"texture": SubResource("11")
}, {
"duration": 1.0,
"texture": SubResource("12")
}, {
"duration": 1.0,
"texture": SubResource("12")
}, {
"duration": 1.0,
"texture": SubResource("11")
}],
"loop": true,
"name": &"active",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("15")
}, {
"duration": 1.0,
"texture": SubResource("16")
}],
"loop": true,
"name": &"down",
"speed": 4.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_t3qtx")
}],
"loop": true,
"name": &"gui",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("4")
}, {
"duration": 1.0,
"texture": SubResource("5")
}],
"loop": true,
"name": &"left",
"speed": 4.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("18")
}],
"loop": false,
"name": &"look",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("17")
}],
"loop": false,
"name": &"none",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("9")
}],
"loop": false,
"name": &"normal",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("2")
}, {
"duration": 1.0,
"texture": SubResource("3")
}],
"loop": true,
"name": &"right",
"speed": 4.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("14")
}],
"loop": false,
"name": &"search",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("19")
}],
"loop": false,
"name": &"talk",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("6")
}, {
"duration": 1.0,
"texture": SubResource("7")
}],
"loop": true,
"name": &"up",
"speed": 4.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("13")
}],
"loop": false,
"name": &"use",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("8")
}],
"loop": false,
"name": &"wait",
"speed": 5.0
}]

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bl3ecai6lvat1"
path="res://.godot/imported/cursor.png-46ea11cf9adf0d4df6d3fbe5a77d49cf.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/popochiu/engine/cursor/sprites/cursor.png"
dest_files=["res://.godot/imported/cursor.png-46ea11cf9adf0d4df6d3fbe5a77d49cf.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1