You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-17 14:11:06 +00:00
Add cache to color picker for presets
This prevents loading from the project metadata more than once, significantly saving performance with nodes that have color pickers.
This commit is contained in:
@@ -40,6 +40,8 @@
|
||||
#endif
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
List<Color> ColorPicker::preset_cache;
|
||||
|
||||
void ColorPicker::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
@@ -57,12 +59,18 @@ void ColorPicker::_notification(int p_what) {
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
if (preset_cache.empty()) {
|
||||
PoolColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PoolColorArray());
|
||||
|
||||
for (int i = 0; i < saved_presets.size(); i++) {
|
||||
add_preset(saved_presets[i]);
|
||||
preset_cache.push_back(saved_presets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < preset_cache.size(); i++) {
|
||||
presets.push_back(preset_cache[i]);
|
||||
}
|
||||
preset->update();
|
||||
}
|
||||
#endif
|
||||
} break;
|
||||
case NOTIFICATION_PARENTED: {
|
||||
@@ -287,6 +295,7 @@ void ColorPicker::add_preset(const Color &p_color) {
|
||||
presets.move_to_back(presets.find(p_color));
|
||||
} else {
|
||||
presets.push_back(p_color);
|
||||
preset_cache.push_back(p_color);
|
||||
}
|
||||
preset->update();
|
||||
|
||||
@@ -301,6 +310,7 @@ void ColorPicker::add_preset(const Color &p_color) {
|
||||
void ColorPicker::erase_preset(const Color &p_color) {
|
||||
if (presets.find(p_color)) {
|
||||
presets.erase(presets.find(p_color));
|
||||
preset_cache.erase(preset_cache.find(p_color));
|
||||
preset->update();
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
@@ -47,6 +47,7 @@ class ColorPicker : public BoxContainer {
|
||||
GDCLASS(ColorPicker, BoxContainer);
|
||||
|
||||
private:
|
||||
static List<Color> preset_cache;
|
||||
Control *screen;
|
||||
Control *uv_edit;
|
||||
Control *w_edit;
|
||||
|
||||
Reference in New Issue
Block a user