From b4e10d3eb5a229f213ce061ceb4124fd9e55ea45 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Sun, 24 Jan 2021 01:15:52 +1030 Subject: [PATCH] Refactor options out of InputHandler --- OptionPanel.tscn | 210 ++++++++++++++++++++++++++++++++++++++++ main.tscn | 142 +-------------------------- scripts/InputHandler.gd | 42 +------- scripts/OptionPanel.gd | 32 ++++++ 4 files changed, 249 insertions(+), 177 deletions(-) create mode 100644 OptionPanel.tscn create mode 100644 scripts/OptionPanel.gd diff --git a/OptionPanel.tscn b/OptionPanel.tscn new file mode 100644 index 0000000..7291a3f --- /dev/null +++ b/OptionPanel.tscn @@ -0,0 +1,210 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1] +[ext_resource path="res://scripts/OptionPanel.gd" type="Script" id=2] + +[sub_resource type="DynamicFont" id=4] +outline_size = 1 +outline_color = Color( 0, 0, 0, 1 ) +font_data = ExtResource( 1 ) + +[sub_resource type="Theme" id=5] +default_font = SubResource( 4 ) + +[sub_resource type="DynamicFont" id=1] +size = 24 +outline_size = 1 +outline_color = Color( 0, 0, 0, 1 ) +font_data = ExtResource( 1 ) + +[sub_resource type="GDScript" id=2] +script/source = "extends Label + +var fps: float = 0.0 +func _draw(): + set_text('FPS: %.0f' % fps) + +var last_latency_check := 0.0 +func _process(delta): + fps = Engine.get_frames_per_second() + update() +" + +[sub_resource type="GDScript" id=3] +script/source = "extends Label + +var audio_latency: float = 0.0 +func _draw(): + set_text('Audio Latency: %.2fms' % (audio_latency*1000)) + +var last_latency_check := 0.0 +func _process(delta): + last_latency_check += delta + if last_latency_check > 5.0: + last_latency_check = 0.0 + audio_latency = AudioServer.get_output_latency() # Note that on official godot builds this will only work ONCE for PulseAudio + update() +" + +[node name="OptionPanel" type="VBoxContainer"] +margin_right = 269.0 +margin_bottom = 234.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme = SubResource( 5 ) +script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="lbl_fps" type="Label" parent="."] +margin_right = 281.0 +margin_bottom = 34.0 +custom_fonts/font = SubResource( 1 ) +text = "FPS: " +script = SubResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="lbl_audiolatency" type="Label" parent="."] +margin_top = 38.0 +margin_right = 281.0 +margin_bottom = 61.0 +text = "Audio Latency: " +script = SubResource( 3 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +margin_top = 65.0 +margin_right = 281.0 +margin_bottom = 105.0 + +[node name="btn_vsync" type="CheckButton" parent="HBoxContainer"] +margin_right = 124.0 +margin_bottom = 40.0 +pressed = true +text = "Vsync" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="btn_wakelock" type="CheckButton" parent="HBoxContainer"] +margin_left = 128.0 +margin_right = 281.0 +margin_bottom = 40.0 +pressed = true +text = "Wakelock" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="lbl_subsampling" type="Label" parent="."] +margin_top = 109.0 +margin_right = 281.0 +margin_bottom = 132.0 +size_flags_vertical = 0 +text = "Subsampling (X, Y)" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="sl_SSX" type="HSlider" parent="."] +margin_top = 136.0 +margin_right = 281.0 +margin_bottom = 152.0 +size_flags_vertical = 1 +min_value = 0.1 +max_value = 1.0 +step = 0.05 +value = 1.0 +tick_count = 9 +ticks_on_borders = true +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="sl_SSY" type="HSlider" parent="."] +margin_top = 156.0 +margin_right = 281.0 +margin_bottom = 172.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_vertical = 1 +min_value = 0.1 +max_value = 1.0 +step = 0.05 +value = 1.0 +tick_count = 9 +ticks_on_borders = true +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="lbl_screenfilter" type="Label" parent="."] +margin_top = 176.0 +margin_right = 281.0 +margin_bottom = 199.0 +text = "Screen Filter Opacity" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="sl_screenfilter" type="HSlider" parent="."] +margin_top = 203.0 +margin_right = 281.0 +margin_bottom = 219.0 +max_value = 1.0 +step = 0.01 +value = 0.2 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="lbl_volume" type="Label" parent="."] +margin_top = 223.0 +margin_right = 281.0 +margin_bottom = 246.0 +text = "Main Volume" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="sl_volume" type="HSlider" parent="."] +margin_top = 250.0 +margin_right = 281.0 +margin_bottom = 266.0 +min_value = -40.0 +max_value = 0.0 +tick_count = 9 +ticks_on_borders = true +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="hbox_language" type="HBoxContainer" parent="."] +margin_top = 270.0 +margin_right = 281.0 +margin_bottom = 299.0 +custom_constants/separation = 12 + +[node name="lbl_language" type="Label" parent="hbox_language"] +margin_top = 3.0 +margin_right = 75.0 +margin_bottom = 26.0 +text = "Language" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="btn_language" type="OptionButton" parent="hbox_language"] +margin_left = 87.0 +margin_right = 281.0 +margin_bottom = 29.0 +size_flags_horizontal = 3 +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/main.tscn b/main.tscn index 657e255..11aaa81 100644 --- a/main.tscn +++ b/main.tscn @@ -12,8 +12,8 @@ [ext_resource path="res://shaders/notelines.shader" type="Shader" id=10] [ext_resource path="res://scripts/NotePainter.gd" type="Script" id=11] [ext_resource path="res://Menu.tscn" type="PackedScene" id=12] +[ext_resource path="res://OptionPanel.tscn" type="PackedScene" id=13] [ext_resource path="res://scripts/Bezel.gd" type="Script" id=15] -[ext_resource path="res://assets/NotoSans.tres" type="DynamicFont" id=16] [ext_resource path="res://scripts/InputHandler.gd" type="Script" id=17] [sub_resource type="ShaderMaterial" id=1] @@ -30,7 +30,7 @@ shader_param/px = 0.00108696 shader_param/px2 = 0.00217391 shader_param/alpha = 1.0 -[sub_resource type="ArrayMesh" id=2] +[sub_resource type="ArrayMesh" id=6] surfaces/0 = { "aabb": AABB( -481.834, -481.834, 0, 963.667, 963.667, 0 ), "array_data": PoolByteArray( 0, 0, 220, 67, 0, 0, 0, 0, 166, 59, 0, 0, 177, 234, 240, 67, 0, 0, 0, 0, 48, 60, 0, 0, 95, 168, 216, 67, 118, 207, 152, 66, 137, 59, 80, 49, 183, 65, 237, 67, 202, 86, 167, 66, 32, 60, 210, 49, 125, 187, 206, 67, 38, 125, 22, 67, 48, 59, 60, 53, 64, 99, 226, 67, 249, 203, 36, 67, 223, 59, 187, 53, 141, 134, 190, 67, 0, 0, 92, 67, 160, 58, 166, 55, 217, 163, 208, 67, 177, 234, 112, 67, 65, 59, 48, 56, 159, 135, 168, 67, 204, 105, 141, 67, 220, 57, 235, 56, 142, 141, 184, 67, 186, 219, 154, 67, 107, 58, 98, 57, 204, 105, 141, 67, 159, 135, 168, 67, 235, 56, 220, 57, 186, 219, 154, 67, 142, 141, 184, 67, 98, 57, 107, 58, 0, 0, 92, 67, 141, 134, 190, 67, 166, 55, 160, 58, 177, 234, 112, 67, 217, 163, 208, 67, 48, 56, 65, 59, 38, 125, 22, 67, 125, 187, 206, 67, 60, 53, 48, 59, 249, 203, 36, 67, 64, 99, 226, 67, 187, 53, 223, 59, 118, 207, 152, 66, 95, 168, 216, 67, 80, 49, 137, 59, 202, 86, 167, 66, 183, 65, 237, 67, 210, 49, 32, 60, 141, 172, 242, 40, 0, 0, 220, 67, 0, 0, 166, 59, 143, 223, 4, 41, 177, 234, 240, 67, 0, 0, 48, 60, 118, 207, 152, 194, 95, 168, 216, 67, 80, 177, 137, 59, 202, 86, 167, 194, 183, 65, 237, 67, 210, 177, 32, 60, 38, 125, 22, 195, 125, 187, 206, 67, 60, 181, 48, 59, 249, 203, 36, 195, 64, 99, 226, 67, 187, 181, 223, 59, 0, 0, 92, 195, 141, 134, 190, 67, 166, 183, 160, 58, 177, 234, 112, 195, 217, 163, 208, 67, 48, 184, 65, 59, 204, 105, 141, 195, 159, 135, 168, 67, 235, 184, 220, 57, 186, 219, 154, 195, 142, 141, 184, 67, 98, 185, 107, 58, 159, 135, 168, 195, 204, 105, 141, 67, 220, 185, 235, 56, 142, 141, 184, 195, 186, 219, 154, 67, 107, 186, 98, 57, 141, 134, 190, 195, 0, 0, 92, 67, 160, 186, 166, 55, 217, 163, 208, 195, 177, 234, 112, 67, 65, 187, 48, 56, 125, 187, 206, 195, 38, 125, 22, 67, 48, 187, 60, 53, 64, 99, 226, 195, 249, 203, 36, 67, 223, 187, 187, 53, 95, 168, 216, 195, 118, 207, 152, 66, 137, 187, 80, 49, 183, 65, 237, 195, 202, 86, 167, 66, 32, 188, 210, 49, 0, 0, 220, 195, 141, 172, 114, 41, 166, 187, 0, 0, 177, 234, 240, 195, 143, 223, 132, 41, 48, 188, 0, 0, 95, 168, 216, 195, 118, 207, 152, 194, 137, 187, 80, 177, 183, 65, 237, 195, 202, 86, 167, 194, 32, 188, 210, 177, 125, 187, 206, 195, 38, 125, 22, 195, 48, 187, 60, 181, 64, 99, 226, 195, 249, 203, 36, 195, 223, 187, 187, 181, 141, 134, 190, 195, 0, 0, 92, 195, 160, 186, 166, 183, 217, 163, 208, 195, 177, 234, 112, 195, 65, 187, 48, 184, 159, 135, 168, 195, 204, 105, 141, 195, 220, 185, 235, 184, 142, 141, 184, 195, 186, 219, 154, 195, 107, 186, 98, 185, 204, 105, 141, 195, 159, 135, 168, 195, 235, 184, 220, 185, 186, 219, 154, 195, 142, 141, 184, 195, 98, 185, 107, 186, 0, 0, 92, 195, 141, 134, 190, 195, 166, 183, 160, 186, 177, 234, 112, 195, 217, 163, 208, 195, 48, 184, 65, 187, 38, 125, 22, 195, 125, 187, 206, 195, 60, 181, 48, 187, 249, 203, 36, 195, 64, 99, 226, 195, 187, 181, 223, 187, 118, 207, 152, 194, 95, 168, 216, 195, 80, 177, 137, 187, 202, 86, 167, 194, 183, 65, 237, 195, 210, 177, 32, 188, 106, 1, 182, 169, 0, 0, 220, 195, 0, 0, 166, 187, 87, 79, 199, 169, 177, 234, 240, 195, 0, 0, 48, 188, 118, 207, 152, 66, 95, 168, 216, 195, 80, 49, 137, 187, 202, 86, 167, 66, 183, 65, 237, 195, 210, 49, 32, 188, 38, 125, 22, 67, 125, 187, 206, 195, 60, 53, 48, 187, 249, 203, 36, 67, 64, 99, 226, 195, 187, 53, 223, 187, 0, 0, 92, 67, 141, 134, 190, 195, 166, 55, 160, 186, 177, 234, 112, 67, 217, 163, 208, 195, 48, 56, 65, 187, 204, 105, 141, 67, 159, 135, 168, 195, 235, 56, 220, 185, 186, 219, 154, 67, 142, 141, 184, 195, 98, 57, 107, 186, 159, 135, 168, 67, 204, 105, 141, 195, 220, 57, 235, 184, 142, 141, 184, 67, 186, 219, 154, 195, 107, 58, 98, 185, 141, 134, 190, 67, 0, 0, 92, 195, 160, 58, 166, 183, 217, 163, 208, 67, 177, 234, 112, 195, 65, 59, 48, 184, 125, 187, 206, 67, 38, 125, 22, 195, 48, 59, 60, 181, 64, 99, 226, 67, 249, 203, 36, 195, 223, 59, 187, 181, 95, 168, 216, 67, 118, 207, 152, 194, 137, 59, 80, 177, 183, 65, 237, 67, 202, 86, 167, 194, 32, 60, 210, 177, 0, 0, 220, 67, 0, 0, 0, 0, 166, 59, 0, 0, 177, 234, 240, 67, 0, 0, 0, 0, 48, 60, 0, 0 ), @@ -101,7 +101,7 @@ script = ExtResource( 3 ) [node name="Receptors" type="MeshInstance2D" parent="."] material = SubResource( 1 ) -mesh = SubResource( 2 ) +mesh = SubResource( 6 ) script = ExtResource( 5 ) [node name="Tween" type="Tween" parent="Receptors"] @@ -139,146 +139,14 @@ script = ExtResource( 11 ) [node name="Bezel" type="Node2D" parent="."] script = ExtResource( 15 ) -[node name="InputHandler" type="Label" parent="."] +[node name="InputHandler" type="Control" parent="."] margin_left = -540.0 margin_top = -540.0 margin_right = 540.0 margin_bottom = 540.0 -custom_fonts/font = ExtResource( 16 ) -text = "FPS: -Audio Latency:" script = ExtResource( 17 ) __meta__ = { "_edit_use_anchors_": false } -[node name="Label" type="Label" parent="InputHandler"] -margin_top = 136.0 -margin_right = 116.0 -margin_bottom = 150.0 -text = "Subsampling (X, Y)" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="SSXSlider" type="HSlider" parent="InputHandler"] -margin_left = 10.0 -margin_top = 150.0 -margin_right = 250.0 -margin_bottom = 166.0 -grow_horizontal = 2 -grow_vertical = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 -min_value = 0.1 -max_value = 1.0 -step = 0.05 -value = 1.0 -tick_count = 9 -ticks_on_borders = true -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="SSYSlider" type="HSlider" parent="InputHandler"] -margin_left = 10.0 -margin_top = 173.0 -margin_right = 250.0 -margin_bottom = 189.0 -grow_horizontal = 2 -grow_vertical = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 -min_value = 0.1 -max_value = 1.0 -step = 0.05 -value = 1.0 -tick_count = 9 -ticks_on_borders = true -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Label2" type="Label" parent="InputHandler"] -margin_top = 200.0 -margin_right = 133.0 -margin_bottom = 214.0 -text = "Screen Filter Opacity" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="FilterSlider" type="HSlider" parent="InputHandler"] -margin_left = 10.0 -margin_top = 218.0 -margin_right = 250.0 -margin_bottom = 234.0 -max_value = 1.0 -step = 0.01 -value = 0.2 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Label3" type="Label" parent="InputHandler"] -margin_top = 240.0 -margin_right = 133.0 -margin_bottom = 254.0 -text = "Main Volume" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="VolumeSlider" type="HSlider" parent="InputHandler"] -margin_left = 10.0 -margin_top = 260.0 -margin_right = 250.0 -margin_bottom = 276.0 -min_value = -40.0 -max_value = 0.0 -tick_count = 9 -ticks_on_borders = true -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Label4" type="Label" parent="InputHandler"] -margin_top = 293.0 -margin_right = 133.0 -margin_bottom = 254.0 -text = "Language" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="BtnLanguage" type="OptionButton" parent="InputHandler"] -margin_left = 65.0 -margin_top = 290.0 -margin_right = 200.0 -margin_bottom = 310.0 -text = "Native" -align = 1 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="VsyncButton" type="CheckButton" parent="InputHandler"] -margin_top = 90.0 -margin_right = 117.0 -margin_bottom = 130.0 -pressed = true -text = "Vsync" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="WakelockButton" type="CheckButton" parent="InputHandler"] -margin_left = 110.0 -margin_top = 90.0 -margin_right = 251.0 -margin_bottom = 130.0 -pressed = true -text = "Wakelock" -__meta__ = { -"_edit_use_anchors_": false -} +[node name="OptionPanel" parent="." instance=ExtResource( 13 )] diff --git a/scripts/InputHandler.gd b/scripts/InputHandler.gd index 36519b7..3c5c2a0 100644 --- a/scripts/InputHandler.gd +++ b/scripts/InputHandler.gd @@ -1,4 +1,4 @@ -extends Label +extends Control var touch_points = {} # dict containing all points touched on the screen var touch_positions = [] # array of above @@ -36,44 +36,12 @@ func _ready(): set_process_unhandled_input(true) # process user input set_fingers(0) # connect('button_pressed', self, 'print_pressed') - $'/root'.connect('size_changed', self, 'resize') - $VsyncButton.connect('toggled', self, 'update_vsync') - $WakelockButton.connect('toggled', self, 'update_wakelock') - $FilterSlider.connect('value_changed', self, 'update_filter') - $VolumeSlider.connect('value_changed', self, 'update_volume') - $SSXSlider.connect('value_changed', Settings, 'SSX_set') - $SSYSlider.connect('value_changed', Settings, 'SSY_set') - $BtnLanguage.add_item('Native') - $BtnLanguage.add_item('Romaji') - $BtnLanguage.add_item('English') - $BtnLanguage.connect('item_selected', self, 'update_display_language') resize() -func update_vsync(setting: bool): - OS.vsync_enabled = setting - -func update_wakelock(setting: bool): - OS.keep_screen_on = setting # This is waiting on godotengine/godot#35536 to be merged to do anything in Linux :( - -func update_filter(alpha: float): - GameTheme.screen_filter_min_alpha = alpha - -func update_volume(volume: float): - AudioServer.set_bus_volume_db(0, volume) - -func update_display_language(index: int): - GameTheme.display_language = ['n', 'tl', 'en'][index] - func print_pressed(col: int): print('Pressed %d'%col) - -########################################################################## -# draw fingers points on screen -var fps: float = 0.0 -var audio_latency: float = 0.0 -func _draw(): - set_text('FPS: %.0f\nAudio Latency: %.2fms'%[fps, audio_latency*1000]) +func _draw(): # draw fingers points on screen # var swipe_origin = Vector2(300, 540) # draw_line(swipe_origin, swipe_origin+swipe_momentum, Color.red) @@ -90,16 +58,10 @@ func _draw(): # # Draw line # draw_line(touch_positions[i], touch_positions[i+1], Color(1,1,1,1)) -var last_latency_check := 0.0 func _process(delta): swipe_momentum *= max(1.0 - 5.0*delta, 0) if swipe_momentum.length_squared() < 1.0: swipe_momentum = Vector2.ZERO - last_latency_check += delta - fps = Engine.get_frames_per_second() - if last_latency_check > 3.0: - last_latency_check = 0.0 - audio_latency = AudioServer.get_output_latency() # Note that on official godot builds this will only work ONCE for PulseAudio update() func update_data(): diff --git a/scripts/OptionPanel.gd b/scripts/OptionPanel.gd new file mode 100644 index 0000000..6f90205 --- /dev/null +++ b/scripts/OptionPanel.gd @@ -0,0 +1,32 @@ +extends VBoxContainer + +func resize(): + var screen_size = $'/root'.get_visible_rect().size + rect_position = -screen_size*0.5 +# rect_size = screen_size + +export var btn_language: NodePath = @"hbox_language/btn_language" +onready var BtnLanguage = get_node(btn_language) +func _ready() -> void: + $'/root'.connect('size_changed', self, 'resize') + $HBoxContainer/btn_vsync.connect('toggled', OS, 'set_use_vsync') + $HBoxContainer/btn_wakelock.connect('toggled', OS, 'set_keep_screen_on') # This is waiting on godotengine/godot#35536 to be merged to do anything in Linux :( + $sl_screenfilter.connect('value_changed', self, 'update_filter') + $sl_volume.connect('value_changed', self, 'update_volume') + $sl_SSX.connect('value_changed', Settings, 'SSX_set') + $sl_SSY.connect('value_changed', Settings, 'SSY_set') + BtnLanguage.add_item('Native') + BtnLanguage.add_item('Romaji') + BtnLanguage.add_item('English') + BtnLanguage.connect('item_selected', self, 'update_display_language') + resize() + + +func update_filter(alpha: float): + GameTheme.screen_filter_min_alpha = alpha + +func update_volume(volume: float): + AudioServer.set_bus_volume_db(0, volume) + +func update_display_language(index: int): + GameTheme.display_language = ['n', 'tl', 'en'][index]