Skip to content

Commit

Permalink
Apply to children context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
NyaNLI authored and Chryfi committed Apr 30, 2022
1 parent 6965b43 commit 09ae333
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/main/java/mchorse/chameleon/lib/ChameleonModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.google.common.collect.ImmutableList;

@SideOnly(Side.CLIENT)
public class ChameleonModel
Expand Down Expand Up @@ -40,6 +43,23 @@ public List<String> getBoneNames()
return this.boneNames = this.getBoneNames(new ArrayList<String>(), this.model.bones);
}

public List<String> getChildren(String parent)
{
List<String> children = new ArrayList<String>();

for (ModelBone bone : this.model.bones)
{
if (Objects.equals(bone.id, parent))
{
this.getBoneNames(children, ImmutableList.of(bone));

break;
}
}

return children;
}

private List<String> getBoneNames(List<String> boneNames, List<ModelBone> bones)
{
for (ModelBone bone : bones)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import net.minecraft.nbt.NBTTagCompound;

import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
* Custom model morph panel which allows editing custom textures
* for materials of the custom model morph
* Custom model morph panel which allows editing custom textures for materials of the custom model morph
*/
public class GuiChameleonMainPanel extends GuiMorphPanel<ChameleonMorph, GuiChameleonMorph> implements IBonePicker
{
Expand Down Expand Up @@ -71,7 +71,8 @@ public static GuiContextMenu createCopyPasteMenu(Runnable copy, Consumer<Animate
pose = loaded;
}
catch (Exception e)
{}
{
}

menu.action(Icons.COPY, IKey.lang("chameleon.gui.editor.context.copy"), copy);

Expand Down Expand Up @@ -132,6 +133,18 @@ public GuiChameleonMainPanel(Minecraft mc, GuiChameleonMorph editor)
this.player.flex().relative(this.animation.pickInterpolation).x(0F).y(1F, 5).w(1F);
this.player.tooltip(IKey.lang("chameleon.gui.editor.player_tooltip"));

GuiSimpleContextMenu glowMenu = new GuiSimpleContextMenu(Minecraft.getMinecraft());
GuiSimpleContextMenu colorMenu = new GuiSimpleContextMenu(Minecraft.getMinecraft());
GuiSimpleContextMenu fixateMenu = new GuiSimpleContextMenu(Minecraft.getMinecraft());

glowMenu.action(IKey.lang("chameleon.gui.editor.context.children"), this.applyToChildren((p, c) -> c.glow = p.glow));
colorMenu.action(IKey.lang("chameleon.gui.editor.context.children"), this.applyToChildren((p, c) -> c.color.copy(p.color)));
fixateMenu.action(IKey.lang("chameleon.gui.editor.context.children"), this.applyToChildren((p, c) -> c.fixed = p.fixed));

this.glow.context(() -> glowMenu);
this.color.context(() -> colorMenu);
this.fixed.context(() -> fixateMenu);

GuiElement lowerBottom = new GuiElement(mc);

lowerBottom.flex().relative(this).xy(1F, 1F).w(130).anchor(1F, 1F).column(5).vertical().stretch().padding(10);
Expand All @@ -151,6 +164,23 @@ private void pastePose(AnimatedPose pose)
this.transforms.set(this.transforms.trans);
}

private Runnable applyToChildren(BiConsumer<AnimatedPoseTransform, AnimatedPoseTransform> apply)
{
return () ->
{
String bone = this.bones.getCurrentFirst();
AnimatedPoseTransform anim = this.morph.pose.bones.get(bone);
List<String> children = this.morph.getModel().getChildren(bone);

for (String child : children)
{
AnimatedPoseTransform childAnim = this.morph.pose.bones.get(child);

apply.accept(anim, childAnim);
}
};
}

private void createResetPose(GuiButtonElement button)
{
if (this.morph.pose == null)
Expand Down Expand Up @@ -197,12 +227,12 @@ public void pickBone(String bone)
this.transforms.set(this.transform);
this.editor.chameleonModelRenderer.boneName = bone;
}

private void setGlow(Double value)
{
this.transform.glow = value.floatValue();
}

private void setColor(int color)
{
this.transform.color.set(color);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/chameleon/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ chameleon.gui.editor.fixed=Fixate movement
chameleon.gui.editor.animated=Animated pose
chameleon.gui.editor.context.copy=Copy pose
chameleon.gui.editor.context.paste=Paste pose
chameleon.gui.editor.context.children=Apply to children

chameleon.gui.editor.scale=Global scale
chameleon.gui.editor.scale_gui=GUI scale
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/chameleon/lang/zh_cn.lang
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ chameleon.gui.editor.fixed=固定动作
chameleon.gui.editor.animated=动画姿势
chameleon.gui.editor.context.copy=拷贝姿势
chameleon.gui.editor.context.paste=粘贴姿势
chameleon.gui.editor.context.children=应用至子肢体

chameleon.gui.editor.scale=全局缩放
chameleon.gui.editor.scale_gui=GUI 缩放
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/chameleon/lang/zh_tw.lang
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ chameleon.gui.editor.fixed=固定動作
chameleon.gui.editor.animated=動畫姿勢
chameleon.gui.editor.context.copy=拷貝姿勢
chameleon.gui.editor.context.paste=粘貼姿勢
chameleon.gui.editor.context.children=應用至子肢體

chameleon.gui.editor.scale=全局縮放
chameleon.gui.editor.scale_gui=GUI 縮放
Expand Down

0 comments on commit 09ae333

Please sign in to comment.