Add area management

This commit is contained in:
Hamcha 2020-07-20 11:15:39 +02:00
parent f53cf355bc
commit 187a46eabd
Signed by: hamcha
GPG key ID: 41467804B19A3315
30 changed files with 653 additions and 70 deletions

View file

@ -70,6 +70,8 @@ func manage_controls(show: bool):
match computer_type: match computer_type:
ComputerType.ShipCommand: ComputerType.ShipCommand:
$Control/ControlComp.visible = show $Control/ControlComp.visible = show
ComputerType.Energy:
$Control/EnergyComp.visible = show
func _input(event): func _input(event):
if event is InputEventMouseButton and event.pressed and not is_inside and open: if event is InputEventMouseButton and event.pressed and not is_inside and open:

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=2] [gd_scene load_steps=16 format=2]
[ext_resource path="res://Graphics/tgstation/computer-screens.png" type="Texture" id=1] [ext_resource path="res://Graphics/tgstation/computer-screens.png" type="Texture" id=1]
[ext_resource path="res://Graphics/tgstation/computer.png" type="Texture" id=2] [ext_resource path="res://Graphics/tgstation/computer.png" type="Texture" id=2]
@ -7,6 +7,7 @@
[ext_resource path="res://Graphics/light_shadow_light.png" type="Texture" id=5] [ext_resource path="res://Graphics/light_shadow_light.png" type="Texture" id=5]
[ext_resource path="res://Actors/Components/ActivationRange.gd" type="Script" id=6] [ext_resource path="res://Actors/Components/ActivationRange.gd" type="Script" id=6]
[ext_resource path="res://Actors/Components/PowerManager.gd" type="Script" id=7] [ext_resource path="res://Actors/Components/PowerManager.gd" type="Script" id=7]
[ext_resource path="res://Actors/Objects/Computer/UI/EnergyComp.tscn" type="PackedScene" id=8]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 16, 16 ) extents = Vector2( 16, 16 )
@ -164,8 +165,6 @@ anims/fadein = SubResource( 5 )
anims/fadeout = SubResource( 6 ) anims/fadeout = SubResource( 6 )
[node name="Control" type="Node2D" parent="."] [node name="Control" type="Node2D" parent="."]
modulate = Color( 1, 1, 1, 0 )
position = Vector2( 0, 10 )
z_index = 999 z_index = 999
[node name="ControlComp" parent="Control" instance=ExtResource( 4 )] [node name="ControlComp" parent="Control" instance=ExtResource( 4 )]
@ -176,6 +175,14 @@ margin_right = 208.0
margin_bottom = 66.0 margin_bottom = 66.0
rect_scale = Vector2( 0.5, 0.5 ) rect_scale = Vector2( 0.5, 0.5 )
[node name="EnergyComp" parent="Control" instance=ExtResource( 8 )]
visible = false
margin_left = -47.0
margin_top = -53.0
margin_right = 207.0
margin_bottom = 36.0
rect_scale = Vector2( 0.5, 0.5 )
[node name="ActivationRange" type="Area2D" parent="."] [node name="ActivationRange" type="Area2D" parent="."]
visible = false visible = false
script = ExtResource( 6 ) script = ExtResource( 6 )

View file

@ -3,6 +3,8 @@ extends Control
onready var scene = $"/root/scene" as GameInstance onready var scene = $"/root/scene" as GameInstance
func _physics_process(_delta): func _physics_process(_delta):
if not visible:
return
var speed_str = str(round(scene.world.map.current_ship_speed * 10000)) + " u/s" var speed_str = str(round(scene.world.map.current_ship_speed * 10000)) + " u/s"
$Margin/Container/VelocityBox/HBoxContainer3/CurrentSpeed.text = speed_str $Margin/Container/VelocityBox/HBoxContainer3/CurrentSpeed.text = speed_str
var dir_str = str(round(rad2deg(scene.world.map.current_ship_direction))) + " deg" var dir_str = str(round(rad2deg(scene.world.map.current_ship_direction))) + " deg"
@ -15,14 +17,8 @@ func _physics_process(_delta):
else: else:
$Margin/Container/VelocityBox/HBoxContainer/CurrentTarget.text = Coordinates.as_string(current_target_str, true) $Margin/Container/VelocityBox/HBoxContainer/CurrentTarget.text = Coordinates.as_string(current_target_str, true)
func _ship_velocity_changed(value):
scene.rpc("process_command", UICommand.new(UICommand.CommandType.SetShipSpeed, [value]))
func _ship_direction_changed(value):
scene.rpc("process_command", UICommand.new(UICommand.CommandType.SetShipDirection, [deg2rad(value)]))
func _map_button_pressed(): func _map_button_pressed():
scene.ui.open_map_popup() scene.ui.open_popup(GameUI.PopupName.SpaceMap)
func force_close(): func force_close():
scene.ui.close_map_popup() scene.ui.close_popup(GameUI.PopupName.SpaceMap)

View file

@ -8,7 +8,7 @@
[node name="ControlComp" type="Control"] [node name="ControlComp" type="Control"]
material = ExtResource( 4 ) material = ExtResource( 4 )
margin_left = -157.0 margin_left = -157.0
margin_top = -150.0 margin_top = -160.0
margin_right = 156.0 margin_right = 156.0
margin_bottom = -20.0 margin_bottom = -20.0
grow_horizontal = 2 grow_horizontal = 2
@ -68,11 +68,12 @@ __meta__ = {
[node name="Container" type="VBoxContainer" parent="Margin"] [node name="Container" type="VBoxContainer" parent="Margin"]
material = ExtResource( 4 ) material = ExtResource( 4 )
margin_right = 293.0 margin_right = 293.0
margin_bottom = 112.0 margin_bottom = 120.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
custom_constants/separation = 10
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
@ -80,7 +81,7 @@ __meta__ = {
[node name="VelocityBox" type="VBoxContainer" parent="Margin/Container"] [node name="VelocityBox" type="VBoxContainer" parent="Margin/Container"]
material = ExtResource( 4 ) material = ExtResource( 4 )
margin_right = 293.0 margin_right = 293.0
margin_bottom = 84.0 margin_bottom = 86.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
alignment = 1 alignment = 1
@ -89,8 +90,9 @@ __meta__ = {
} }
[node name="HBoxContainer" type="HBoxContainer" parent="Margin/Container/VelocityBox"] [node name="HBoxContainer" type="HBoxContainer" parent="Margin/Container/VelocityBox"]
margin_top = 1.0
margin_right = 293.0 margin_right = 293.0
margin_bottom = 18.0 margin_bottom = 19.0
custom_constants/separation = 10 custom_constants/separation = 10
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
@ -117,9 +119,9 @@ text = "2A.01/10"
align = 2 align = 2
[node name="HBoxContainer4" type="HBoxContainer" parent="Margin/Container/VelocityBox"] [node name="HBoxContainer4" type="HBoxContainer" parent="Margin/Container/VelocityBox"]
margin_top = 22.0 margin_top = 23.0
margin_right = 293.0 margin_right = 293.0
margin_bottom = 40.0 margin_bottom = 41.0
custom_constants/separation = 10 custom_constants/separation = 10
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
@ -146,9 +148,9 @@ text = "0A.00/00"
align = 2 align = 2
[node name="HBoxContainer3" type="HBoxContainer" parent="Margin/Container/VelocityBox"] [node name="HBoxContainer3" type="HBoxContainer" parent="Margin/Container/VelocityBox"]
margin_top = 44.0 margin_top = 45.0
margin_right = 293.0 margin_right = 293.0
margin_bottom = 62.0 margin_bottom = 63.0
custom_constants/separation = 10 custom_constants/separation = 10
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
@ -174,9 +176,9 @@ custom_colors/font_color = Color( 0.494118, 0.52549, 0.737255, 1 )
align = 2 align = 2
[node name="HBoxContainer2" type="HBoxContainer" parent="Margin/Container/VelocityBox"] [node name="HBoxContainer2" type="HBoxContainer" parent="Margin/Container/VelocityBox"]
margin_top = 66.0 margin_top = 67.0
margin_right = 293.0 margin_right = 293.0
margin_bottom = 84.0 margin_bottom = 85.0
[node name="ShipDirectionLabel" type="Label" parent="Margin/Container/VelocityBox/HBoxContainer2"] [node name="ShipDirectionLabel" type="Label" parent="Margin/Container/VelocityBox/HBoxContainer2"]
material = ExtResource( 4 ) material = ExtResource( 4 )
@ -199,9 +201,9 @@ align = 2
[node name="Button" type="Button" parent="Margin/Container"] [node name="Button" type="Button" parent="Margin/Container"]
material = ExtResource( 4 ) material = ExtResource( 4 )
margin_top = 88.0 margin_top = 96.0
margin_right = 293.0 margin_right = 293.0
margin_bottom = 112.0 margin_bottom = 120.0
theme = ExtResource( 3 ) theme = ExtResource( 3 )
text = "Open map" text = "Open map"
[connection signal="pressed" from="Margin/Container/Button" to="." method="_map_button_pressed"] [connection signal="pressed" from="Margin/Container/Button" to="." method="_map_button_pressed"]

View file

@ -0,0 +1,26 @@
extends Control
onready var scene = $"/root/scene" as GameInstance
func _physics_process(_delta):
if not visible:
return
var children = scene.systems.get_children()
var total_sink = 0
var total_source = 0
var total_alerts = 0
for child in children:
if child is PowerNetwork:
var network = child as PowerNetwork
total_sink += network.total_usage
total_source += network.total_source
total_alerts += network.unpowered
$Margin/Container/EnergyBox/CurrentSource/Value.text = str(round(total_source)) + " kW"
$Margin/Container/EnergyBox/CurrentSink/Value.text = str(round(total_sink)) + " kW"
$Margin/Container/EnergyBox/CurrentAlerts/Value.text = str(total_alerts)
func _map_button_pressed():
scene.ui.open_popup(GameUI.PopupName.EnergyUsage)
func force_close():
scene.ui.close_popup(GameUI.PopupName.EnergyUsage)

View file

@ -0,0 +1,187 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Actors/Objects/Computer/UI/EnergyComp.gd" type="Script" id=1]
[ext_resource path="res://Graphics/UI/ui-popup-panel.png" type="Texture" id=2]
[ext_resource path="res://Graphics/UI/ui_theme.tres" type="Theme" id=3]
[ext_resource path="res://Graphics/unshaded_mat.tres" type="Material" id=4]
[node name="EnergyComp" type="Control"]
material = ExtResource( 4 )
margin_left = -157.0
margin_top = -144.0
margin_right = 156.0
margin_bottom = -20.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 1
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TextureRect" type="TextureRect" parent="."]
material = ExtResource( 4 )
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -8.0
margin_top = -16.5409
margin_right = 8.27014
margin_bottom = 15.4881
texture = ExtResource( 2 )
stretch_mode = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="NinePatchRect" type="NinePatchRect" parent="."]
material = ExtResource( 4 )
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 2 )
region_rect = Rect2( 0, 0, 16, 16 )
patch_margin_left = 4
patch_margin_top = 4
patch_margin_right = 4
patch_margin_bottom = 5
axis_stretch_horizontal = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Margin" type="MarginContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 10.0
margin_top = 10.0
margin_right = -10.0
margin_bottom = -10.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Container" type="VBoxContainer" parent="Margin"]
material = ExtResource( 4 )
margin_right = 293.0
margin_bottom = 104.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/separation = 10
__meta__ = {
"_edit_use_anchors_": false
}
[node name="EnergyBox" type="VBoxContainer" parent="Margin/Container"]
material = ExtResource( 4 )
margin_right = 293.0
margin_bottom = 104.0
size_flags_horizontal = 3
size_flags_vertical = 3
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="CurrentSource" type="HBoxContainer" parent="Margin/Container/EnergyBox"]
margin_top = 21.0
margin_right = 293.0
margin_bottom = 39.0
custom_constants/separation = 10
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="Margin/Container/EnergyBox/CurrentSource"]
material = ExtResource( 4 )
margin_right = 106.0
margin_bottom = 18.0
mouse_filter = 1
theme = ExtResource( 3 )
text = "Available power"
[node name="Value" type="Label" parent="Margin/Container/EnergyBox/CurrentSource"]
material = ExtResource( 4 )
margin_left = 116.0
margin_right = 293.0
margin_bottom = 18.0
mouse_filter = 1
size_flags_horizontal = 3
theme = ExtResource( 3 )
custom_colors/font_color = Color( 0.494118, 0.52549, 0.737255, 1 )
text = "2A.01/10"
align = 2
[node name="CurrentSink" type="HBoxContainer" parent="Margin/Container/EnergyBox"]
margin_top = 43.0
margin_right = 293.0
margin_bottom = 61.0
custom_constants/separation = 10
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="Margin/Container/EnergyBox/CurrentSink"]
material = ExtResource( 4 )
margin_right = 130.0
margin_bottom = 18.0
mouse_filter = 1
theme = ExtResource( 3 )
text = "Current power load"
[node name="Value" type="Label" parent="Margin/Container/EnergyBox/CurrentSink"]
material = ExtResource( 4 )
margin_left = 140.0
margin_right = 293.0
margin_bottom = 18.0
mouse_filter = 1
size_flags_horizontal = 3
theme = ExtResource( 3 )
custom_colors/font_color = Color( 0.494118, 0.52549, 0.737255, 1 )
text = "0A.00/00"
align = 2
[node name="CurrentAlerts" type="HBoxContainer" parent="Margin/Container/EnergyBox"]
margin_top = 65.0
margin_right = 293.0
margin_bottom = 83.0
custom_constants/separation = 10
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="Margin/Container/EnergyBox/CurrentAlerts"]
material = ExtResource( 4 )
margin_right = 130.0
margin_bottom = 18.0
mouse_filter = 1
theme = ExtResource( 3 )
text = "Unpowered devices"
[node name="Value" type="Label" parent="Margin/Container/EnergyBox/CurrentAlerts"]
material = ExtResource( 4 )
margin_left = 140.0
margin_right = 293.0
margin_bottom = 18.0
mouse_filter = 1
size_flags_horizontal = 3
theme = ExtResource( 3 )
custom_colors/font_color = Color( 0.494118, 0.52549, 0.737255, 1 )
text = "0A.00/00"
align = 2
[node name="Button" type="Button" parent="Margin/Container"]
visible = false
material = ExtResource( 4 )
margin_top = 80.0
margin_right = 293.0
margin_bottom = 104.0
theme = ExtResource( 3 )
text = "Open usage monitor"
[connection signal="pressed" from="Margin/Container/Button" to="." method="_map_button_pressed"]

View file

@ -46,6 +46,7 @@ radius = 18.0
[node name="Door" type="StaticBody2D"] [node name="Door" type="StaticBody2D"]
input_pickable = true input_pickable = true
collision_layer = 17
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]

View file

@ -29,13 +29,14 @@ func _ready():
func _physics_process(delta): func _physics_process(delta):
var motion = Vector2.ZERO var motion = Vector2.ZERO
if is_network_master(): if is_network_master():
if not scene.writing:
motion = Vector2( motion = Vector2(
Input.get_action_strength("ui_right")-Input.get_action_strength("ui_left"), Input.get_action_strength("ui_right")-Input.get_action_strength("ui_left"),
Input.get_action_strength("ui_down")-Input.get_action_strength("ui_up")) Input.get_action_strength("ui_down")-Input.get_action_strength("ui_up"))
# Check sprinting # Check sprinting
var speed = BASE_SPEED var speed = BASE_SPEED
if Input.is_action_pressed("sprint"): if Input.is_action_pressed("sprint") and not scene.writing:
if motion.length() > EPSILON and stamina > 0: if motion.length() > EPSILON and stamina > 0:
speed_boost += BOOST_COEFF * delta * ease(stamina/MAX_STAMINA, 1.1) speed_boost += BOOST_COEFF * delta * ease(stamina/MAX_STAMINA, 1.1)
stamina -= delta stamina -= delta

View file

@ -0,0 +1,117 @@
tool
extends Node2D
class_name ProbeArea
export(String) var area_name
export(NodePath) var wall_tilemap
export(NodePath) var base_tilemap
var debug_font = preload("res://Graphics/UI/uifont.tres")
const AREA_LAYER_ID = 16
onready var walls = get_node(wall_tilemap) as TileMap
onready var base = get_node(base_tilemap) as TileMap
onready var physics = get_world_2d().direct_space_state
onready var map = walls.get_parent() as GameMap
const TILE_SIZE = 32
var cells = {}
var bounds = {}
func _ready():
scout()
update()
func _physics_process(delta):
if Engine.editor_hint:
update()
func scout():
# Reset lists
cells = {}
bounds = {}
# Get origin and immediate neighbour of probe
var origin = Vector2(floor(position.x / TILE_SIZE), floor(position.y / TILE_SIZE))
cells[origin] = true
var queue = get_neighbours(origin)
# Use children probes for extra areas
for child in get_children():
var child_origin = Vector2(floor((position.x + child.position.x) / TILE_SIZE), floor((position.y + child.position.y) / TILE_SIZE))
cells[child_origin] = true
for neighbour in get_neighbours(child_origin):
queue.push_front(neighbour)
# Depth-first search
while not queue.empty():
var current = queue.pop_front()
# Have we checked this already?
if not is_valid(current):
continue
var wall_tile = walls.get_cellv(current)
if wall_tile == -1:
var objects = physics.intersect_point(current * TILE_SIZE + Vector2.ONE * TILE_SIZE / 2.0, 1, [], AREA_LAYER_ID)
if objects.size() > 0:
bounds[current] = true
else:
cells[current] = true
for neighbour in get_neighbours(current):
queue.push_front(neighbour)
else:
bounds[current] = true
# Join walls
var joined = []
for cell in bounds:
var sides = [
[Vector2(cell.x, cell.y-1),Vector2(cell.x, cell.y+1)],
[Vector2(cell.x-1, cell.y),Vector2(cell.x+1, cell.y)],
]
for side_pair in sides:
if cells.has(side_pair[0]) and cells.has(side_pair[1]):
# This bound is joined at one side, make it a cell and not a bound
joined.push_back(cell)
for wall in joined:
bounds.erase(wall)
cells[wall] = true
func is_valid(cell: Vector2) -> bool:
# Have we checked this already?
if cells.has(cell) or bounds.has(cell):
return false
# Is it a valid tile for an area
return base.get_cellv(cell) != -1
func get_neighbours(cell: Vector2) -> Array:
var neighbours = [
Vector2(cell.x-1, cell.y-1), Vector2(cell.x, cell.y-1), Vector2(cell.x+1, cell.y-1),
Vector2(cell.x-1, cell.y), Vector2(cell.x+1, cell.y),
Vector2(cell.x-1, cell.y+1), Vector2(cell.x, cell.y+1), Vector2(cell.x+1, cell.y+1)
]
var out = []
for neighbour in neighbours:
# Have we checked this already?
if not is_valid(neighbour):
continue
out.push_back(neighbour)
return out
func _draw():
if map == null or not map.debug_areas:
return
var origin = Vector2(floor(position.x / TILE_SIZE), floor(position.y / TILE_SIZE))
var draw_origin = origin * TILE_SIZE - position
var rect_size = Vector2.ONE * TILE_SIZE
draw_rect(Rect2(draw_origin, rect_size), Color.red, false, 2)
draw_string(debug_font, Vector2.ZERO, area_name, Color.blue)
for child in get_children():
var child_origin = Vector2(floor(child.position.x / TILE_SIZE), floor(child.position.y / TILE_SIZE))
draw_rect(Rect2(draw_origin + child_origin * TILE_SIZE, rect_size), Color.orange, false, 2)
draw_string(debug_font, child.position, area_name + "/" + child.name, Color.blue)
for wall in bounds:
draw_rect(Rect2(wall * TILE_SIZE - position + Vector2.ONE * (TILE_SIZE / 2.0 - TILE_SIZE / 4.0), rect_size/2.0), Color(0,0.5,1,0.5))
func _area_moved():
scout()
update()

View file

@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Actors/Systems/Area/AreaProbe.gd" type="Script" id=1]
[node name="AreaProbe" type="Sprite"]
script = ExtResource( 1 )
[connection signal="item_rect_changed" from="." to="." method="_area_moved"]

View file

@ -9,6 +9,7 @@ var sockets = []
var total_source = 0 var total_source = 0
var total_usage = 0 var total_usage = 0
var unpowered = 0
var debugColor = Color.cyan var debugColor = Color.cyan
@ -67,6 +68,7 @@ func _physics_process(_delta: float) -> void:
sources.append(manager) sources.append(manager)
# Update manager stats # Update manager stats
var available_supply = total_source var available_supply = total_source
unpowered = 0
for sink in sinks: for sink in sinks:
# Check if item can be powered this cycle # Check if item can be powered this cycle
if sink.power_usage > 0: if sink.power_usage > 0:
@ -77,6 +79,7 @@ func _physics_process(_delta: float) -> void:
else: else:
if sink.powered: if sink.powered:
sink.rpc("set_powered", false) sink.rpc("set_powered", false)
unpowered += 1
# Update available power to sinks # Update available power to sinks
for sink in sinks: for sink in sinks:
sink.available = available_supply sink.available = available_supply

View file

@ -25,6 +25,6 @@ static func to_letter(num: int) -> String:
var out = "" var out = ""
var base = letters.length() var base = letters.length()
while num > 0: while num > 0:
out += letters.substr(num % base, 1) out = letters.substr(num % base, 1) + out
num /= base num /= base
return out return out

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/tcomm.png-d10359105f84709691a87ffd8437229d.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Graphics/tgstation/tcomm.png"
dest_files=[ "res://.import/tcomm.png-d10359105f84709691a87ffd8437229d.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View file

@ -9,13 +9,15 @@ onready var world = $world
onready var systems = $systems onready var systems = $systems
onready var netgame = $"/root/Multiplayer" onready var netgame = $"/root/Multiplayer"
var writing = false
func _ready() -> void: func _ready() -> void:
randomize() randomize()
ui.connect("command", world, "process_command") ui.connect("command", world, "process_command")
if netgame.hosting: if netgame.hosting:
world.load_map(netgame.get_current_map()) world.load_map(netgame.get_current_map())
world.map.current_ship_position = Vector2(randf() * 1e4, randf() * 1e4) world.map.current_ship_position = Vector2(randf() * 1e4, randf() * 1e4)
world.map.current_ship_target = null world.map.current_ship_target = world.map.current_ship_position + Vector2(randf() * 1e2, randf() * 1e2)
rpc("spawn_player", 1) rpc("spawn_player", 1)
else: else:
world.load_map(GameWorld.Map.EMPTY) world.load_map(GameWorld.Map.EMPTY)

View file

@ -94,6 +94,7 @@ func host():
bind_events() bind_events()
var peer = NetworkedMultiplayerENet.new() var peer = NetworkedMultiplayerENet.new()
peer.compression_mode = NetworkedMultiplayerENet.COMPRESS_FASTLZ
var server_res = peer.create_server(port, MAX_PLAYERS) var server_res = peer.create_server(port, MAX_PLAYERS)
if server_res != OK: if server_res != OK:
match server_res: match server_res:

View file

@ -3,6 +3,8 @@ extends Node2D
class_name GameMap class_name GameMap
var debug_areas = false
var ship_direction = 0 var ship_direction = 0
var ship_speed = 0 var ship_speed = 0

File diff suppressed because one or more lines are too long

View file

@ -1,24 +1,39 @@
extends Control extends Control
class_name GameUI
signal command(command) signal command(command)
enum ServerMenuItem { enum ServerMenuItem {
SERVER_INFO ServerInfo
}
enum PopupName {
SpaceMap,
EnergyUsage
} }
func _ready() -> void: func _ready() -> void:
# Add options to menu buttons # Add options to menu buttons
var serverMenu = $Menu/Margins/Grid/Server.get_popup() var serverMenu = $Menu/Margins/Grid/Server.get_popup()
serverMenu.connect("id_pressed", self, "_server_option_chosen") serverMenu.connect("id_pressed", self, "_server_option_chosen")
serverMenu.add_item("Server info", ServerMenuItem.SERVER_INFO) serverMenu.add_item("Server info", ServerMenuItem.ServerInfo)
func _server_option_chosen(id) -> void: func _server_option_chosen(id) -> void:
match id: match id:
ServerMenuItem.SERVER_INFO: ServerMenuItem.ServerInfo:
$ServerInfoPopup.popup_centered() $ServerInfoPopup.popup_centered()
func open_map_popup() -> void: func open_popup(map_name) -> void:
match map_name:
PopupName.SpaceMap:
$MapPopup.popup_centered_ratio() $MapPopup.popup_centered_ratio()
PopupName.EnergyUsage:
pass
func close_map_popup() -> void: func close_popup(map_name) -> void:
match map_name:
PopupName.SpaceMap:
$MapPopup.visible = false $MapPopup.visible = false
PopupName.EnergyUsage:
pass

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=5 format=2] [gd_scene load_steps=6 format=2]
[ext_resource path="res://Scenes/UI/SpaceMap.tscn" type="PackedScene" id=1] [ext_resource path="res://Scenes/UI/SpaceMap.tscn" type="PackedScene" id=1]
[ext_resource path="res://Scenes/UI.gd" type="Script" id=2] [ext_resource path="res://Scenes/UI.gd" type="Script" id=2]
[ext_resource path="res://Scenes/UI/Widgets/ResizablePanel.tscn" type="PackedScene" id=3] [ext_resource path="res://Scenes/UI/Widgets/ResizablePanel.tscn" type="PackedScene" id=3]
[ext_resource path="res://Scenes/UI/ServerInfo.tscn" type="PackedScene" id=4]
[sub_resource type="StyleBoxFlat" id=1] [sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0.133333, 0.12549, 0.203922, 0.705882 ) bg_color = Color( 0.133333, 0.12549, 0.203922, 0.705882 )
@ -31,8 +32,10 @@ __meta__ = {
[node name="MapPopup" parent="." instance=ExtResource( 1 )] [node name="MapPopup" parent="." instance=ExtResource( 1 )]
[node name="Logs" parent="." instance=ExtResource( 3 )] [node name="Logs" parent="." instance=ExtResource( 3 )]
margin_right = 392.0 margin_left = 10.0
margin_bottom = 256.0 margin_top = 10.0
margin_right = -857.0
margin_bottom = -566.0
title = "Log" title = "Log"
[node name="Menu" type="PanelContainer" parent="."] [node name="Menu" type="PanelContainer" parent="."]
@ -83,13 +86,8 @@ margin_right = 144.0
margin_bottom = 20.0 margin_bottom = 20.0
text = "Preferences" text = "Preferences"
[node name="ServerInfoPopup" type="WindowDialog" parent="."] [node name="ServerInfoPopup" parent="." instance=ExtResource( 4 )]
margin_left = -278.587 margin_left = 31.2773
margin_top = 58.4538 margin_top = 46.9222
margin_right = -22.587 margin_right = 287.277
margin_bottom = 226.454 margin_bottom = 214.923
window_title = "Server info"
resizable = true
__meta__ = {
"_edit_use_anchors_": false
}

6
Scenes/UI/ServerInfo.gd Normal file
View file

@ -0,0 +1,6 @@
extends WindowDialog
func _physics_process(delta):
if not visible:
return
multiplayer

22
Scenes/UI/ServerInfo.tscn Normal file
View file

@ -0,0 +1,22 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/UI/ServerInfo.gd" type="Script" id=1]
[node name="ServerInfoPopup" type="WindowDialog"]
visible = true
margin_left = 19.9312
margin_top = 34.9087
margin_right = 275.931
margin_bottom = 202.909
window_title = "Server info"
resizable = true
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ItemList" type="ItemList" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3

View file

@ -26,11 +26,22 @@ func _handle_resize(event):
rect_size = last_origin + (event.global_position - last_mouse) rect_size = last_origin + (event.global_position - last_mouse)
func _input(event): func _input(event):
if dragging and event is InputEventMouseButton and not event.pressed: if event is InputEventMouseButton:
if dragging and not event.pressed:
dragging = false dragging = false
if resizing and event is InputEventMouseButton and not event.pressed: if resizing and not event.pressed:
resizing = false resizing = false
if not chat_bar_focus:
$LineEdit.release_focus()
func set_title(val): func set_title(val):
title = val title = val
$DragHandle/Label.text = title $DragHandle/Label.text = title
var chat_bar_focus = false
func _chat_bar_status(editing):
$"/root/scene".writing = editing
func _chat_bar_focus(entered):
chat_bar_focus = entered

View file

@ -1,6 +1,10 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=11 format=2]
[ext_resource path="res://Scenes/UI/Widgets/ResizablePanel.gd" type="Script" id=1] [ext_resource path="res://Scenes/UI/Widgets/ResizablePanel.gd" type="Script" id=1]
[ext_resource path="res://Graphics/UI/iosevka-aile-regular.ttf" type="DynamicFontData" id=2]
[ext_resource path="res://Graphics/UI/iosevka-aile-bold.ttf" type="DynamicFontData" id=3]
[ext_resource path="res://Graphics/UI/iosevka-aile-italic.ttf" type="DynamicFontData" id=4]
[ext_resource path="res://Graphics/UI/iosevka-aile-bolditalic.ttf" type="DynamicFontData" id=5]
[sub_resource type="StyleBoxFlat" id=1] [sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0.133333, 0.12549, 0.203922, 0.705882 ) bg_color = Color( 0.133333, 0.12549, 0.203922, 0.705882 )
@ -15,11 +19,29 @@ corner_radius_top_right = 4
corner_radius_bottom_right = 4 corner_radius_bottom_right = 4
corner_radius_bottom_left = 4 corner_radius_bottom_left = 4
[sub_resource type="DynamicFont" id=2]
size = 14
use_mipmaps = true
font_data = ExtResource( 5 )
[sub_resource type="DynamicFont" id=3]
size = 14
use_mipmaps = true
font_data = ExtResource( 4 )
[sub_resource type="DynamicFont" id=4]
size = 14
use_mipmaps = true
font_data = ExtResource( 3 )
[sub_resource type="DynamicFont" id=5]
size = 14
use_mipmaps = true
font_data = ExtResource( 2 )
[node name="ResizablePanel" type="Panel"] [node name="ResizablePanel" type="Panel"]
margin_left = 10.0 anchor_right = 1.0
margin_top = 10.0 anchor_bottom = 1.0
margin_right = 376.0
margin_bottom = 336.0
custom_styles/panel = SubResource( 1 ) custom_styles/panel = SubResource( 1 )
script = ExtResource( 1 ) script = ExtResource( 1 )
__meta__ = { __meta__ = {
@ -65,5 +87,38 @@ size_flags_vertical = 0
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="RichTextLabel" type="RichTextLabel" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 10.0
margin_top = 40.0
margin_right = -10.0
margin_bottom = -10.0
focus_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
custom_fonts/bold_italics_font = SubResource( 2 )
custom_fonts/italics_font = SubResource( 3 )
custom_fonts/bold_font = SubResource( 4 )
custom_fonts/normal_font = SubResource( 5 )
selection_enabled = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="LineEdit" type="LineEdit" parent="."]
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_bottom = 24.0
focus_mode = 1
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="gui_input" from="DragHandle" to="." method="_handle_drag"] [connection signal="gui_input" from="DragHandle" to="." method="_handle_drag"]
[connection signal="gui_input" from="ResizeHandle" to="." method="_handle_resize"] [connection signal="gui_input" from="ResizeHandle" to="." method="_handle_resize"]
[connection signal="focus_entered" from="LineEdit" to="." method="_chat_bar_status" binds= [ true ]]
[connection signal="focus_exited" from="LineEdit" to="." method="_chat_bar_status" binds= [ false ]]
[connection signal="mouse_entered" from="LineEdit" to="." method="_chat_bar_focus" binds= [ true ]]
[connection signal="mouse_exited" from="LineEdit" to="." method="_chat_bar_focus" binds= [ false ]]

View file

@ -49,3 +49,7 @@ func _make_socket(direction: String) -> void:
socket.owner = map socket.owner = map
socket.global_position = node.global_position + offset socket.global_position = node.global_position + offset
socket.connectionPaths = [socket.get_path_to(node)] socket.connectionPaths = [socket.get_path_to(node)]
func _area_debug_modified(button_pressed):
var map = api.get_editor_interface().get_edited_scene_root() as GameMap
map.debug_areas = button_pressed

View file

@ -31,33 +31,43 @@ text = "Make socket "
[node name="Type" type="OptionButton" parent="Commands/MakeSocket"] [node name="Type" type="OptionButton" parent="Commands/MakeSocket"]
margin_left = 88.0 margin_left = 88.0
margin_right = 117.0 margin_right = 142.0
margin_bottom = 20.0 margin_bottom = 20.0
text = "SNK"
items = [ "SNK", null, false, 0, null, "SRC", null, false, 1, null, "BID", null, false, 2, null ]
selected = 0
[node name="Left" type="Button" parent="Commands/MakeSocket"] [node name="Left" type="Button" parent="Commands/MakeSocket"]
margin_left = 121.0 margin_left = 146.0
margin_right = 141.0 margin_right = 166.0
margin_bottom = 20.0 margin_bottom = 20.0
text = "<" text = "<"
[node name="Up" type="Button" parent="Commands/MakeSocket"] [node name="Up" type="Button" parent="Commands/MakeSocket"]
margin_left = 145.0 margin_left = 170.0
margin_right = 164.0 margin_right = 189.0
margin_bottom = 20.0 margin_bottom = 20.0
text = "^" text = "^"
[node name="Down" type="Button" parent="Commands/MakeSocket"] [node name="Down" type="Button" parent="Commands/MakeSocket"]
margin_left = 168.0 margin_left = 193.0
margin_right = 187.0 margin_right = 212.0
margin_bottom = 20.0 margin_bottom = 20.0
text = "v" text = "v"
[node name="Right" type="Button" parent="Commands/MakeSocket"] [node name="Right" type="Button" parent="Commands/MakeSocket"]
margin_left = 191.0 margin_left = 216.0
margin_right = 211.0 margin_right = 236.0
margin_bottom = 20.0 margin_bottom = 20.0
text = ">" text = ">"
[node name="DebugAreas" type="CheckBox" parent="Commands"]
margin_top = 24.0
margin_right = 1280.0
margin_bottom = 48.0
text = "Show areas"
[connection signal="pressed" from="Commands/MakeSocket/Left" to="." method="_make_socket" binds= [ "left" ]] [connection signal="pressed" from="Commands/MakeSocket/Left" to="." method="_make_socket" binds= [ "left" ]]
[connection signal="pressed" from="Commands/MakeSocket/Up" to="." method="_make_socket" binds= [ "up" ]] [connection signal="pressed" from="Commands/MakeSocket/Up" to="." method="_make_socket" binds= [ "up" ]]
[connection signal="pressed" from="Commands/MakeSocket/Down" to="." method="_make_socket" binds= [ "down" ]] [connection signal="pressed" from="Commands/MakeSocket/Down" to="." method="_make_socket" binds= [ "down" ]]
[connection signal="pressed" from="Commands/MakeSocket/Right" to="." method="_make_socket" binds= [ "right" ]] [connection signal="pressed" from="Commands/MakeSocket/Right" to="." method="_make_socket" binds= [ "right" ]]
[connection signal="toggled" from="Commands/DebugAreas" to="." method="_area_debug_modified"]

View file

@ -64,6 +64,11 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://Actors/Objects/Scanner/Scanner.gd" "path": "res://Actors/Objects/Scanner/Scanner.gd"
}, { }, {
"base": "Control",
"class": "GameUI",
"language": "GDScript",
"path": "res://Scenes/UI.gd"
}, {
"base": "Node2D", "base": "Node2D",
"class": "GameWorld", "class": "GameWorld",
"language": "GDScript", "language": "GDScript",
@ -119,6 +124,11 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://Actors/Systems/Electricity/PowerNetwork.gd" "path": "res://Actors/Systems/Electricity/PowerNetwork.gd"
}, { }, {
"base": "Node2D",
"class": "ProbeArea",
"language": "GDScript",
"path": "res://Actors/Systems/Area/AreaProbe.gd"
}, {
"base": "Area2D", "base": "Area2D",
"class": "ProbeElectric", "class": "ProbeElectric",
"language": "GDScript", "language": "GDScript",
@ -161,6 +171,7 @@ _global_script_class_icons={
"GameObjectLightbulb": "", "GameObjectLightbulb": "",
"GameObjectPowerStorage": "", "GameObjectPowerStorage": "",
"GameObjectScanner": "", "GameObjectScanner": "",
"GameUI": "",
"GameWorld": "", "GameWorld": "",
"GotmDebug": "", "GotmDebug": "",
"GotmFile": "", "GotmFile": "",
@ -172,6 +183,7 @@ _global_script_class_icons={
"POI": "", "POI": "",
"PowerManager": "", "PowerManager": "",
"PowerNetwork": "", "PowerNetwork": "",
"ProbeArea": "",
"ProbeElectric": "", "ProbeElectric": "",
"ResourceQueue": "", "ResourceQueue": "",
"UICommand": "", "UICommand": "",
@ -259,6 +271,7 @@ sprint={
2d_physics/layer_2="Projectile" 2d_physics/layer_2="Projectile"
2d_physics/layer_3="Electric" 2d_physics/layer_3="Electric"
2d_physics/layer_4="Actors" 2d_physics/layer_4="Actors"
2d_physics/layer_5="AreaBound"
[rendering] [rendering]