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

Individual materials for GUI nodes #7606

Merged
merged 21 commits into from Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -53,6 +53,7 @@
import com.dynamo.gamesys.proto.Gui.SceneDesc.LayerDesc;
import com.dynamo.gamesys.proto.Gui.SceneDesc.LayoutDesc;
import com.dynamo.gamesys.proto.Gui.SceneDesc.TextureDesc;
import com.dynamo.gamesys.proto.Gui.SceneDesc.MaterialDesc;
import com.dynamo.gamesys.proto.Gui.SceneDesc.ResourceDesc;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.GeneratedMessage;
Expand Down Expand Up @@ -240,7 +241,7 @@ private static void flattenTemplates(HashMap<String, ArrayList<NodeDesc>> scene,
}
}

private static void validateNodeResources(NodeDesc n, GuiBuilder builder, String input, Set<String> resourceNames, Set<String> fontNames, Set<String> particlefxNames, Set<String> textureNames, Set<String> layerNames) throws CompileExceptionError {
private static void validateNodeResources(NodeDesc n, GuiBuilder builder, String input, Set<String> resourceNames, Set<String> fontNames, Set<String> particlefxNames, Set<String> textureNames, Set<String> layerNames, Set<String> materialNames) throws CompileExceptionError {
if(builder == null) {
return;
}
Expand All @@ -264,6 +265,11 @@ private static void validateNodeResources(NodeDesc n, GuiBuilder builder, String
throw new CompileExceptionError(builder.project.getResource(input), 0, BobNLS.bind(Messages.GuiBuilder_MISSING_TEXTURE, n.getTexture().split("/")[0]));
}
}
if (n.hasMaterial() && !n.getMaterial().isEmpty()) {
if (!materialNames.contains(n.getMaterial())) {
throw new CompileExceptionError(builder.project.getResource(input), 0, BobNLS.bind(Messages.GuiBuilder_MISSING_TEXTURE, n.getMaterial()));
}
}
if (n.hasFont() && !n.getFont().isEmpty()) {
if (!fontNames.contains(n.getFont())) {
throw new CompileExceptionError(builder.project.getResource(input), 0, BobNLS.bind(Messages.GuiBuilder_MISSING_FONT, n.getFont()));
Expand Down Expand Up @@ -394,6 +400,9 @@ public static SceneDesc.Builder transformScene(GuiBuilder builder, String input,
Set<String> resourceNames = new HashSet<String>();
List<ResourceDesc> newResourcesList = new ArrayList<>();

Set<String> materialNames = new HashSet<String>();
List<MaterialDesc> newMaterialList = new ArrayList<MaterialDesc>();


if(builder != null) {
// transform and register scene external resources (if compiling)
Expand Down Expand Up @@ -437,6 +446,15 @@ public static SceneDesc.Builder transformScene(GuiBuilder builder, String input,
newTextureList.add(TextureDesc.newBuilder().mergeFrom(f).setTexture(replaceTextureName(f.getTexture())).build());
}

for (MaterialDesc f : sceneBuilder.getMaterialsList()) {
if (materialNames.contains(f.getName())) {
throw new CompileExceptionError(builder.project.getResource(input), 0, BobNLS.bind(Messages.GuiBuilder_DUPLICATED_TEXTURE,
f.getName()));
}
materialNames.add(f.getName());
newMaterialList.add(MaterialDesc.newBuilder().mergeFrom(f).setMaterial(BuilderUtil.replaceExt(f.getMaterial(), ".material", ".materialc")).build());
}

for (ResourceDesc f : sceneBuilder.getResourcesList()) {
if (resourceNames.contains(f.getName())) {
throw new CompileExceptionError(builder.project.getResource(input), 0, BobNLS.bind(Messages.BuilderUtil_DUPLICATE_RESOURCE,
Expand Down Expand Up @@ -512,11 +530,11 @@ public static SceneDesc.Builder transformScene(GuiBuilder builder, String input,

// add current scene nodes
newScene.get("").add(node);
validateNodeResources(node, builder, input, resourceNames, fontNames, particlefxNames, textureNames, layerNames);
validateNodeResources(node, builder, input, resourceNames, fontNames, particlefxNames, textureNames, layerNames, materialNames);
for(String layout : layouts) {
NodeDesc n = nodeMap.get(layout).get(node.getId());
if(n != null) {
validateNodeResources(n, builder, input, resourceNames, fontNames, particlefxNames, textureNames, layerNames);
validateNodeResources(n, builder, input, resourceNames, fontNames, particlefxNames, textureNames, layerNames, materialNames);
newScene.get(layout).add(n);
}
}
Expand Down Expand Up @@ -587,6 +605,13 @@ public static SceneDesc.Builder transformScene(GuiBuilder builder, String input,
textureNames.add(f.getName());
newTextureList.add(f);
}
for (MaterialDesc f : templateBuilder.getMaterialsList()) {
if (materialNames.contains(f.getName())) {
continue;
}
materialNames.add(f.getName());
newMaterialList.add(f);
}
for (ResourceDesc f : templateBuilder.getResourcesList()) {
if (resourceNames.contains(f.getName())) {
continue;
Expand Down Expand Up @@ -642,6 +667,9 @@ public static SceneDesc.Builder transformScene(GuiBuilder builder, String input,
sceneBuilder.clearTextures();
sceneBuilder.addAllTextures(newTextureList);

sceneBuilder.clearMaterials();
sceneBuilder.addAllMaterials(newMaterialList);

sceneBuilder.clearResources();
sceneBuilder.addAllResources(newResourcesList);

Expand Down
2 changes: 2 additions & 0 deletions editor/src/clj/dev.clj
Expand Up @@ -71,6 +71,8 @@
selected-nodes))))
first))

(def sel (comp first selection))

(defn prefs []
(prefs/make-prefs "defold"))

Expand Down