Browse Source

save working first time

meemknight 2 years ago
parent
commit
24fc84d24b

+ 39 - 0
Pika/core/sharedRuntime/pikaImgui/pikaImgui.cpp

@@ -151,6 +151,45 @@ bool pika::pikaImgui::greenButton(const char *label, const ImVec2 &size_arg)
 	return colouredButton(label, {0,1,0,1}, size_arg);
 }
 
+
+void addColorButton(const char *id, const ImVec4 &col, float outCol[4])
+{
+	if (ImGui::ColorButton(id, col))
+	{
+		outCol[0] = col.x;
+		outCol[1] = col.y;
+		outCol[2] = col.z;
+		outCol[3] = col.w;
+	}
+}
+
+bool pika::pikaImgui::ColorEdit4Swatches(const char *label, float col[4], ImGuiColorEditFlags flags)
+{
+	bool rez = ::ImGui::ColorEdit4(label, col);
+
+	::ImGui::BeginGroup();
+	::ImGui::PushID(label);
+
+	if (::ImGui::BeginPopup("picker"))
+	{
+		addColorButton("0", {0,0,0,1}, col); ImGui::SameLine(); 
+		addColorButton("1", {1,0,0,1}, col); ImGui::SameLine();
+		addColorButton("2", {0,1,0,1}, col); ImGui::SameLine();
+		addColorButton("3", {0,0,1,1}, col); ImGui::SameLine();
+		addColorButton("4", {1,1,0,1}, col); ImGui::SameLine();
+		addColorButton("5", {1,0,1,1}, col); ImGui::SameLine();
+		addColorButton("6", {0,1,1,1}, col); ImGui::SameLine();
+		addColorButton("7", {1,1,1,1}, col);
+		
+		::ImGui::EndPopup();
+	}
+
+	::ImGui::PopID();
+	::ImGui::EndGroup();
+
+	return rez;
+}
+
 bool pika::pikaImgui::blueButton(const char *label, const ImVec2 &size_arg)
 {
 	return colouredButton(label, {0,0,1,1}, size_arg);

+ 2 - 0
Pika/core/sharedRuntime/pikaImgui/pikaImgui.h

@@ -73,6 +73,8 @@ namespace pika
 		bool blueButton(const char *label, const ImVec2 &size_arg = {});
 		bool colouredButton(const char *label, glm::vec4 color, const ImVec2 &size_arg = {});
 
+		bool ColorEdit4Swatches(const char *label, float col[4], ImGuiColorEditFlags flags = 0);
+
 		bool BeginChildFrameColoured(ImGuiID id,
 			glm::vec4 color,
 			const ImVec2 &size = {},

+ 1 - 1
Pika/pluggins/pluggins/sushiViewer/sushiViewer.cpp

@@ -28,7 +28,7 @@ void SushiViewer::displaySushiBackgroundImgui(::sushi::Background &e, int id)
 	{
 		ImGui::Text("Background element editor");
 
-		ImGui::ColorEdit4("Background color", &e.color[0]);
+		pika::pikaImgui::ColorEdit4Swatches("Background color", &e.color[0]);
 
 		//todo texture stuff
 	}

+ 2 - 3
Pika/resources/logs.txt

@@ -1,3 +1,2 @@
-#2023-09-08 13:58:59: Reloaded dll
-#2023-09-08 13:59:03: Created container: SushiViewer
-#2023-09-08 14:00:55: Destroyed continer: SushiViewer #1
+#2023-09-08 14:51:34: Created container: SushiViewer
+#2023-09-08 14:51:44: Destroyed continer: SushiViewer #1

BIN
Pika/resources/sushi/test2.sushi


+ 69 - 55
Pika/thirdparty/sushi/src/sushi.cpp

@@ -454,83 +454,101 @@ namespace sushi
 
 		LoadeData loaded;
 
-		if (!loadAllData(data, loaded)) { return 0; }
+		if (!loadAllData(data, loaded)) { *this = {}; return 0; }
 
 		if (loaded.mainParent)
 		{
 			unsigned int oldId = root.id;
 			root = *loaded.mainParent;
 			root.id = oldId;
+			root.orderedElementsIds = {};
 		}
 
 		SushiParent *parentToAddTo = &root;
 		
-		//todo if no loaded.mainParent we will make the first found parent root
+		//todo if no loaded.mainParent we will make a default root
 
 		if (!loaded.parents.empty())
 		{
+			struct ParentPair
+			{
+				SushiParent *element = 0;
+				SushiParent *parentToAddTo = 0;
+			};
+
+			std::vector<ParentPair> parentsToAdd;
+
 		#pragma region find first parent
-			SushiParent *firstParent = 0;
 			if (loaded.mainParent)
 			{
-				firstParent = &(*loaded.mainParent);
-			}
-			else
+				for (auto &id : loaded.mainParent->orderedElementsIds)
 				{
-					//determine the main parent
-					std::unordered_set<unsigned int> allparentsids;
-					for (auto &p : loaded.parents)
+					bool found = 0;
+
+					for (auto &e : loaded.parents)
 					{
-						if (allparentsids.find(p.id) != allparentsids.end())
+						if (e.id == id)
 						{
-							return 0;
+							parentsToAdd.push_back({&e,&this->root});
+							found = true;
+							break;
 						}
-						allparentsids.insert(p.id);
 					}
 
-					for (auto &p : loaded.parents)
+					if (!found) { *this = {}; return 0; }
+				}
+			}
+			else //not tested
+			{
+				SushiParent *firstParent = 0;
+
+				//determine the main parent
+				std::unordered_set<unsigned int> allparentsids;
+				for (auto &p : loaded.parents)
+				{
+					if (allparentsids.find(p.id) != allparentsids.end())
 					{
-						for (auto &id : p.orderedElementsIds)
-						{
-							auto f = allparentsids.find(id);
-							if (f != allparentsids.end())
-							{
-								allparentsids.erase(f);
-							}
-						}
+						*this = {};
+						return 0;
 					}
+					allparentsids.insert(p.id);
+				}
 
-					//we found the main parent id
-					if (allparentsids.size() == 1)
+				for (auto &p : loaded.parents)
+				{
+					for (auto &id : p.orderedElementsIds)
 					{
-						unsigned int id = *allparentsids.begin();
-
-						for (auto &p : loaded.parents)
+						auto f = allparentsids.find(id);
+						if (f != allparentsids.end())
 						{
-							if (p.id == id)
-							{
-								firstParent = &p;
-							}
+							allparentsids.erase(f);
 						}
 					}
-					else
+				}
+
+				//we found the main parent id
+				if (allparentsids.size() == 1)
+				{
+					unsigned int id = *allparentsids.begin();
+
+					for (auto &p : loaded.parents)
 					{
-						return 0;
+						if (p.id == id)
+						{
+							firstParent = &p;
+						}
 					}
-
 				}
-		#pragma endregion
-
-			if (!firstParent) { return 0; }
+				else
+				{
+					*this = {};
+					return 0;
+				}
 
-			struct ParentPair
-			{
-				SushiParent *element = 0;
-				SushiParent *parentToAddTo = 0;
-			};
+				parentsToAdd.push_back({firstParent, parentToAddTo});
+			}
+		#pragma endregion
 
-			std::vector<ParentPair> parentsToAdd;
-			parentsToAdd.push_back({firstParent, parentToAddTo});
 
 			while (parentsToAdd.size())
 			{
@@ -540,27 +558,23 @@ namespace sushi
 				addParent(*currentP.parentToAddTo, currentP.element->name, currentP.element->transform,
 					currentP.element->background);
 
-				bool found = 0;
 				for (auto &id : currentP.element->orderedElementsIds)
 				{
+					bool found = 0;
 
-					if (!found)
+					for (auto &e : loaded.parents)
 					{
-						for (auto &e : loaded.parents)
+						if (e.id == id)
 						{
-							if (e.id == id)
-							{
-								parentsToAdd.push_back({&e,currentP.element});
-								found = true;
-								break;
-							}
+							parentsToAdd.push_back({&e,currentP.element});
+							found = true;
+							break;
 						}
 					}
-					if (found) { break; }
+					
+					if (!found) { *this = {}; return 0; }
 				}
 
-				if (!found) { return 0; }
-
 			}
 
 		}