Fixed some dialog bugs.
This commit is contained in:
parent
9d3914d46e
commit
ea991ab816
5 changed files with 59 additions and 113 deletions
|
@ -9,33 +9,35 @@ var _line_edit
|
|||
var _result
|
||||
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
|
||||
func _alertClosed():
|
||||
_dialog.queue_free()
|
||||
emit_signal("_dialog_closed")
|
||||
|
||||
|
||||
func _confirmAccepted():
|
||||
func _accepted():
|
||||
_dialog.queue_free()
|
||||
_result = true
|
||||
emit_signal("_dialog_closed")
|
||||
|
||||
|
||||
func _confirmCanceled():
|
||||
func _canceled():
|
||||
_dialog.queue_free()
|
||||
_result = false
|
||||
emit_signal("_dialog_closed")
|
||||
|
||||
|
||||
func _closed():
|
||||
_dialog.queue_free()
|
||||
emit_signal("_dialog_closed")
|
||||
|
||||
|
||||
func _submitted(_text: String):
|
||||
_dialog.queue_free()
|
||||
_result = true
|
||||
emit_signal("_dialog_closed")
|
||||
|
||||
|
||||
func alert(title: String, text: String, parent: Node = null):
|
||||
_dialog = AcceptDialog.new()
|
||||
_dialog.dialog_text = text
|
||||
_dialog.title = title
|
||||
_dialog.unresizable = true
|
||||
_dialog.get_ok_button().pressed.connect(_alertClosed)
|
||||
_dialog.get_ok_button().pressed.connect(_closed)
|
||||
if parent == null:
|
||||
var scene_tree = Engine.get_main_loop()
|
||||
scene_tree.current_scene.add_child(_dialog)
|
||||
|
@ -50,8 +52,8 @@ func confirm(title: String, text: String, parent: Node = null):
|
|||
_dialog.dialog_text = text
|
||||
_dialog.title = title
|
||||
_dialog.unresizable = true
|
||||
_dialog.get_ok_button().pressed.connect(_confirmAccepted)
|
||||
_dialog.get_cancel_button().pressed.connect(_confirmCanceled)
|
||||
_dialog.get_ok_button().pressed.connect(_accepted)
|
||||
_dialog.get_cancel_button().pressed.connect(_canceled)
|
||||
if parent == null:
|
||||
var scene_tree = Engine.get_main_loop()
|
||||
scene_tree.current_scene.add_child(_dialog)
|
||||
|
@ -62,8 +64,7 @@ func confirm(title: String, text: String, parent: Node = null):
|
|||
return _result
|
||||
|
||||
|
||||
#***TODO*** This is ugly. Pressing ENTER cancels!
|
||||
func prompt(title: String, text: String, parent: Node = null):
|
||||
func prompt(title: String, text: String, parent: Node = null, chars: int = 32):
|
||||
var hbox := HBoxContainer.new()
|
||||
hbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var label := Label.new()
|
||||
|
@ -71,19 +72,22 @@ func prompt(title: String, text: String, parent: Node = null):
|
|||
hbox.add_child(label)
|
||||
hbox.add_spacer(false)
|
||||
_line_edit = LineEdit.new()
|
||||
_line_edit.max_length = 32 #12345678901234567890123456789012
|
||||
_line_edit.placeholder_text = " "
|
||||
var size = _line_edit.get_minimum_size()
|
||||
size.x = _line_edit.get_theme_default_font_size() * chars
|
||||
_line_edit.set_custom_minimum_size(size)
|
||||
_line_edit.max_length = chars
|
||||
_line_edit.expand_to_text_length = true
|
||||
_line_edit.secret = true
|
||||
_line_edit.select_all_on_focus = true
|
||||
_line_edit.text_submitted.connect(_submitted)
|
||||
hbox.add_child(_line_edit)
|
||||
_dialog = AcceptDialog.new()
|
||||
_dialog.title = title
|
||||
_dialog.unresizable = true
|
||||
_dialog.register_text_enter(_line_edit) #***TODO*** This does not press OK on ENTER! It cancels!
|
||||
_dialog.register_text_enter(_line_edit)
|
||||
var cancel = _dialog.add_cancel_button("Cancel")
|
||||
_dialog.get_ok_button().pressed.connect(_confirmAccepted)
|
||||
cancel.pressed.connect(_confirmCanceled)
|
||||
_dialog.get_ok_button().pressed.connect(_accepted)
|
||||
cancel.pressed.connect(_canceled)
|
||||
_dialog.add_child(hbox)
|
||||
if parent == null:
|
||||
var scene_tree = Engine.get_main_loop()
|
||||
|
|
|
@ -35,7 +35,7 @@ var _ip := ""
|
|||
|
||||
|
||||
func _data_recieved(type, data):
|
||||
print(type, ": ", data)
|
||||
#print(type, ": ", data)
|
||||
if type == "info":
|
||||
_ip = data[0]["ip4addr"]
|
||||
my_ip_label.text = _ip
|
||||
|
@ -52,9 +52,9 @@ func _data_recieved(type, data):
|
|||
for peer in Peers.peerArray:
|
||||
var child = peers_tree.create_item(root)
|
||||
child.set_text(0, peer["user"] + " (" + peer["ip"] + ")")
|
||||
# Handle empty peer list.
|
||||
if data.size() == 0 and peers_tree.get_root() != null:
|
||||
peers_tree.clear()
|
||||
# Handle empty peer list.
|
||||
if data.size() == 0 and peers_tree.get_root() != null:
|
||||
peers_tree.clear()
|
||||
|
||||
|
||||
func _go_offline():
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
extends Node
|
||||
|
||||
|
||||
const ENET_SERVICE_EVENT_TYPE = 0
|
||||
const ENET_SERVICE_PEER = 1
|
||||
const ENET_SERVICE_EVENT_DATA = 2
|
||||
const ENET_SERVICE_EVENT_CHANNEL = 3
|
||||
|
||||
|
||||
var _enet := ENetMultiplayerPeer.new()
|
||||
var _basePort: int
|
||||
var _serverRunning: bool
|
||||
|
@ -56,20 +62,35 @@ func _process(_delta):
|
|||
|
||||
|
||||
func _process_enet(host: ENetConnection, id: int):
|
||||
var ret = host.service()
|
||||
if ret[0] == host.EVENT_CONNECT:
|
||||
print("Adding host %d" % id)
|
||||
_enet.add_mesh_peer(id, host)
|
||||
elif ret[0] != host.EVENT_NONE:
|
||||
print("Mesh peer error %d" % id)
|
||||
#***TODO*** Attempt disconnect/reconnect
|
||||
if host == null:
|
||||
return
|
||||
var ret = host.service() # Returns an array of ENET_SERVICE_* items.
|
||||
match ret[ENET_SERVICE_EVENT_TYPE]:
|
||||
host.EVENT_CONNECT:
|
||||
print("Adding host %d" % id)
|
||||
_enet.add_mesh_peer(id, host)
|
||||
|
||||
host.EVENT_DISCONNECT:
|
||||
print("Mesh peer disconnected %d" % id)
|
||||
host = null
|
||||
|
||||
host.EVENT_ERROR:
|
||||
print("Mesh peer error %d" % id)
|
||||
host = null
|
||||
#***TODO*** Attempt disconnect/reconnect
|
||||
|
||||
host.EVENT_NONE:
|
||||
pass
|
||||
|
||||
host.EVENT_RECEIVE:
|
||||
print("Mesh peer recieved data %d" % id)
|
||||
|
||||
|
||||
func _ready():
|
||||
_serverRunning = false
|
||||
clear()
|
||||
multiplayer.peer_connected.connect(self._peer_connected)
|
||||
multiplayer.peer_disconnected.connect(self._peer_disconnected)
|
||||
multiplayer.peer_connected.connect(_peer_connected)
|
||||
multiplayer.peer_disconnected.connect(_peer_disconnected)
|
||||
|
||||
|
||||
func _sort_by_ip(a, b):
|
||||
|
|
|
@ -22,7 +22,6 @@ func _elevate_unix(program: String, arguments: PackedStringArray):
|
|||
OS.set_environment("SUDO_ASKPASS", _ask_pass_script)
|
||||
var options = ["-A", program]
|
||||
options.append_array(arguments)
|
||||
print("Starting sudo with ", options)
|
||||
var pid = OS.create_process("sudo", options, false)
|
||||
return pid
|
||||
|
||||
|
@ -38,10 +37,8 @@ func _process(_delta):
|
|||
var peer: PacketPeerUDP = _udp.take_connection()
|
||||
var data = peer.get_packet().get_string_from_ascii()
|
||||
if peer.get_packet_error() == OK:
|
||||
print("Password: ", data.strip_edges(), " == ", _ask_pass_password)
|
||||
if data.strip_edges() == _ask_pass_password:
|
||||
if _root_password != null:
|
||||
print("Sending root password")
|
||||
peer.put_packet(_root_password.to_ascii_buffer())
|
||||
_root_password = null
|
||||
peer.close()
|
||||
|
@ -56,7 +53,6 @@ func elevate(program: String, arguments: PackedStringArray):
|
|||
|
||||
func shutdown():
|
||||
_udp.stop()
|
||||
print("UDP ask_pass closed")
|
||||
if FileAccess.file_exists(_ask_pass_script):
|
||||
print("Removing ", _ask_pass_script)
|
||||
DirAccess.remove_absolute(_ask_pass_script)
|
||||
|
@ -65,4 +61,3 @@ func shutdown():
|
|||
func startup(port: int = 19999):
|
||||
_ask_pass_port = port
|
||||
_udp.listen(_ask_pass_port, "127.0.0.1")
|
||||
print("UDP ask_pass open")
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
[gd_scene format=3 uid="uid://bxuogpn8f5sd3"]
|
||||
|
||||
[node name="MainWindowControl" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -93.5
|
||||
offset_top = -51.0
|
||||
offset_right = 53.5
|
||||
offset_bottom = 11.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
|
||||
[node name="MenuBar" type="MenuBar" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
|
||||
[node name="File" type="PopupMenu" parent="VBoxContainer/HBoxContainer/MenuBar"]
|
||||
item_count = 3
|
||||
item_0/text = "Settings..."
|
||||
item_0/id = 0
|
||||
item_1/text = ""
|
||||
item_1/id = 1
|
||||
item_1/separator = true
|
||||
item_2/text = "Exit"
|
||||
item_2/id = 2
|
||||
|
||||
[node name="Help" type="PopupMenu" parent="VBoxContainer/HBoxContainer/MenuBar"]
|
||||
item_count = 2
|
||||
item_0/text = "About..."
|
||||
item_0/id = 0
|
||||
item_1/text = "Manual..."
|
||||
item_1/id = 1
|
||||
|
||||
[node name="OnlineCheckButton" type="CheckButton" parent="VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 8
|
||||
text = "Online"
|
||||
|
||||
[node name="MyIPLabel" type="Label" parent="VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/margin_left = 20
|
||||
theme_override_constants/margin_top = 20
|
||||
theme_override_constants/margin_right = 20
|
||||
theme_override_constants/margin_bottom = 20
|
||||
|
||||
[node name="PeersTree" type="Tree" parent="VBoxContainer/MarginContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
hide_folding = true
|
||||
hide_root = true
|
Loading…
Add table
Reference in a new issue