Bugbot/UI/bug_report_form.gd

188 lines
9.3 KiB
GDScript

class_name BugReportForm
extends ColorRect
@onready var __product_name : Label = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/ProductName as Label
@onready var __version_label : Label = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/VersionLabel as Label
@onready var __version_button : MenuButton = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/VersionButton as MenuButton
@onready var __hardware_label : Label = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/HardwareLabel as Label
@onready var __hardware_button : MenuButton = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/HardwareButton as MenuButton
@onready var __os_label : Label = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/OSLabel as Label
@onready var __os_button : MenuButton = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/OSButton as MenuButton
@onready var __component_label : Label = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/ComponentLabel as Label
@onready var __component_button : MenuButton = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/ComponentButton as MenuButton
@onready var __severity_label : Label = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/SeverityLabel as Label
@onready var __severity_button : MenuButton = $VBoxContainer/Form/VBoxContainerLeft/GridContainer/SeverityButton as MenuButton
@onready var __summary_label : Label = $VBoxContainer/Form/VBoxContainerRight/GridContainer/SummaryLabel as Label
@onready var __summary_text : LineEdit = $VBoxContainer/Form/VBoxContainerRight/GridContainer/SummaryText as LineEdit
@onready var __description_label : Label = $VBoxContainer/Form/VBoxContainerRight/GridContainer/DescriptionLabel as Label
@onready var __description_text : TextEdit = $VBoxContainer/Form/VBoxContainerRight/GridContainer/DescriptionText as TextEdit
@onready var __submit_button : Button = $VBoxContainer/Form/VBoxContainerRight/SubmitButton as Button
signal submitted(map_name:String, bug_location:Vector3, bug_rotation:Vector3)
signal cancelled
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
var __text_input_dialogue_preload : PackedScene = preload("res://addons/Bugbot/UI/ControllerInput/controller_input_wheel_screen.tscn")
var __text_input_dialogue : ControllerInputWheelTextEdit
const __DEFAULT_PRODUCT_NAME : StringName = &"NameOfProductHere"
const __BUTTON_DISABLED_MESSAGE : StringName = &"Not available"
const __ERROR_TEXT_COLOUR : Color = Color(0.75, 0.0, 0.0)
func _enter_tree() -> void:
__stored_mouse_mode = Input.mouse_mode
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
__server_api = BugbotServerAPI._create_new_server_api()
func _exit_tree() -> void:
Input.mouse_mode = __stored_mouse_mode
func fill_tags(tag_list:Array) -> void:
__label_groups.resize(BugbotServerAPI.BugbotTagArray.MAX)
__label_groups = tag_list
if __label_groups.size() != BugbotServerAPI.BugbotTagArray.MAX:
printerr("Invalid tag array format.")
return
__product_name.text = __server_api._get_project_name()
__fill_item_list(__version_button, __version_label, BugbotServerAPI.BugbotTagArray.VERSION)
__fill_item_list(__hardware_button, __hardware_label, BugbotServerAPI.BugbotTagArray.HARDWARE)
__fill_item_list(__os_button, __os_label, BugbotServerAPI.BugbotTagArray.OS)
__fill_item_list(__component_button, __component_label, BugbotServerAPI.BugbotTagArray.COMPONENT)
__fill_item_list(__severity_button, __severity_label, BugbotServerAPI.BugbotTagArray.SEVERITY)
if __version_button.visible: __version_button.grab_focus()
elif __hardware_button.visible: __hardware_button.grab_focus()
elif __os_button.visible: __os_button.grab_focus()
elif __component_button.visible: __component_button.grab_focus()
elif __severity_button.visible: __severity_button.grab_focus()
else: __submit_button.grab_focus()
func __fill_item_list(menu_button:MenuButton, menu_label:Label, label_group:int) -> void:
var menu_options : Array = __label_groups[label_group]
if menu_options.is_empty():
menu_button.text = __BUTTON_DISABLED_MESSAGE
menu_button.disabled = true
menu_button.visible = false
menu_label.visible = false
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_summary_text_gui_input(event:InputEvent) -> void:
if event.is_action_pressed(&"ui_accept") and event is InputEventJoypadButton:
__text_input_dialogue = __text_input_dialogue_preload.instantiate()
add_child(__text_input_dialogue)
__text_input_dialogue.edit_mode = ControllerInputWheelTextEdit.EditMode.LINE_EDIT
__text_input_dialogue.tree_exiting.connect(__retrieve_summary_text)
__text_input_dialogue.text = __summary_text.text
func __retrieve_summary_text():
__summary_text.text = __text_input_dialogue.text
__summary_text.grab_focus()
func _on_description_text_gui_input(event:InputEvent) -> void:
if event.is_action_pressed(&"ui_accept") and event is InputEventJoypadButton:
__text_input_dialogue = __text_input_dialogue_preload.instantiate()
add_child(__text_input_dialogue)
__text_input_dialogue.edit_mode = ControllerInputWheelTextEdit.EditMode.TEXT_EDIT
__text_input_dialogue.tree_exiting.connect(__retrieve_description_text)
__text_input_dialogue.text = __description_text.text
func __retrieve_description_text():
__description_text.text = __text_input_dialogue.text
__description_text.grab_focus()
func _on_submit_button_pressed() -> void:
__submit_button.disabled = true
var summary_error : bool = false
var summary_text : String = __summary_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)
summary_error = true
else:
__summary_label.remove_theme_color_override("font_color")
__summary_text.remove_theme_color_override("font_color")
var description_error : bool = false
var description_text : String = __description_text.text
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)
description_error = true
else:
__description_label.remove_theme_color_override("font_color")
__description_text.remove_theme_color_override("font_color")
var version_tags : Array = []
var hardware_tags : Array = []
var os_tags : Array = []
var component_tags : Array = []
var severity_tags : Array = []
var version_error : bool = !__get_label_ids_for_submission_data(version_tags, BugbotServerAPI.BugbotTagArray.VERSION, __version_label, __version_button)
var hardware_error : bool = !__get_label_ids_for_submission_data(hardware_tags, BugbotServerAPI.BugbotTagArray.HARDWARE, __hardware_label, __hardware_button)
var os_error : bool = !__get_label_ids_for_submission_data(os_tags, BugbotServerAPI.BugbotTagArray.OS, __os_label, __os_button)
var component_error : bool = !__get_label_ids_for_submission_data(component_tags, BugbotServerAPI.BugbotTagArray.COMPONENT, __component_label, __component_button)
var severity_error : bool = !__get_label_ids_for_submission_data(severity_tags, BugbotServerAPI.BugbotTagArray.SEVERITY, __severity_label, __severity_button)
if summary_error or description_error or version_error or hardware_error or os_error or component_error or severity_error:
__submit_button.disabled = false
return
var bug_report_form_data : Dictionary = {
"title": summary_text,
"body": description_text,
"labels": {},
}
if not version_tags.is_empty(): bug_report_form_data["labels"]["version"] = version_tags[0]
if not hardware_tags.is_empty(): bug_report_form_data["labels"]["hardware"] = hardware_tags[0]
if not os_tags.is_empty(): bug_report_form_data["labels"]["os"] = os_tags[0]
if not component_tags.is_empty(): bug_report_form_data["labels"]["component"] = component_tags[0]
if not severity_tags.is_empty(): bug_report_form_data["labels"]["severity"] = severity_tags[0]
__server_api._send_form_data(bug_report_form_data, map_name, bug_location, bug_rotation, __submission_response)
func __get_label_ids_for_submission_data(tag:Array, label_group_id:int, label:Label, button:MenuButton) -> bool:
for applied_label:Dictionary in __label_groups[label_group_id]:
if applied_label["name"] == button.text:
var label_data : Dictionary = { "name": applied_label["name"], "id": applied_label["id"] }
if applied_label.has("child_name"):
label_data["child_name"] = applied_label["child_name"]
label_data["child_id"] = applied_label["child_id"]
tag.append(label_data)
break
if tag.is_empty() and not (__label_groups[label_group_id] as Array).is_empty():
printerr("You must select a label for \"%s\"" % [label.text])
label.add_theme_color_override("font_color", __ERROR_TEXT_COLOUR)
button.add_theme_color_override("font_color", __ERROR_TEXT_COLOUR)
return false
label.remove_theme_color_override("font_color")
button.remove_theme_color_override("font_color")
return true
func __submission_response(bug:BugbotBugData) -> void:
submitted.emit(bug)
queue_free()
func _on_cancel_button_pressed() -> void:
cancelled.emit()
queue_free()