103 lines
3.3 KiB
GDScript
103 lines
3.3 KiB
GDScript
extends Control
|
|
|
|
class_name GameUI
|
|
|
|
enum ServerMenuItem {
|
|
ServerInfo
|
|
}
|
|
|
|
enum PopupName {
|
|
SpaceMap,
|
|
EnergyUsage
|
|
}
|
|
|
|
onready var logs = $Logs
|
|
onready var inspect_box = $InspectBox as RichTextLabel
|
|
|
|
onready var scene = $"/root/scene"
|
|
onready var netgame = $"/root/Multiplayer"
|
|
|
|
const WHISPER_RADIUS = 32*3
|
|
const CHAT_RADIUS = 32*10
|
|
const SHOUT_RADIUS = 32*14
|
|
|
|
var inspect_mode = false
|
|
var current_inspecting = null
|
|
|
|
func _ready() -> void:
|
|
# Add options to menu buttons
|
|
var serverMenu = $Menu/Margins/Grid/Server.get_popup()
|
|
serverMenu.connect("id_pressed", self, "_server_option_chosen")
|
|
serverMenu.add_item("Server info", ServerMenuItem.ServerInfo)
|
|
|
|
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
|
|
|
|
func _server_option_chosen(id) -> void:
|
|
match id:
|
|
ServerMenuItem.ServerInfo:
|
|
$ServerInfoPopup.popup_centered()
|
|
|
|
func open_popup(popup_name) -> void:
|
|
match popup_name:
|
|
PopupName.SpaceMap:
|
|
$MapPopup.popup_centered_ratio()
|
|
PopupName.EnergyUsage:
|
|
pass
|
|
|
|
func close_popup(popup_name) -> void:
|
|
match popup_name:
|
|
PopupName.SpaceMap:
|
|
$MapPopup.visible = false
|
|
PopupName.EnergyUsage:
|
|
pass
|
|
|
|
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)
|
|
|
|
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
|