@@ -77,13 +77,19 @@ bool CColorIO::Parse(pugi::xml_document& document, const std::string, bool bUser
7777
7878 std::unordered_map<NamedColor::knownColorName, ColorPalette::Color> NamedColors;
7979 std::unordered_map<std::string, ColorPalette::GroupColorInfo> GroupColors;
80+ std::vector<ColorPalette::Color> UIPreviewColors;
8081 std::string parentName = outer.attribute (" parentName" ).as_string (HardcodedDefaultPalette->PaletteName .c_str ());
8182 std::string colorSchemeName = outer.attribute (" name" ).as_string (); // definitely exists, we checked above
8283
8384 for (pugi::xml_attribute attribute : outer.attributes ())
8485 {
8586 if (strcmp (attribute.name ()," parentName" ) == 0 || strcmp (attribute.name ()," name" ) == 0 ) continue ;
8687
88+ if (strcmp (attribute.name ()," uiPreviewColors" ) == 0 ){
89+ UIPreviewColors = GetAttributeAsColorList (attribute);
90+ continue ;
91+ }
92+
8793 NamedColors[attribute.name ()] = ColorPalette::Color (attribute.as_string ());
8894 }
8995
@@ -106,8 +112,24 @@ bool CColorIO::Parse(pugi::xml_document& document, const std::string, bool bUser
106112 GroupColors[groupInfo.attribute (" name" ).as_string ()] = group;
107113 }
108114
115+ // could not be loaded, determine default colors by search first group >=4 and sample four equally spaced colors
116+ if (UIPreviewColors.size () != 4 ){
117+ UIPreviewColors.clear ();
118+ for (auto & [name, group] : GroupColors){
119+ if (group.nodeColorSequence .size () >= 4 ){
120+ UIPreviewColors.push_back (group.nodeColorSequence .front ());
121+ UIPreviewColors.push_back (group.nodeColorSequence [group.nodeColorSequence .size () / 3 ]);
122+ UIPreviewColors.push_back (group.nodeColorSequence [group.nodeColorSequence .size () / 3 * 2 ]);
123+ UIPreviewColors.push_back (group.nodeColorSequence .back ());
124+ break ;
125+ }
126+ }
127+ }
128+ std::array<ColorPalette::Color, 4 > uiColorsArray;
129+ std::copy_n (std::make_move_iterator (UIPreviewColors.begin ()), uiColorsArray.size (), uiColorsArray.begin ());
130+
109131 // "HardcodedDefault" is the parent for now, later on the parents get relinked by looking up the parentNames
110- KnownPalettes[colorSchemeName] = new ColorPalette (HardcodedDefaultPalette, parentName, NamedColors, GroupColors, colorSchemeName);
132+ KnownPalettes[colorSchemeName] = new ColorPalette (HardcodedDefaultPalette, parentName, NamedColors, GroupColors, uiColorsArray, colorSchemeName);
111133
112134 return true ;
113135}
@@ -170,5 +192,12 @@ void CColorIO::CreateDefault() {
170192 {NamedColor::gameGuide, ColorPalette::Color (255 , 100 , 204 , 255 )}
171193 };
172194
173- HardcodedDefaultPalette = new ColorPalette (nullptr , " NonExistentRootRootPalette" , NamedColors, {}, " HardcodedDefault" ); // TODO: No groups for now, but will later be added
195+ std::array<ColorPalette::Color, 4 > uiColorsArray = {
196+ ColorPalette::Color (0 , 0 , 0 , 255 ),
197+ ColorPalette::Color (255 , 0 , 255 , 255 ),
198+ ColorPalette::Color (0 , 0 , 0 , 255 ),
199+ ColorPalette::Color (255 , 0 , 255 , 255 )
200+ };
201+
202+ HardcodedDefaultPalette = new ColorPalette (nullptr , " NonExistentRootRootPalette" , NamedColors, {}, uiColorsArray, " HardcodedDefault" ); // TODO: No groups for now, but will later be added
174203}
0 commit comments