|
| 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 | +} |
0 commit comments