Skip to content

Commit 38579a1

Browse files
committed
Unify editor version buttons
1 parent 76a1359 commit 38579a1

File tree

8 files changed

+152
-92
lines changed

8 files changed

+152
-92
lines changed

editor/editor_about.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@
3333
#include "core/authors.gen.h"
3434
#include "core/donors.gen.h"
3535
#include "core/license.gen.h"
36-
#include "core/os/time.h"
37-
#include "core/version.h"
3836
#include "editor/editor_string_names.h"
37+
#include "editor/gui/editor_version_button.h"
3938
#include "editor/themes/editor_scale.h"
4039
#include "scene/gui/item_list.h"
4140
#include "scene/resources/style_box.h"
4241

43-
// The metadata key used to store and retrieve the version text to copy to the clipboard.
44-
const String EditorAbout::META_TEXT_TO_COPY = "text_to_copy";
45-
4642
void EditorAbout::_notification(int p_what) {
4743
switch (p_what) {
4844
case NOTIFICATION_THEME_CHANGED: {
@@ -81,10 +77,6 @@ void EditorAbout::_license_tree_selected() {
8177
_tpl_text->set_text(selected->get_metadata(0));
8278
}
8379

84-
void EditorAbout::_version_button_pressed() {
85-
DisplayServer::get_singleton()->clipboard_set(version_btn->get_meta(META_TEXT_TO_COPY));
86-
}
87-
8880
void EditorAbout::_item_with_website_selected(int p_id, ItemList *p_il) {
8981
const String website = p_il->get_item_metadata(p_id);
9082
if (!website.is_empty()) {
@@ -198,25 +190,7 @@ EditorAbout::EditorAbout() {
198190
Control *v_spacer = memnew(Control);
199191
version_info_vbc->add_child(v_spacer);
200192

201-
version_btn = memnew(LinkButton);
202-
String hash = String(VERSION_HASH);
203-
if (hash.length() != 0) {
204-
hash = " " + vformat("[%s]", hash.left(9));
205-
}
206-
version_btn->set_text(VERSION_FULL_NAME + hash);
207-
// Set the text to copy in metadata as it slightly differs from the button's text.
208-
version_btn->set_meta(META_TEXT_TO_COPY, "v" VERSION_FULL_BUILD + hash);
209-
version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
210-
String build_date;
211-
if (VERSION_TIMESTAMP > 0) {
212-
build_date = Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC";
213-
} else {
214-
build_date = TTR("(unknown)");
215-
}
216-
version_btn->set_tooltip_text(vformat(TTR("Git commit date: %s\nClick to copy the version number."), build_date));
217-
218-
version_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorAbout::_version_button_pressed));
219-
version_info_vbc->add_child(version_btn);
193+
version_info_vbc->add_child(memnew(EditorVersionButton(EditorVersionButton::FORMAT_WITH_NAME_AND_BUILD)));
220194

221195
Label *about_text = memnew(Label);
222196
about_text->set_v_size_flags(Control::SIZE_SHRINK_CENTER);

editor/editor_about.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#include "scene/gui/dialogs.h"
3535
#include "scene/gui/item_list.h"
36-
#include "scene/gui/link_button.h"
3736
#include "scene/gui/rich_text_label.h"
3837
#include "scene/gui/scroll_container.h"
3938
#include "scene/gui/separator.h"
@@ -49,16 +48,12 @@
4948
class EditorAbout : public AcceptDialog {
5049
GDCLASS(EditorAbout, AcceptDialog);
5150

52-
static const String META_TEXT_TO_COPY;
53-
5451
private:
5552
void _license_tree_selected();
56-
void _version_button_pressed();
5753
void _item_with_website_selected(int p_id, ItemList *p_il);
5854
void _item_list_resized(ItemList *p_il);
5955
ScrollContainer *_populate_list(const String &p_name, const List<String> &p_sections, const char *const *const p_src[], int p_single_column_flags = 0, bool p_allow_website = false);
6056

61-
LinkButton *version_btn = nullptr;
6257
Tree *_tpl_tree = nullptr;
6358
RichTextLabel *license_text_label = nullptr;
6459
RichTextLabel *_tpl_text = nullptr;

editor/gui/editor_bottom_panel.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,17 @@
3030

3131
#include "editor_bottom_panel.h"
3232

33-
#include "core/os/time.h"
34-
#include "core/version.h"
3533
#include "editor/debugger/editor_debugger_node.h"
3634
#include "editor/editor_about.h"
3735
#include "editor/editor_command_palette.h"
3836
#include "editor/editor_node.h"
3937
#include "editor/editor_string_names.h"
4038
#include "editor/engine_update_label.h"
4139
#include "editor/gui/editor_toaster.h"
40+
#include "editor/gui/editor_version_button.h"
4241
#include "editor/themes/editor_scale.h"
4342
#include "scene/gui/box_container.h"
4443
#include "scene/gui/button.h"
45-
#include "scene/gui/link_button.h"
46-
47-
// The metadata key used to store and retrieve the version text to copy to the clipboard.
48-
static const String META_TEXT_TO_COPY = "text_to_copy";
4944

5045
void EditorBottomPanel::_notification(int p_what) {
5146
switch (p_what) {
@@ -110,10 +105,6 @@ void EditorBottomPanel::_expand_button_toggled(bool p_pressed) {
110105
EditorNode::get_top_split()->set_visible(!p_pressed);
111106
}
112107

113-
void EditorBottomPanel::_version_button_pressed() {
114-
DisplayServer::get_singleton()->clipboard_set(version_btn->get_meta(META_TEXT_TO_COPY));
115-
}
116-
117108
bool EditorBottomPanel::_button_drag_hover(const Vector2 &, const Variant &, Button *p_button, Control *p_control) {
118109
if (!p_button->is_pressed()) {
119110
_switch_by_control(true, p_control);
@@ -262,25 +253,9 @@ EditorBottomPanel::EditorBottomPanel() {
262253
editor_toaster = memnew(EditorToaster);
263254
bottom_hbox->add_child(editor_toaster);
264255

265-
version_btn = memnew(LinkButton);
266-
version_btn->set_text(VERSION_FULL_CONFIG);
267-
String hash = String(VERSION_HASH);
268-
if (hash.length() != 0) {
269-
hash = " " + vformat("[%s]", hash.left(9));
270-
}
271-
// Set the text to copy in metadata as it slightly differs from the button's text.
272-
version_btn->set_meta(META_TEXT_TO_COPY, "v" VERSION_FULL_BUILD + hash);
256+
EditorVersionButton *version_btn = memnew(EditorVersionButton(EditorVersionButton::FORMAT_BASIC));
273257
// Fade out the version label to be less prominent, but still readable.
274258
version_btn->set_self_modulate(Color(1, 1, 1, 0.65));
275-
version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
276-
String build_date;
277-
if (VERSION_TIMESTAMP > 0) {
278-
build_date = Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC";
279-
} else {
280-
build_date = TTR("(unknown)");
281-
}
282-
version_btn->set_tooltip_text(vformat(TTR("Git commit date: %s\nClick to copy the version information."), build_date));
283-
version_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorBottomPanel::_version_button_pressed));
284259
version_btn->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
285260
bottom_hbox->add_child(version_btn);
286261

editor/gui/editor_bottom_panel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class Button;
3737
class ConfigFile;
3838
class EditorToaster;
3939
class HBoxContainer;
40-
class LinkButton;
4140
class VBoxContainer;
4241

4342
class EditorBottomPanel : public PanelContainer {
@@ -55,14 +54,12 @@ class EditorBottomPanel : public PanelContainer {
5554
HBoxContainer *bottom_hbox = nullptr;
5655
HBoxContainer *button_hbox = nullptr;
5756
EditorToaster *editor_toaster = nullptr;
58-
LinkButton *version_btn = nullptr;
5957
Button *expand_button = nullptr;
6058
Control *last_opened_control = nullptr;
6159

6260
void _switch_by_control(bool p_visible, Control *p_control);
6361
void _switch_to_item(bool p_visible, int p_idx);
6462
void _expand_button_toggled(bool p_pressed);
65-
void _version_button_pressed();
6663

6764
bool _button_drag_hover(const Vector2 &, const Variant &, Button *p_button, Control *p_control);
6865

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**************************************************************************/
2+
/* editor_version_button.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include "editor_version_button.h"
32+
33+
#include "core/os/time.h"
34+
#include "core/version.h"
35+
36+
String _get_version_string(EditorVersionButton::VersionFormat p_format) {
37+
String main;
38+
switch (p_format) {
39+
case EditorVersionButton::FORMAT_BASIC: {
40+
return VERSION_FULL_CONFIG;
41+
} break;
42+
case EditorVersionButton::FORMAT_WITH_BUILD: {
43+
main = "v" VERSION_FULL_BUILD;
44+
} break;
45+
case EditorVersionButton::FORMAT_WITH_NAME_AND_BUILD: {
46+
main = VERSION_FULL_NAME;
47+
} break;
48+
default: {
49+
ERR_FAIL_V_MSG(VERSION_FULL_NAME, "Unexpected format: " + itos(p_format));
50+
} break;
51+
}
52+
53+
String hash = VERSION_HASH;
54+
if (!hash.is_empty()) {
55+
hash = vformat(" [%s]", hash.left(9));
56+
}
57+
return main + hash;
58+
}
59+
60+
void EditorVersionButton::_notification(int p_what) {
61+
switch (p_what) {
62+
case NOTIFICATION_POSTINITIALIZE: {
63+
// This can't be done in the constructor because theme cache is not ready yet.
64+
set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
65+
set_text(_get_version_string(format));
66+
} break;
67+
}
68+
}
69+
70+
void EditorVersionButton::pressed() {
71+
DisplayServer::get_singleton()->clipboard_set(_get_version_string(FORMAT_WITH_BUILD));
72+
}
73+
74+
EditorVersionButton::EditorVersionButton(VersionFormat p_format) {
75+
format = p_format;
76+
set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
77+
78+
String build_date;
79+
if (VERSION_TIMESTAMP > 0) {
80+
build_date = Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC";
81+
} else {
82+
build_date = TTR("(unknown)");
83+
}
84+
set_tooltip_text(vformat(TTR("Git commit date: %s\nClick to copy the version information."), build_date));
85+
}

editor/gui/editor_version_button.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**************************************************************************/
2+
/* editor_version_button.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#ifndef EDITOR_VERSION_BUTTON_H
32+
#define EDITOR_VERSION_BUTTON_H
33+
34+
#include "scene/gui/link_button.h"
35+
36+
class EditorVersionButton : public LinkButton {
37+
GDCLASS(EditorVersionButton, LinkButton);
38+
39+
public:
40+
enum VersionFormat {
41+
// 4.3.2.stable
42+
FORMAT_BASIC,
43+
// v4.3.2.stable.mono [HASH]
44+
FORMAT_WITH_BUILD,
45+
// Godot Engine v4.3.2.stable.mono.official [HASH]
46+
FORMAT_WITH_NAME_AND_BUILD,
47+
};
48+
49+
private:
50+
VersionFormat format = FORMAT_WITH_NAME_AND_BUILD;
51+
52+
protected:
53+
void _notification(int p_what);
54+
55+
virtual void pressed() override;
56+
57+
public:
58+
EditorVersionButton(VersionFormat p_format);
59+
};
60+
61+
#endif // EDITOR_VERSION_BUTTON_H

editor/project_manager.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
#include "core/io/stream_peer_tls.h"
3939
#include "core/os/keyboard.h"
4040
#include "core/os/os.h"
41-
#include "core/os/time.h"
4241
#include "core/version.h"
4342
#include "editor/editor_about.h"
4443
#include "editor/editor_settings.h"
4544
#include "editor/editor_string_names.h"
4645
#include "editor/engine_update_label.h"
4746
#include "editor/gui/editor_file_dialog.h"
4847
#include "editor/gui/editor_title_bar.h"
48+
#include "editor/gui/editor_version_button.h"
4949
#include "editor/plugins/asset_library_editor_plugin.h"
5050
#include "editor/project_manager/project_dialog.h"
5151
#include "editor/project_manager/project_list.h"
@@ -398,12 +398,6 @@ void ProjectManager::_restart_confirmed() {
398398
get_tree()->quit();
399399
}
400400

401-
// Footer.
402-
403-
void ProjectManager::_version_button_pressed() {
404-
DisplayServer::get_singleton()->clipboard_set(version_btn->get_text());
405-
}
406-
407401
// Project list.
408402

409403
void ProjectManager::_update_list_placeholder() {
@@ -1459,23 +1453,9 @@ ProjectManager::ProjectManager() {
14591453
update_label->connect("offline_clicked", callable_mp(this, &ProjectManager::_show_quick_settings));
14601454
#endif
14611455

1462-
version_btn = memnew(LinkButton);
1463-
String hash = String(VERSION_HASH);
1464-
if (hash.length() != 0) {
1465-
hash = " " + vformat("[%s]", hash.left(9));
1466-
}
1467-
version_btn->set_text("v" VERSION_FULL_BUILD + hash);
1456+
EditorVersionButton *version_btn = memnew(EditorVersionButton(EditorVersionButton::FORMAT_WITH_BUILD));
14681457
// Fade the version label to be less prominent, but still readable.
14691458
version_btn->set_self_modulate(Color(1, 1, 1, 0.6));
1470-
version_btn->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
1471-
String build_date;
1472-
if (VERSION_TIMESTAMP > 0) {
1473-
build_date = Time::get_singleton()->get_datetime_string_from_unix_time(VERSION_TIMESTAMP, true) + " UTC";
1474-
} else {
1475-
build_date = TTR("(unknown)");
1476-
}
1477-
version_btn->set_tooltip_text(vformat(TTR("Git commit date: %s\nClick to copy the version information."), build_date));
1478-
version_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectManager::_version_button_pressed));
14791459
footer_bar->add_child(version_btn);
14801460
}
14811461

editor/project_manager.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class EditorFileDialog;
4141
class EditorTitleBar;
4242
class HFlowContainer;
4343
class LineEdit;
44-
class LinkButton;
4544
class MarginContainer;
4645
class OptionButton;
4746
class PanelContainer;
@@ -124,12 +123,6 @@ class ProjectManager : public Control {
124123
void _show_quick_settings();
125124
void _restart_confirmed();
126125

127-
// Footer.
128-
129-
LinkButton *version_btn = nullptr;
130-
131-
void _version_button_pressed();
132-
133126
// Project list.
134127

135128
VBoxContainer *empty_list_placeholder = nullptr;

0 commit comments

Comments
 (0)