Added a new App Web interface demo.

This commit is contained in:
Relintai 2024-01-02 12:07:55 +01:00
parent b7f40836a4
commit 95ed8ef7a7
8 changed files with 238 additions and 0 deletions

View File

@ -0,0 +1,8 @@
extends Button
export(NodePath) var target_node : NodePath
func _on_ColorSetButton_pressed() -> void:
var color : Color = get_parent().get_node("ColorPickerButton").color
get_node(target_node).set_color(color)

View File

@ -0,0 +1,13 @@
extends Node
export(NodePath) var color_picker_path
func get_color() -> Color:
var style_box : StyleBoxFlat = get_node(^"PanelContainer").get_theme_stylebox("panel")
return style_box.bg_color
func set_color(color : Color):
var style_box : StyleBoxFlat = get_node(^"PanelContainer").get_theme_stylebox("panel")
style_box.bg_color = color
get_node(color_picker_path).color = color

View File

@ -0,0 +1,87 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://ColorSetButton.gd" type="Script" id=1]
[ext_resource path="res://WebInterface.gd" type="Script" id=2]
[ext_resource path="res://MainScene.gd" type="Script" id=3]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0, 0, 0, 1 )
[sub_resource type="StyleBoxFlat" id=2]
bg_color = Color( 1, 1, 1, 1 )
[node name="MainScene" type="Node"]
script = ExtResource( 3 )
color_picker_path = NodePath("PanelContainer/VBoxContainer/PanelContainer/MarginContainer/HBoxContainer/ColorPickerButton")
[node name="WebServerSimple" type="WebServerSimple" parent="."]
start_on_ready = true
[node name="WebInterface" type="WebNode" parent="WebServerSimple"]
script = ExtResource( 2 )
target_node = NodePath("../..")
[node name="PanelContainer" type="PanelContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
custom_styles/panel = SubResource( 1 )
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"]
margin_right = 1024.0
margin_bottom = 600.0
[node name="LinkButton" type="LinkButton" parent="PanelContainer/VBoxContainer"]
margin_left = 359.0
margin_right = 665.0
margin_bottom = 14.0
size_flags_horizontal = 4
text = "Open the web interface at http://127.0.0.1:8080"
uri = "http://127.0.0.1:8080"
[node name="PanelContainer" type="PanelContainer" parent="PanelContainer/VBoxContainer"]
margin_left = 418.0
margin_top = 289.0
margin_right = 606.0
margin_bottom = 329.0
size_flags_horizontal = 6
size_flags_vertical = 6
custom_styles/panel = SubResource( 2 )
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer/VBoxContainer/PanelContainer"]
margin_right = 188.0
margin_bottom = 40.0
custom_constants/margin_left = 10
custom_constants/margin_top = 10
custom_constants/margin_right = 10
custom_constants/margin_bottom = 10
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBoxContainer/PanelContainer/MarginContainer"]
margin_left = 10.0
margin_top = 10.0
margin_right = 178.0
margin_bottom = 30.0
size_flags_vertical = 0
alignment = 1
[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/PanelContainer/MarginContainer/HBoxContainer"]
margin_top = 3.0
margin_right = 80.0
margin_bottom = 17.0
custom_colors/font_color = Color( 0, 0, 0, 1 )
text = "Set BG Color"
[node name="ColorPickerButton" type="ColorPickerButton" parent="PanelContainer/VBoxContainer/PanelContainer/MarginContainer/HBoxContainer"]
margin_left = 84.0
margin_right = 132.0
margin_bottom = 20.0
text = " "
[node name="ColorSetButton" type="Button" parent="PanelContainer/VBoxContainer/PanelContainer/MarginContainer/HBoxContainer"]
margin_left = 136.0
margin_right = 168.0
margin_bottom = 20.0
text = "Set"
script = ExtResource( 1 )
target_node = NodePath("../../../../../..")
[connection signal="pressed" from="PanelContainer/VBoxContainer/PanelContainer/MarginContainer/HBoxContainer/ColorSetButton" to="PanelContainer/VBoxContainer/PanelContainer/MarginContainer/HBoxContainer/ColorSetButton" method="_on_ColorSetButton_pressed"]

View File

@ -0,0 +1,63 @@
extends WebNode
export(NodePath) var target_node : NodePath
func _handle_request(request: WebServerRequest) -> void:
if request.get_method() == HTTPServerEnums.HTTP_METHOD_POST:
var cs : String = request.get_post_parameter("bg_color")
if cs.is_valid_html_color():
var c : Color = Color(cs)
get_node(target_node).set_color(c)
var color : Color = get_node(target_node).get_color()
var b : HTMLBuilder = HTMLBuilder.new()
b.style()
b.w("body { background-color: #%s; }" % [ color.to_html(false) ])
b.w(".content {")
b.w("width: 200px;")
b.w("margin-left: auto;")
b.w("margin-right: auto;")
b.w("text-align: center;")
b.w("margin-top: 360px;")
b.w("background-color: white;")
b.w("padding: 10px;")
b.w("}")
b.cstyle()
b.write_tag()
request.head += b.result
b.result = ""
b.div("content")
b.a("/").f().w("Refresh").ca()
b.br()
b.br()
b.form_post("/")
if true: # Scope for better separation
b.label().fora("bg_color")
b.w("Set BG Color ")
b.clabel()
b.input_color("bg_color", "#" + color.to_html(false), "", "bg_color")
b.br()
b.br()
b.input_submit("Set")
b.cform()
b.cdiv()
b.write_tag()
request.body += b.result
request.compile_and_send_body()

View File

@ -0,0 +1,7 @@
[gd_resource type="Environment3D" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -0,0 +1,25 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
[application]
config/name="App Web Interface"
run/main_scene="res://MainScene.tscn"
config/icon="res://icon.png"
[physics]
common/enable_pause_aware_picking=true
[rendering]
vram_compression/import_etc=true
vram_compression/import_etc2=false
environment/default_environment="res://default_env.tres"