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 15 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_MATERIAL, 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_MATERIAL,
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
Expand Up @@ -24,11 +24,13 @@ public class Messages extends BobNLS {
public static String BuilderUtil_DUPLICATE_RESOURCE;

public static String GuiBuilder_MISSING_TEXTURE;
public static String GuiBuilder_MISSING_MATERIAL;
public static String GuiBuilder_MISSING_FONT;
public static String GuiBuilder_MISSING_PARTICLEFX;
public static String GuiBuilder_MISSING_LAYER;

public static String GuiBuilder_DUPLICATED_TEXTURE;
public static String GuiBuilder_DUPLICATED_MATERIAL;
public static String GuiBuilder_DUPLICATED_FONT;
public static String GuiBuilder_DUPLICATED_PARTICLEFX;
public static String GuiBuilder_DUPLICATED_LAYER;
Expand Down
Expand Up @@ -3,11 +3,13 @@ BuilderUtil_MISSING_RESOURCE=the {0} ''{1}'' can't be found
BuilderUtil_DUPLICATE_RESOURCE=the resource ''{0}'' is duplicated

GuiBuilder_MISSING_TEXTURE=the texture ''{0}'' has not been added as a resource
GuiBuilder_MISSING_MATERIAL=the material ''{0}'' has not been added as a resource
GuiBuilder_MISSING_FONT=the font ''{0}'' has not been added as a resource
GuiBuilder_MISSING_LAYER=the layer ''{0}'' has not been added to the scene
GuiBuilder_MISSING_PARTICLEFX=the particlefx ''{0}'' has not been added to the scene

GuiBuilder_DUPLICATED_TEXTURE=the texture ''{0}'' is duplicated
GuiBuilder_DUPLICATED_MATERIAL=the material ''{0}'' is duplicated
GuiBuilder_DUPLICATED_FONT=the font ''{0}'' is duplicated
GuiBuilder_DUPLICATED_LAYER=the layer ''{0}'' is duplicated
GuiBuilder_DUPLICATED_PARTICLEFX=the particlefx ''{0}'' is duplicated
Expand Down