Skip to content

Commit

Permalink
move custom code to base system
Browse files Browse the repository at this point in the history
  • Loading branch information
myin142 committed Oct 29, 2023
1 parent d35f533 commit 1d9f739
Show file tree
Hide file tree
Showing 161 changed files with 15,446 additions and 312 deletions.
23 changes: 23 additions & 0 deletions godot/addons/base-system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Base system

1. [Base](#base) - generic nodes that did not yet for any groups
1. [Input](#input)
1. [Menu](#menu)
1. [Save](#save)

## Base

## Input

- `PlayerInput`: input for a single player
- `DeviceSwitcher`: add as child to a player input to switch between controller and keyboard

## Menu

TODO

## Save

- `CacheManager`: save data for all `Persist` groups within the scene. Scene names has to be unique
- `SaveManager`: saves data to a file, accessed by a slot number
- `CacheProperies`: define properties to be saved by `CacheManager` for a node
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
extends Node

@export var input_path: NodePath
@onready var input: PlayerInput = get_node(input_path) if input_path else get_parent()
@export var input: PlayerInput

var logger = Logger.new("DeviceSwitcher")


func _unhandled_input(event: InputEvent):
if event.device != input.device_id or input.is_player_event(event):
if input == null or event.device != input.device_id or input.is_player_event(event):
return

var joypad = event is InputEventJoypadButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ func handle_input(event: InputEvent):
continue

action_strength[action] = event.get_action_strength(action)

if actions.size() > 0:
_register_action(event, actions[0])
_register_action(event, action)


func _register_action(event: InputEvent, action: String):
Expand Down Expand Up @@ -70,11 +68,14 @@ func get_action_strength(key: String) -> float:

func disable(exceptions: Array = []) -> void:
self._disabled = true
inputs.clear()
action_strength.clear()
reset()
disabled_exception = exceptions


func enable() -> void:
self._disabled = false
disabled_exception = []

func reset() -> void:
inputs.clear()
action_strength.clear()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://blurtq1v44gav"]

[ext_resource type="Script" path="res://addons/menu-system/RemapButton.gd" id="1"]
[ext_resource type="Script" path="res://addons/base-system/menu/RemapButton.gd" id="1"]

[node name="RemapButton" type="Button"]
anchors_preset = 15
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion godot/addons/debug/Env.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ func is_web() -> bool:
return OS.has_feature("web")

func is_demo() -> bool:
return _demo
return _demo
127 changes: 127 additions & 0 deletions godot/addons/gut/GutScene.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
extends Node2D
# ##############################################################################
# This is a wrapper around the normal and compact gui controls and serves as
# the interface between gut.gd and the gui. The GutRunner creates an instance
# of this and then this takes care of managing the different GUI controls.
# ##############################################################################
@onready var _normal_gui = $Normal
@onready var _compact_gui = $Compact

var gut = null :
set(val):
gut = val
_set_gut(val)


func _ready():
_normal_gui.switch_modes.connect(use_compact_mode.bind(true))
_compact_gui.switch_modes.connect(use_compact_mode.bind(false))

_normal_gui.set_title("GUT")
_compact_gui.set_title("GUT")

_normal_gui.align_right()
_compact_gui.to_bottom_right()

use_compact_mode(false)

if(get_parent() == get_tree().root):
_test_running_setup()

func _test_running_setup():
set_font_size(100)
_normal_gui.get_textbox().text = "hello world, how are you doing?"

# ------------------------
# Private
# ------------------------
func _set_gut(val):
if(_normal_gui.get_gut() == val):
return
_normal_gui.set_gut(val)
_compact_gui.set_gut(val)

val.start_run.connect(_on_gut_start_run)
val.end_run.connect(_on_gut_end_run)
val.start_pause_before_teardown.connect(_on_gut_pause)
val.end_pause_before_teardown.connect(_on_pause_end)

func _set_both_titles(text):
_normal_gui.set_title(text)
_compact_gui.set_title(text)


# ------------------------
# Events
# ------------------------
func _on_gut_start_run():
_set_both_titles('Running')

func _on_gut_end_run():
_set_both_titles('Finished')

func _on_gut_pause():
_set_both_titles('-- Paused --')

func _on_pause_end():
_set_both_titles('Running')


# ------------------------
# Public
# ------------------------
func get_textbox():
return _normal_gui.get_textbox()


func set_font_size(new_size):
var rtl = _normal_gui.get_textbox()

rtl.set('theme_override_font_sizes/bold_italics_font_size', new_size)
rtl.set('theme_override_font_sizes/bold_font_size', new_size)
rtl.set('theme_override_font_sizes/italics_font_size', new_size)
rtl.set('theme_override_font_sizes/normal_font_size', new_size)


func set_font(font_name):
_set_all_fonts_in_rtl(_normal_gui.get_textbox(), font_name)


func _set_font(rtl, font_name, custom_name):
if(font_name == null):
rtl.add_theme_font_override(custom_name, null)
else:
var dyn_font = FontFile.new()
dyn_font.load_dynamic_font('res://addons/gut/fonts/' + font_name + '.ttf')
rtl.add_theme_font_override(custom_name, dyn_font)


func _set_all_fonts_in_rtl(rtl, base_name):
if(base_name == 'Default'):
_set_font(rtl, null, 'normal_font')
_set_font(rtl, null, 'bold_font')
_set_font(rtl, null, 'italics_font')
_set_font(rtl, null, 'bold_italics_font')
else:
_set_font(rtl, base_name + '-Regular', 'normal_font')
_set_font(rtl, base_name + '-Bold', 'bold_font')
_set_font(rtl, base_name + '-Italic', 'italics_font')
_set_font(rtl, base_name + '-BoldItalic', 'bold_italics_font')


func set_default_font_color(color):
_normal_gui.get_textbox().set('custom_colors/default_color', color)


func set_background_color(color):
_normal_gui.set_bg_color(color)


func use_compact_mode(should=true):
_compact_gui.visible = should
_normal_gui.visible = !should


func set_opacity(val):
_normal_gui.modulate.a = val
_compact_gui.modulate.a = val
16 changes: 16 additions & 0 deletions godot/addons/gut/GutScene.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[gd_scene load_steps=4 format=3 uid="uid://m28heqtswbuq"]

[ext_resource type="Script" path="res://addons/gut/GutScene.gd" id="1_b4m8y"]
[ext_resource type="PackedScene" uid="uid://duxblir3vu8x7" path="res://addons/gut/gui/NormalGui.tscn" id="2_j6ywb"]
[ext_resource type="PackedScene" uid="uid://cnqqdfsn80ise" path="res://addons/gut/gui/MinGui.tscn" id="3_3glw1"]

[node name="GutScene" type="Node2D"]
script = ExtResource("1_b4m8y")

[node name="Normal" parent="." instance=ExtResource("2_j6ywb")]

[node name="Compact" parent="." instance=ExtResource("3_3glw1")]
offset_left = 5.0
offset_top = 273.0
offset_right = 265.0
offset_bottom = 403.0
22 changes: 22 additions & 0 deletions godot/addons/gut/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)
=====================

Copyright (c) 2018 Tom "Butch" Wesley

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
52 changes: 52 additions & 0 deletions godot/addons/gut/UserFileViewer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
extends Window

@onready var rtl = $TextDisplay/RichTextLabel

func _get_file_as_text(path):
var to_return = null
var f = FileAccess.open(path, FileAccess.READ)
if(f != null):
to_return = f.get_as_text()
else:
to_return = str('ERROR: Could not open file. Error code ', FileAccess.get_open_error())
return to_return

func _ready():
rtl.clear()

func _on_OpenFile_pressed():
$FileDialog.popup_centered()

func _on_FileDialog_file_selected(path):
show_file(path)

func _on_Close_pressed():
self.hide()

func show_file(path):
var text = _get_file_as_text(path)
if(text == ''):
text = '<Empty File>'
rtl.set_text(text)
self.window_title = path

func show_open():
self.popup_centered()
$FileDialog.popup_centered()

func get_rich_text_label():
return $TextDisplay/RichTextLabel

func _on_Home_pressed():
rtl.scroll_to_line(0)

func _on_End_pressed():
rtl.scroll_to_line(rtl.get_line_count() -1)

func _on_Copy_pressed():
return
# OS.clipboard = rtl.text

func _on_file_dialog_visibility_changed():
if rtl.text.length() == 0 and not $FileDialog.visible:
self.hide()
92 changes: 92 additions & 0 deletions godot/addons/gut/UserFileViewer.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[gd_scene load_steps=2 format=3 uid="uid://bsm7wtt1gie4v"]

[ext_resource type="Script" path="res://addons/gut/UserFileViewer.gd" id="1"]

[node name="UserFileViewer" type="Window"]
exclusive = true
script = ExtResource("1")

[node name="FileDialog" type="FileDialog" parent="."]
access = 1
show_hidden_files = true
__meta__ = {
"_edit_use_anchors_": false
}

[node name="TextDisplay" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 8.0
offset_right = -10.0
offset_bottom = -65.0
color = Color(0.2, 0.188235, 0.188235, 1)

[node name="RichTextLabel" type="RichTextLabel" parent="TextDisplay"]
anchor_right = 1.0
anchor_bottom = 1.0
focus_mode = 2
text = "In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used before final copy is available, but it may also be used to temporarily replace copy in a process called greeking, which allows designers to consider form without the meaning of the text influencing the design.
Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a first-century BCE text by the Roman statesman and philosopher Cicero, with words altered, added, and removed to make it nonsensical, improper Latin.
Versions of the Lorem ipsum text have been used in typesetting at least since the 1960s, when it was popularized by advertisements for Letraset transfer sheets. Lorem ipsum was introduced to the digital world in the mid-1980s when Aldus employed it in graphic and word-processing templates for its desktop publishing program PageMaker. Other popular word processors including Pages and Microsoft Word have since adopted Lorem ipsum as well."
selection_enabled = true

[node name="OpenFile" type="Button" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -158.0
offset_top = -50.0
offset_right = -84.0
offset_bottom = -30.0
text = "Open File"

[node name="Home" type="Button" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -478.0
offset_top = -50.0
offset_right = -404.0
offset_bottom = -30.0
text = "Home"

[node name="Copy" type="Button" parent="."]
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 160.0
offset_top = -50.0
offset_right = 234.0
offset_bottom = -30.0
text = "Copy"

[node name="End" type="Button" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -318.0
offset_top = -50.0
offset_right = -244.0
offset_bottom = -30.0
text = "End"

[node name="Close" type="Button" parent="."]
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 10.0
offset_top = -50.0
offset_right = 80.0
offset_bottom = -30.0
text = "Close"

[connection signal="file_selected" from="FileDialog" to="." method="_on_FileDialog_file_selected"]
[connection signal="visibility_changed" from="FileDialog" to="." method="_on_file_dialog_visibility_changed"]
[connection signal="pressed" from="OpenFile" to="." method="_on_OpenFile_pressed"]
[connection signal="pressed" from="Home" to="." method="_on_Home_pressed"]
[connection signal="pressed" from="Copy" to="." method="_on_Copy_pressed"]
[connection signal="pressed" from="End" to="." method="_on_End_pressed"]
[connection signal="pressed" from="Close" to="." method="_on_Close_pressed"]
Loading

0 comments on commit 1d9f739

Please sign in to comment.