Work on the new controls.

This commit is contained in:
Relintai 2020-07-15 00:41:25 +02:00
parent 729fc06bc3
commit 1e14874db8
12 changed files with 101 additions and 420 deletions

View File

@ -3,7 +3,7 @@
[ext_resource path="res://characters/SimpleCharacter.tscn" type="PackedScene" id=1]
[ext_resource path="res://player/Body.gd" type="Script" id=6]
[sub_resource type="CircleShape2D" id=4]
[sub_resource type="CircleShape2D" id=1]
radius = 8.0
[node name="Body" type="KinematicBody2D"]
@ -12,4 +12,6 @@ script = ExtResource( 6 )
[node name="Character" parent="." instance=ExtResource( 1 )]
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 4 )
shape = SubResource( 1 )
[node name="Ray" type="RayCast2D" parent="."]

View File

@ -23,55 +23,24 @@
extends KinematicBody2D
export(float) var MOUSE_SENSITIVITY : float = 0.05
export(String) var world_path : String = "../.."
export(NodePath) var model_path : NodePath = "Rotation_Helper/Model"
export(NodePath) var character_skeleton_path : NodePath = "Character"
const BASE_SPEED = 60.0
const ray_length = 1000
const ACCEL : float = 100.0
const DEACCEL : float = 100.0
const MOUSE_TARGET_MAX_OFFSET : int = 10
var _on : bool = true
var input_direction : Vector2
var y_rot : float = 0.0
var vel : Vector2 = Vector2()
var dir : Vector2 = Vector2()
var input_dir : Vector2 = Vector2()
var mouse_dir : Vector2 = Vector2()
var mouse_move_dir : Vector2 = Vector2()
var mouse_left_down : bool = false
var mouse_right_down : bool = false
var touchpad_dir : Vector2 = Vector2()
var mouse_down_delta : Vector2 = Vector2()
var key_left : bool = false
var key_right : bool = false
var key_up : bool = false
var key_down : bool = false
var cursor_grabbed : bool = false
var last_cursor_pos : Vector2 = Vector2()
var mouse_down_pos : Vector2 = Vector2()
var total_down_mouse_delta : Vector2 = Vector2()
var target_movement_direction : Vector2 = Vector2()
var target_position : Vector2
var path : PoolVector2Array
var current_movement_target : Vector2
var camera : Camera2D
var animation_run : bool = false
var moving : bool = false
var casting_anim : bool = false
var last_mouse_over : Entity = null
var world : Node = null
var world : Navigation2D = null
var _controlled : bool = false
@ -85,7 +54,10 @@ var character_skeleton : CharacterSkeleton2D
var visibility_update_timer : float = randi()
var ray : RayCast2D
func _enter_tree() -> void:
ray = $Ray
world = get_node(world_path) as Node
camera = get_node_or_null("Camera") as Camera2D
@ -102,6 +74,9 @@ func _enter_tree() -> void:
transform = entity.get_transform_2d(true)
set_physics_process(true)
set_process_input(false)
set_process_unhandled_input(false)
func _process(delta : float) -> void:
if entity.ai_state == EntityEnums.AI_STATE_OFF:
@ -130,12 +105,6 @@ func _process(delta : float) -> void:
func _physics_process(delta : float) -> void:
if not _on:
return
if world.initial_generation:
return
if entity.sentity_data == null:
return
@ -143,8 +112,7 @@ func _physics_process(delta : float) -> void:
return
if entity.c_is_controlled:
process_input(delta)
process_movement_player(delta)
process_movement(delta)
else:
if sleep:
sleep_recheck_timer += delta
@ -158,198 +126,94 @@ func _physics_process(delta : float) -> void:
# if not world.is_position_walkable(transform.origin):
# return
process_movement_mob(delta)
func process_input(delta: float) -> void:
var key_dir : Vector2 = Vector2()
if key_up:
key_dir.y -= 1
if key_down:
key_dir.y += 1
if key_left:
key_dir.x -= 1
if key_right:
key_dir.x += 1
input_dir = key_dir + mouse_dir + touchpad_dir + mouse_move_dir
var state : int = entity.getc_state()
if state & EntityEnums.ENTITY_STATE_TYPE_FLAG_ROOT != 0 or state & EntityEnums.ENTITY_STATE_TYPE_FLAG_STUN != 0:
input_dir = Vector2()
return
var input_length : float = input_dir.length_squared()
if input_length > 0.1:
#handle_graphic_facing(abs(dir.dot(Vector2(0, 1))) > 0.9)
character_skeleton.update_facing(input_dir)
# character_skeleton.get_animation_tree().set("parameters/walking/blend_amount", input_dir.length())
process_movement(delta)
func process_movement(delta : float) -> void:
var state : int = entity.getc_state()
if state & EntityEnums.ENTITY_STATE_TYPE_FLAG_ROOT != 0 or state & EntityEnums.ENTITY_STATE_TYPE_FLAG_STUN != 0:
moving = false
return
if (input_dir.length_squared() > 0.1):
moving = true
# entity.moved()
else:
moving = false
var hvel = vel
#
# if (input_dir.length_squared() > 0.1):
# moving = true
## entity.moved()
# else:
# moving = false
#
# var hvel = vel
#
# var target = dir
# target *= entity.get_speed().ccurrent
#
# var accel
# if dir.dot(hvel) > 0:
# accel = ACCEL
# else:
# accel = DEACCEL
#
# hvel = hvel.linear_interpolate(target, accel*delta)
# vel = hvel
# vel = move_and_slide(vel)
var target = dir
target *= entity.get_speed().ccurrent
var accel
if dir.dot(hvel) > 0:
accel = ACCEL
else:
accel = DEACCEL
hvel = hvel.linear_interpolate(target, accel*delta)
vel = hvel
vel = move_and_slide(vel)
if multiplayer.has_network_peer():
if not multiplayer.is_network_server():
rpc_id(1, "sset_position", position)
else:
sset_position(position)
func process_movement_player(delta : float) -> void:
var state : int = entity.getc_state()
if state & EntityEnums.ENTITY_STATE_TYPE_FLAG_ROOT != 0 or state & EntityEnums.ENTITY_STATE_TYPE_FLAG_STUN != 0:
moving = false
return
if (input_dir.length_squared() > 0.1):
moving = true
# moved()
else:
moving = false
var hvel = vel
var target = input_dir.normalized()
# target *= 100
target *= entity.getc_speed().current_value / 100.0 * BASE_SPEED
var accel
if dir.dot(hvel) > 0:
accel = ACCEL
else:
accel = DEACCEL
hvel = hvel.linear_interpolate(target, accel*delta)
vel = hvel
vel = move_and_slide(vel)
if multiplayer.has_network_peer():
if not multiplayer.is_network_server():
rpc_id(1, "sset_position", position)
else:
sset_position(position)
func process_movement_mob(delta : float) -> void:
var state : int = entity.getc_state()
if state & EntityEnums.ENTITY_STATE_TYPE_FLAG_ROOT != 0 or state & EntityEnums.ENTITY_STATE_TYPE_FLAG_STUN != 0:
moving = false
return
if (target_movement_direction.length_squared() > 0.1):
moving = true
# moved()
else:
moving = false
if not moving and sleep:
return
if moving and sleep:
sleep = false
var hvel = vel
var target = dir.normalized()
target *= entity.getc_speed().current_value / 100.0 * BASE_SPEED
var accel
if dir.dot(hvel) > 0:
accel = ACCEL
else:
accel = DEACCEL
hvel = hvel.linear_interpolate(target, accel*delta)
vel = hvel
vel = move_and_slide(vel)
sset_position(position)
if vel.length_squared() < 0.12:
sleep = true
func _input(event: InputEvent) -> void:
if not cursor_grabbed:
set_process_input(false)
return
if event is InputEventMouseMotion and event.device != -1:
var s : float = ProjectSettings.get("display/mouse_cursor/sensitivity")
var relx : float = event.relative.x * s
var rely : float = event.relative.y * s
mouse_down_delta.x += relx
mouse_down_delta.y += rely
total_down_mouse_delta.x += relx
total_down_mouse_delta.y += rely
get_tree().set_input_as_handled()
# if input_length > 0.1:
# #handle_graphic_facing(abs(dir.dot(Vector2(0, 1))) > 0.9)
# character_skeleton.update_facing(input_dir)
#
# character_skeleton.get_animation_tree().set("parameters/walking/blend_amount", input_dir.length())
#
# if multiplayer.has_network_peer():
# if not multiplayer.is_network_server():
# rpc_id(1, "sset_position", position)
# else:
# sset_position(position)
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventKey:
var ievkey : InputEventKey = event as InputEventKey
if ievkey.scancode == KEY_W:
key_up = ievkey.pressed
if ievkey.scancode == KEY_S:
key_down = ievkey.pressed
if ievkey.scancode == KEY_A:
key_left = ievkey.pressed
if ievkey.scancode == KEY_D:
key_right = ievkey.pressed
if ievkey.echo:
return
if event is InputEventMouseMotion and not (mouse_right_down or mouse_left_down) and event.device != -1:
var val : int = 1
if not event.pressed:
val = -1
if ievkey.scancode == KEY_W:
input_direction.y -= val
if ievkey.scancode == KEY_S:
input_direction.y += val
if ievkey.scancode == KEY_A:
input_direction.x -= val
if ievkey.scancode == KEY_D:
input_direction.x += val
if event is InputEventMouseMotion and event.device != -1:
cmouseover(event)
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.device != -1:
mouse_left_down = event.pressed
if event.button_index == BUTTON_WHEEL_DOWN and event.device != -1:
if camera == null:
return
if mouse_left_down:
mouse_dir = (event.position - get_viewport_rect().size / 2).normalized()
if camera.zoom.x >= 1:
return
else:
mouse_dir = Vector2()
camera.zoom += Vector2(event.factor, event.factor) * 0.01
elif event.button_index == BUTTON_WHEEL_UP and event.device != -1:
if camera == null:
return
if camera.zoom.x <= 0.2:
return
else:
camera.zoom -= Vector2(event.factor, event.factor) * 0.01
elif event.button_index == BUTTON_LEFT and event.device != -1:
if event.pressed:
target(event.position)
# if event.is_pressed() and event.device != -1:
# if event.button_index == BUTTON_WHEEL_UP:
# camera_pivot.camera_distance_set_delta(-0.2)
# if event.button_index == BUTTON_WHEEL_DOWN:
# camera_pivot.camera_distance_set_delta(0.2)
# if not event.pressed and event.button_index == BUTTON_LEFT and event.device != -1:
# if mouse_down_delta.length() < MOUSE_TARGET_MAX_OFFSET:
# target(event.position)
@ -361,33 +225,9 @@ func _unhandled_input(event: InputEvent) -> void:
if event is InputEventScreenTouch and event.pressed:
target(event.position)
if event is InputEventMouseMotion and mouse_left_down and event.device != -1:
mouse_dir = (event.position - get_viewport_rect().size / 2).normalized()
#update_cursor_mode()
func update_cursor_mode():
if mouse_left_down or mouse_right_down:
if not cursor_grabbed:
set_process_input(true)
total_down_mouse_delta = Vector2()
cursor_grabbed = true
last_cursor_pos = get_viewport().get_mouse_position()
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
else:
if cursor_grabbed:
set_process_input(false)
cursor_grabbed = false
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
get_viewport().warp_mouse(last_cursor_pos)
if total_down_mouse_delta.length_squared() < 8:
target(last_cursor_pos)
func target(position : Vector2):
func target(position : Vector2) -> bool:
var space_state = get_world_2d().direct_space_state
var results = space_state.intersect_point(world.make_canvas_position_local(position), 32, [], get_collision_layer())
#var results = space_state.intersect_point(position, 32, [], 2)
@ -396,11 +236,13 @@ func target(position : Vector2):
for result in results:
if result.collider and result.collider.owner is Entity:
entity.target_crequest_change((result.collider.owner as Node).get_path())
return
return true
entity.target_crequest_change(NodePath())
else:
entity.target_crequest_change(NodePath())
return false
func cmouseover(event):
var space_state = get_world_2d().direct_space_state
@ -429,44 +271,6 @@ func cmouseover(event):
last_mouse_over = null
func analog_force_change(vector, touchpad):
if touchpad.padname == "TouchPad":
touchpad_dir = vector
touchpad_dir.y *= -1
elif touchpad.padname == "TargetPad":
#try to target
return
#
#func on_notification_ccast(what : int, info : SpellCastInfo) -> void:
# if what == SpellEnums.NOTIFICATION_CAST_STARTED:
# if anim_node_state_machine != null and not casting_anim:
# anim_node_state_machine.travel("casting-loop")
# casting_anim = true
# animation_run = false
# elif what == SpellEnums.NOTIFICATION_CAST_FAILED:
# if anim_node_state_machine != null and casting_anim:
# anim_node_state_machine.travel("idle-loop")
# casting_anim = false
#
# if animation_run:
# anim_node_state_machine.travel("run-loop")
# elif what == SpellEnums.NOTIFICATION_CAST_FINISHED:
# if anim_node_state_machine != null:
# anim_node_state_machine.travel("cast-end")
# casting_anim = false
#
# if animation_run:
# anim_node_state_machine.travel("run-loop")
# elif what == SpellEnums.NOTIFICATION_CAST_SUCCESS:
# if anim_node_state_machine != null:
# anim_node_state_machine.travel("cast-end")
# casting_anim = false
#
# if animation_run:
# anim_node_state_machine.travel("run-loop")
func on_c_controlled_changed(val):
#create camera and pivot if true
_controlled = val

View File

@ -30,6 +30,7 @@ loading_screen_path = NodePath("LoadingScreen/PanelContainer")
worlds = [ ExtResource( 7 ), ExtResource( 10 ), ExtResource( 12 ), ExtResource( 9 ), ExtResource( 13 ), ExtResource( 8 ), ExtResource( 11 ) ]
world_scales = [ Vector2( 0.5, 0.5 ), Vector2( 0.8, 0.8 ), Vector2( 0.8, 0.8 ), Vector2( 0.8, 0.8 ), Vector2( 0.5, 0.5 ), Vector2( 0.4, 0.4 ), Vector2( 0.3, 0.3 ) ]
bodies = [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ) ]
tile_sizes = [ 16, 32, 32, 32, 8, 8, 8 ]
[node name="LoadingScreen" type="CanvasLayer" parent="."]
layer = 100

View File

@ -30,6 +30,7 @@ export(int) var curent_style : int = 0
export(Array, PackedScene) var worlds : Array
export(Array, Vector2) var world_scales : Array
export(Array, PackedScene) var bodies : Array
export(Array, int) var tile_sizes : Array
enum StartSceneTypes {
NONE, MENU, WORLD
@ -191,3 +192,6 @@ func get_world_scale():
func get_body():
return bodies[curent_style]
func get_tile_size():
return tile_sizes[curent_style]

View File

@ -4,7 +4,7 @@
[ext_resource path="res://world/WorldLayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://tilesets/16x16_orthogonal/new_tileset.tres" type="TileSet" id=3]
[node name="World" type="Node2D" groups=[
[node name="World" type="Navigation2D" groups=[
"save",
]]
script = ExtResource( 1 )

View File

@ -4,7 +4,7 @@
[ext_resource path="res://world/WorldLayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://tilesets/dc_32x32/tileset.tres" type="TileSet" id=3]
[node name="World" type="Node2D" groups=[
[node name="World" type="Navigation2D" groups=[
"save",
]]
script = ExtResource( 1 )

View File

@ -4,7 +4,7 @@
[ext_resource path="res://world/WorldLayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://tilesets/denzi_32x32_orthogonal/new_tileset.tres" type="TileSet" id=3]
[node name="World" type="Node2D" groups=[
[node name="World" type="Navigation2D" groups=[
"save",
]]
script = ExtResource( 1 )

View File

@ -4,7 +4,7 @@
[ext_resource path="res://world/WorldLayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://tilesets/denzi_public_domain/new_tileset.tres" type="TileSet" id=3]
[node name="World" type="Node2D" groups=[
[node name="World" type="Navigation2D" groups=[
"save",
]]
script = ExtResource( 1 )

View File

@ -4,7 +4,7 @@
[ext_resource path="res://world/WorldLayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://tilesets/rogue_db32/tileset.tres" type="TileSet" id=3]
[node name="World" type="Node2D" groups=[
[node name="World" type="Navigation2D" groups=[
"save",
]]
script = ExtResource( 1 )

View File

@ -4,7 +4,7 @@
[ext_resource path="res://world/WorldLayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://tilesets/rogue_dungeon/tileset.tres" type="TileSet" id=3]
[node name="World" type="Node2D" groups=[
[node name="World" type="Navigation2D" groups=[
"save",
]]
script = ExtResource( 1 )

View File

@ -4,7 +4,7 @@
[ext_resource path="res://world/WorldLayer.tscn" type="PackedScene" id=2]
[ext_resource path="res://tilesets/rogue_lite/tileset.tres" type="TileSet" id=3]
[node name="World" type="Node2D" groups=[
[node name="World" type="Navigation2D" groups=[
"save",
]]
script = ExtResource( 1 )

View File

@ -1,17 +1,15 @@
[gd_scene load_steps=27 format=2]
[gd_scene load_steps=25 format=2]
[ext_resource path="res://player/GUI.gd" type="Script" id=1]
[ext_resource path="res://ui/ingame_menu/IngameMenu.tscn" type="PackedScene" id=2]
[ext_resource path="res://player/Unitframes.gd" type="Script" id=3]
[ext_resource path="res://ui/errorframe/ErrorFrame.tscn" type="PackedScene" id=4]
[ext_resource path="res://ui/auraframe/AuraFrame.tscn" type="PackedScene" id=5]
[ext_resource path="res://ui/touch_pad/TurnPanel.gd" type="Script" id=7]
[ext_resource path="res://ui/actionbars/Actionbars.gd" type="Script" id=8]
[ext_resource path="res://ui/buttons/Buttons.gd" type="Script" id=9]
[ext_resource path="res://ui/theme/ui_theme.tres" type="Theme" id=10]
[ext_resource path="res://ui/windows/TalentWindow.tscn" type="PackedScene" id=11]
[ext_resource path="res://ui/unitframes/TargetUnitframe.tscn" type="PackedScene" id=12]
[ext_resource path="res://ui/touch_pad/analog.tscn" type="PackedScene" id=13]
[ext_resource path="res://ui/actionbars/ActionBar.tscn" type="PackedScene" id=14]
[ext_resource path="res://ui/bags/Bag.tscn" type="PackedScene" id=15]
[ext_resource path="res://ui/castbar/Castbar.tscn" type="PackedScene" id=16]
@ -42,134 +40,6 @@ __meta__ = {
}
child_controls = [ NodePath("Unitframes"), NodePath("Actionbars"), NodePath("Windows/SpellBookWindow"), NodePath("Buttons"), NodePath("Castbar"), NodePath("AuraFrame"), NodePath("Windows/Inventory"), NodePath("Windows/LootWindow"), NodePath("Windows/TalentWindow"), NodePath("Windows/CraftingWindow") ]
[node name="TouchTargetControls" type="MarginContainer" parent="GUI"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
custom_constants/margin_right = 272
custom_constants/margin_top = 481
custom_constants/margin_left = 60
custom_constants/margin_bottom = 41
__meta__ = {
"_edit_group_": true
}
[node name="HBoxContainer" type="HBoxContainer" parent="GUI/TouchTargetControls"]
margin_left = 60.0
margin_top = 481.0
margin_right = 752.0
margin_bottom = 559.0
mouse_filter = 2
size_flags_horizontal = 7
size_flags_vertical = 7
[node name="Control" type="Control" parent="GUI/TouchTargetControls/HBoxContainer"]
margin_right = 603.0
margin_bottom = 78.0
mouse_filter = 2
size_flags_horizontal = 15
size_flags_vertical = 15
size_flags_stretch_ratio = 12.0
[node name="TargetPad" type="Control" parent="GUI/TouchTargetControls/HBoxContainer"]
margin_left = 611.0
margin_right = 692.0
margin_bottom = 78.0
mouse_filter = 2
size_flags_horizontal = 15
size_flags_vertical = 15
size_flags_stretch_ratio = 1.6
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Analog" parent="GUI/TouchTargetControls/HBoxContainer/TargetPad" instance=ExtResource( 13 )]
position = Vector2( 40, 30 )
padname = "TargetPad"
[node name="TouchMovementControls" type="MarginContainer" parent="GUI"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
custom_constants/margin_top = 200
__meta__ = {
"_edit_group_": true,
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="GUI/TouchMovementControls"]
margin_top = 200.0
margin_right = 1024.0
margin_bottom = 600.0
mouse_filter = 2
size_flags_horizontal = 7
size_flags_vertical = 7
[node name="VBoxContainer" type="VBoxContainer" parent="GUI/TouchMovementControls/HBoxContainer"]
margin_right = 323.0
margin_bottom = 400.0
mouse_filter = 2
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 1.4
[node name="Control" type="Control" parent="GUI/TouchMovementControls/HBoxContainer/VBoxContainer"]
margin_right = 323.0
margin_bottom = 196.0
mouse_filter = 2
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="TouchPad" type="Control" parent="GUI/TouchMovementControls/HBoxContainer/VBoxContainer"]
margin_top = 204.0
margin_right = 323.0
margin_bottom = 400.0
mouse_filter = 2
size_flags_horizontal = 15
size_flags_vertical = 15
[node name="Analog" parent="GUI/TouchMovementControls/HBoxContainer/VBoxContainer/TouchPad" instance=ExtResource( 13 )]
position = Vector2( 107.368, 94.2101 )
padname = "TouchPad"
[node name="Control" type="Control" parent="GUI/TouchMovementControls/HBoxContainer"]
margin_left = 327.0
margin_right = 557.0
margin_bottom = 400.0
mouse_filter = 2
size_flags_horizontal = 15
size_flags_vertical = 15
[node name="VBoxContainer2" type="VBoxContainer" parent="GUI/TouchMovementControls/HBoxContainer"]
margin_left = 561.0
margin_right = 1024.0
margin_bottom = 400.0
mouse_filter = 2
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 2.0
[node name="Control" type="Control" parent="GUI/TouchMovementControls/HBoxContainer/VBoxContainer2"]
margin_right = 463.0
margin_bottom = 150.0
mouse_filter = 2
size_flags_vertical = 3
[node name="TurnPanel" type="Control" parent="GUI/TouchMovementControls/HBoxContainer/VBoxContainer2"]
margin_top = 158.0
margin_right = 463.0
margin_bottom = 400.0
mouse_filter = 2
size_flags_horizontal = 15
size_flags_vertical = 15
size_flags_stretch_ratio = 1.6
[node name="Node2D" type="Node2D" parent="GUI/TouchMovementControls/HBoxContainer/VBoxContainer2/TurnPanel"]
position = Vector2( -600, -200 )
script = ExtResource( 7 )
listenerNodePath = "../../../../../../.."
[node name="Buttons" type="Control" parent="GUI"]
anchor_left = 0.5
anchor_top = 1.0