more b3d parsing
24
scenes/joystick_test.tscn
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://clnrhrasxrueq"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://src/touch_screen_joystick.gd" id="2_duapw"]
|
||||||
|
|
||||||
|
[node name="Main" type="Node2D"]
|
||||||
|
|
||||||
|
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
|
[node name="TouchScreenJoystick" type="Control" parent="CanvasLayer"]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 2
|
||||||
|
anchor_top = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_top = -386.0
|
||||||
|
offset_right = 466.0
|
||||||
|
grow_vertical = 0
|
||||||
|
pivot_offset = Vector2(233, 193)
|
||||||
|
script = ExtResource("2_duapw")
|
||||||
|
anti_aliased = true
|
||||||
|
deadzone = 40.0
|
||||||
|
smooth_reset = true
|
||||||
|
smooth_speed = 15.0
|
||||||
|
change_opacity_when_touched = true
|
||||||
|
use_input_actions = true
|
|
@ -61,3 +61,26 @@ func readFloat() -> float:
|
||||||
var value = buffer.decode_float(offset)
|
var value = buffer.decode_float(offset)
|
||||||
offset += 4
|
offset += 4
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
func readCString() -> String:
|
||||||
|
var offsetAtStart = offset
|
||||||
|
while true:
|
||||||
|
var byte = readUByte()
|
||||||
|
if byte == 0:
|
||||||
|
break
|
||||||
|
var stringSize = offset - offsetAtStart
|
||||||
|
offset -= stringSize
|
||||||
|
return readBuffer(stringSize).get_string_from_ascii()
|
||||||
|
|
||||||
|
func readVector2() -> Vector2:
|
||||||
|
return Vector2(readFloat(), readFloat())
|
||||||
|
|
||||||
|
func readVector3() -> Vector3:
|
||||||
|
return Vector3(readFloat(), readFloat(), readFloat())
|
||||||
|
|
||||||
|
func readQuaternion() -> Quaternion:
|
||||||
|
var w = readFloat()
|
||||||
|
return Quaternion(readFloat(), readFloat(), readFloat(), w)
|
||||||
|
|
||||||
|
func readColor() -> Color:
|
||||||
|
return Color(readFloat(), readFloat(), readFloat(), readFloat())
|
||||||
|
|
|
@ -5,6 +5,7 @@ var roomTemplatesRaw = Dictionary()
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
#RMesh.LoadRMesh(self, "GFX\\map\\gatea_opt.rmesh")
|
#RMesh.LoadRMesh(self, "GFX\\map\\gatea_opt.rmesh")
|
||||||
#B3D.Load("GFX\\npcs\\106_2.b3d")
|
#B3D.Load("GFX\\npcs\\106_2.b3d")
|
||||||
|
add_child(B3D.Load("GFX\\apache.b3d"))
|
||||||
var rooms = INI.Load("res://Data/rooms.ini")
|
var rooms = INI.Load("res://Data/rooms.ini")
|
||||||
for room in rooms:
|
for room in rooms:
|
||||||
if room == "loose":
|
if room == "loose":
|
||||||
|
@ -20,7 +21,7 @@ func _ready() -> void:
|
||||||
roomTemplatesRaw.get_or_add(room, roomInfo)
|
roomTemplatesRaw.get_or_add(room, roomInfo)
|
||||||
#RMesh.LoadRMesh(self, roomInfo["mesh path"])
|
#RMesh.LoadRMesh(self, roomInfo["mesh path"])
|
||||||
|
|
||||||
CreateMap()
|
#CreateMap()
|
||||||
|
|
||||||
var I_Zone: MapZones = MapZones.new()
|
var I_Zone: MapZones = MapZones.new()
|
||||||
var RandomSeed: String = ""
|
var RandomSeed: String = ""
|
||||||
|
|
|
@ -1,12 +1,108 @@
|
||||||
class_name B3D
|
class_name B3D
|
||||||
|
|
||||||
|
var textures: Array = []
|
||||||
|
var brushes: Array = []
|
||||||
|
|
||||||
static func ReadChunk(reader:BufferStuffReader):
|
static func ReadChunk(reader:BufferStuffReader):
|
||||||
var chunk = B3DChunk.new()
|
var chunk = B3DChunk.new()
|
||||||
chunk.name = reader.readBuffer(4).get_string_from_ascii()
|
chunk.name = reader.readBuffer(4).get_string_from_ascii()
|
||||||
var chunkSize = reader.readInt()
|
var chunkSize = reader.readInt()
|
||||||
chunk.bytes = reader.readBuffer(chunkSize)
|
chunk.bytes = reader.readBuffer(chunkSize)
|
||||||
|
|
||||||
return chunk;
|
return chunk
|
||||||
|
|
||||||
|
static func ReadChunks(reader:BufferStuffReader):
|
||||||
|
var chunks:Array = []
|
||||||
|
while reader.offset < reader.buffer.size():
|
||||||
|
var chunk = ReadChunk(reader)
|
||||||
|
chunks.push_back(chunk)
|
||||||
|
|
||||||
|
return chunks
|
||||||
|
|
||||||
|
static func ReadTextures(reader:BufferStuffReader, parsedResult: B3D):
|
||||||
|
while reader.offset < reader.buffer.size():
|
||||||
|
var textureChunk = B3DTexture.new()
|
||||||
|
textureChunk.name = reader.readCString()
|
||||||
|
textureChunk.flags = reader.readInt()
|
||||||
|
textureChunk.blend = reader.readInt()
|
||||||
|
textureChunk.pos = reader.readVector2()
|
||||||
|
textureChunk.scale = reader.readVector2()
|
||||||
|
textureChunk.rotation = reader.readFloat()
|
||||||
|
parsedResult.textures.push_back(textureChunk)
|
||||||
|
|
||||||
|
static func ReadBone(reader:BufferStuffReader):
|
||||||
|
var boneChunk = B3DBone.new()
|
||||||
|
while reader.offset < reader.buffer.size():
|
||||||
|
var boneWeightChunk = B3DBoneWeight.new()
|
||||||
|
boneWeightChunk.vertexId = reader.readInt()
|
||||||
|
boneWeightChunk.weight = reader.readFloat()
|
||||||
|
boneChunk.weights.push_back(boneWeightChunk)
|
||||||
|
|
||||||
|
return boneChunk
|
||||||
|
|
||||||
|
static func ReadVRTS(reader:BufferStuffReader):
|
||||||
|
var vrtsChunk = B3DVertices.new()
|
||||||
|
vrtsChunk.flags = reader.readInt()
|
||||||
|
vrtsChunk.tex_coord_sets = reader.readInt()
|
||||||
|
vrtsChunk.tex_coord_set_size = reader.readInt()
|
||||||
|
|
||||||
|
while reader.offset < reader.buffer.size():
|
||||||
|
var vertex = reader.readVector3()
|
||||||
|
vrtsChunk.vertices.push_back(vertex)
|
||||||
|
|
||||||
|
if vrtsChunk.containsNormals:
|
||||||
|
var normal = reader.readVector3()
|
||||||
|
vrtsChunk.normals.push_back(normal)
|
||||||
|
|
||||||
|
if vrtsChunk.containsColors:
|
||||||
|
var color = reader.readColor()
|
||||||
|
vrtsChunk.colors.push_back(color)
|
||||||
|
|
||||||
|
for i in range(vrtsChunk.tex_coord_sets):
|
||||||
|
for i1 in range(vrtsChunk.tex_coord_set_size):
|
||||||
|
vrtsChunk.uv.push_back(reader.readVector2())
|
||||||
|
|
||||||
|
return vrtsChunk
|
||||||
|
|
||||||
|
static func ReadTRIS(reader:BufferStuffReader):
|
||||||
|
var trisChunk = B3DTris.new()
|
||||||
|
trisChunk.brushId = reader.readInt()
|
||||||
|
|
||||||
|
while reader.offset < reader.buffer.size():
|
||||||
|
trisChunk.triangles.push_back(reader.readInt())
|
||||||
|
|
||||||
|
return trisChunk
|
||||||
|
|
||||||
|
static func ReadMesh(reader:BufferStuffReader):
|
||||||
|
var meshChunk = B3DMesh.new()
|
||||||
|
meshChunk.brushId = reader.readInt()
|
||||||
|
|
||||||
|
var chunks = ReadChunks(reader)
|
||||||
|
for chunk in chunks:
|
||||||
|
if chunk.name == "VRTS":
|
||||||
|
meshChunk.verts = ReadVRTS(reader)
|
||||||
|
elif chunk.name == "TRIS":
|
||||||
|
meshChunk.surfaces = ReadTRIS(reader)
|
||||||
|
|
||||||
|
static func ReadNode(reader:BufferStuffReader):
|
||||||
|
var node = B3DNode.new()
|
||||||
|
node.name = reader.readCString()
|
||||||
|
|
||||||
|
node.position = reader.readVector3()
|
||||||
|
node.scale = reader.readVector3()
|
||||||
|
node.rotation = reader.readQuaternion().get_euler()
|
||||||
|
|
||||||
|
var chunks = ReadChunks(reader)
|
||||||
|
for chunk in chunks:
|
||||||
|
var chunkReader = BufferStuffReader.create(chunk.bytes)
|
||||||
|
if chunk.name == "NODE":
|
||||||
|
node.add_child(ReadNode(chunkReader))
|
||||||
|
elif chunk.name == "BONE":
|
||||||
|
node.bone = ReadBone(chunkReader)
|
||||||
|
elif chunk.name == "MESH":
|
||||||
|
node.mesh = ReadMesh(chunkReader)
|
||||||
|
|
||||||
|
return node
|
||||||
|
|
||||||
static func Load(filePath: String):
|
static func Load(filePath: String):
|
||||||
var correctedPath = filePath.replace("\\", "/")
|
var correctedPath = filePath.replace("\\", "/")
|
||||||
|
@ -15,14 +111,27 @@ static func Load(filePath: String):
|
||||||
var reader = BufferStuffReader.create(fileHandle.get_buffer(fileHandle.get_length()))
|
var reader = BufferStuffReader.create(fileHandle.get_buffer(fileHandle.get_length()))
|
||||||
fileHandle.close()
|
fileHandle.close()
|
||||||
|
|
||||||
|
var parsedResult = B3D.new()
|
||||||
|
var resultScene = Node3D.new()
|
||||||
|
|
||||||
var bb3dChunk = ReadChunk(reader)
|
var bb3dChunk = ReadChunk(reader)
|
||||||
print(bb3dChunk.name)
|
|
||||||
if bb3dChunk.name == "BB3D":
|
if bb3dChunk.name == "BB3D":
|
||||||
var bb3dReader = BufferStuffReader.create(bb3dChunk.bytes)
|
var bb3dReader = BufferStuffReader.create(bb3dChunk.bytes)
|
||||||
var version = bb3dReader.readInt()
|
var version = bb3dReader.readInt()
|
||||||
|
|
||||||
if version == 1:
|
if version == 1:
|
||||||
pass
|
var chunks = ReadChunks(bb3dReader)
|
||||||
|
for chunk in chunks:
|
||||||
|
var chunkReader = BufferStuffReader.create(chunk.bytes)
|
||||||
|
if chunk.name == "TEXS":
|
||||||
|
ReadTextures(chunkReader, parsedResult)
|
||||||
|
elif chunk.name == "BRUS":
|
||||||
|
continue
|
||||||
|
elif chunk.name == "NODE":
|
||||||
|
resultScene.add_child(ReadNode(chunkReader))
|
||||||
|
|
||||||
|
print(parsedResult.textures[0].name)
|
||||||
|
return resultScene
|
||||||
else:
|
else:
|
||||||
print(str("Unknown b3d version. ", version))
|
print(str("Unknown b3d version. ", version))
|
||||||
return null
|
return null
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class_name B3DMesh
|
class_name B3DMesh
|
||||||
|
|
||||||
var brushId: int = -1
|
var brushId: int = -1
|
||||||
var vertsData # TODO: B3D_VRTS
|
var verts: B3DVertices # B3D_VRTS
|
||||||
var surfaces: Array # B3D_TRIS
|
var surfaces: B3DTris # B3D_TRIS
|
||||||
|
|
14
src/objects/B3DNode.gd
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
class_name B3DNode
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
#var name: String = ""
|
||||||
|
#var position: Vector3 = Vector3.ZERO
|
||||||
|
#var scale: Vector3 = Vector3.ZERO
|
||||||
|
#var rotation: Quaternion = Quaternion.IDENTITY
|
||||||
|
|
||||||
|
var bone: B3DBone
|
||||||
|
var mesh: B3DMesh
|
||||||
|
var children: Array = []
|
||||||
|
var anim: B3DAnim
|
||||||
|
var animationKeys: Array = []
|
||||||
|
var parent: B3DNode
|
8
src/objects/B3DTexture.gd
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class_name B3DTexture
|
||||||
|
|
||||||
|
var name: String = ""
|
||||||
|
var flags: int = 0
|
||||||
|
var blend: int = 0
|
||||||
|
var pos: Vector2
|
||||||
|
var scale: Vector2
|
||||||
|
var rotation: float = 0.0
|
4
src/objects/B3DTris.gd
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
class_name B3DTris
|
||||||
|
|
||||||
|
var brushId: int = -1
|
||||||
|
var triangles: PackedInt32Array = PackedInt32Array()
|
19
src/objects/B3DVertices.gd
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
class_name B3DVertices
|
||||||
|
|
||||||
|
var flags: int: set = _flagsUpdated
|
||||||
|
var tex_coord_sets: int = 1
|
||||||
|
var tex_coord_set_size: int = 0
|
||||||
|
|
||||||
|
var containsNormals: bool = false
|
||||||
|
var containsColors: bool = false
|
||||||
|
|
||||||
|
func _flagsUpdated(flagValue: int):
|
||||||
|
flags = flagValue
|
||||||
|
containsNormals = (flags & 1) != 0
|
||||||
|
containsColors = (flags & 2) != 0
|
||||||
|
|
||||||
|
|
||||||
|
var vertices: PackedVector3Array = PackedVector3Array()
|
||||||
|
var normals: PackedVector3Array = PackedVector3Array()
|
||||||
|
var colors: PackedColorArray = PackedColorArray()
|
||||||
|
var uv: PackedVector2Array = PackedVector2Array()
|
360
src/touch_screen_joystick.gd
Normal file
|
@ -0,0 +1,360 @@
|
||||||
|
@tool
|
||||||
|
extends Control
|
||||||
|
class_name TouchScreenJoystick
|
||||||
|
|
||||||
|
@export var use_textures : bool:
|
||||||
|
set(new_bool):
|
||||||
|
use_textures = new_bool
|
||||||
|
notify_property_list_changed()
|
||||||
|
@export var knob_color := Color.WHITE
|
||||||
|
@export var base_color := Color.WHITE
|
||||||
|
@export var background_color := Color(Color.BLACK, 0.25)
|
||||||
|
|
||||||
|
@export var base_radius := 130.0
|
||||||
|
@export var knob_radius := 65.0
|
||||||
|
@export var thickness := 1.8
|
||||||
|
@export var anti_aliased : bool
|
||||||
|
|
||||||
|
@export_group("Textures")
|
||||||
|
@export var use_custom_max_length : bool:
|
||||||
|
set(new_bool):
|
||||||
|
use_custom_max_length = new_bool
|
||||||
|
notify_property_list_changed()
|
||||||
|
|
||||||
|
@export var max_length := 120.0
|
||||||
|
@export var base_texture : Texture2D
|
||||||
|
@export var knob_texture : Texture2D
|
||||||
|
@export var background_texture : Texture2D
|
||||||
|
|
||||||
|
@export_group("Joystick Params")
|
||||||
|
@export_enum("FIXED", "DYNAMIC") var mode := 0
|
||||||
|
@export var deadzone := 10.0:
|
||||||
|
set(new_deadzone):
|
||||||
|
deadzone = clamp(new_deadzone, 10, base_radius)
|
||||||
|
|
||||||
|
@export var smooth_reset : bool:
|
||||||
|
set(new_bool):
|
||||||
|
smooth_reset = new_bool
|
||||||
|
notify_property_list_changed()
|
||||||
|
@export var smooth_speed := 5.0
|
||||||
|
@export var change_opacity_when_touched : bool:
|
||||||
|
set(new_bool):
|
||||||
|
change_opacity_when_touched = new_bool
|
||||||
|
notify_property_list_changed()
|
||||||
|
|
||||||
|
@export_range(0, 100, 0.01, "suffix:%") var from_opacity := 50.0
|
||||||
|
@export_range(0, 100, 0.01, "suffix:%") var to_opacity := 100.0
|
||||||
|
@export var use_input_actions : bool:
|
||||||
|
set(new_bool):
|
||||||
|
use_input_actions = new_bool
|
||||||
|
notify_property_list_changed()
|
||||||
|
|
||||||
|
@export_subgroup("Input Actions")
|
||||||
|
@export var action_left := "ui_left"
|
||||||
|
@export var action_right := "ui_right"
|
||||||
|
@export var action_up := "ui_up"
|
||||||
|
@export var action_down := "ui_down"
|
||||||
|
|
||||||
|
@export_group("Debug")
|
||||||
|
@export var draw_debugs : bool:
|
||||||
|
set(new_bool):
|
||||||
|
draw_debugs = new_bool
|
||||||
|
notify_property_list_changed()
|
||||||
|
@export var deadzone_color := Color(Color.RED, 0.5)
|
||||||
|
@export var current_max_length_color := Color(Color.BLUE, 0.5)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var is_pressing : bool
|
||||||
|
var knob_position : Vector2
|
||||||
|
var finger_index : int
|
||||||
|
var default_pos : Vector2
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
default_pos = position
|
||||||
|
change_opacity()
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
|
||||||
|
# checks if currently pressing
|
||||||
|
if is_pressing:
|
||||||
|
|
||||||
|
move_knob_pos()
|
||||||
|
else:
|
||||||
|
reset_knob_pos()
|
||||||
|
|
||||||
|
# update necessities
|
||||||
|
update_input_actions()
|
||||||
|
pivot_offset = size / 2
|
||||||
|
queue_redraw()
|
||||||
|
|
||||||
|
#moves the knob position when pressing
|
||||||
|
func move_knob_pos() -> void:
|
||||||
|
if get_distance() <= get_current_max_length():
|
||||||
|
knob_position = get_local_touch_pos()
|
||||||
|
else:
|
||||||
|
# calculates the angle position of the knob if it's position --
|
||||||
|
# -- exceeds from the current max length
|
||||||
|
var angle := get_center_pos().angle_to_point(get_global_mouse_position())
|
||||||
|
knob_position.x = (get_center_pos().x + cos(angle) * get_current_max_length()) - get_center_pos().x
|
||||||
|
knob_position.y = (get_center_pos().y + sin(angle) * get_current_max_length()) - get_center_pos().y
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# triggers an specific input action based on the --
|
||||||
|
# -- current direction
|
||||||
|
func trigger_input_actions() -> void:
|
||||||
|
|
||||||
|
var dir := get_deadzoned_vector().normalized()
|
||||||
|
|
||||||
|
if dir.x > 0:
|
||||||
|
Input.action_release(action_left)
|
||||||
|
Input.action_press(action_right, dir.x)
|
||||||
|
else:
|
||||||
|
Input.action_release(action_right)
|
||||||
|
Input.action_press(action_left, -dir.x)
|
||||||
|
|
||||||
|
if dir.y < 0:
|
||||||
|
Input.action_release(action_down)
|
||||||
|
Input.action_press(action_up, -dir.y)
|
||||||
|
else:
|
||||||
|
Input.action_release(action_up)
|
||||||
|
Input.action_press(action_down, dir.y)
|
||||||
|
|
||||||
|
# releases all input actions
|
||||||
|
func release_input_actions() -> void:
|
||||||
|
Input.action_release(action_right)
|
||||||
|
Input.action_release(action_left)
|
||||||
|
Input.action_release(action_up)
|
||||||
|
Input.action_release(action_down)
|
||||||
|
|
||||||
|
# resets knob position if not pressing
|
||||||
|
func reset_knob_pos() -> void:
|
||||||
|
if smooth_reset:
|
||||||
|
knob_position = lerp(knob_position, Vector2.ZERO, smooth_speed * get_process_delta_time())
|
||||||
|
else:
|
||||||
|
knob_position = Vector2.ZERO
|
||||||
|
|
||||||
|
func _validate_property(property: Dictionary) -> void:
|
||||||
|
validitate_default_drawing_properties(property)
|
||||||
|
validitate_texture_drawing_properties(property)
|
||||||
|
validitate_input_action_properties(property)
|
||||||
|
if property.name == "smooth_speed" and not smooth_reset:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "from_opacity" and not change_opacity_when_touched:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "to_opacity" and not change_opacity_when_touched:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "deadzone_color" and not draw_debugs:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "current_max_length_color" and not draw_debugs:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func validitate_input_action_properties(property : Dictionary) -> void:
|
||||||
|
if property.name == "action_left" and not use_input_actions:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "action_right" and not use_input_actions:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "action_up" and not use_input_actions:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "action_down" and not use_input_actions:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
func validitate_default_drawing_properties(property : Dictionary) -> void:
|
||||||
|
if property.name == "base_color" and use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "knob_color" and use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "background_color" and use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "base_radius" and use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
|
||||||
|
if property.name == "knob_radius" and use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "thickness" and use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "anti_aliased" and use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
|
||||||
|
func validitate_texture_drawing_properties(property : Dictionary) -> void:
|
||||||
|
|
||||||
|
|
||||||
|
if property.name == "background_texture" and not use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "use_custom_max_length" and not use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "max_length" and not use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "max_length" and not use_custom_max_length:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "base_texture" and not use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
if property.name == "knob_texture" and not use_textures:
|
||||||
|
property.usage = PROPERTY_USAGE_READ_ONLY
|
||||||
|
|
||||||
|
|
||||||
|
func _draw() -> void:
|
||||||
|
if not use_textures:
|
||||||
|
draw_default_joystick()
|
||||||
|
else:
|
||||||
|
draw_textured_joystick()
|
||||||
|
|
||||||
|
if draw_debugs:
|
||||||
|
draw_debug()
|
||||||
|
|
||||||
|
func draw_default_joystick() -> void:
|
||||||
|
|
||||||
|
draw_set_transform(size / 2)
|
||||||
|
# background
|
||||||
|
draw_circle(Vector2.ZERO, base_radius, background_color, true, -1.0, anti_aliased)
|
||||||
|
|
||||||
|
# base
|
||||||
|
draw_circle(Vector2.ZERO, base_radius, base_color, false, thickness, anti_aliased)
|
||||||
|
var pos := knob_position
|
||||||
|
# knob
|
||||||
|
draw_circle(pos, knob_radius, knob_color, true, -1.0, anti_aliased)
|
||||||
|
|
||||||
|
|
||||||
|
func draw_textured_joystick() -> void:
|
||||||
|
|
||||||
|
if background_texture:
|
||||||
|
var centered_base_pos := size / 2 - (base_texture.get_size() / 2)
|
||||||
|
draw_set_transform(centered_base_pos)
|
||||||
|
draw_texture_rect(background_texture, Rect2(Vector2.ZERO, base_texture.get_size()), false)
|
||||||
|
|
||||||
|
# draw textured base
|
||||||
|
if base_texture:
|
||||||
|
var centered_base_pos := size / 2 - (base_texture.get_size() / 2)
|
||||||
|
|
||||||
|
size.x = clamp(size.x, base_texture.get_size().x, INF)
|
||||||
|
size.y = clamp(size.y, base_texture.get_size().y, INF)
|
||||||
|
draw_set_transform(centered_base_pos)
|
||||||
|
draw_texture_rect(base_texture, Rect2(Vector2.ZERO, base_texture.get_size()), false)
|
||||||
|
|
||||||
|
# draw texture knob
|
||||||
|
|
||||||
|
if knob_texture:
|
||||||
|
var centered_knob_pos := (Vector2.ZERO - knob_texture.get_size() / 2) + size / 2
|
||||||
|
|
||||||
|
draw_set_transform(centered_knob_pos)
|
||||||
|
draw_texture_rect(knob_texture, Rect2(knob_position, knob_texture.get_size()), false)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func draw_debug() -> void:
|
||||||
|
draw_set_transform(size / 2)
|
||||||
|
# draw deadzone
|
||||||
|
|
||||||
|
draw_circle(Vector2.ZERO, deadzone, deadzone_color, false, 1.0, true)
|
||||||
|
|
||||||
|
# draw current max length
|
||||||
|
draw_circle(Vector2.ZERO, get_current_max_length(), current_max_length_color, false, 1.0, true)
|
||||||
|
|
||||||
|
draw_circle(knob_position, 10, Color.RED, true, -1.0, true)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func _input(event: InputEvent) -> void:
|
||||||
|
if event is InputEventScreenTouch:
|
||||||
|
var is_touching := event.pressed and get_global_rect().has_point(event.position) as bool
|
||||||
|
|
||||||
|
if is_touching:
|
||||||
|
on_touched(event)
|
||||||
|
else:
|
||||||
|
on_touch_released(event)
|
||||||
|
|
||||||
|
|
||||||
|
func on_touched(event: InputEventScreenTouch) -> void:
|
||||||
|
is_pressing = true
|
||||||
|
finger_index = event.index
|
||||||
|
change_opacity()
|
||||||
|
var mouse_pos := get_global_mouse_position() - size / 2
|
||||||
|
if mode == 1 and event.index == finger_index and get_global_rect().has_point(mouse_pos):
|
||||||
|
position = mouse_pos
|
||||||
|
#update_input_actions()
|
||||||
|
|
||||||
|
func on_touch_released(event: InputEventScreenTouch) -> void:
|
||||||
|
if event.index == finger_index:
|
||||||
|
is_pressing = false
|
||||||
|
if mode == 1:
|
||||||
|
position = default_pos
|
||||||
|
change_opacity()
|
||||||
|
#update_input_actions()
|
||||||
|
|
||||||
|
|
||||||
|
func update_input_actions() -> void:
|
||||||
|
if use_input_actions and is_pressing:
|
||||||
|
trigger_input_actions()
|
||||||
|
else:
|
||||||
|
release_input_actions()
|
||||||
|
|
||||||
|
func get_vector() -> Vector2:
|
||||||
|
return get_center_pos().direction_to(knob_position + get_center_pos())
|
||||||
|
|
||||||
|
|
||||||
|
func get_deadzoned_vector() -> Vector2:
|
||||||
|
var vector : Vector2
|
||||||
|
if is_pressing and not is_in_deadzone():
|
||||||
|
vector = get_center_pos().direction_to(knob_position + get_center_pos())
|
||||||
|
else:
|
||||||
|
vector = Vector2.ZERO
|
||||||
|
return vector
|
||||||
|
|
||||||
|
func get_center_pos() -> Vector2:
|
||||||
|
return position + size / 2
|
||||||
|
|
||||||
|
func get_local_touch_pos() -> Vector2:
|
||||||
|
return (get_global_mouse_position() - get_center_pos()) / scale.x
|
||||||
|
|
||||||
|
func get_distance() -> float:
|
||||||
|
return get_global_mouse_position().distance_to(get_center_pos()) / scale.x
|
||||||
|
|
||||||
|
# get the current max length of the knob's position. --
|
||||||
|
# -- if you use textures, the current max length will --
|
||||||
|
# -- automatically set to the half base texture's width
|
||||||
|
func get_current_max_length() -> float:
|
||||||
|
var curr_max_length : float
|
||||||
|
if not use_textures:
|
||||||
|
curr_max_length = base_radius
|
||||||
|
else:
|
||||||
|
if use_custom_max_length:
|
||||||
|
curr_max_length = max_length
|
||||||
|
elif not use_custom_max_length and base_texture:
|
||||||
|
curr_max_length = base_texture.get_size().x / 2
|
||||||
|
|
||||||
|
return curr_max_length
|
||||||
|
|
||||||
|
# changes the opacity when touched
|
||||||
|
func change_opacity() -> void:
|
||||||
|
if change_opacity_when_touched and not Engine.is_editor_hint():
|
||||||
|
if is_pressing:
|
||||||
|
modulate.a = to_opacity / 100.0
|
||||||
|
else:
|
||||||
|
modulate.a = from_opacity / 100.0
|
||||||
|
else:
|
||||||
|
modulate.a = 1.0
|
||||||
|
|
||||||
|
func is_in_deadzone() -> bool:
|
||||||
|
return get_distance() <= deadzone
|
BIN
textures/VirtualJoystickPack/Joystick.png
Normal file
After Width: | Height: | Size: 12 KiB |
34
textures/VirtualJoystickPack/Joystick.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://kgegtvvkasmh"
|
||||||
|
path="res://.godot/imported/Joystick.png-f4c6f88ef9ef2fd1b4ed8c8562aa88c4.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://textures/VirtualJoystickPack/Joystick.png"
|
||||||
|
dest_files=["res://.godot/imported/Joystick.png-f4c6f88ef9ef2fd1b4ed8c8562aa88c4.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
|
BIN
textures/VirtualJoystickPack/JoystickPack Preview.png
Normal file
After Width: | Height: | Size: 96 KiB |
34
textures/VirtualJoystickPack/JoystickPack Preview.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dqgoyfgebhqmt"
|
||||||
|
path="res://.godot/imported/JoystickPack Preview.png-cad2cbfc624f33460e27843d4eddb5f8.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://textures/VirtualJoystickPack/JoystickPack Preview.png"
|
||||||
|
dest_files=["res://.godot/imported/JoystickPack Preview.png-cad2cbfc624f33460e27843d4eddb5f8.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
|
BIN
textures/VirtualJoystickPack/JoystickPack.png
Normal file
After Width: | Height: | Size: 48 KiB |
34
textures/VirtualJoystickPack/JoystickPack.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://b2nh445b2tt8d"
|
||||||
|
path="res://.godot/imported/JoystickPack.png-ff571482e5201edf644b6dfa5efd257e.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://textures/VirtualJoystickPack/JoystickPack.png"
|
||||||
|
dest_files=["res://.godot/imported/JoystickPack.png-ff571482e5201edf644b6dfa5efd257e.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
|
BIN
textures/VirtualJoystickPack/JoystickSplitted.png
Normal file
After Width: | Height: | Size: 12 KiB |
34
textures/VirtualJoystickPack/JoystickSplitted.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://3s2n2pi4u3p4"
|
||||||
|
path="res://.godot/imported/JoystickSplitted.png-6932d8f057f1cd8a62dfca37ff10f3ce.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://textures/VirtualJoystickPack/JoystickSplitted.png"
|
||||||
|
dest_files=["res://.godot/imported/JoystickSplitted.png-6932d8f057f1cd8a62dfca37ff10f3ce.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
|
BIN
textures/VirtualJoystickPack/LargeHandleFilled.png
Normal file
After Width: | Height: | Size: 5.3 KiB |
34
textures/VirtualJoystickPack/LargeHandleFilled.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://1f45s46ro0ua"
|
||||||
|
path="res://.godot/imported/LargeHandleFilled.png-2cad4614d0b76be8d02c020956ef23b4.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://textures/VirtualJoystickPack/LargeHandleFilled.png"
|
||||||
|
dest_files=["res://.godot/imported/LargeHandleFilled.png-2cad4614d0b76be8d02c020956ef23b4.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
|
BIN
textures/VirtualJoystickPack/LargeHandleFilledGrey.png
Normal file
After Width: | Height: | Size: 5.2 KiB |
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bwa5fpygwbwkw"
|
||||||
|
path="res://.godot/imported/LargeHandleFilledGrey.png-673eb0a5dc7350a468dcb401866c77ee.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://textures/VirtualJoystickPack/LargeHandleFilledGrey.png"
|
||||||
|
dest_files=["res://.godot/imported/LargeHandleFilledGrey.png-673eb0a5dc7350a468dcb401866c77ee.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
|
BIN
textures/VirtualJoystickPack/SmallHandle.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
34
textures/VirtualJoystickPack/SmallHandle.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dnihylyhtdeag"
|
||||||
|
path="res://.godot/imported/SmallHandle.png-883b3f2a2d4d8297c3a3c1174787ece9.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://textures/VirtualJoystickPack/SmallHandle.png"
|
||||||
|
dest_files=["res://.godot/imported/SmallHandle.png-883b3f2a2d4d8297c3a3c1174787ece9.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
|
BIN
textures/VirtualJoystickPack/SmallHandleFilled.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
34
textures/VirtualJoystickPack/SmallHandleFilled.png.import
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://cimue7to0w30k"
|
||||||
|
path="res://.godot/imported/SmallHandleFilled.png-b05ea1c4c699eec1a35a0d4e5f216398.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://textures/VirtualJoystickPack/SmallHandleFilled.png"
|
||||||
|
dest_files=["res://.godot/imported/SmallHandleFilled.png-b05ea1c4c699eec1a35a0d4e5f216398.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
|
BIN
textures/VirtualJoystickPack/SmallHandleFilledGrey.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dstq5nmmahvtb"
|
||||||
|
path="res://.godot/imported/SmallHandleFilledGrey.png-8d4b91d411c1dfd052d5445245fb00a8.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://textures/VirtualJoystickPack/SmallHandleFilledGrey.png"
|
||||||
|
dest_files=["res://.godot/imported/SmallHandleFilledGrey.png-8d4b91d411c1dfd052d5445245fb00a8.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
|