Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
uhb217 committed Jan 10, 2024
1 parent 7a74d9d commit 0560b46
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 70 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'maven-publish'
}

Expand Down
100 changes: 39 additions & 61 deletions src/client/java/net/uhb217/glowingentity/gui/TestGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.mojang.authlib.GameProfile;
import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription;
import io.github.cottonmc.cotton.gui.widget.*;
import io.github.cottonmc.cotton.gui.widget.WPlainPanel;
import io.github.cottonmc.cotton.gui.widget.WToggleButton;
import io.github.cottonmc.cotton.gui.widget.data.Insets;
import io.github.cottonmc.cotton.gui.widget.data.Texture;
import io.github.cottonmc.cotton.gui.widget.icon.ItemIcon;
Expand All @@ -19,9 +20,11 @@
import net.minecraft.util.Identifier;
import net.uhb217.glowingentity.GlowingEntity;
import net.uhb217.glowingentity.gui.widgeds.Button;
import net.uhb217.glowingentity.gui.widgeds.Sprite;
import net.uhb217.glowingentity.utils.IEntityDataSaver;

import java.util.List;
import java.util.UUID;

@Environment(EnvType.CLIENT)
public class TestGUI extends LightweightGuiDescription {
Expand All @@ -38,7 +41,7 @@ public TestGUI(MinecraftClient client) {
}

public void createGlowingEntityModule(NbtCompound nbt, WPlainPanel root) {
WSprite glowingEntities = new WSprite(new Texture(new Identifier(GlowingEntity.MOD_ID, "textures/gui/glow.png")));
Sprite glowingEntities = new Sprite(new Texture(new Identifier(GlowingEntity.MOD_ID, "textures/gui/glow.png"))).setToolTip(Text.literal("Glowing Entity").formatted(Formatting.GOLD));
root.add(glowingEntities, 5, 10);
WToggleButton button = new WToggleButton(Text.literal("Off").formatted(Formatting.RED));
if (nbt.contains("glow") && nbt.getInt("glow") > 0) {
Expand All @@ -62,7 +65,7 @@ public void createGlowingEntityModule(NbtCompound nbt, WPlainPanel root) {
root.add(button, 28, 11);
}
public void createPlayerTrackerModule(NbtCompound nbt, WPlainPanel root,MinecraftClient mc){
WSprite playerTracker = new WSprite(new Texture(new Identifier(GlowingEntity.MOD_ID, "textures/gui/player_tracker.png")));
Sprite playerTracker = new Sprite(new Texture(new Identifier(GlowingEntity.MOD_ID, "textures/gui/player_tracker.png"))).setToolTip(Text.literal("Player Tracker").formatted(Formatting.DARK_RED));
root.add(playerTracker, 5, 31);
WToggleButton button = new WToggleButton(Text.literal("Off").formatted(Formatting.RED));
if (nbt.contains("player_tracker") && nbt.getBoolean("player_tracker")){
Expand All @@ -82,76 +85,51 @@ public void createPlayerTrackerModule(NbtCompound nbt, WPlainPanel root,Minecraf
}
public static class PlayerTrackerSetTargetGUI extends LightweightGuiDescription{
public PlayerTrackerSetTargetGUI(MinecraftClient mc){
WPlainPanel root = new WPlainPanel().setInsets(new Insets(2,2,2,2));
WPlainPanel root = new WPlainPanel().setInsets(new Insets(0,0,0,0));
this.setRootPanel(root);
root.setSize(140, 190);


// WItemSlot itemSlot = WItemSlot.of(new Inventory() {
// @Override
// public int size() {
// return 0;
// }
//
// @Override
// public boolean isEmpty() {
// return false;
// }
//
// @Override
// public ItemStack getStack(int slot) {
// return null;
// }
//
// @Override
// public ItemStack removeStack(int slot, int amount) {
// return null;
// }
//
// @Override
// public ItemStack removeStack(int slot) {
// return null;
// }
//
// @Override
// public void setStack(int slot, ItemStack stack) {
//
// }
//
// @Override
// public void markDirty() {
//
// }
//
// @Override
// public boolean canPlayerUse(PlayerEntity player) {
// return false;
// }
//
// @Override
// public void clear() {
//
// }
// }, 0, 7, 3).setIcon(new ItemIcon(getPLayersHeads(mc)[0]));
Button button = new Button(new ItemIcon(getPLayersHeads(mc)[0]),Text.literal("ToolTip!").formatted(Formatting.GREEN));
// WButton button = new WButton(new TextureIcon(new Texture(new Identifier(GlowingEntity.MOD_ID, "textures/gui/player_tracker.png"))));
button.setOnClick(()-> mc.player.sendMessage(Text.literal("Clicked!"))).setIconSize(13);
Button button1 = new Button(new ItemIcon(getPLayersHeads(mc)[0]),Text.literal("ToolTip 0.2!").formatted(Formatting.GREEN));
button1.setOnClick(()-> mc.player.sendMessage(Text.literal("Clicked!"))).setIconSize(13);
root.add(button,5,5);
// root.add(button1,25,5);
root.setSize(108, 70);

Button[][] buttons = new Button[5][3];
for (int i = 0; i < buttons.length; i++) {
for (int j = 0; j < buttons[i].length; j++) {
buttons[i][j] = new Button(new ItemIcon(getPLayersHeads(mc)[0])).setToolTip(Text.literal(getPLayersNames(mc)[0]).formatted(Formatting.GREEN));
int I = i,J = j;
buttons[i][j].setOnClick(()->{
NbtCompound nbt = ((IEntityDataSaver)mc.player).getPersistentData();
if (I + J > getPLayersNames(mc).length)
nbt.putUuid("compass_target",getPlayerUUidFromName(getPLayersNames(mc)[I+J],mc));
else
nbt.putUuid("compass_target",null);
});
buttons[i][j].setSize(25,25);
root.add(buttons[i][j],5+(20 * i),5+(20*j));
}
}
}
private UUID getPlayerUUidFromName(String name,MinecraftClient mc){
for (AbstractClientPlayerEntity player: mc.world.getPlayers()){
if (player.getName().getString().equals(name))
return player.getUuid();
}
return null;
}

public static ItemStack[] getPLayersHeads(MinecraftClient client) {
List<AbstractClientPlayerEntity> players = client.world.getPlayers();
ItemStack[] skulls = new ItemStack[players.size()];
for (int i = 0; i < skulls.length; i++) {
skulls[i] = Items.PLAYER_HEAD.getDefaultStack();
skulls[i].setNbt(getNbtFromProfile(players.get(i).getGameProfile()));
}

return skulls;
}
public static String[] getPLayersNames(MinecraftClient client) {
List<AbstractClientPlayerEntity> players = client.world.getPlayers();
String[] names = new String[players.size()];
for (int i = 0; i < names.length; i++)
names[i] = players.get(i).getName().getString();
return names;
}
public static NbtCompound getNbtFromProfile(GameProfile profile) {
// apply player's skin to head
NbtCompound nbtCompound = new NbtCompound();
Expand Down
37 changes: 29 additions & 8 deletions src/client/java/net/uhb217/glowingentity/gui/widgeds/Button.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
package net.uhb217.glowingentity.gui.widgeds;

import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.impl.client.WidgetTextures;
import io.github.cottonmc.cotton.gui.widget.WButton;
import io.github.cottonmc.cotton.gui.widget.WWidget;
import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment;
import io.github.cottonmc.cotton.gui.widget.icon.Icon;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.uhb217.glowingentity.GlowingEntity;
import org.jetbrains.annotations.Nullable;

public class Button extends WButton {
private static final int ICON_SPACING = 2;
private Text toolTip;
public Button(@Nullable Icon icon,Text toolTip){
public Button(@Nullable Icon icon){
this.setIcon(icon);
this.toolTip = toolTip;
}
public void setToolTip(Text toolTip){
public Button setToolTip(Text toolTip){
this.toolTip = toolTip;
return this;
}
public void drawToolTip(DrawContext context, int x, int y, int mouseX, int mouseY, WWidget widget){
public static void drawToolTip(DrawContext context, int x, int y, int mouseX, int mouseY, WWidget widget,Text toolTip){
boolean shouldDrawToolTip = mouseX >= 0 && mouseX <=widget.getWidth() && mouseY >= 0 && mouseY <= widget.getHeight();
if (shouldDrawToolTip){
var client = MinecraftClient.getInstance();
context.drawTooltip(client.textRenderer,toolTip,x + mouseX,y + mouseY);
}else
System.out.println("X: "+mouseX+" Y: "+mouseY);
}
}
@Override
public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {
super.paint(context, x, y, mouseX, mouseY);
drawToolTip(context,x,y,mouseX,mouseY,this);
Identifier t = new Identifier(GlowingEntity.MOD_ID,"textures/gui/slot_button_off.png");;
if (isWithinBounds(mouseX, mouseY) || isFocused())
t = new Identifier(GlowingEntity.MOD_ID,"textures/gui/slot_button_on.png");
context.drawTexture(t,x,y,0.0f,0.5f,getWidth(),getHeight(),getWidth(),getHeight());

if (getIcon() != null) {
setIconSize(19);
getIcon().paint(context, x, y-1+(getHeight()-iconSize)/2, iconSize);
}

if (getLabel()!=null) {
int color = 0xE0E0E0;

int xOffset = (getIcon() != null && alignment == HorizontalAlignment.LEFT) ? ICON_SPACING+iconSize+ICON_SPACING : 0;
ScreenDrawing.drawStringWithShadow(context, getLabel().asOrderedText(), alignment, x + xOffset, y + ((getHeight() - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color);
}
drawToolTip(context,x,y,mouseX,mouseY,this,toolTip);
}
}
42 changes: 42 additions & 0 deletions src/client/java/net/uhb217/glowingentity/gui/widgeds/Sprite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.uhb217.glowingentity.gui.widgeds;

import io.github.cottonmc.cotton.gui.widget.WSprite;
import io.github.cottonmc.cotton.gui.widget.data.Texture;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import static net.uhb217.glowingentity.gui.widgeds.Button.drawToolTip;

public class Sprite extends WSprite {
private Text toolTip = null;
public Sprite(Texture texture) {
super(texture);
}

public Sprite(Identifier image) {
super(image);
}

public Sprite(Identifier image, float u1, float v1, float u2, float v2) {
super(image, u1, v1, u2, v2);
}

public Sprite(int frameTime, Identifier... frames) {
super(frameTime, frames);
}

public Sprite(int frameTime, Texture... frames) {
super(frameTime, frames);
}
public Sprite setToolTip(Text toolTip){
this.toolTip = toolTip;
return this;
}

@Override
public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {
super.paint(context, x, y, mouseX, mouseY);
drawToolTip(context,x,y,mouseX,mouseY,this,toolTip);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0560b46

Please sign in to comment.