diff --git a/UI/bug_report_form.gd b/UI/bug_report_form.gd index f706f84..b0a920c 100644 --- a/UI/bug_report_form.gd +++ b/UI/bug_report_form.gd @@ -4,24 +4,24 @@ 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 __product_name : Label = $Form/VBoxContainerLeft/GridContainer/ProductName as Label +@onready var __version_label : Label = $Form/VBoxContainerLeft/GridContainer/VersionLabel as Label +@onready var __version_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/VersionButton as MenuButton +@onready var __hardware_label : Label = $Form/VBoxContainerLeft/GridContainer/HardwareLabel as Label +@onready var __hardware_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/HardwareButton as MenuButton +@onready var __os_label : Label = $Form/VBoxContainerLeft/GridContainer/OSLabel as Label +@onready var __os_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/OSButton as MenuButton +@onready var __component_label : Label = $Form/VBoxContainerLeft/GridContainer/ComponentLabel as Label +@onready var __component_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/ComponentButton as MenuButton +@onready var __severity_label : Label = $Form/VBoxContainerLeft/GridContainer/SeverityLabel as Label +@onready var __severity_button : MenuButton = $Form/VBoxContainerLeft/GridContainer/SeverityButton as MenuButton -@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 __summary_label : Label = $Form/VBoxContainerRight/GridContainer/SummaryLabel as Label +@onready var __summary_text : LineEdit = $Form/VBoxContainerRight/GridContainer/SummaryText as LineEdit +@onready var __description_label : Label = $Form/VBoxContainerRight/GridContainer/DescriptionLabel as Label +@onready var __description_text : TextEdit = $Form/VBoxContainerRight/GridContainer/DescriptionText as TextEdit -@onready var __submit_button : Button = $Form/VBoxContainerRight/SubmitButton +@onready var __submit_button : Button = $Form/VBoxContainerRight/SubmitButton as Button var map_name : String var bug_location : Vector3 @@ -31,6 +31,7 @@ var __label_groups : Array var __stored_mouse_mode : int var __server_api : BugbotServerAPI +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) @@ -49,7 +50,7 @@ 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", "") + __product_name.text = ProjectSettings.get_setting("application/config/name", __DEFAULT_PRODUCT_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) @@ -71,49 +72,39 @@ func __fill_item_list(menu_button:MenuButton, label_group:int): func _on_submit_button_pressed() -> void: __submit_button.disabled = true - var error_detected : bool = false - + var summary_error : 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 + 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) - error_detected = true + description_error = 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") + var version_error : bool = !__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.VERSION, __version_label, __version_button) + var hardware_error : bool = !__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.HARDWARE, __hardware_label, __hardware_button) + var os_error : bool = !__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.OS, __os_label, __os_button) + var component_error : bool = !__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.COMPONENT, __component_label, __component_button) + var severity_error : bool = !__get_label_ids_for_submission_data(labels_to_be_added, BugbotServerAPI.BugbotTagArray.SEVERITY, __severity_label, __severity_button) - if error_detected: + 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 - __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, @@ -122,13 +113,25 @@ func _on_submit_button_pressed() -> void: __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"]) +func __get_label_ids_for_submission_data(label_array:Array, label_group_id:int, label:Label, button:MenuButton) -> bool: + var labels : Array + for applied_label in __label_groups[label_group_id]: + if applied_label["name"] == __severity_button.text: + labels.append(applied_label["id"]) break + + if labels.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_array.append_array(labels) + label.remove_theme_color_override("font_color") + button.remove_theme_color_override("font_color") + return true -func __submission_response(response:Variant): +func __submission_response(response:Variant) -> void: submitted.emit(map_name, bug_location, bug_rotation) queue_free()