138 lines
5.7 KiB
GDScript
138 lines
5.7 KiB
GDScript
class_name BugReportForm
|
|
extends ColorRect
|
|
|
|
signal submitted(map_name:String, bug_location:Vector3, bug_rotation:Vector3)
|
|
signal cancelled
|
|
|
|
@onready var __product_name : Label = $Form/VBoxContainerLeft/GridContainer/ProductName
|
|
@onready var __version_label : Label = $Form/VBoxContainerLeft/GridContainer/VersionLabel
|
|
@onready var __version_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/VersionButton
|
|
@onready var __hardware_label : MenuButton = $Form/VBoxContainerLeft/GridContainer/HardwareLabel
|
|
@onready var __hardware_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/HardwareButton
|
|
@onready var __os_label : Label = $Form/VBoxContainerLeft/GridContainer/OSLabel
|
|
@onready var __os_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/OSButton
|
|
@onready var __component_label : Label = $Form/VBoxContainerLeft/GridContainer/ComponentLabel
|
|
@onready var __component_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/ComponentButton
|
|
@onready var __severity_label : Label = $Form/VBoxContainerLeft/GridContainer/SeverityLabel
|
|
@onready var __severity_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/SeverityButton
|
|
|
|
@onready var __summary_label : Label = $Form/VBoxContainerRight/GridContainer/SummaryLabel
|
|
@onready var __summary_text : LineEdit = $Form/VBoxContainerRight/GridContainer/SummaryText
|
|
@onready var __description_label : Label = $Form/VBoxContainerRight/GridContainer/DescriptionLabel
|
|
@onready var __description_text : TextEdit = $Form/VBoxContainerRight/GridContainer/DescriptionText
|
|
|
|
@onready var __submit_button : Button = $Form/VBoxContainerRight/SubmitButton
|
|
|
|
var map_name : String
|
|
var bug_location : Vector3
|
|
var bug_rotation : Vector3
|
|
|
|
var __label_groups : Array
|
|
var __stored_mouse_mode : int
|
|
var __server_api : BugbotServerAPI
|
|
|
|
const __BUTTON_DISABLED_MESSAGE : StringName = &"Not available"
|
|
const __ERROR_TEXT_COLOUR : Color = Color(0.75, 0.0, 0.0)
|
|
|
|
|
|
func _enter_tree():
|
|
__stored_mouse_mode = Input.mouse_mode
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
__server_api = BugbotServerAPI._create_new_server_api()
|
|
|
|
func _exit_tree():
|
|
Input.mouse_mode = __stored_mouse_mode
|
|
|
|
|
|
func fill_tags(tag_list:Array):
|
|
__label_groups.resize(BugbotServerAPI.BugbotTagArray.MAX)
|
|
__label_groups = tag_list
|
|
|
|
__product_name.text = ProjectSettings.get_setting("application/config/name", "")
|
|
__fill_item_list(__version_button, BugbotServerAPI.BugbotTagArray.VERSION)
|
|
__fill_item_list(__hardware_button, BugbotServerAPI.BugbotTagArray.HARDWARE)
|
|
__fill_item_list(__os_button, BugbotServerAPI.BugbotTagArray.OS)
|
|
__fill_item_list(__component_button, BugbotServerAPI.BugbotTagArray.COMPONENT)
|
|
__fill_item_list(__severity_button, BugbotServerAPI.BugbotTagArray.SEVERITY)
|
|
|
|
func __fill_item_list(menu_button:MenuButton, label_group:int):
|
|
var menu_options : Array = __label_groups[label_group]
|
|
if menu_options.is_empty():
|
|
menu_button.text = __BUTTON_DISABLED_MESSAGE
|
|
menu_button.disabled = true
|
|
else:
|
|
var menu : PopupMenu = menu_button.get_popup()
|
|
for i in menu_options.size():
|
|
menu.add_item(menu_options[i]["name"], i)
|
|
menu.id_pressed.connect(func(id:int): menu_button.text = menu_options[id]["name"])
|
|
|
|
|
|
func _on_submit_button_pressed() -> void:
|
|
__submit_button.disabled = true
|
|
|
|
var error_detected : bool = false
|
|
|
|
var summary_text : String = __summary_text.text
|
|
var description_text : String = __description_text.text
|
|
if summary_text.is_empty():
|
|
printerr("You must fill in a summary.")
|
|
__summary_label.add_theme_color_override("font_color", __ERROR_TEXT_COLOUR)
|
|
__summary_text.add_theme_color_override("font_color", __ERROR_TEXT_COLOUR)
|
|
error_detected = true
|
|
else:
|
|
__summary_label.remove_theme_color_override("font_color")
|
|
__summary_text.remove_theme_color_override("font_color")
|
|
|
|
if description_text.is_empty():
|
|
printerr("You must fill in a description.")
|
|
__description_label.add_theme_color_override("font_color", __ERROR_TEXT_COLOUR)
|
|
__description_text.add_theme_color_override("font_color", __ERROR_TEXT_COLOUR)
|
|
error_detected = true
|
|
else:
|
|
__description_label.remove_theme_color_override("font_color")
|
|
__description_text.remove_theme_color_override("font_color")
|
|
|
|
var labels_to_be_added : Array
|
|
# Check severity first, since this is a requirement.
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.SEVERITY)
|
|
if labels_to_be_added.is_empty():
|
|
printerr("You must select a severity level.")
|
|
__severity_label.add_theme_color_override("font_color", __ERROR_TEXT_COLOUR)
|
|
__severity_button.add_theme_color_override("font_color", __ERROR_TEXT_COLOUR)
|
|
error_detected = true
|
|
else:
|
|
__severity_label.remove_theme_color_override("font_color")
|
|
__severity_button.remove_theme_color_override("font_color")
|
|
|
|
if error_detected:
|
|
__submit_button.disabled = false
|
|
return
|
|
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.VERSION)
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.HARDWARE)
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.OS)
|
|
__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.COMPONENT)
|
|
|
|
var bug_report_form_data : Dictionary = {
|
|
"title": summary_text,
|
|
"body": description_text,
|
|
"labels": labels_to_be_added,
|
|
}
|
|
|
|
__server_api._send_form_data(bug_report_form_data, map_name, bug_location, bug_rotation, __submission_response)
|
|
|
|
func __get_label_ids_for_submission_data(label_array:Array, label_group_id:int):
|
|
for label in __label_groups[label_group_id]:
|
|
if label["name"] == __severity_button.text:
|
|
label_array.append(label["id"])
|
|
break
|
|
|
|
func __submission_response(response:Variant):
|
|
submitted.emit(map_name, bug_location, bug_rotation)
|
|
queue_free()
|
|
|
|
func _on_cancel_button_pressed() -> void:
|
|
cancelled.emit()
|
|
queue_free()
|