Added easier to use dialog boxes.

This commit is contained in:
Scott Duensing 2023-08-26 19:51:18 -05:00
parent 66f8369e1a
commit 5dd6a03572
7 changed files with 138 additions and 60 deletions

View file

@ -1,36 +1,45 @@
#!/bin/bash
# Eventially provide a build_profile file to reduce file size.
TEMPLATE="disable_3d=yes svg=no"
LTO="lto=none" # Use "lto=full" for releases.
pushd godot
# Use Our Custom Settings.
ln -f -s ../custom.py .
TEMPLATE="disable_3d=yes svg=no"
# Clean Prior Builds.
scons --clean
#scons platform=list
# Build Editor.
scons platform=linuxbsd target=editor arch=x86_64 ${LTO}
#scons --clean
# Create JSON for IDE support.
if [[ ! -f compile_commands.json ]]; then
scons compiledb=yes
fi
# Build editor
#scons platform=linuxbsd target=editor arch=x86_64 lto=full
#scons platform=linuxbsd target=editor arch=x86_64
scons platform=windows target=template_release arch=x86_64 ${TEMPLATE}
# Build Templates.
scons platform=linuxbsd target=template_release arch=x86_64 ${TEMPLATE} ${LTO}
scons platform=windows target=template_release arch=x86_64 ${TEMPLATE} ${LTO}
popd
:<<SKIP
# Build all templates
:<<NOTES
#scons platform=list
# Linux
#scons platform=linuxbsd target=template_release arch=x86_32 ${TEMPLATE}
#scons platform=linuxbsd target=template_debug arch=x86_32 ${TEMPLATE}
scons platform=linuxbsd target=template_release arch=x86_32 ${TEMPLATE}
scons platform=linuxbsd target=template_debug arch=x86_32 ${TEMPLATE}
scons platform=linuxbsd target=template_release arch=x86_64 ${TEMPLATE}
scons platform=linuxbsd target=template_debug arch=x86_64 ${TEMPLATE}
# Windows
#scons platform=windows target=template_debug arch=x86_32 ${TEMPLATE}
#scons platform=windows target=template_release arch=x86_32 ${TEMPLATE}
scons platform=windows target=template_debug arch=x86_32 ${TEMPLATE}
scons platform=windows target=template_release arch=x86_32 ${TEMPLATE}
scons platform=windows target=template_debug arch=x86_64 ${TEMPLATE}
scons platform=windows target=template_release arch=x86_64 ${TEMPLATE}
@ -47,4 +56,4 @@ scons platform=macos target=template_debug osxcross_sdk=darwin15 arch=arm64 $
#cp bin/godot.macos.opt.debug.universal macos_template.app/Contents/MacOS/godot_macos_debug.64
#chmod +x macos_template.app/Contents/MacOS/godot_macos*
SKIP
NOTES

54
hamncheese/global.gd Normal file
View file

@ -0,0 +1,54 @@
extends Node
signal _dialog_closed
var _dialog
var _result
func _ready():
pass
func _alertClosed():
_dialog.queue_free
emit_signal("_dialog_closed")
func _confirmAccepted():
_dialog.queue_free
_result = true
emit_signal("_dialog_closed")
func _confirmCanceled():
_dialog.queue_free
_result = false
emit_signal("_dialog_closed")
func alert(title: String, text: String):
_dialog = AcceptDialog.new()
_dialog.dialog_text = text
_dialog.title = title
_dialog.unresizable = true
_dialog.get_ok_button().pressed.connect(_alertClosed)
var scene_tree = Engine.get_main_loop()
scene_tree.current_scene.add_child(_dialog)
_dialog.popup_centered()
await _dialog_closed
func confirm(title: String, text: String):
_dialog = ConfirmationDialog.new()
_dialog.dialog_text = text
_dialog.title = title
_dialog.unresizable = true
_dialog.get_ok_button().pressed.connect(_confirmAccepted)
_dialog.get_cancel_button().pressed.connect(_confirmCanceled)
var scene_tree = Engine.get_main_loop()
scene_tree.current_scene.add_child(_dialog)
_dialog.popup_centered()
await _dialog_closed
return _result

View file

@ -24,39 +24,16 @@ const HELP_ID_MANUAL = 1
@onready var compression_check_button = %CompressionCheckButton
@onready var auto_start_check_button = %AutoStartCheckButton
@onready var exit_dialog = %ExitDialog
@onready var about_window = %AboutWindow
@onready var manual_window = %ManualWindow
var net;
func alert(text: String, title: String):
var dialog = AcceptDialog.new()
dialog.dialog_text = text
dialog.title = title
dialog.unresizable = true
dialog.get_ok_button().pressed.connect(dialog.queue_free)
var scene_tree = Engine.get_main_loop()
scene_tree.current_scene.add_child(dialog)
dialog.popup_centered()
func confirm(text: String, title: String):
var dialog = ConfirmationDialog.new()
dialog.dialog_text = text
dialog.title = title
dialog.unresizable = true
dialog.get_ok_button().pressed.connect(dialog.queue_free)
dialog.get_cancel_button().pressed.connect(self.canceled)
var scene_tree = Engine.get_main_loop()
scene_tree.current_scene.add_child(dialog)
dialog.popup_centered()
func _notification(what):
# Window manager requested app close.
if what == NOTIFICATION_WM_CLOSE_REQUEST:
exit_dialog.popup()
_show_exit_dialog()
func _on_about_window_close_requested():
@ -67,10 +44,6 @@ func _on_ip_check_button_toggled(button_pressed):
ip_line_edit.editable = !ip_check_button.button_pressed
func _on_exit_dialog_confirmed():
get_tree().quit()
func _on_file_id_pressed(id):
match id:
FILE_ID_SETTINGS:
@ -78,7 +51,7 @@ func _on_file_id_pressed(id):
settings_window.move_to_foreground()
FILE_ID_EXIT:
exit_dialog.popup()
_show_exit_dialog()
#get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
#SceneTree.quit()
@ -196,5 +169,15 @@ func _ready():
compression_check_button.button_pressed = config.get_value("settings", "compression")
auto_start_check_button.button_pressed = config.get_value("settings", "autoStart")
online_check_button.button_pressed = auto_start_check_button.button_pressed
alert("My Dumb Dialog", "Test dialog box.")
func _show_exit_dialog():
var message = "Are you sure you wish to exit?"
if online_check_button.button_pressed:
message = message + "\n\nThis will disconnect you from the network!\n"
var result = await Global.confirm("Exit", message)
if result:
if online_check_button.button_pressed:
net.stop_network()
get_tree().quit()

View file

@ -225,17 +225,6 @@ unique_name_in_owner = true
layout_mode = 2
text = "Save"
[node name="ExitDialog" type="ConfirmationDialog" parent="."]
unique_name_in_owner = true
title = "Exit?"
initial_position = 2
size = Vector2i(300, 200)
unresizable = true
dialog_text = "Are you sure you wish to exit?
This will disconnect you from the network!"
dialog_autowrap = true
[node name="AboutWindow" type="Window" parent="."]
unique_name_in_owner = true
title = "About"
@ -261,7 +250,6 @@ autostart = true
[connection signal="toggled" from="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer/IPCheckButton" to="." method="_on_ip_check_button_toggled"]
[connection signal="toggled" from="SettingsWindow/MarginContainer/VBoxContainer/AddressesGridContainer/MACCheckButton" to="." method="_on_mac_check_button_toggled"]
[connection signal="pressed" from="SettingsWindow/MarginContainer/VBoxContainer/ButtonsHBoxContainer/SaveSettingsButton" to="." method="_on_save_settings_button_pressed"]
[connection signal="confirmed" from="ExitDialog" to="." method="_on_exit_dialog_confirmed"]
[connection signal="close_requested" from="AboutWindow" to="." method="_on_about_window_close_requested"]
[connection signal="close_requested" from="ManualWindow" to="." method="_on_manual_window_close_requested"]
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

View file

@ -18,6 +18,10 @@ config/features=PackedStringArray("4.2", "Forward Plus")
run/low_processor_mode=true
config/icon="res://icon.svg"
[autoload]
Global="*res://global.gd"
[display]
window/size/viewport_width=400

View file

@ -6,6 +6,7 @@
extern "C" {
#include "random_numbers.h"
#include "sn_selection.h"
#include "pearson.h"
#include "uthash.h"
#ifdef _WIN32
#include "win32/defs.h"
@ -34,8 +35,12 @@ void N2NVPN::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_peers"), &N2NVPN::get_peers);
ClassDB::bind_method(D_METHOD("reset_configuration"), &N2NVPN::reset_configuration);
ClassDB::bind_method(D_METHOD("set_addresses", "ip_address", "mac_address"), &N2NVPN::set_addresses);
ClassDB::bind_method(D_METHOD("set_binding", "ip_address", "port"), &N2NVPN::set_binding);
ClassDB::bind_method(D_METHOD("set_compression", "enabled"), &N2NVPN::set_compression);
ClassDB::bind_method(D_METHOD("set_management", "password", "port"), &N2NVPN::set_management);
ClassDB::bind_method(D_METHOD("set_network", "user_name", "network_name", "network_password"), &N2NVPN::set_network);
ClassDB::bind_method(D_METHOD("set_registration", "interval", "ttl"), &N2NVPN::set_registration);
ClassDB::bind_method(D_METHOD("set_routing", "enabled"), &N2NVPN::set_routing);
ClassDB::bind_method(D_METHOD("set_supernode", "address", "port"), &N2NVPN::set_supernode);
ClassDB::bind_method(D_METHOD("start_network"), &N2NVPN::start_network);
ClassDB::bind_method(D_METHOD("stop_network"), &N2NVPN::stop_network);
@ -112,6 +117,8 @@ void N2NVPN::reset_configuration() {
_conf.tos = 16; // Type of service for sent packets
_conf.transop_id = N2N_TRANSFORM_ID_TWOFISH; // Use the twofish encryption
// _conf.network_traffic_filter_rules
_conf.compression = N2N_COMPRESSION_ID_ZSTD;
_ip_address = ""; // Empty addresses will cause them to be generated / acquired.
@ -125,17 +132,46 @@ void N2NVPN::set_addresses(const String ip, const String mac) {
}
void N2NVPN::set_binding(String ip, int16_t port) {
if (ip != "") {
_conf.bind_address = ntohl(inet_addr(ip.ascii().get_data()));
} else {
_conf.bind_address = INADDR_ANY;
}
_conf.local_port = port; // Local listen port, or 0 for any.
}
void N2NVPN::set_compression(bool enabled) {
_conf.compression = (enabled ? N2N_COMPRESSION_ID_ZSTD : N2N_COMPRESSION_ID_NONE);
}
void N2NVPN::set_management(String password, int16_t port) {
if (password != "") {
_conf.mgmt_password_hash = pearson_hash_64((uint8_t *)password.ascii().get_data(), strlen(password.ascii().get_data()));
}
_conf.mgmt_port = port;
}
void N2NVPN::set_network(const String user_name, const String network_name, const String network_password) {
_user_name = user_name;
_network_password = network_password;
snprintf((char *)_conf.community_name, sizeof(_conf.community_name), "%s", network_name.ascii().get_data()); // Community to connect to
_conf.encrypt_key = (char *)strdup(_network_password.ascii().get_data()); // Secret to decrypt & encrypt with
_conf.encrypt_key = (char *)strdup(_network_password.ascii().get_data()); // Secret to decrypt & encrypt with.
}
void N2NVPN::set_registration(int16_t interval, int16_t ttl) {
_conf.register_interval = interval;
_conf.register_ttl = ttl;
}
void N2NVPN::set_routing(bool enabled) {
_conf.allow_routing = enabled ? 1 : 0;
}

View file

@ -38,12 +38,16 @@ class N2NVPN : public RefCounted {
Array get_peers();
void reset_configuration();
void set_addresses(String ip, String mac);
void set_binding(String ip, int16_t port);
void set_compression(bool enabled);
void set_management(String password, int16_t port);
void set_network(String user_name, String network_name, String network_password);
void set_registration(int16_t interval, int16_t ttl);
void set_routing(bool enabled);
void set_supernode(String address, int port);
int start_network();
int stop_network();
};
#endif // GODOT_N2NVPN_H
#endif // GODOT_N2NVPN_H