Skip to content

Commit

Permalink
- Made DialogueButton extend Button instead of ExtendedButton
Browse files Browse the repository at this point in the history
- Removed Emotion enum and instead created a few constant fields
  • Loading branch information
Dweblenod committed Apr 7, 2024
1 parent d723d18 commit 5efc039
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.FormattedCharSequence;
import net.minecraftforge.client.gui.widget.ExtendedButton;

import java.util.List;

@MethodsReturnNonnullByDefault
public class DialogueButton extends ExtendedButton
public class DialogueButton extends Button
{
public static final int TEXT_SPACING = 9;
public static final int NORMAL_DEFAULT_HEIGHT = 17;
Expand All @@ -25,7 +25,7 @@ public class DialogueButton extends ExtendedButton

public DialogueButton(ResourceLocation gui, boolean isResponse, int xPos, int yPos, int width, int defaultHeight, Component displayString, OnPress handler)
{
super(xPos, yPos, width, defaultHeight, displayString, handler);
super(xPos, yPos, width, defaultHeight, displayString, handler, DEFAULT_NARRATION);
this.gui = gui;
this.isResponse = isResponse;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,8 @@ private void renderAnimation(GuiGraphics guiGraphics)
int moddedHeight = (int) (animationData.spriteHeight() * scale);

//if there is a .png.mcmeta file associated with the sprite, the animation for it is updated here
AnimatableTexture.setAndUpdate(sprite, animationTick);
AnimatableTexture.setAndUpdate(sprite, animationTick++);
guiGraphics.blit(sprite, xOffset + GUI_WIDTH + animationData.xOffset(), (this.height / 2) - (animationData.spriteHeight() / 2), 0, 0, moddedWidth, moddedHeight, moddedWidth, moddedHeight);

animationTick++;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ public NodeBuilder addDescription(MessageProducer message)
return this;
}

public NodeBuilder animation(DialogueAnimationData.Emotion emotion)
public NodeBuilder animation(String emotion)
{
return animation(new DialogueAnimationData(emotion.getSerializedName(), DialogueAnimationData.DEFAULT_SPRITE_HEIGHT, DialogueAnimationData.DEFAULT_SPRITE_WIDTH, 0, 0, 1.0F));
return animation(new DialogueAnimationData(emotion, DialogueAnimationData.DEFAULT_SPRITE_HEIGHT, DialogueAnimationData.DEFAULT_SPRITE_WIDTH, 0, 0, 1.0F));
}

public NodeBuilder animation(DialogueAnimationData animation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

public record DialogueAnimationData(String emotion, int spriteHeight, int spriteWidth, int xOffset, int yOffset, float scale)
{
public static final String GENERIC_EMOTION = "generic";
public static final String PLEASED_EMOTION = "pleased";
public static final String UPSET_EMOTION = "upset";
public static final String SCARED_EMOTION = "scared";

public static final int DEFAULT_SPRITE_WIDTH = 128;
public static final int DEFAULT_SPRITE_HEIGHT = 128;

public static final DialogueAnimationData DEFAULT_ANIMATION = new DialogueAnimationData(Emotion.GENERIC.getSerializedName(), DEFAULT_SPRITE_HEIGHT, DEFAULT_SPRITE_WIDTH, 0, 0, 1.0F);
public static final DialogueAnimationData DEFAULT_ANIMATION = new DialogueAnimationData(GENERIC_EMOTION, DEFAULT_SPRITE_HEIGHT, DEFAULT_SPRITE_WIDTH, 0, 0, 1.0F);

public static Codec<DialogueAnimationData> CODEC = RecordCodecBuilder.create(instance -> instance.group(
PreservingOptionalFieldCodec.withDefault(Codec.STRING, "emotion", Emotion.GENERIC.getSerializedName()).forGetter(DialogueAnimationData::emotion),
PreservingOptionalFieldCodec.withDefault(Codec.STRING, "emotion", GENERIC_EMOTION).forGetter(DialogueAnimationData::emotion),
PreservingOptionalFieldCodec.withDefault(Codec.INT, "height", DEFAULT_SPRITE_HEIGHT).forGetter(DialogueAnimationData::spriteHeight),
PreservingOptionalFieldCodec.withDefault(Codec.INT, "width", DEFAULT_SPRITE_WIDTH).forGetter(DialogueAnimationData::spriteWidth),
PreservingOptionalFieldCodec.withDefault(Codec.INT, "x_offset", 0).forGetter(DialogueAnimationData::xOffset),
Expand Down Expand Up @@ -65,7 +70,7 @@ public ResourceLocation getRenderPath(String spriteType)
//if the sprite for the given emotion cannot be found, it will try to render the generic sprite instead. If the generic sprite cannot be found, the invalid texture is allowed to proceed
if(!(abstractTexture instanceof SimpleTexture))
{
ResourceLocation fallbackSpritePath = new ResourceLocation(Minestuck.MOD_ID, "textures/gui/dialogue/entity/" + spriteType + "/" + Emotion.GENERIC.getSerializedName() + ".png");
ResourceLocation fallbackSpritePath = new ResourceLocation(Minestuck.MOD_ID, "textures/gui/dialogue/entity/" + spriteType + "/" + GENERIC_EMOTION + ".png");
if(Minecraft.getInstance().getTextureManager().getTexture(fallbackSpritePath) instanceof SimpleTexture fallbackTexture)
{
ensureAnimatable(fallbackTexture, fallbackSpritePath);
Expand All @@ -88,22 +93,4 @@ private static void ensureAnimatable(AbstractTexture abstractTexture, ResourceLo
Minecraft.getInstance().getTextureManager().register(sprite, animatableTexture);
}
}

/**
* List of supported/used emotion types. Custom emotions can still be declared through datapacks
*/
public enum Emotion implements StringRepresentable
{
GENERIC,
PLEASED,
UPSET,
SCARED,
ANXIOUS;

@Override
public String getSerializedName()
{
return name().toLowerCase(Locale.ROOT);
}
}
}

0 comments on commit 5efc039

Please sign in to comment.