2020-07-06 22:00:39 +00:00
|
|
|
extends Control
|
|
|
|
|
2020-07-20 09:15:39 +00:00
|
|
|
class_name GameUI
|
|
|
|
|
2020-07-10 11:31:16 +00:00
|
|
|
enum ServerMenuItem {
|
2020-07-20 09:15:39 +00:00
|
|
|
ServerInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
enum PopupName {
|
|
|
|
SpaceMap,
|
|
|
|
EnergyUsage
|
2020-07-10 11:31:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 17:47:33 +00:00
|
|
|
onready var logs = $Logs
|
2020-07-23 12:21:27 +00:00
|
|
|
onready var inspect_box = $InspectBox as RichTextLabel
|
|
|
|
|
2020-07-22 13:57:33 +00:00
|
|
|
onready var scene = $"/root/scene"
|
2020-07-23 08:51:39 +00:00
|
|
|
onready var netgame = $"/root/Multiplayer"
|
2020-07-22 13:57:33 +00:00
|
|
|
|
2020-07-23 08:51:39 +00:00
|
|
|
const WHISPER_RADIUS = 32*3
|
2020-07-22 15:34:04 +00:00
|
|
|
const CHAT_RADIUS = 32*10
|
2020-07-23 08:51:39 +00:00
|
|
|
const SHOUT_RADIUS = 32*14
|
2020-07-21 17:47:33 +00:00
|
|
|
|
2020-07-23 12:21:27 +00:00
|
|
|
var inspect_mode = false
|
|
|
|
var current_inspecting = null
|
|
|
|
|
2020-07-10 11:31:16 +00:00
|
|
|
func _ready() -> void:
|
|
|
|
# Add options to menu buttons
|
|
|
|
var serverMenu = $Menu/Margins/Grid/Server.get_popup()
|
|
|
|
serverMenu.connect("id_pressed", self, "_server_option_chosen")
|
2020-07-20 09:15:39 +00:00
|
|
|
serverMenu.add_item("Server info", ServerMenuItem.ServerInfo)
|
2020-07-23 12:21:27 +00:00
|
|
|
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
|
|
if inspect_mode:
|
|
|
|
var mouse_pos = scene.world.get_local_mouse_position() * scene.world.scale
|
|
|
|
var results = scene.physics.intersect_point(mouse_pos, 1, [], 2)
|
|
|
|
if results.size() > 0:
|
|
|
|
var obj = results[0].collider
|
|
|
|
if obj != current_inspecting:
|
|
|
|
current_inspecting = obj
|
|
|
|
if obj.has_method("inspect"):
|
|
|
|
var data = obj.inspect()
|
|
|
|
inspect_box.bbcode_text = ""
|
|
|
|
inspect_box.rect_size.y = 0
|
|
|
|
if "object_name" in obj and obj.object_name != "":
|
|
|
|
inspect_box.append_bbcode("[b]%s[/b] (%s)" % [obj.object_name, data.type])
|
|
|
|
else:
|
|
|
|
inspect_box.append_bbcode("A [b]%s[/b]" % data.type)
|
|
|
|
if "description" in data:
|
|
|
|
inspect_box.append_bbcode("\n" + data.description)
|
|
|
|
if "interaction" in data:
|
|
|
|
inspect_box.append_bbcode("\n\n[i]%s[/i]" % data.interaction)
|
|
|
|
inspect_box.visible = true
|
|
|
|
else:
|
|
|
|
current_inspecting = null
|
|
|
|
inspect_box.visible = false
|
|
|
|
|
2020-07-10 11:31:16 +00:00
|
|
|
func _server_option_chosen(id) -> void:
|
|
|
|
match id:
|
2020-07-20 09:15:39 +00:00
|
|
|
ServerMenuItem.ServerInfo:
|
2020-07-10 11:31:16 +00:00
|
|
|
$ServerInfoPopup.popup_centered()
|
2020-07-14 21:28:13 +00:00
|
|
|
|
2020-07-23 08:51:39 +00:00
|
|
|
func open_popup(popup_name) -> void:
|
|
|
|
match popup_name:
|
2020-07-20 09:15:39 +00:00
|
|
|
PopupName.SpaceMap:
|
|
|
|
$MapPopup.popup_centered_ratio()
|
|
|
|
PopupName.EnergyUsage:
|
|
|
|
pass
|
2020-07-14 21:28:13 +00:00
|
|
|
|
2020-07-23 08:51:39 +00:00
|
|
|
func close_popup(popup_name) -> void:
|
|
|
|
match popup_name:
|
2020-07-20 09:15:39 +00:00
|
|
|
PopupName.SpaceMap:
|
|
|
|
$MapPopup.visible = false
|
|
|
|
PopupName.EnergyUsage:
|
|
|
|
pass
|
2020-07-22 13:57:33 +00:00
|
|
|
|
2020-07-23 08:51:39 +00:00
|
|
|
const say_format = "%s says \"%s\"\n"
|
|
|
|
const shout_format = "%s shouts \"[b]%s[/b]\"\n"
|
|
|
|
const whisper_format = "[i]%s whispers \"%s\"[/i]\n"
|
|
|
|
func _send_chat(text: String) -> void:
|
|
|
|
var escaped_text = text.replace("[", "[\u8203") # Hacky way to escape BBCode
|
|
|
|
if text.ends_with("!!"):
|
|
|
|
scene.rpc("broadcast_zone", shout_format % [netgame.player_name, escaped_text], scene.world.player.global_position, SHOUT_RADIUS)
|
|
|
|
elif text.begins_with("#"):
|
|
|
|
scene.rpc("broadcast_zone", whisper_format % [netgame.player_name, escaped_text.substr(1)], scene.world.player.global_position, WHISPER_RADIUS)
|
|
|
|
else:
|
|
|
|
scene.rpc("broadcast_zone", say_format % [netgame.player_name, escaped_text], scene.world.player.global_position, CHAT_RADIUS)
|
2020-07-23 12:21:27 +00:00
|
|
|
|
|
|
|
var inspect_offset = Vector2(20, 20)
|
|
|
|
func set_inspect(active: bool) -> void:
|
|
|
|
inspect_box.visible = inspect_box.visible and active
|
|
|
|
inspect_mode = active
|
|
|
|
inspect_box.rect_global_position = get_viewport().get_mouse_position() + inspect_offset
|
|
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
|
|
if event.is_action_released("inspect"):
|
|
|
|
set_inspect(false)
|
|
|
|
elif event.is_action_pressed("inspect"):
|
|
|
|
set_inspect(true)
|
|
|
|
elif event is InputEventMouseMotion:
|
|
|
|
var mousemotion = event as InputEventMouseMotion
|
|
|
|
if inspect_mode:
|
|
|
|
inspect_box.rect_global_position = mousemotion.position + inspect_offset
|