Skip to content

Commit

Permalink
IMPROVEMENT: Render quality slider and filter button implemented. Bac…
Browse files Browse the repository at this point in the history
…kspace now hides the bottom bar.
  • Loading branch information
roalyr committed Oct 29, 2021
1 parent 7cd14f1 commit 78a0719
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 21 deletions.
1 change: 1 addition & 0 deletions Default_env.tres
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ background_color = Color( 0.0156863, 0.0156863, 0.0745098, 1 )
fog_color = Color( 0, 0, 0, 1 )
fog_sun_color = Color( 0, 0, 0, 1 )
tonemap_mode = 3
glow_bicubic_upscale = true
4 changes: 1 addition & 3 deletions Scenes/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ __meta__ = {
[node name="View" type="Viewport" parent="."]
size = Vector2( 1024, 600 )
handle_input_locally = false
msaa = 1
render_target_update_mode = 3
script = ExtResource( 13 )
scale_factor = 1.0

[node name="Main" type="Spatial" parent="View"]
script = ExtResource( 1 )
Expand Down Expand Up @@ -72,5 +72,3 @@ accel_ticks_max = 100

[node name="Camera_rig" parent="View/Main/Player_ship" instance=ExtResource( 2 )]
script = ExtResource( 7 )

[connection signal="size_changed" from="View" to="View" method="_on_View_size_changed"]
18 changes: 9 additions & 9 deletions Scenes/Systems/System_1.tscn

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions Scenes/UI/UI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ __meta__ = {
}

[node name="_ColorRect" type="ColorRect" parent="Main3D/Debug"]
visible = false
material = SubResource( 2 )
anchor_right = 1.0
anchor_bottom = 1.0
Expand Down Expand Up @@ -121,6 +122,7 @@ __meta__ = {
}

[node name="_ColorRect" type="ColorRect" parent="Main3D/Text_panel"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.529412, 0.258824, 0.360784, 1 )
Expand Down Expand Up @@ -223,10 +225,43 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Button_screen_filter" type="Button" parent="Controls"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -168.0
margin_top = 40.0
margin_right = -87.0
margin_bottom = 60.0
toggle_mode = true
keep_pressed_outside = true
text = "Scren filter"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Slider_screen_res" type="HSlider" parent="Controls"]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -168.0
margin_top = 8.0
margin_right = -88.0
margin_bottom = 28.0
min_value = 0.1
max_value = 1.0
step = 0.1
value = 0.7
tick_count = 10
ticks_on_borders = true
__meta__ = {
"_edit_use_anchors_": false
}

[connection signal="mouse_entered" from="Main3D" to="." method="_on_Viewport_main_mouse_entered"]
[connection signal="mouse_exited" from="Main3D" to="." method="_on_Viewport_main_mouse_exited"]
[connection signal="resized" from="Main3D" to="." method="_on_Viewport_main_resized"]
[connection signal="toggled" from="Controls/Button_turret" to="." method="_on_Button_turret_toggled"]
[connection signal="toggled" from="Controls/Button_debug" to="." method="_on_Button_debug_toggled"]
[connection signal="toggled" from="Controls/Button_text_panel" to="." method="_on_Button_text_panel_toggled"]
[connection signal="pressed" from="Controls/Button_quit" to="." method="_on_Button_quit_pressed"]
[connection signal="toggled" from="Controls/Button_screen_filter" to="." method="_on_Button_screen_filter_toggled"]
[connection signal="value_changed" from="Controls/Slider_screen_res" to="." method="_on_Slider_screen_res_value_changed"]
1 change: 1 addition & 0 deletions Scripts/Camera_rig.gd
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func zoom_camera(mouse_event):
zoom_ticks -= 1
$Camera.translation.z = current_zoom

# ============================ Signal processing ==============================
func is_turret_mode_on(flag):
if flag:
# Reset camera first.
Expand Down
19 changes: 17 additions & 2 deletions Scripts/Input.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ var player_ship_state = Node
var signals = Node
var ui = Node
var ui_button_turret = Node
var ui_controls_bar = Node

func _ready():
# ============================ Initialize nodes ===========================
camera_rig = get_node("/root/Cont/View/Main/Player_ship/Camera_rig")
player_ship_state = get_node("/root/Cont/View/Main/State/Player_ship")
signals = get_node("/root/Cont/View/Main/Input/Signals")
ui = get_node("/root/Cont/UI")
ui_controls_bar = get_node("/root/Cont/UI/Controls")
ui_button_turret = get_node("/root/Cont/UI/Controls/Button_turret")
# ============================ Connect signals ============================
signals.connect("sig_mouse_on_viewport", self, "is_mouse_on_viewport")
Expand Down Expand Up @@ -72,9 +74,10 @@ func _input(event):
if event is InputEventMouseButton and player_ship_state.turret_mode:
camera_rig.zoom_camera(event)

# ======================= For keyboard buttons ========================
# ======================= For keyboard buttons =========================
if event is InputEventKey:

# ============================ UI Controls =========================
# Mouse flight.
if event.pressed and event.scancode == KEY_SPACE:
if player_ship_state.mouse_flight:
Expand All @@ -84,11 +87,22 @@ func _input(event):
player_ship_state.mouse_flight = true
signals.emit_signal("sig_mouse_flight_on", true)

# TODO: Should also be accessible from other areas and windows.
# Show toolbar.
if event.pressed and event.scancode == KEY_BACKSPACE:
if ui_controls_bar.visible:
ui_controls_bar.visible = false
else:
ui_controls_bar.visible = true


# Turret mode. UI shortcut. Signal is emitted by UI.
if event.pressed and event.scancode == KEY_H:
if not player_ship_state.turret_mode: ui_button_turret.pressed = true
if not player_ship_state.turret_mode:
ui_button_turret.pressed = true
else: ui_button_turret.pressed = false

# ============================= Ship controls ======================
# Accelerate forward.
# TODO: unique signals for simultaneous action.
if event.pressed and event.scancode == KEY_UP:
Expand Down Expand Up @@ -145,6 +159,7 @@ func _input(event):
# ============================ Signal processing ==============================
# Check if viewport resized and get new values. Required for mouse coordinates.
func is_viewport_update():
# For mouse coords.
viewport_size = OS.window_size

# Check if we are hovering mouse over the control bar.
Expand Down
2 changes: 2 additions & 0 deletions Scripts/Signals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ extends Node
# warning-ignore-all:unused_signal
# ============================== Generic =====================================
signal sig_mouse_on_viewport(flag)
signal sig_screen_filter_on(flag)
signal sig_screen_res_value_changed(value)
signal sig_viewport_update
signal sig_quit_game

Expand Down
7 changes: 7 additions & 0 deletions Scripts/UI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ func _on_Button_debug_toggled(button_pressed):
func _on_Button_text_panel_toggled(button_pressed):
if button_pressed: text_panel.show()
else: text_panel.hide()

func _on_Button_screen_filter_toggled(button_pressed):
if button_pressed: signals.emit_signal("sig_screen_filter_on", true)
else: signals.emit_signal("sig_screen_filter_on", false)

func _on_Slider_screen_res_value_changed(value):
signals.emit_signal("sig_screen_res_value_changed", value)
37 changes: 30 additions & 7 deletions Scripts/View.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
extends Viewport

export var scale_factor = 0.65
# Values.
# TODO: Throw it into options and sync with slider
var screen_res_factor = 0.7
# Objects.
# Parameters.
# Nodes.
var signals = Node

func _ready():
self.get_texture().flags = Texture.FLAG_FILTER
self.size = Vector2(1024, 600)*scale_factor
# ======================Z====== Initialize nodes ===========================
signals = get_node("/root/Cont/View/Main/Input/Signals")
# ============================ Connect signals ============================
signals.connect("sig_screen_filter_on", self, "is_screen_filter_on")
signals.connect("sig_viewport_update", self, "is_viewport_update")
signals.connect("sig_screen_res_value_changed", self, "is_screen_res_value_changed")
# =========================================================================


# ============================ Signal processing ==============================
func is_screen_filter_on(flag):
if flag:
self.get_texture().flags = Texture.FLAG_FILTER
print("ON")
else:
self.get_texture().flags = !Texture.FLAG_FILTER
print("OFF")

func is_viewport_update():
self.size = OS.window_size*screen_res_factor

# TODO: implement ratio setting, factor, size

func _on_View_size_changed():
self.size = Vector2(1024, 600)*scale_factor
func is_screen_res_value_changed(value):
screen_res_factor = value
self.size = OS.window_size*screen_res_factor

0 comments on commit 78a0719

Please sign in to comment.