-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
203 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 38 additions & 2 deletions
40
common/src/main/java/cn/zbx1425/worldcomment/gui/CommentTypeButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,57 @@ | ||
package cn.zbx1425.worldcomment.gui; | ||
|
||
import cn.zbx1425.worldcomment.Main; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
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.util.Mth; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class CommentTypeButton extends Button { | ||
|
||
private static final ResourceLocation ATLAS_LOCATION = new ResourceLocation(Main.MOD_ID, "textures/gui/comment-tool.png"); | ||
|
||
private static final int[] COMMENT_TYPE_COLOR = { | ||
0xFF8BC34A, 0xFFCDDC39, 0xFFFFEB3B, 0xFFFF9800, | ||
0xFF607D8B, 0xFFFFC107, 0xFF03A9F4, 0xFF009888 | ||
}; | ||
|
||
public int commentType; | ||
public int topColor; | ||
|
||
public static int BTN_WIDTH = 40; | ||
public static int BTN_HEIGHT = 40; | ||
|
||
protected CommentTypeButton(int x, int y, int type, OnPress onPress) { | ||
super(x, y, BTN_WIDTH, 20, | ||
public CommentTypeButton(int x, int y, int type, OnPress onPress) { | ||
super(x, y, BTN_WIDTH, BTN_HEIGHT, | ||
Component.translatable("gui.worldcomment.comment_type." + type), | ||
onPress, Supplier::get); | ||
this.commentType = type; | ||
this.topColor = COMMENT_TYPE_COLOR[type - 1]; | ||
} | ||
|
||
@Override | ||
protected void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
RenderSystem.enableBlend(); | ||
guiGraphics.setColor(((topColor >> 16) & 0xFF) / 255f, ((topColor >> 8) & 0xFF) / 255f, | ||
(topColor & 0xFF) / 255f, 1); | ||
guiGraphics.blit(ATLAS_LOCATION, getX(), getY(), getWidth(), 12, | ||
active ? 0 : 40, 58, 40, 12, 256, 256); | ||
guiGraphics.setColor(1, 1, 1, 1); | ||
guiGraphics.blit(ATLAS_LOCATION, getX(), getY() + 12, getWidth(), 28, | ||
active ? 0 : 40, 70, 40, 28, 256, 256); | ||
if (isHovered && active) { | ||
guiGraphics.blit(ATLAS_LOCATION, getX(), getY(), getWidth(), 40, | ||
80, 58, 40, 40, 256, 256); | ||
} | ||
guiGraphics.blit(ATLAS_LOCATION, getX() + 8 - 1, getY() + 14 - 1, 24, 24, | ||
((commentType - 1) % 4) * 64, (int)((commentType - 1) / 4) * 64 + 128, 64, 64, 256, 256); | ||
renderScrollingString(guiGraphics, minecraft.font, getMessage(), | ||
getX(), getY(), getX() + getWidth(), getY() + 12, active ? 0xFFFFFFFF : 0xFFA0A0A0); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetColorButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cn.zbx1425.worldcomment.gui; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
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.util.Mth; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class WidgetColorButton extends Button { | ||
|
||
int color; | ||
|
||
public WidgetColorButton(int i, int j, int k, int l, Component component, int color, OnPress onPress) { | ||
super(i, j, k, l, component, onPress, Supplier::get); | ||
this.color = color; | ||
} | ||
|
||
@Override | ||
protected void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
if (this.active) { | ||
guiGraphics.setColor(((color >> 16) & 0xFF) / 255f, ((color >> 8) & 0xFF) / 255f, | ||
(color & 0xFF) / 255f, this.alpha); | ||
} else { | ||
guiGraphics.setColor(1.0f, 1.0f, 1.0f, this.alpha); | ||
} | ||
RenderSystem.enableBlend(); | ||
RenderSystem.enableDepthTest(); | ||
guiGraphics.blitNineSliced(WIDGETS_LOCATION, this.getX(), this.getY(), this.getWidth(), this.getHeight(), 20, 4, 200, 20, 0, this.getTextureY()); | ||
guiGraphics.setColor(1.0f, 1.0f, 1.0f, 1.0f); | ||
int i = this.active ? 0xFFFFFF : 0xA0A0A0; | ||
this.renderString(guiGraphics, minecraft.font, i | Mth.ceil(this.alpha * 255.0f) << 24); | ||
} | ||
|
||
private int getTextureY() { | ||
int i = 1; | ||
if (!this.active) { | ||
i = 0; | ||
} else if (this.isHoveredOrFocused()) { | ||
i = 2; | ||
} | ||
return 46 + i * 20; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetCommentEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cn.zbx1425.worldcomment.gui; | ||
|
||
import cn.zbx1425.worldcomment.data.CommentEntry; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.AbstractWidget; | ||
import net.minecraft.client.gui.narration.NarrationElementOutput; | ||
import net.minecraft.network.chat.Component; | ||
|
||
public class WidgetCommentEntry extends AbstractWidget { | ||
|
||
private final CommentEntry comment; | ||
|
||
public static final int TOP_SINK = 10; | ||
|
||
public WidgetCommentEntry(int x, int y, int width, CommentEntry comment) { | ||
super(x, y, width, 0, Component.literal(comment.message)); | ||
this.comment = comment; | ||
} | ||
|
||
@Override | ||
protected void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { | ||
|
||
} | ||
|
||
@Override | ||
protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) { | ||
|
||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
common/src/main/java/cn/zbx1425/worldcomment/gui/WidgetFlagLabel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cn.zbx1425.worldcomment.gui; | ||
|
||
import cn.zbx1425.worldcomment.Main; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class WidgetFlagLabel extends WidgetLabel { | ||
|
||
private static final ResourceLocation ATLAS_LOCATION = new ResourceLocation(Main.MOD_ID, "textures/gui/comment-tool.png"); | ||
|
||
public int color; | ||
|
||
public WidgetFlagLabel(int x, int y, int width, int height, int color, Component text) { | ||
super(x, y, width, height, text); | ||
this.color = color; | ||
this.padding = 6; | ||
} | ||
|
||
@Override | ||
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { | ||
guiGraphics.setColor(((color >> 16) & 0xFF) / 255f, ((color >> 8) & 0xFF) / 255f, | ||
(color & 0xFF) / 255f, 1); | ||
guiGraphics.blit(ATLAS_LOCATION, getX(), getY(), 10, getHeight(), | ||
0, 48, 20, 10, 256, 256); | ||
guiGraphics.blit(ATLAS_LOCATION, getX() + 10, getY(), getWidth() - 20, getHeight(), | ||
10, 48, 108, 10, 256, 256); | ||
guiGraphics.blit(ATLAS_LOCATION, getX() + getWidth() - 10, getY(), 10, getHeight(), | ||
118, 48, 10, 10, 256, 256); | ||
guiGraphics.setColor(1, 1, 1, 1); | ||
super.renderWidget(guiGraphics, mouseX, mouseY, delta); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
common/src/main/java/cn/zbx1425/worldcomment/mixin/InGameHudMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cn.zbx1425.worldcomment.mixin; | ||
|
||
import net.minecraft.client.gui.Gui; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.Slice; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Gui.class) | ||
public class InGameHudMixin { | ||
|
||
@Inject(method = "render", at = @At(value = "TAIL"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/PlayerTabOverlay;render(Lnet/minecraft/client/gui/GuiGraphics;ILnet/minecraft/world/scores/Scoreboard;Lnet/minecraft/world/scores/Objective;)V"))) | ||
public void render(GuiGraphics guiGraphics, float partialTick, CallbackInfo callbackInfo) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+32.5 KB
common/src/main/resources/assets/worldcomment/textures/gui/comment-tool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.