Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save color palette as resources to reuse later #91604

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

nongvantinh
Copy link
Contributor

@nongvantinh nongvantinh commented May 5, 2024

Close godotengine/godot-proposals#7946

The lack of a palette library slows down development time because swatches contain many colors that may not match the mood an artist is trying to achieve. This can hinder their workflow as they search for the right color within a large set of mostly irrelevant options.

Untitled.video.-.Made.with.Clipchamp.mp4

@AThousandShips AThousandShips changed the title [feat] Save color palette as resources to reuse later Save color palette as resources to reuse later May 6, 2024
@AThousandShips
Copy link
Member

This should use icons available at runtime, not editor icons, there are some appropriate ones available, and otherwise they should be added, this shouldn't depend on the editor

@nongvantinh nongvantinh force-pushed the implement-7946 branch 2 times, most recently from 7c37110 to 0839503 Compare May 6, 2024 14:49
@fire
Copy link
Member

fire commented May 6, 2024

I approve of allowing saving the color pallete from a usability team perspective.

@fire fire requested a review from a team May 6, 2024 14:54
@nongvantinh
Copy link
Contributor Author

Update:

  • Use FileDialog instead of EditorFileDialog.
  • Save the palette in the user:// path instead of placing it in the project folder.
  • Remove the Palette resource class because it doesn't need anymore.

@AThousandShips What do you mean when you say use icons available at runtime? I couldn't find the correct function to call.

@AThousandShips
Copy link
Member

Icons available at runtime are those which aren't editor specific, meant in running projects not running the program itself sorry for confusion

AThousandShips
AThousandShips previously approved these changes May 6, 2024
@nongvantinh nongvantinh force-pushed the implement-7946 branch 2 times, most recently from 04ebe85 to acdd5f8 Compare May 6, 2024 15:11
@AThousandShips AThousandShips dismissed their stale review May 6, 2024 15:12

Accidental approval

@nongvantinh
Copy link
Contributor Author

Sorry for the annoying force push. I wasn't familiar with the TTR part. I need one more favor. I couldn't find the correct icon to use in the function get_theme_icon.

@AThousandShips
Copy link
Member

AThousandShips commented May 6, 2024

If it isn't in the default theme scene/theme/icons/ then you can add them from the editor or create new ones, and then you need to add them to the default theme, see in scene/theme/default_theme.cpp for details

But I think the normal folder icon is sufficient

Gonna test this one probably tomorrow but code looks good, got some final remarks I'll add when I've tested it out

@Calinou
Copy link
Member

Calinou commented May 6, 2024

I wonder if it should be possible to give a name to each color, and have the name displayed in a tooltip when hovering the color in the ColorPicker's swatch list.

It's common for designers to assign names to colors to make slightly different colors easier to distinguish from each other, or even to refer to them in natural language. If I refer to "lime 800" from Tailwind's color palette, you can immediately know it's #3f6212.

This could be left to a future PR, but we should make sure this feature can be implemented in the future without breaking compatibility (i.e. without changing the data structure in the resource).

@nongvantinh nongvantinh force-pushed the implement-7946 branch 2 times, most recently from 768da7a to 10f2235 Compare May 6, 2024 23:22
@AThousandShips
Copy link
Member

AThousandShips commented May 7, 2024

Tested and it works as expected, however I don't think the list of resources allowed makes sense, it should probably just limit to res and tres because it currently allows you to save as things like animtex and mesh, which don't make sense

Edit: correction, it shouldn't even be that, it should be some binary format dedicated to this, it doesn't actually store a res or tres file either, so that needs to be fixed

@Calinou
Copy link
Member

Calinou commented May 7, 2024

I suggest using ConfigFile to save palettes as opposed to FileAccess, so you have a text format that is friendly to version control. I'd also give them a custom file extension so they can be targeted more specifically, e.g. cpl.

A similar approach is used for script editor syntax themes, which use a tet file extension.

@nongvantinh nongvantinh force-pushed the implement-7946 branch 2 times, most recently from feca7e7 to 1e0de24 Compare May 8, 2024 12:42
@Mickeon
Copy link
Contributor

Mickeon commented Aug 19, 2024

@Calinou Would you like to take a look to see if this PR is satisfactory as is?

@tokengamedev
Copy link

Also is it possible to decrease the swatch colors size by 25% at least so more colors can fit in a row

@timshannon
Copy link

Also is it possible to decrease the swatch colors size by 25% at least so more colors can fit in a row

That's handled by the editor theme isn't it?

@nongvantinh
Copy link
Contributor Author

@tokengamedev @timshannon Look at the code: the size is fixed. There is no way to change the size of the preset.

inline int ColorPicker::_get_preset_size() {
return (int(get_minimum_size().width) - (preset_container->get_h_separation() * (PRESET_COLUMN_COUNT - 1))) / PRESET_COLUMN_COUNT;
}

@Mickeon
Copy link
Contributor

Mickeon commented Oct 6, 2024

Let's think about that in another PR if necessary.

@nongvantinh
Copy link
Contributor Author

@Calinou Could you spend some time reviewing my PR again?

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected.

I noticed a few UI issues though:

  • When using Quick Load, the color picker closes, so you can't see your palette being loaded (it still loads correctly when you reopen the color picker). This does not happen when using Load - the color picker stays open as expected.
  • The button in the dropdown is Save, but it always displays a file dialog even if a color palette file was already loaded. In this case, it should be renamed to Save As.... A Save button that overwrites the existing loaded palette could also be added above Save As... (this button should be disabled if no palette is loaded).

@nongvantinh
Copy link
Contributor Author

nongvantinh commented Oct 11, 2024

@Calinou Yes, I noticed the problem with Quick Load when developing this PR. However, I cannot resolve this issue because Godot doesn't support having two exclusive dialogs at the same time in one node. This means the EditorNode already has the ColorPickerPopupPanel as an exclusive child to keep it always visible. When the EditorQuickOpenDialog shows up, it tries to set itself as an exclusive child but fails to do so. Therefore, it prints an error indicating that another dialog is already set as an exclusive child when you try to open Quick Load while the color picker is still open.
image

As for the Save As option, I will add it when I return home from work.

@nongvantinh
Copy link
Contributor Author

@Calinou I tried to move the Quick Load dialog to the color picker to avoid the limitation mentioned above. However, I realized that someone had told me I cannot include editor code in the core code, if I remember correctly. As for your first point, I still cannot resolve it, but I have implemented the second point.

Please review it again when you have time.

@Calinou
Copy link
Member

Calinou commented Dec 4, 2024

@Calinou I tried to move the Quick Load dialog to the color picker to avoid the limitation mentioned above. However, I realized that someone had told me I cannot include editor code in the core code, if I remember correctly. As for your first point, I still cannot resolve it, but I have implemented the second point.

Please review it again when you have time.

Sorry for the delay. I've tested the latest revision of this PR, but I frequently get a freeze when adding some colors to the swatches (even without saving the palette). This occurs both in a standalone ColorPicker and ColorPickerButton.

Testing project: test_color_picker.zip

Co-authored-by: Micky <66727710+Mickeon@users.noreply.github.com>
@nongvantinh
Copy link
Contributor Author

Could you upload a video showing the issue? I just rebased the code and tested it, but I could not observe the described behavior. Maybe I was just careless and didn't pay enough attention to the details, overlooking something really important.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested the rebased PR and it works great now. The freezing issue may have been unrelated to this PR and was perhaps due to the state of master back in October.

I took a look at the code and it seems good to me.

@Repiteo Repiteo merged commit e9679a2 into godotengine:master Dec 9, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 9, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Save and Load ability to swatches