refactor UI

This commit is contained in:
James 2023-12-28 19:47:27 +00:00
parent 3943a1eff2
commit 4a11cc42e4
9 changed files with 183 additions and 60 deletions

26
Map.gd
View File

@ -21,29 +21,29 @@ func _unhandled_input(event):
func spawn(pos,vol):
var tool=$"../ScreenOverlay/HUD/HBoxContainer/ToolSelect".get_selected()
var tool=%ToolSelect.get_selected()
if tool.name=="Create Player":
spawn_player(pos,vol)
if tool.name=="Create Pool":
var r=int(tool.get_node("Red").text)
var g=int(tool.get_node("Green").text)
var b=int(tool.get_node("Blue").text)
var r=int(tool.get_node("Red/val").text)
var g=int(tool.get_node("Green/val").text)
var b=int(tool.get_node("Blue/val").text)
if r+g+b>0:
spawm_pool(pos,r,g,b)
if tool.name=="Paste":
var filename="user://saves/"+tool.get_item_text(tool.get_selected_id())
get_tree().root.get_node("Sim/Map").paste_map(filename,pos)
if tool.name=="Create Pool Circle":
var r=int(tool.get_node("Red").text)
var g=int(tool.get_node("Green").text)
var b=int(tool.get_node("Blue").text)
var rad=int(tool.get_node("Radius").text)
var cnt=int(tool.get_node("Count").text)
var r=int(tool.get_node("Red/val").text)
var g=int(tool.get_node("Green/val").text)
var b=int(tool.get_node("Blue/val").text)
var rad=int(tool.get_node("Radius/val").text)
var cnt=int(tool.get_node("Count/val").text)
if r+g+b>0:
spawn_pool_circle(pos,rad,cnt,r,g,b)
if tool.name=="Create Player Circle":
var rad=int(tool.get_node("Radius").text)
var cnt=int(tool.get_node("Count").text)
var rad=int(tool.get_node("Radius/val").text)
var cnt=int(tool.get_node("Count/val").text)
spawn_player_circle(pos,rad,cnt)
if tool.name=="Delete":
var space_state = get_world_2d().direct_space_state
@ -72,8 +72,8 @@ func spawn(pos,vol):
if node is Player:
var direction = vol.normalized()
var distance = pos.distance_to(node.position)
var dropOff = int(tool.get_node("DropOff").text)
var power = int(tool.get_node("Power").text)
var dropOff = int(tool.get_node("Attenuation/val").text)
var power = int(tool.get_node("Power/val").text)
var magnitude = power * vol.length()
if dropOff:
magnitude/= distance * dropOff

View File

@ -14,7 +14,7 @@ func _integrate_forces(state: PhysicsDirectBodyState2D):
handle_pool_collision(collider_object)
func handle_player_collision(player: Player):
if not get_tree().root.get_node("Sim/ScreenOverlay/Settings/VBoxContainer/DropOnColl").is_pressed():
if not get_tree().root.get_node("Sim/ScreenOverlay/SettingsWindow/VBoxContainer/DropOnColl").is_pressed():
return
if is_carrying() and player.is_carrying():
doubledrop(player)
@ -148,7 +148,7 @@ func load_data(data):
update()
func _on_health_timer_timeout():
if not get_tree().root.get_node("Sim/ScreenOverlay/Settings/VBoxContainer/Health").is_pressed():
if not get_tree().root.get_node("Sim/ScreenOverlay/SettingsWindow/VBoxContainer/Health").is_pressed():
return
if is_carrying():

View File

@ -123,7 +123,7 @@ func load_data(data):
mana_b=data["b"]
func _on_decay_timer_timeout():
if not get_tree().root.get_node("Sim/ScreenOverlay/Settings/VBoxContainer/Decay").is_pressed():
if not get_tree().root.get_node("Sim/ScreenOverlay/SettingsWindow/VBoxContainer/Decay").is_pressed():
return
if (mana_r+mana_g+mana_b)>randf_range(0,99999):
decay()

View File

@ -14,8 +14,8 @@ func _ready():
if not DirAccess.dir_exists_absolute(session_path):
DirAccess.make_dir_recursive_absolute(session_path)
$"../ScreenOverlay/Settings/VBoxContainer/HBoxContainer/Interval".text=str(wait_time)
$"../ScreenOverlay/Settings/VBoxContainer/HBoxContainer/Screenshots".set_pressed(is_stopped() == false)
$"../ScreenOverlay/SettingsWindow/VBoxContainer/HBoxContainer/Interval".text=str(wait_time)
$"../ScreenOverlay/SettingsWindow/VBoxContainer/HBoxContainer/Screenshots".set_pressed(is_stopped() == false)
func _on_timeout():
var image = get_viewport().get_texture().get_image()

View File

@ -1,15 +1,23 @@
extends Window
var elapsed_time = 0.0 # Initialize a variable to keep track of elapsed time
var time_text=""
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
elapsed_time += delta # Increment the elapsed time by the frame's delta time
var hours = int(elapsed_time / 3600)
var minutes = int(elapsed_time / 60) % 60
var seconds = int(elapsed_time) % 60
var time_string = "%02d:%02d:%02d" % [hours, minutes, seconds] # Format time as H:M:S
var fps = Engine.get_frames_per_second() # Get the current FPS
time_text = time_string+" "+str(fps) + " fps" # Combine FPS and runtime into one string
if %Map.controlling and is_instance_valid(%Map.controlling):
time_text += " [H:"+str(%Map.controlling.health)+"]"
func _on_timer_timeout():
var pl=0
@ -33,6 +41,7 @@ func _on_timer_timeout():
gpo+=node.mana_g
bpo+=node.mana_b
$Label.text=\
time_text + "\n" +\
"Players: "+str(pl)+"\n"+ \
"Pools: "+str(po)+"\n"+ \
"R: "+str(rpo+rpl)+" ("+str(rpo)+"+"+str(rpl)+")\n"+\

View File

@ -58,6 +58,7 @@ dialog_text = "Clear current map?"
title = "Stats"
position = Vector2i(15, 197)
size = Vector2i(200, 200)
visible = false
script = ExtResource("7_8peal")
[node name="Timer" type="Timer" parent="ScreenOverlay/StatsWindow"]
@ -67,9 +68,11 @@ autostart = true
offset_right = 40.0
offset_bottom = 23.0
[node name="Settings" parent="ScreenOverlay" instance=ExtResource("8_yj6l1")]
[node name="SettingsWindow" parent="ScreenOverlay" instance=ExtResource("8_yj6l1")]
visible = false
[node name="ToolSelect" parent="ScreenOverlay" instance=ExtResource("8_wgtoc")]
unique_name_in_owner = true
position = Vector2i(20, 50)
[node name="ScreenShots" type="Timer" parent="."]
@ -84,4 +87,5 @@ script = ExtResource("3_7b3mn")
[connection signal="confirmed" from="ScreenOverlay/NewDialog" to="Map" method="_on_new_dialog_confirmed"]
[connection signal="close_requested" from="ScreenOverlay/StatsWindow" to="ScreenOverlay/StatsWindow" method="_on_close_requested"]
[connection signal="timeout" from="ScreenOverlay/StatsWindow/Timer" to="ScreenOverlay/StatsWindow" method="_on_timer_timeout"]
[connection signal="close_requested" from="ScreenOverlay/SettingsWindow" to="ScreenOverlay/SettingsWindow" method="_on_close_requested"]
[connection signal="timeout" from="ScreenShots" to="ScreenShots" method="_on_timeout"]

View File

@ -1,11 +1,4 @@
extends Window
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_close_requested():
hide()

View File

@ -2,6 +2,7 @@ extends Window
# Called when the node enters the scene tree for the first time.
func _ready():
$VBoxContainer/OptionButton.clear()
var first_child = true # Flag to identify the first child node
for child in $VBoxContainer.get_children():
if child != $VBoxContainer/OptionButton:
@ -58,3 +59,30 @@ func get_selected():
if i - 1 == index: # Adjusted index because of the OptionButton
return child
return null
func _on_tool_select_container_resized():
print($VBoxContainer.get_rect())
size=Vector2(200,$VBoxContainer.get_rect().size[1])
func _on_new_pressed():
$"../NewDialog".popup_centered()
func _on_load_pressed():
$"../LoadDialog".popup_centered()
func _on_save_pressed():
$"../SaveDialog".popup_centered()
func _on_kill_all_pressed():
for node in %Map.get_children():
if node is Player:
node.queue_free()
func _on_control_stop_pressed():
%Map.controlling=null
func _on_stats_pressed():
$"../StatsWindow".popup_centered()
func _on_settings_pressed():
$"../SettingsWindow".popup_centered()

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://bfjdgwkowj6rr"]
[ext_resource type="Script" path="res://src/Windows/ToolSelect.gd" id="1_suvl4"]
[ext_resource type="Script" path="res://src/Windows/tool_select.gd" id="1_suvl4"]
[node name="ToolSelect" type="Window"]
title = "Tool"
position = Vector2i(0, 36)
size = Vector2i(200, 200)
script = ExtResource("1_suvl4")
@ -13,129 +14,198 @@ offset_bottom = 31.0
[node name="OptionButton" type="OptionButton" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
item_count = 1
selected = 0
popup/item_0/text = "Select Tool..."
popup/item_0/id = 0
[node name="File" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
[node name="New" type="Button" parent="VBoxContainer/File"]
layout_mode = 2
size_flags_horizontal = 0
text = "New..."
[node name="Load" type="Button" parent="VBoxContainer/File"]
layout_mode = 2
size_flags_horizontal = 0
text = "Load..."
[node name="Save" type="Button" parent="VBoxContainer/File"]
layout_mode = 2
size_flags_horizontal = 0
text = "Save..."
[node name="Stats" type="Button" parent="VBoxContainer/File"]
layout_mode = 2
size_flags_horizontal = 0
text = "Stats..."
[node name="Settings" type="Button" parent="VBoxContainer/File"]
layout_mode = 2
size_flags_horizontal = 0
text = "Settings..."
[node name="Create Player" type="VBoxContainer" parent="VBoxContainer"]
visible = false
layout_mode = 2
[node name="Create Pool" type="VBoxContainer" parent="VBoxContainer"]
visible = false
layout_mode = 2
[node name="Label" type="Label" parent="VBoxContainer/Create Pool"]
[node name="Red" type="HBoxContainer" parent="VBoxContainer/Create Pool"]
layout_mode = 2
[node name="Label" type="Label" parent="VBoxContainer/Create Pool/Red"]
layout_mode = 2
text = "R:"
[node name="Red" type="LineEdit" parent="VBoxContainer/Create Pool"]
[node name="val" type="LineEdit" parent="VBoxContainer/Create Pool/Red"]
layout_mode = 2
text = "100"
placeholder_text = "0"
[node name="Label5" type="Label" parent="VBoxContainer/Create Pool"]
[node name="Blue" type="HBoxContainer" parent="VBoxContainer/Create Pool"]
layout_mode = 2
text = "G:"
[node name="Green" type="LineEdit" parent="VBoxContainer/Create Pool"]
[node name="Label4" type="Label" parent="VBoxContainer/Create Pool/Blue"]
layout_mode = 2
text = "B:"
[node name="val" type="LineEdit" parent="VBoxContainer/Create Pool/Blue"]
layout_mode = 2
text = "100"
placeholder_text = "0"
max_length = 5
[node name="Label4" type="Label" parent="VBoxContainer/Create Pool"]
[node name="Green" type="HBoxContainer" parent="VBoxContainer/Create Pool"]
layout_mode = 2
text = "B:"
[node name="Blue" type="LineEdit" parent="VBoxContainer/Create Pool"]
[node name="Label5" type="Label" parent="VBoxContainer/Create Pool/Green"]
layout_mode = 2
text = "G:"
[node name="val" type="LineEdit" parent="VBoxContainer/Create Pool/Green"]
layout_mode = 2
text = "100"
placeholder_text = "0"
max_length = 5
[node name="Create Player Circle" type="VBoxContainer" parent="VBoxContainer"]
visible = false
layout_mode = 2
[node name="Label2" type="Label" parent="VBoxContainer/Create Player Circle"]
[node name="Radius" type="HBoxContainer" parent="VBoxContainer/Create Player Circle"]
layout_mode = 2
[node name="Label2" type="Label" parent="VBoxContainer/Create Player Circle/Radius"]
layout_mode = 2
text = "Radius:"
[node name="Radius" type="LineEdit" parent="VBoxContainer/Create Player Circle"]
[node name="val" type="LineEdit" parent="VBoxContainer/Create Player Circle/Radius"]
layout_mode = 2
text = "50"
placeholder_text = "0"
max_length = 5
[node name="Label3" type="Label" parent="VBoxContainer/Create Player Circle"]
[node name="Count" type="HBoxContainer" parent="VBoxContainer/Create Player Circle"]
layout_mode = 2
[node name="Label3" type="Label" parent="VBoxContainer/Create Player Circle/Count"]
layout_mode = 2
text = "Count:"
[node name="Count" type="LineEdit" parent="VBoxContainer/Create Player Circle"]
[node name="val" type="LineEdit" parent="VBoxContainer/Create Player Circle/Count"]
layout_mode = 2
text = "16"
placeholder_text = "0"
max_length = 5
[node name="Create Pool Circle" type="VBoxContainer" parent="VBoxContainer"]
visible = false
layout_mode = 2
[node name="Label" type="Label" parent="VBoxContainer/Create Pool Circle"]
[node name="Red" type="HBoxContainer" parent="VBoxContainer/Create Pool Circle"]
layout_mode = 2
[node name="Label" type="Label" parent="VBoxContainer/Create Pool Circle/Red"]
layout_mode = 2
text = "R:"
[node name="Red" type="LineEdit" parent="VBoxContainer/Create Pool Circle"]
[node name="val" type="LineEdit" parent="VBoxContainer/Create Pool Circle/Red"]
layout_mode = 2
text = "100"
placeholder_text = "0"
max_length = 5
[node name="Label5" type="Label" parent="VBoxContainer/Create Pool Circle"]
[node name="Green" type="HBoxContainer" parent="VBoxContainer/Create Pool Circle"]
layout_mode = 2
[node name="Label5" type="Label" parent="VBoxContainer/Create Pool Circle/Green"]
layout_mode = 2
text = "G:"
[node name="Green" type="LineEdit" parent="VBoxContainer/Create Pool Circle"]
[node name="val" type="LineEdit" parent="VBoxContainer/Create Pool Circle/Green"]
layout_mode = 2
text = "100"
placeholder_text = "0"
max_length = 5
[node name="Label4" type="Label" parent="VBoxContainer/Create Pool Circle"]
[node name="Blue" type="HBoxContainer" parent="VBoxContainer/Create Pool Circle"]
layout_mode = 2
[node name="Label4" type="Label" parent="VBoxContainer/Create Pool Circle/Blue"]
layout_mode = 2
text = "B:"
[node name="Blue" type="LineEdit" parent="VBoxContainer/Create Pool Circle"]
[node name="val" type="LineEdit" parent="VBoxContainer/Create Pool Circle/Blue"]
layout_mode = 2
text = "100"
placeholder_text = "0"
max_length = 5
[node name="Label2" type="Label" parent="VBoxContainer/Create Pool Circle"]
[node name="Radius" type="HBoxContainer" parent="VBoxContainer/Create Pool Circle"]
layout_mode = 2
[node name="Label2" type="Label" parent="VBoxContainer/Create Pool Circle/Radius"]
layout_mode = 2
text = "Radius:"
[node name="Radius" type="LineEdit" parent="VBoxContainer/Create Pool Circle"]
[node name="val" type="LineEdit" parent="VBoxContainer/Create Pool Circle/Radius"]
layout_mode = 2
text = "200"
placeholder_text = "0"
max_length = 5
[node name="Label3" type="Label" parent="VBoxContainer/Create Pool Circle"]
[node name="Count" type="HBoxContainer" parent="VBoxContainer/Create Pool Circle"]
layout_mode = 2
[node name="Label3" type="Label" parent="VBoxContainer/Create Pool Circle/Count"]
layout_mode = 2
text = "Count:"
[node name="Count" type="LineEdit" parent="VBoxContainer/Create Pool Circle"]
[node name="val" type="LineEdit" parent="VBoxContainer/Create Pool Circle/Count"]
layout_mode = 2
text = "16"
placeholder_text = "0"
max_length = 5
[node name="Paste" type="OptionButton" parent="VBoxContainer"]
visible = false
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
[node name="Delete" type="VBoxContainer" parent="VBoxContainer"]
visible = false
layout_mode = 2
[node name="Impulse" type="VBoxContainer" parent="VBoxContainer"]
visible = false
layout_mode = 2
[node name="Type" type="OptionButton" parent="VBoxContainer/Impulse"]
@ -147,28 +217,37 @@ popup/item_0/id = 0
popup/item_1/text = "Radial"
popup/item_1/id = 1
[node name="Label2" type="Label" parent="VBoxContainer/Impulse"]
[node name="Power" type="HBoxContainer" parent="VBoxContainer/Impulse"]
layout_mode = 2
[node name="Label2" type="Label" parent="VBoxContainer/Impulse/Power"]
layout_mode = 2
text = "Power
"
[node name="Power" type="LineEdit" parent="VBoxContainer/Impulse"]
[node name="val" type="LineEdit" parent="VBoxContainer/Impulse/Power"]
layout_mode = 2
text = "1"
[node name="Label" type="Label" parent="VBoxContainer/Impulse"]
[node name="Attenuation" type="HBoxContainer" parent="VBoxContainer/Impulse"]
layout_mode = 2
text = "Dampening"
[node name="DropOff" type="LineEdit" parent="VBoxContainer/Impulse"]
[node name="Label" type="Label" parent="VBoxContainer/Impulse/Attenuation"]
layout_mode = 2
text = "Attenuation"
[node name="val" type="LineEdit" parent="VBoxContainer/Impulse/Attenuation"]
layout_mode = 2
text = "1"
[node name="Control Player" type="VBoxContainer" parent="VBoxContainer"]
visible = false
layout_mode = 2
[node name="Button" type="Button" parent="VBoxContainer/Control Player"]
[node name="control_stop" type="Button" parent="VBoxContainer/Control Player"]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
text = "Stop"
[node name="GOD" type="VBoxContainer" parent="VBoxContainer"]
@ -176,6 +255,16 @@ layout_mode = 2
[node name="kill all" type="Button" parent="VBoxContainer/GOD"]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
text = "Kill All"
[connection signal="resized" from="VBoxContainer" to="." method="_on_tool_select_container_resized"]
[connection signal="item_selected" from="VBoxContainer/OptionButton" to="." method="_on_option_button_item_selected"]
[connection signal="pressed" from="VBoxContainer/File/New" to="." method="_on_new_pressed"]
[connection signal="pressed" from="VBoxContainer/File/Load" to="." method="_on_load_pressed"]
[connection signal="pressed" from="VBoxContainer/File/Save" to="." method="_on_save_pressed"]
[connection signal="pressed" from="VBoxContainer/File/Stats" to="." method="_on_stats_pressed"]
[connection signal="pressed" from="VBoxContainer/File/Settings" to="." method="_on_settings_pressed"]
[connection signal="pressed" from="VBoxContainer/Control Player/control_stop" to="." method="_on_control_stop_pressed"]
[connection signal="pressed" from="VBoxContainer/GOD/kill all" to="." method="_on_kill_all_pressed"]