Skip to content

Instantly share code, notes, and snippets.

@ZodmanPerth
Last active December 30, 2018 08:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ZodmanPerth/72e45974a579cbca22255e40169f4f28 to your computer and use it in GitHub Desktop.
Godot Dynamic Menu for Capability Tests. Blog post at http://www.redperegrine.net/2018/09/26/menu-all-gui/
extends Node
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
var appInstance = load("res://game/menu/Main.tscn").instance()
add_child(appInstance)
[gd_scene load_steps=2 format=2]
[ext_resource path="res://game.gd" type="Script" id=1]
[node name="game" type="Node"]
script = ExtResource( 1 )
# This is the script for the menu scene "Main.tscn"
extends Node
onready var MenuContainer = $menuContainer
onready var SceneButtonGrid = $menuContainer/VBoxContainer/MarginContainer/SceneButtonGrid
var Apps = [
{
name = "Touch Manipulation",
thumbnail = "res://game/menu/thumbnails/ManipulationTest.png",
path = "res://touchInput/touchInput.tscn",
},
{
name = "Accelerometer",
thumbnail = "res://game/menu/thumbnails/AccelerometerTest.png",
path = "res://sensorInput/sensorInput.tscn",
},
]
func _ready():
for app in Apps:
var sceneButton = load("res://game/menu/SceneButton.tscn").instance()
sceneButton.Initialise(app.name, app.thumbnail, app.path)
sceneButton.connect("pressed", self, "OnButtonPressed")
SceneButtonGrid.add_child(sceneButton)
func OnButtonPressed(scenePath):
var appInstance = load(scenePath).instance()
add_child(appInstance)
remove_child(MenuContainer)
[gd_scene load_steps=4 format=2]
[ext_resource path="res://game/menu/Main.gd" type="Script" id=1]
[ext_resource path="res://test/uiLayout/theme.tres" type="Theme" id=2]
[ext_resource path="res://test/uiLayout/TitleFont.tres" type="DynamicFont" id=3]
[node name="Main" type="Node"]
script = ExtResource( 1 )
[node name="menuContainer" type="MarginContainer" parent="." index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
theme = ExtResource( 2 )
custom_constants/margin_right = 120
custom_constants/margin_top = 100
custom_constants/margin_left = 120
custom_constants/margin_bottom = 100
_sections_unfolded = [ "Margin", "Theme", "custom_constants" ]
[node name="VBoxContainer" type="VBoxContainer" parent="menuContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 120.0
margin_top = 100.0
margin_right = 1928.0
margin_bottom = 1052.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
[node name="Label" type="Label" parent="menuContainer/VBoxContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 1808.0
margin_bottom = 72.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
theme = ExtResource( 2 )
custom_fonts/font = ExtResource( 3 )
text = "CAPABILITY TESTS"
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Theme", "custom_fonts" ]
[node name="MarginContainer" type="MarginContainer" parent="menuContainer/VBoxContainer" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 76.0
margin_right = 1808.0
margin_bottom = 952.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 3
custom_constants/margin_top = 60
_sections_unfolded = [ "Size Flags", "custom_constants" ]
[node name="SceneButtonGrid" type="GridContainer" parent="menuContainer/VBoxContainer/MarginContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 60.0
margin_bottom = 60.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 2
size_flags_vertical = 2
custom_constants/vseparation = 30
custom_constants/hseparation = 40
columns = 5
_sections_unfolded = [ "Margin", "Rect", "Size Flags", "custom_constants" ]
extends Control
signal pressed(pathToScene)
export(String) var Title = "Name of app"
export(String, FILE, '*.gd') var Thumbnail = 'res://game/menu/thumbnails/sample.png'
export(String, FILE, '*.gd') var ScenePath = 'res://touchInput/touchInput.tscn'
onready var titleNode = $Panel/MarginContainer/Button/VBoxContainer/LabelMargin/Label
onready var imageNode = $Panel/MarginContainer/Button/VBoxContainer/ImageMargin/TextureRect
onready var buttonNode = $Panel/MarginContainer/Button
func Initialise(title, thumbnail, scenePath):
if title != "":
Title = title.to_upper()
if thumbnail != "":
Thumbnail = thumbnail
ScenePath = scenePath
func _ready():
titleNode.text = Title
imageNode.texture = load(Thumbnail)
buttonNode.connect("pressed", self, "OnButtonPressed")
func OnButtonPressed():
emit_signal("pressed", ScenePath)
[gd_scene load_steps=5 format=2]
[ext_resource path="res://game/menu/theme.tres" type="Theme" id=1]
[ext_resource path="res://game/menu/SceneButton.gd" type="Script" id=2]
[ext_resource path="res://icon.png" type="Texture" id=3]
[sub_resource type="StyleBoxFlat" id=1]
content_margin_left = -1.0
content_margin_right = -1.0
content_margin_top = -1.0
content_margin_bottom = -1.0
bg_color = Color( 0.135117, 0.160484, 0.214844, 1 )
draw_center = true
border_width_left = 0
border_width_top = 0
border_width_right = 0
border_width_bottom = 0
border_color = Color( 0.8, 0.8, 0.8, 1 )
border_blend = false
corner_radius_top_left = 0
corner_radius_top_right = 0
corner_radius_bottom_right = 0
corner_radius_bottom_left = 0
corner_detail = 8
expand_margin_left = 0.0
expand_margin_right = 0.0
expand_margin_top = 0.0
expand_margin_bottom = 0.0
shadow_color = Color( 0, 0, 0, 0.6 )
shadow_size = 0
anti_aliasing = true
anti_aliasing_size = 1
[node name="SceneButton" type="Control" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_min_size = Vector2( 440, 300 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
theme = ExtResource( 1 )
script = ExtResource( 2 )
_sections_unfolded = [ "Mouse", "Theme" ]
Title = "Name of app"
Thumbnail = "res://game/menu/thumbnails/sample.png"
ScenePath = "res://touchInput/touchInput.tscn"
[node name="Panel" type="Panel" parent="." index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_styles/panel = SubResource( 1 )
_sections_unfolded = [ "Mouse", "custom_styles" ]
[node name="MarginContainer" type="MarginContainer" parent="Panel" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/margin_right = 10
custom_constants/margin_top = 10
custom_constants/margin_left = 10
custom_constants/margin_bottom = 10
_sections_unfolded = [ "Mouse", "Size Flags", "custom_constants" ]
[node name="Button" type="Button" parent="Panel/MarginContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 10.0
margin_top = 10.0
margin_right = 2038.0
margin_bottom = 1142.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
flat = false
align = 1
_sections_unfolded = [ "Mouse", "Size Flags" ]
[node name="VBoxContainer" type="VBoxContainer" parent="Panel/MarginContainer/Button" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0
_sections_unfolded = [ "Mouse", "custom_constants" ]
[node name="ImageMargin" type="MarginContainer" parent="Panel/MarginContainer/Button/VBoxContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 2028.0
margin_bottom = 1060.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/margin_right = 20
custom_constants/margin_top = 30
custom_constants/margin_left = 20
custom_constants/margin_bottom = 30
_sections_unfolded = [ "Mouse", "custom_constants" ]
[node name="TextureRect" type="TextureRect" parent="Panel/MarginContainer/Button/VBoxContainer/ImageMargin" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 20.0
margin_top = 30.0
margin_right = 2008.0
margin_bottom = 1030.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
texture = ExtResource( 3 )
expand = true
stretch_mode = 6
_sections_unfolded = [ "Mouse", "Size Flags", "Theme" ]
[node name="LabelMargin" type="MarginContainer" parent="Panel/MarginContainer/Button/VBoxContainer" index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 1064.0
margin_right = 2028.0
margin_bottom = 1132.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
custom_constants/margin_top = 20
custom_constants/margin_bottom = 20
_sections_unfolded = [ "Mouse", "Size Flags", "custom_constants" ]
[node name="Label" type="Label" parent="Panel/MarginContainer/Button/VBoxContainer/LabelMargin" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 20.0
margin_right = 2028.0
margin_bottom = 48.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 4
text = "NAME OF TEST"
align = 1
percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
_sections_unfolded = [ "Mouse", "custom_fonts" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment