1
0
Fork 0

add delivery command

This commit is contained in:
Michaël Lemaire 2022-10-21 01:16:48 +02:00
parent 93dc2d1ef5
commit 3840c135a7
14 changed files with 223 additions and 20 deletions

View File

@ -1,4 +1,5 @@
extends Node2D
extends CanvasLayer
class_name BattleField
var _ticker1 := 0.0
@ -10,3 +11,6 @@ func _physics_process(delta):
func ticker(group_name: String):
get_tree().call_group_flags(SceneTree.GROUP_CALL_DEFERRED, group_name, "tick")
func _on_commands_changed(commander, commands):
get_tree().call_group("unit", "_on_commands_changed", commander, commands)

View File

@ -2,5 +2,6 @@
[ext_resource type="Script" path="res://core/battlefield.gd" id="1_u7icn"]
[node name="battlefield" type="Node2D"]
[node name="battlefield" type="CanvasLayer"]
follow_viewport_enabled = true
script = ExtResource("1_u7icn")

View File

@ -6,3 +6,4 @@
script = ExtResource("1_1h78t")
[node name="delivery" type="Marker2D" parent="."]
position = Vector2(100, 0)

32
core/ui/command.gd Normal file
View File

@ -0,0 +1,32 @@
@tool
extends Composer
class_name Command
signal clicked
@export var icon: Texture2D:
set(val):
if val is Texture2D:
icon = val
else:
icon = PlaceholderTexture2D.new()
_check_compose()
@export var code: String
func _compose():
$badge/icon.texture = icon
super._compose()
func _on_click_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
get_viewport().set_input_as_handled()
clicked.emit()
func apply(container: Node2D, pos: Vector2):
if get_parent() != container:
if get_parent():
get_parent().remove_child(self)
container.add_child(self)
position = pos

35
core/ui/command.tscn Normal file
View File

@ -0,0 +1,35 @@
[gd_scene load_steps=5 format=3 uid="uid://b3l4jfjieucrc"]
[ext_resource type="Script" path="res://core/ui/command.gd" id="1_bwbsk"]
[sub_resource type="Gradient" id="Gradient_i2fje"]
offsets = PackedFloat32Array(0, 0.845528, 1)
colors = PackedColorArray(0.631696, 0, 0.0105082, 1, 0.604306, 0, 0.0100526, 0.95664, 0, 0, 0, 0)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_3dnb6"]
gradient = SubResource("Gradient_i2fje")
width = 160
height = 160
fill = 1
fill_from = Vector2(0.5, 0.5)
fill_to = Vector2(0.5, 0)
[sub_resource type="CircleShape2D" id="CircleShape2D_7etna"]
radius = 80.0
[node name="command" type="Node2D"]
script = ExtResource("1_bwbsk")
[node name="badge" type="Sprite2D" parent="."]
texture = SubResource("GradientTexture2D_3dnb6")
[node name="icon" type="Sprite2D" parent="badge"]
[node name="click" type="Area2D" parent="."]
monitoring = false
monitorable = false
[node name="area" type="CollisionShape2D" parent="click"]
shape = SubResource("CircleShape2D_7etna")
[connection signal="input_event" from="click" to="." method="_on_click_input_event"]

49
core/ui/commands.gd Normal file
View File

@ -0,0 +1,49 @@
extends CanvasLayer
@export var player: Node:
set(val):
if val is Player:
player = val
else:
player = null
@export var available_commands: Array[PackedScene]
signal commands_changed(commander, commands)
func _ready():
$stock.visible = false
$wheel.visible = false
if available_commands:
for command_scene in available_commands:
var command := command_scene.instantiate()
$stock.add_child(command)
func _unhandled_input(event: InputEvent):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
get_viewport().set_input_as_handled()
_show_command_wheel(event.position)
func _show_command_wheel(pos: Vector2):
var wheel := $wheel as Node2D
wheel.position = pos
# TODO center cam ?
for command in $wheel.get_children():
command.queue_free()
for command in $stock.get_children():
# TODO only available
command = command.duplicate()
command.connect("clicked", _on_wheel_command_clicked.bind(command))
$wheel.add_child(command)
wheel.visible = true
func _on_wheel_command_clicked(command: Command):
command.apply($active, $wheel.position)
$wheel.visible = false
commands_changed.emit(player, $active.get_children())

15
core/ui/commands.tscn Normal file
View File

@ -0,0 +1,15 @@
[gd_scene load_steps=2 format=3 uid="uid://xoup4vukp3ni"]
[ext_resource type="Script" path="res://core/ui/commands.gd" id="1_8b4dn"]
[node name="commands" type="CanvasLayer"]
layer = 2
follow_viewport_enabled = true
script = ExtResource("1_8b4dn")
[node name="wheel" type="Node2D" parent="."]
[node name="stock" type="Node2D" parent="."]
visible = false
[node name="active" type="Node2D" parent="."]

View File

@ -1,8 +1,10 @@
[gd_scene load_steps=7 format=3 uid="uid://c6omib6txy3qh"]
[gd_scene load_steps=8 format=3 uid="uid://c6omib6txy3qh"]
[ext_resource type="PackedScene" uid="uid://brbtq46uk18gg" path="res://core/battlefield.tscn" id="1_x63ik"]
[ext_resource type="PackedScene" uid="uid://dqaabctftkakr" path="res://core/player.tscn" id="2_o4smw"]
[ext_resource type="PackedScene" uid="uid://b8uik6q4v35o3" path="res://tac/units/factory.tscn" id="2_wnc50"]
[ext_resource type="PackedScene" uid="uid://xoup4vukp3ni" path="res://core/ui/commands.tscn" id="4_1gkbi"]
[ext_resource type="PackedScene" uid="uid://dr1e0h27nuam" path="res://tac/commands/delivery.tscn" id="5_fi2mi"]
[sub_resource type="GDScript" id="GDScript_8ehhf"]
script/source = "extends Camera2D
@ -25,24 +27,18 @@ script/source = "extends Control
signal scrolled(diff)
signal zoomed(diff)
func _gui_input(event):
func _unhandled_input(event):
if event is InputEventMouseMotion:
if event.button_mask & MOUSE_BUTTON_LEFT:
scrolled.emit(event.relative)
accept_event()
if event is InputEventMouseButton and event.pressed:
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
zoomed.emit(signf(event.factor))
accept_event()
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
zoomed.emit(-signf(event.factor))
"
[sub_resource type="GDScript" id="GDScript_0x6ru"]
script/source = "extends Control
func _gui_input(event):
if event is InputEventMouseButton:
if event.button_mask & MOUSE_BUTTON_LEFT:
pass
accept_event()
"
[node name="main" type="Node2D"]
@ -50,7 +46,6 @@ func _gui_input(event):
[node name="camera" type="Camera2D" parent="."]
position = Vector2(640, 360)
current = true
smoothing_enabled = true
script = SubResource("GDScript_8ehhf")
[node name="battlefield" parent="." instance=ExtResource("1_x63ik")]
@ -71,7 +66,12 @@ player = NodePath("../player1")
position = Vector2(929, 429)
player = NodePath("../player2")
[node name="commands" parent="." node_paths=PackedStringArray("player") instance=ExtResource("4_1gkbi")]
player = NodePath("../battlefield/player1")
available_commands = [ExtResource("5_fi2mi")]
[node name="ui" type="CanvasLayer" parent="."]
layer = 3
[node name="camcontrol" type="Control" parent="ui"]
layout_mode = 3
@ -82,13 +82,10 @@ grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2
mouse_force_pass_scroll_events = false
script = SubResource("GDScript_0auct")
[node name="orders" type="Control" parent="ui"]
layout_mode = 3
anchors_preset = 0
script = SubResource("GDScript_0x6ru")
[connection signal="commands_changed" from="commands" to="battlefield" method="_on_commands_changed"]
[connection signal="scrolled" from="ui/camcontrol" to="camera" method="scroll"]
[connection signal="zoomed" from="ui/camcontrol" to="camera" method="change_zoom"]

View File

@ -9,6 +9,16 @@
config_version=5
_global_script_classes=[{
"base": "CanvasLayer",
"class": &"BattleField",
"language": &"GDScript",
"path": "res://core/battlefield.gd"
}, {
"base": "Composer",
"class": &"Command",
"language": &"GDScript",
"path": "res://core/ui/command.gd"
}, {
"base": "Node2D",
"class": &"Composer",
"language": &"GDScript",
@ -35,6 +45,8 @@ _global_script_classes=[{
"path": "res://core/weapon.gd"
}]
_global_script_class_icons={
"BattleField": "",
"Command": "",
"Composer": "",
"Player": "",
"Spawner": "",

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://6yj7ng334117"
path="res://.godot/imported/delivery.png-236d717b15cf923339c60cb0dbc4593c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://tac/assets/commands/delivery.png"
dest_files=["res://.godot/imported/delivery.png-236d717b15cf923339c60cb0dbc4593c.ctex"]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
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

View File

@ -0,0 +1,11 @@
[gd_scene load_steps=3 format=3 uid="uid://dr1e0h27nuam"]
[ext_resource type="PackedScene" uid="uid://b3l4jfjieucrc" path="res://core/ui/command.tscn" id="1_s822j"]
[ext_resource type="Texture2D" uid="uid://6yj7ng334117" path="res://tac/assets/commands/delivery.png" id="2_6sktn"]
[node name="command_delivery" instance=ExtResource("1_s822j")]
icon = ExtResource("2_6sktn")
code = "delivery"
[node name="icon" parent="badge" index="0"]
texture = ExtResource("2_6sktn")

View File

@ -10,3 +10,16 @@ func _compose():
$spawner.unit_type = produced_unit
$spawner.player = player
super._compose()
func _on_commands_changed(commander, commands):
if commander == player:
var nearest := Vector2(INF, INF)
var distance := INF
for command in commands:
if command.code == "delivery":
var d := position.distance_to(command.position)
if d < distance:
distance = d
nearest = command.position
if distance != INF:
$spawner.delivery = nearest

View File

@ -11,7 +11,6 @@ script = ExtResource("2_r2sw4")
produced_unit = ExtResource("3_u6npr")
sprite = ExtResource("2_43eyp")
hitpoints = 150
rotation_offset = null
[node name="spawner" parent="." index="0" instance=ExtResource("2_ulexw")]
unit_type = ExtResource("3_u6npr")