diff --git a/project.godot b/project.godot index 300a00a..24173eb 100644 --- a/project.godot +++ b/project.godot @@ -18,6 +18,7 @@ config/icon="res://icon.svg" [autoload] Gamestate="*res://scripts/gamestate.gd" +ConfigFileHandler="*res://scripts/configFileHandler.gd" [display] diff --git a/scenes/menu.tscn b/scenes/menu.tscn index 3678c3a..b4d468b 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -1,14 +1,59 @@ -[gd_scene load_steps=10 format=3 uid="uid://b1uhymisifcho"] +[gd_scene load_steps=16 format=3 uid="uid://b1uhymisifcho"] [ext_resource type="Script" path="res://scripts/menu.gd" id="1_fushn"] [ext_resource type="Script" path="res://scripts/menudisplay.gd" id="2_jc4pv"] [ext_resource type="Script" path="res://scripts/map_selection.gd" id="3_c0mhk"] [ext_resource type="Texture2D" uid="uid://my0glsan1h2e" path="res://scenes/map_preview/map_00.png" id="3_p822h"] +[ext_resource type="Shader" path="res://shader/menubg.gdshader" id="3_vry7a"] [ext_resource type="Texture2D" uid="uid://bk32usoetq3b" path="res://scenes/map_preview/map_01.png" id="4_ac8w4"] [ext_resource type="Texture2D" uid="uid://ole07xte1dxp" path="res://scenes/map_preview/map_02.png" id="5_pnyq7"] [ext_resource type="Texture2D" uid="uid://mkjrrv20lhkc" path="res://scenes/map_preview/map_03.png" id="7_5f67q"] [ext_resource type="Script" path="res://scripts/rounds_selection.gd" id="7_cr4tq"] [ext_resource type="Texture2D" uid="uid://dku8jinmijays" path="res://scenes/map_preview/map_04.png" id="8_46b6b"] +[ext_resource type="Texture2D" uid="uid://bst8p5s1sgurm" path="res://sprites/menu_bg.png" id="10_equk1"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_kpdum"] +shader = ExtResource("3_vry7a") +shader_parameter/strength = 1.0 +shader_parameter/iChannel0 = ExtResource("10_equk1") + +[sub_resource type="Animation" id="Animation_hwlp0"] +resource_name = "menu_idle" +length = 60.0 +loop_mode = 1 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("MenuBg:rotation") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 60), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [0.0, -6.28319] +} + +[sub_resource type="Animation" id="Animation_l7n24"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("MenuBg:rotation") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [0.0] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_1aer6"] +_data = { +"RESET": SubResource("Animation_l7n24"), +"menu_idle": SubResource("Animation_hwlp0") +} [node name="Menu" type="Node"] script = ExtResource("1_fushn") @@ -16,6 +61,13 @@ script = ExtResource("1_fushn") [node name="MenuDisplay" type="Node2D" parent="."] script = ExtResource("2_jc4pv") +[node name="MenuBg" type="Sprite2D" parent="MenuDisplay"] +material = SubResource("ShaderMaterial_kpdum") +position = Vector2(1170, 338) +scale = Vector2(2.65635, 2.65635) +texture = ExtResource("10_equk1") +offset = Vector2(0.92, 14.62) + [node name="Playerlist" type="Label" parent="MenuDisplay"] offset_left = 131.0 offset_top = 58.0 @@ -100,6 +152,13 @@ offset_bottom = 571.0 scale = Vector2(2, 2) text = "Fullscreen" +[node name="Button" type="Button" parent="MenuDisplay"] +offset_left = 862.0 +offset_top = 602.0 +offset_right = 1011.0 +offset_bottom = 633.0 +text = "Save Key Whitelist" + [node name="map_container" type="HFlowContainer" parent="MenuDisplay"] offset_left = 613.0 offset_top = 31.0 @@ -163,10 +222,17 @@ offset_right = -7.0 offset_bottom = 26.0 text = "Rounds:" +[node name="AnimationPlayer" type="AnimationPlayer" parent="MenuDisplay"] +libraries = { +"": SubResource("AnimationLibrary_1aer6") +} +autoplay = "menu_idle" + [node name="Timer" type="Timer" parent="."] wait_time = 5.0 [connection signal="toggled" from="MenuDisplay/btn_fullscreen" to="." method="_on_btn_fullscreen_toggled"] +[connection signal="pressed" from="MenuDisplay/Button" to="." method="_on_button_pressed"] [connection signal="map_changed" from="MenuDisplay/map_container" to="." method="_on_map_container_map_changed"] [connection signal="item_selected" from="MenuDisplay/rounds_selection" to="." method="_on_rounds_selection_item_selected"] [connection signal="item_selected" from="MenuDisplay/rounds_selection" to="MenuDisplay/rounds_selection" method="_on_item_selected"] diff --git a/scripts/configFileHandler.gd b/scripts/configFileHandler.gd new file mode 100644 index 0000000..9367fd3 --- /dev/null +++ b/scripts/configFileHandler.gd @@ -0,0 +1,44 @@ +extends Node + +var config = ConfigFile.new() +const SETTINGS_FILE_PATH = "config.ini" + +func _ready() -> void: + if !FileAccess.file_exists(SETTINGS_FILE_PATH): + + config.set_value("keywhitelist", "enabled", false) + + config.set_value("video", "fullscreen", false) + + config.save(SETTINGS_FILE_PATH) + else: + config.load(SETTINGS_FILE_PATH) + +func save_video_setting(key: String, value): + config.set_value("video", key,value) + config.save(SETTINGS_FILE_PATH) + +func get_video_setting(key: String): + return config.get_value("video", key) + +func get_keywhitelist_setting(): + var keywhitelist=[] + if config.get_value("keywhitelist", "enabled"): + for key in config.get_section_keys("keywhitelist"): + if key.is_valid_int(): #is a playernumber + print("added "+str(key)+" to whitelist of keys") + keywhitelist.append(int(config.get_value("keywhitelist",key))) + return keywhitelist #returns empty list if enabled is false + +func save_keywhitelist_setting(whitelist): + for key in config.get_section_keys("keywhitelist"): + if key.is_valid_int(): #is a playernumber + config.set_value("keywhitelist",key,"none") #set all existing keys to -1 = none + + var i=0 + for k in whitelist: + print("saving keywhitelist "+str(i)+" = "+str(k)) + + config.set_value("keywhitelist",str(i),str(k)) + i+=1 + config.save(SETTINGS_FILE_PATH) diff --git a/scripts/generate_road_polyon.gd b/scripts/generate_road_polyon.gd index 2657c35..cee1f97 100644 --- a/scripts/generate_road_polyon.gd +++ b/scripts/generate_road_polyon.gd @@ -2,16 +2,17 @@ extends Polygon2D @export var line_road_left: Line2D @export var line_road_right: Line2D - +@export var left_road_show_closed: bool=false +@export var right_road_show_closed: bool=false # Called when the node enters the scene tree for the first time. -func _ready() -> void: +func _ready() -> void: var road=PackedVector2Array() road.append_array(line_road_right.points) - if line_road_right.closed and line_road_right.points.size()>0: + if (line_road_right.closed or right_road_show_closed) and line_road_right.points.size()>0: road.append(line_road_right.points[0]) #add first point again to close gap - if line_road_left.closed and line_road_left.points.size()>0: + if (line_road_left.closed or left_road_show_closed) and line_road_left.points.size()>0: road.append(line_road_left.points[0]) #add first point to close gap var reversed=PackedVector2Array(line_road_left.points) reversed.reverse() diff --git a/scripts/menu.gd b/scripts/menu.gd index 1083ff0..2c19009 100644 --- a/scripts/menu.gd +++ b/scripts/menu.gd @@ -1,13 +1,28 @@ extends Node - @onready var countdown: Label = $MenuDisplay/countdown +@onready var btn_fullscreen = $MenuDisplay/btn_fullscreen +var keywhitelist func _ready(): removeAssignedKeys() Gamestate.removeAllPlayers() $Timer.stop() + + btn_fullscreen.button_pressed=DisplayServer.window_get_mode(0)==DisplayServer.WINDOW_MODE_FULLSCREEN #toogle fullscreen switch to correct init state + + btn_fullscreen.button_pressed=ConfigFileHandler.get_video_setting("fullscreen") + + keywhitelist=ConfigFileHandler.get_keywhitelist_setting() #empty list if disabled + print("Loaded Keywhitelist="+str(keywhitelist)) + + if keywhitelist.size()>0: #add whitelisted players if whitelist enabled and remove them afterwards to preset colors + for k in keywhitelist: + Gamestate.addPlayer(k) + Gamestate.removeAllPlayers() + + func assignKeys(): var i=0 @@ -27,17 +42,19 @@ func removeAssignedKeys(): func _unhandled_key_input(event: InputEvent) -> void: if event is InputEventKey: if event.pressed: - #print("Key keycode:"+str(event.keycode)) - var addedID=Gamestate.addPlayer(event.keycode) - - $MenuDisplay.update_playerlist(Gamestate.players) - - if addedID!=-1: - if len(Gamestate.getPlayerkeys())>=1: - $Timer.start() - else: - $Timer.stop() + if keywhitelist.has(event.keycode) or keywhitelist.size()<1: + print("Key keycode:"+str(event.keycode)) + var addedID=Gamestate.addPlayer(event.keycode) + $MenuDisplay.update_playerlist(Gamestate.players) + + if addedID!=-1: + if len(Gamestate.getPlayerkeys())>=1: + $Timer.start() + else: + $Timer.stop() + else: + print("keycode "+str(event.keycode)+" is not whitelisted") @@ -66,6 +83,7 @@ func _on_btn_fullscreen_toggled(toggled_on: bool) -> void: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) else: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) + #ConfigFileHandler.save_video_setting("fullscreen", toggled_on) func _on_rounds_selection_item_selected(index: int) -> void: @@ -75,3 +93,10 @@ func _on_rounds_selection_item_selected(index: int) -> void: func _on_map_container_map_changed() -> void: if not $Timer.is_stopped(): #only restart $Timer.start() + + +func _on_button_pressed() -> void: + if len(Gamestate.getPlayerkeys())>=1: + var _playerkeys=Gamestate.getPlayerkeys() + print("Keys ="+str(_playerkeys)) + ConfigFileHandler.save_keywhitelist_setting(_playerkeys) diff --git a/shader/menubg.gdshader b/shader/menubg.gdshader new file mode 100644 index 0000000..d67b191 --- /dev/null +++ b/shader/menubg.gdshader @@ -0,0 +1,40 @@ +shader_type canvas_item; + +#define pow2(x) (x * x) +#define iResolution vec2(0.001,0.001) + +uniform sampler2D iChannel0; +uniform float strength : hint_range(0.0, 5.0, 0.1) = 1.0; +const float pi = atan(1.0) * 4.0; +const int samples = 35; +const float sigma = float(samples) * 0.25; + +float gaussian(vec2 i) { + return 1.0 / (2.0 * pi * pow2(sigma)) * exp(-((pow2(i.x) + pow2(i.y)) / (2.0 * pow2(sigma)))); +} + +vec3 blur(sampler2D sp, vec2 uv, vec2 scale) { + vec3 col = vec3(0.0); + float accum = 0.0; + float weight; + vec2 offset; + + for (int x = -samples / 2; x < samples / 2; ++x) { + for (int y = -samples / 2; y < samples / 2; ++y) { + offset = vec2(float(x), float(y)); + weight = gaussian(offset); + col += texture(sp, uv + scale * offset).rgb * weight; + accum += weight; + } + } + + return col / accum; +} + +void fragment() { + vec2 ps = vec2(1.0) / iResolution.xy * .000001 * strength; + vec2 uv = UV ; + + COLOR.rgb = blur(iChannel0, uv, ps ); + COLOR.a = 1.0; +} \ No newline at end of file diff --git a/sprites/menu_bg.png b/sprites/menu_bg.png new file mode 100644 index 0000000..4926725 Binary files /dev/null and b/sprites/menu_bg.png differ diff --git a/sprites/menu_bg.png.import b/sprites/menu_bg.png.import new file mode 100644 index 0000000..5ecf7ee --- /dev/null +++ b/sprites/menu_bg.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bst8p5s1sgurm" +path="res://.godot/imported/menu_bg.png-93eaa1e1ebd8e5d9dbeb249ddf92d93d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://sprites/menu_bg.png" +dest_files=["res://.godot/imported/menu_bg.png-93eaa1e1ebd8e5d9dbeb249ddf92d93d.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