-
Notifications
You must be signed in to change notification settings - Fork 1
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
6 changed files
with
111 additions
and
70 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
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' | ||
} | ||
|
||
|
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
37 changes: 29 additions & 8 deletions
37
src/client/java/net/uhb217/glowingentity/gui/widgeds/Button.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,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
42
src/client/java/net/uhb217/glowingentity/gui/widgeds/Sprite.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,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); | ||
} | ||
} |
Binary file added
BIN
+182 Bytes
src/main/resources/assets/glowingentity/textures/gui/slot_button_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+186 Bytes
src/main/resources/assets/glowingentity/textures/gui/slot_button_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.