Fix theme changed notifications for the layered tile map's editor.

This commit is contained in:
Relintai 2024-03-07 22:56:23 +01:00
parent 564469a118
commit 2702aa5d65
3 changed files with 112 additions and 5 deletions

View File

@ -47,6 +47,8 @@
#include "scene/gui/popup_menu.h"
#include "scene/gui/split_container.h"
#include "theme_changed_notifier.h"
#include "core/containers/hash_set.h"
#include "core/input/input.h"
#include "core/math/geometry.h"
@ -2451,13 +2453,18 @@ LayeredTileMapLayerEditorTilesPlugin::LayeredTileMapLayerEditorTilesPlugin() {
// --- Bottom panel tiles ---
tiles_bottom_panel = memnew(VBoxContainer);
tiles_bottom_panel->connect("visibility_changed", this, "_stop_dragging");
tiles_bottom_panel->connect("visibility_changed", this, "_tab_changed");
tiles_bottom_panel->set_name(TTR("Tiles"));
// FIXME: This can trigger theme updates when the nodes that we want to update are not yet available.
// The toolbar should be extracted to a dedicated control and theme updates should be handled through
// the notification.
//tiles_bottom_panel->connect("theme_changed", this, "_update_theme");
tiles_bottom_panel->connect("visibility_changed", this, "_stop_dragging");
tiles_bottom_panel->connect("visibility_changed", this, "_tab_changed");
tiles_bottom_panel->set_name(TTR("Tiles"));
ThemeChangedNotifier *theme_changed_notifier = memnew(ThemeChangedNotifier);
theme_changed_notifier->connect("theme_changed", this, "_update_theme");
tiles_bottom_panel->add_child(theme_changed_notifier);
missing_source_label = memnew(Label);
missing_source_label->set_text(TTR("This LayeredTileMap's LayeredTileSet has no source configured. Go to the LayeredTileSet bottom panel to add one."));
@ -3612,11 +3619,14 @@ void LayeredTileMapLayerEditorTerrainsPlugin::edit(ObjectID p_edited_tile_map_la
LayeredTileMapLayerEditorTerrainsPlugin::LayeredTileMapLayerEditorTerrainsPlugin() {
main_vbox_container = memnew(VBoxContainer);
main_vbox_container->set_name(TTR("Terrains"));
// FIXME: This can trigger theme updates when the nodes that we want to update are not yet available.
// The toolbar should be extracted to a dedicated control and theme updates should be handled through
// the notification.
//main_vbox_container->connect("theme_changed", this, "_update_theme");
main_vbox_container->set_name(TTR("Terrains"));
ThemeChangedNotifier *theme_changed_notifier = memnew(ThemeChangedNotifier);
theme_changed_notifier->connect("theme_changed", this, "_update_theme");
main_vbox_container->add_child(theme_changed_notifier);
HSplitContainer *tilemap_tab_terrains = memnew(HSplitContainer);
tilemap_tab_terrains->set_h_size_flags(Control::SIZE_EXPAND_FILL);

View File

@ -0,0 +1,48 @@
/*************************************************************************/
/* theme_changed_notifier.cpp */
/*************************************************************************/
/* This file is part of: */
/* PANDEMONIUM ENGINE */
/* https://github.com/Relintai/pandemonium_engine */
/*************************************************************************/
/* Copyright (c) 2022-present Péter Magyar. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "theme_changed_notifier.h"
void ThemeChangedNotifier::_notification(int p_what) {
if (p_what == NOTIFICATION_THEME_CHANGED) {
emit_signal("theme_changed");
}
}
void ThemeChangedNotifier::_bind_methods() {
ADD_SIGNAL(MethodInfo("theme_changed"));
}
ThemeChangedNotifier::ThemeChangedNotifier() {
}
ThemeChangedNotifier::~ThemeChangedNotifier() {
}

View File

@ -0,0 +1,49 @@
#ifndef THEME_CHANGED_NOTIFIER_H
#define THEME_CHANGED_NOTIFIER_H
/*************************************************************************/
/* theme_changed_notifier.h */
/*************************************************************************/
/* This file is part of: */
/* PANDEMONIUM ENGINE */
/* https://github.com/Relintai/pandemonium_engine */
/*************************************************************************/
/* Copyright (c) 2022-present Péter Magyar. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/main/control.h"
class ThemeChangedNotifier : public Control {
GDCLASS(ThemeChangedNotifier, Control);
protected:
void _notification(int p_what);
static void _bind_methods();
public:
ThemeChangedNotifier();
~ThemeChangedNotifier();
};
#endif