diff --git a/scenes/Catapult.tscn b/scenes/Catapult.tscn index 315fe537..099ea477 100644 --- a/scenes/Catapult.tscn +++ b/scenes/Catapult.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=33 format=2] +[gd_scene load_steps=34 format=2] [ext_resource path="res://icons/info.svg" type="Texture" id=1] [ext_resource path="res://icons/download.svg" type="Texture" id=2] @@ -31,6 +31,7 @@ [ext_resource path="res://scenes/FontSizeHelpDialog.tscn" type="PackedScene" id=29] [ext_resource path="res://icons/help.svg" type="Texture" id=30] [ext_resource path="res://scripts/PathHelper.gd" type="Script" id=31] +[ext_resource path="res://scenes/ChangelogDialog.tscn" type="PackedScene" id=32] [sub_resource type="ButtonGroup" id=1] @@ -127,12 +128,11 @@ margin_bottom = 91.0 ]] margin_top = 97.0 margin_right = 784.0 -margin_bottom = 594.0 +margin_bottom = 418.0 tab_align = 0 script = ExtResource( 16 ) [node name="Game" type="VBoxContainer" parent="Main/Tabs"] -visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 7.5 @@ -282,6 +282,8 @@ margin_top = 275.0 margin_right = 769.0 margin_bottom = 275.0 +[node name="ChangelogDialog" parent="Main/Tabs/Game" instance=ExtResource( 32 )] + [node name="Mods" type="VBoxContainer" parent="Main/Tabs"] visible = false anchor_right = 1.0 @@ -587,8 +589,8 @@ window_title = "Open a File" mode = 0 access = 2 filters = PoolStringArray( "*.zip" ) -current_dir = "/mnt/data/Godot/Catapult/Project" -current_path = "/mnt/data/Godot/Catapult/Project/" +current_dir = "/mnt/data/Godot/Catapult/Changelog" +current_path = "/mnt/data/Godot/Catapult/Changelog/" [node name="Fonts" type="VBoxContainer" parent="Main/Tabs"] visible = false @@ -871,6 +873,7 @@ margin_right = 769.0 margin_bottom = 539.0 [node name="Settings" type="VBoxContainer" parent="Main/Tabs"] +visible = false anchor_right = 1.0 anchor_bottom = 1.0 margin_left = 7.5 @@ -961,10 +964,33 @@ min_value = 1.0 value = 30.0 rounded = true -[node name="ScaleOverride" type="HBoxContainer" parent="Main/Tabs/Settings"] +[node name="NumPrs" type="HBoxContainer" parent="Main/Tabs/Settings"] margin_top = 280.0 margin_right = 769.0 margin_bottom = 309.0 +hint_tooltip = "How many recent pull requests (code additions) +will be requested from GitHub to form the changelog. +High numbers may lead to slow responses and failures." + +[node name="Label" type="Label" parent="Main/Tabs/Settings/NumPrs"] +margin_right = 390.0 +margin_bottom = 29.0 +text = "Number of results to download for the changelog:" + +[node name="sbNumPRs" type="SpinBox" parent="Main/Tabs/Settings/NumPrs"] +margin_left = 639.0 +margin_right = 769.0 +margin_bottom = 29.0 +size_flags_horizontal = 10 +min_value = 10.0 +step = 10.0 +value = 100.0 +rounded = true + +[node name="ScaleOverride" type="HBoxContainer" parent="Main/Tabs/Settings"] +margin_top = 315.0 +margin_right = 769.0 +margin_bottom = 344.0 hint_tooltip = "Use this if the automatically inferred UI scale looks too large or too small on your system. (Automatic scale relies on system-reported @@ -1001,14 +1027,14 @@ editable = false suffix = "%" [node name="HSeparator" type="HSeparator" parent="Main/Tabs/Settings"] -margin_top = 315.0 +margin_top = 350.0 margin_right = 769.0 -margin_bottom = 323.0 +margin_bottom = 358.0 [node name="Migration" type="VBoxContainer" parent="Main/Tabs/Settings"] -margin_top = 329.0 +margin_top = 364.0 margin_right = 769.0 -margin_bottom = 451.0 +margin_bottom = 486.0 hint_tooltip = "Choose which types of game data to carry over into the new game version when updating." @@ -1110,13 +1136,13 @@ autowrap = true [node name="Button" type="Button" parent="Main/Tabs/Debug"] margin_left = 273.0 margin_top = 56.0 -margin_right = 496.0 +margin_right = 495.0 margin_bottom = 85.0 size_flags_horizontal = 6 text = "Test mod directory parsing" [node name="Button2" type="Button" parent="Main/Tabs/Debug"] -margin_left = 266.0 +margin_left = 267.0 margin_top = 91.0 margin_right = 502.0 margin_bottom = 120.0 @@ -1124,7 +1150,7 @@ size_flags_horizontal = 6 text = "Test sound directory parsing" [node name="Button3" type="Button" parent="Main/Tabs/Debug"] -margin_left = 201.0 +margin_left = 202.0 margin_top = 126.0 margin_right = 567.0 margin_bottom = 155.0 @@ -1134,13 +1160,13 @@ text = "Test passing of arguments to shell commands" [node name="Button4" type="Button" parent="Main/Tabs/Debug"] margin_left = 228.0 margin_top = 161.0 -margin_right = 541.0 +margin_right = 540.0 margin_bottom = 190.0 size_flags_horizontal = 6 text = "Test different types of status messages" [node name="Button5" type="Button" parent="Main/Tabs/Debug"] -margin_left = 261.0 +margin_left = 262.0 margin_top = 196.0 margin_right = 507.0 margin_bottom = 225.0 @@ -1158,13 +1184,13 @@ text = "Print a random Tip of the Day" [node name="Button7" type="Button" parent="Main/Tabs/Debug"] margin_left = 245.0 margin_top = 266.0 -margin_right = 524.0 +margin_right = 523.0 margin_bottom = 295.0 size_flags_horizontal = 4 text = "Test path resolution in PathHelper" [node name="Log" type="RichTextLabel" parent="Main"] -margin_top = 600.0 +margin_top = 424.0 margin_right = 784.0 margin_bottom = 984.0 focus_mode = 2 @@ -1288,6 +1314,7 @@ __meta__ = { [connection signal="toggled" from="Main/Tabs/Settings/InstallArchivedMods" to="Main/Tabs/Settings" method="_on_InstallArchivedMods_toggled"] [connection signal="toggled" from="Main/Tabs/Settings/ShowDebug" to="Main/Tabs/Settings" method="_on_ShowDebug_toggled"] [connection signal="value_changed" from="Main/Tabs/Settings/NumReleases/sbNumReleases" to="Main/Tabs/Settings" method="_on_sbNumReleases_value_changed"] +[connection signal="value_changed" from="Main/Tabs/Settings/NumPrs/sbNumPRs" to="Main/Tabs/Settings" method="_on_sbNumPRs_value_changed"] [connection signal="toggled" from="Main/Tabs/Settings/ScaleOverride/cbScaleOverrideEnable" to="Main/Tabs/Settings" method="_on_cbScaleOverrideEnable_toggled"] [connection signal="value_changed" from="Main/Tabs/Settings/ScaleOverride/sbScaleOverride" to="Main/Tabs/Settings" method="_on_sbScaleOverride_value_changed"] [connection signal="toggled" from="Main/Tabs/Settings/Migration/Grid/Savegames" to="Main/Tabs/Settings" method="_on_any_migration_checkbox_toggled"] diff --git a/scenes/ChangelogDialog.tscn b/scenes/ChangelogDialog.tscn new file mode 100644 index 00000000..ca83bb2d --- /dev/null +++ b/scenes/ChangelogDialog.tscn @@ -0,0 +1,81 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://scripts/ChangelogDialod.gd" type="Script" id=1] +[ext_resource path="res://fonts/OpenSans-SemiboldItalic.tres" type="DynamicFont" id=2] +[ext_resource path="res://fonts/OpenSans-Regular.tres" type="DynamicFont" id=3] +[ext_resource path="res://fonts/OpenSans-Italic.tres" type="DynamicFont" id=4] +[ext_resource path="res://fonts/OpenSans-Semibold.tres" type="DynamicFont" id=5] + +[node name="ChangelogDialog" type="WindowDialog"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -240.0 +margin_top = -160.0 +margin_right = 240.0 +margin_bottom = 160.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Panel" type="PanelContainer" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Margin" type="MarginContainer" parent="Panel"] +margin_left = 9.0 +margin_top = 6.0 +margin_right = 471.0 +margin_bottom = 314.0 +custom_constants/margin_top = 8 +custom_constants/margin_bottom = 8 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBox" type="VBoxContainer" parent="Panel/Margin"] +margin_top = 8.0 +margin_right = 462.0 +margin_bottom = 300.0 +custom_constants/separation = 8 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ChangelogText" type="RichTextLabel" parent="Panel/Margin/VBox"] +margin_right = 462.0 +margin_bottom = 255.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +custom_fonts/bold_italics_font = ExtResource( 2 ) +custom_fonts/italics_font = ExtResource( 4 ) +custom_fonts/bold_font = ExtResource( 5 ) +custom_fonts/normal_font = ExtResource( 3 ) +bbcode_enabled = true +text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="BtnCloseChangelog" type="Button" parent="Panel/Margin/VBox"] +margin_left = 201.0 +margin_top = 263.0 +margin_right = 260.0 +margin_bottom = 292.0 +size_flags_horizontal = 4 +text = "Close" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="PullRequests" type="HTTPRequest" parent="."] +timeout = 20 + +[connection signal="meta_clicked" from="Panel/Margin/VBox/ChangelogText" to="." method="_on_ChangelogText_meta_clicked"] +[connection signal="pressed" from="Panel/Margin/VBox/BtnCloseChangelog" to="." method="_on_BtnCloseChangelog_pressed"] +[connection signal="request_completed" from="PullRequests" to="." method="_on_PullRequests_request_completed"] diff --git a/scenes/FontSizeHelpDialog.tscn b/scenes/FontSizeHelpDialog.tscn index 3644c632..13667e8c 100644 --- a/scenes/FontSizeHelpDialog.tscn +++ b/scenes/FontSizeHelpDialog.tscn @@ -37,7 +37,7 @@ custom_constants/separation = 16 [node name="Help" type="RichTextLabel" parent="Panel/Margin/VBox"] margin_right = 772.0 -margin_bottom = 919.0 +margin_bottom = 903.0 size_flags_vertical = 3 custom_fonts/bold_italics_font = ExtResource( 2 ) custom_fonts/italics_font = ExtResource( 3 ) @@ -87,9 +87,9 @@ It is also recommended to turn on Font Blending for smoother font rendering. [node name="BtnOK" type="Button" parent="Panel/Margin/VBox"] margin_left = 345.0 -margin_top = 935.0 +margin_top = 919.0 margin_right = 427.0 -margin_bottom = 972.0 +margin_bottom = 956.0 size_flags_horizontal = 4 text = "Close" diff --git a/scripts/Catapult.gd b/scripts/Catapult.gd index 134dee2a..6bafed3a 100644 --- a/scripts/Catapult.gd +++ b/scripts/Catapult.gd @@ -3,9 +3,9 @@ extends Node const _GAME_DESC = { "dda": - "[b]Cataclysm: Dark Days Ahead[/b] is a turn-based survival game set in a post-apocalyptic world. Scavenge, explore, craft, build, farm, repair and modify vehicles, install bionics, mutate, defend against [color=#009900]zombies[/color] and countless other monstrosities — all in a limitless, procedurally generated world!", + "[b]Cataclysm: Dark Days Ahead[/b] is a turn-based survival game set in a post-apocalyptic world. Scavenge, explore, craft, build, farm, repair and modify vehicles, install bionics, mutate, defend against [color=#009900]zombies[/color] and countless other monstrosities — all in a limitless, procedurally generated world! [color=#3b93f7][url=CHANGELOG]View Changelog[/url][/color]", "bn": - "[b]Cataclysm: Bright Nights[/b]. Reject pedantry, embrace [color=#ff3300]!!fun!![/color]. This fork takes the game back to its sci-fi roguelike roots and reverts many controversial changes by the DDA team (pockets, proficiencies, freezing, and [color=#3b93f7][url=https://github.com/cataclysmbnteam/Cataclysm-BN/wiki/Changes-so-far]more[/url][/color]). Special attention is paid to combat, game balance and pacing.", + "[b]Cataclysm: Bright Nights[/b]. Reject pedantry, embrace [color=#ff3300]!!fun!![/color]. This fork takes the game back to its sci-fi roguelike roots and reverts many controversial changes by the DDA team (pockets, proficiencies, freezing, and [color=#3b93f7][url=https://github.com/cataclysmbnteam/Cataclysm-BN/wiki/Changes-so-far]more[/url][/color]). Special attention is paid to combat, game balance and pacing. [color=#3b93f7][url=CHANGELOG]View Changelog[/url][/color]", } onready var _settings = $"/root/SettingsManager" @@ -25,6 +25,7 @@ onready var _fshelper = $FSHelper onready var _installer = $ReleaseInstaller onready var _btn_install = $Main/Tabs/Game/BtnInstall onready var _btn_refresh = $Main/Tabs/Game/Builds/BtnRefresh +onready var _changelog = $Main/Tabs/Game/ChangelogDialog onready var _btn_game_dir = $Main/Tabs/Game/CurrentInstall/Build/GameDir onready var _btn_play = $Main/Tabs/Game/CurrentInstall/BtnPlay onready var _lst_builds = $Main/Tabs/Game/Builds/BuildsList @@ -33,7 +34,6 @@ onready var _rbtn_stable = $Main/Tabs/Game/Channel/Group/RBtnStable onready var _rbtn_exper = $Main/Tabs/Game/Channel/Group/RBtnExperimental onready var _lbl_build = $Main/Tabs/Game/CurrentInstall/Build/Name - var _disable_savestate = {} var _ui_staring_sizes = {} # For UI scaling on the fly @@ -271,7 +271,10 @@ func _on_soundpack_operation_finished() -> void: func _on_Description_meta_clicked(meta) -> void: - OS.shell_open(meta) + if meta == "CHANGELOG": + _changelog.open() + else: + OS.shell_open(meta) func _on_BtnRefresh_pressed() -> void: @@ -368,6 +371,7 @@ func apply_game_choice() -> void: _btn_refresh.disabled = true else: _btn_refresh.disabled = false + "bn": _lst_games.select(1) _rbtn_exper.pressed = true diff --git a/scripts/ChangelogDialod.gd b/scripts/ChangelogDialod.gd new file mode 100644 index 00000000..9902da34 --- /dev/null +++ b/scripts/ChangelogDialod.gd @@ -0,0 +1,182 @@ +extends WindowDialog + + +const _PR_URL = { + "dda": "https://api.github.com/repos/cleverraven/cataclysm-dda/pulls", + "bn": "https://api.github.com/repos/cataclysmbnteam/Cataclysm-BN/pulls", +} + + +onready var _settings = $"/root/SettingsManager" +onready var _pullRequests = $PullRequests +onready var _changelogTextBox = $Panel/Margin/VBox/ChangelogText + +var _pr_data = "" + + +func open() -> void: + + download_pull_requests() + rect_min_size = get_tree().root.size * Vector2(0.9, 0.9) + set_as_minsize() + popup_centered() + + +func download_pull_requests(): + var game_selected = _settings.read("game") + var prs = _settings.read("num_prs_to_request") + var url = _PR_URL[_settings.read("game")] + url += "?state=closed&sort=updated&direction=desc&per_page=" + prs + var headers = ["user-agent: CatapultGodotApp"] + var pat = _settings.read("github_pat") + if (pat.length() == 40): + headers.push_back("Authorization: token " + pat) + _pr_data = "Fetching recent changes from GitHub. Please wait..." + _pullRequests.request(url, headers) + _changelogTextBox.clear() + _changelogTextBox.append_bbcode(_pr_data) + _changelogTextBox.clear() + _changelogTextBox.append_bbcode(_pr_data) + + +func _on_PullRequests_request_completed(result, response_code, headers, body): + var json = parse_json(body.get_string_from_utf8()) + if response_code != 200: + _pr_data = "Error retrieving data from GitHub API." + _pr_data += "\n\nHTTP response code: " + str(response_code) + if (json) and ("message" in json): + _pr_data += "\nGitHub says: [i]%s[/i]" % json["message"] + _pr_data += "\n\nSometimes, requests will fail repeatedly due to excessive load on the server, especially for DDA. This may depend on the time of day, your location, etc. There's little anyone can do about this. If you are registered on GitHub, you can add your [url=https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token]PAT (Personal Access Token)[/url] to Catapult config file to increase the priority of your requests or bypass rate limits." + else: + _pr_data = process_pr_data(json) + _changelogTextBox.clear() + _changelogTextBox.append_bbcode(_pr_data) + + +func process_pr_data(data): + var pr_array = [] + for json in data: + if json["merged_at"] == null or json["merged_at"] == "null" : + continue + var pr = PullRequest.pullrequest_from_datestring(json["merged_at"], json["title"], json["html_url"]) + pr_array.push_back(pr) + pr_array.sort_custom(PullRequest, "compare_to") + var now = OS.get_datetime(true) + var latest_year = now["year"] + 1 + var latest_month = now["month"] + var latest_day = now["day"] + var mon_str = PullRequest.format_two_digit(str(latest_month)) + var day_str = PullRequest.format_two_digit(str(latest_day)) + + var game_title = "" + match _settings.read("game"): + "dda": + game_title = "Cataclysm: Dark Days Ahead" + "bn": + game_title = "Cataclysm: Bright Nights" + _: + game_title = "{BUG!!}" + + var r_val = ("Showing the last [b]%s[/b] completed pull requests (code additions) to [b]%s[/b].\n\nThe chronology may be slightly off due to GitHub API limitations.\n\nYou can click on any item to view the corresponding PR on GitHub and learn more about the change.\n" + % [_settings.read("num_prs_to_request"), game_title]) + + for pr in pr_array: + var switch_date = false + switch_date = switch_date or (pr.get_year() < latest_year) + switch_date = switch_date or (pr.get_month() < latest_month) + switch_date = switch_date or (pr.get_day() < latest_day) + if switch_date: + latest_year = pr.get_year() + latest_month = pr.get_month() + latest_day = pr.get_day() + mon_str = PullRequest.format_two_digit(latest_month) + day_str = PullRequest.format_two_digit(latest_day) + r_val = r_val + "\n[b]" + str(latest_year) + "-" + mon_str+ "-" + day_str + "[/b]\n" + r_val = r_val + "[indent]• [url=" + pr.get_link() + "]" + pr.get_summary() + "[/url][/indent]\n" + return r_val + + +func _on_ChangelogText_meta_clicked(meta): + OS.shell_open(str(meta)) + + +class PullRequest: + var timestring setget set_timestring,get_timestring + var year setget ,get_year + var month setget ,get_month + var day setget ,get_day + var hour setget ,get_hour + var minute setget ,get_minute + var second setget ,get_second + var summary setget ,get_summary + var link setget ,get_link + + func get_year(): + return year + + func get_month(): + return month + + func get_day(): + return day + + func get_hour(): + return hour + + func get_minute(): + return minute + + func get_second(): + return second + + func get_summary(): + return summary + + func get_link(): + return link + + func set_timestring(t): + timestring = t + + func get_timestring(): + return timestring + + static func format_two_digit(time): + if (str(time).length() == 1): + return "0" + str(time) + return str(time) + + # Sorts dates in descending order (that is, the latest date comes first). + static func compare_to(a, b): + return a.timestring > b.timestring + + # We just need to get Github API strings. Nothing else. + static func pullrequest_from_datestring(date, sum, link): + var r_val = PullRequest.new( + int(date.substr(0,4)), + int(date.substr(5,2)), + int(date.substr(8,2)), + int(date.substr(11,2)), + int(date.substr(14,2)), + int(date.substr(16,2)), + sum, + link) + r_val.set_timestring(date) + return r_val + + func _init(y, mo, d, h, mi, s, sum, url): + year = y + month = mo + day = d + hour = h + minute = mi + second = s + summary = sum + link = url + + func print_date(): + return str(year) + "-" + str(month) + "-" + str(day) + + +func _on_BtnCloseChangelog_pressed() -> void: + hide() diff --git a/scripts/SettingsUI.gd b/scripts/SettingsUI.gd index 7186df78..7ed3f0cb 100644 --- a/scripts/SettingsUI.gd +++ b/scripts/SettingsUI.gd @@ -30,6 +30,7 @@ func _ready() -> void: $InstallArchivedMods.pressed = _settings.read("install_archived_mods") $ShowDebug.pressed = _settings.read("debug_mode") $NumReleases/sbNumReleases.value = _settings.read("num_releases_to_request") as int + $NumPrs/sbNumPRs.value = _settings.read("num_prs_to_request") as int $ScaleOverride/cbScaleOverrideEnable.pressed = _settings.read("ui_scale_override_enabled") $ScaleOverride/sbScaleOverride.editable = _settings.read("ui_scale_override_enabled") @@ -87,6 +88,10 @@ func _on_sbNumReleases_value_changed(value: float) -> void: _settings.store("num_releases_to_request", str(value)) +func _on_sbNumPRs_value_changed(value: float) -> void: + + _settings.store("num_prs_to_request", str(value)) + func _on_cbScaleOverrideEnable_toggled(button_pressed: bool) -> void: @@ -116,3 +121,8 @@ func _on_any_migration_checkbox_toggled(_asdf: bool) -> void: data_types.append(type) _settings.store("game_data_to_migrate", data_types) + + +func _on_lePATUse_text_changed(new_text): + if (new_text.length() == 40 or new_text.length() == 0): + _settings.store("github_pat", new_text) diff --git a/scripts/settings_manager.gd b/scripts/settings_manager.gd index 467c46bd..fed4a64a 100644 --- a/scripts/settings_manager.gd +++ b/scripts/settings_manager.gd @@ -13,6 +13,8 @@ const _HARDCODED_DEFAULTS = { "update_to_same_build_allowed": false, "shorten_release_names": false, "num_releases_to_request": 10, + "num_prs_to_request": 50, + "github_pat": "", "ui_scale_override": 1.0, "ui_scale_override_enabled": false, "show_stock_mods": false,