-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can now add and remove HUD widgets. However, they don't automatically update yet, and there isn't a "grid snapping" feature when dragging the widgets around. Still a lot of work left to do.
- Loading branch information
Showing
16 changed files
with
370 additions
and
10 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
47 changes: 47 additions & 0 deletions
47
...in/java/io/github/thecsdev/betterstats/api/client/gui/stats/widget/CustomStatElement.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 io.github.thecsdev.betterstats.api.client.gui.stats.widget; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import io.github.thecsdev.betterstats.api.util.stats.SUGeneralStat; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.other.TBlankElement; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.util.TDrawContext; | ||
import io.github.thecsdev.tcdcommons.api.util.annotations.Virtual; | ||
import io.github.thecsdev.tcdcommons.api.util.enumerations.HorizontalAlignment; | ||
import net.minecraft.text.Text; | ||
|
||
/** | ||
* A {@link TBlankElement} that only renders {@link Text}s on the | ||
* left and right side of the {@link CustomStatElement}.<br/> | ||
* Does not handle any user input or have a background color. | ||
*/ | ||
public @Virtual class CustomStatElement extends TBlankElement | ||
{ | ||
// ================================================== | ||
public static final int HEIGHT = Math.max(GeneralStatWidget.HEIGHT, ItemStatWidget.SIZE); | ||
// -------------------------------------------------- | ||
protected @Nullable Text txtLeft, txtRight; | ||
// ================================================== | ||
public CustomStatElement(int x, int y, int width, SUGeneralStat generalStat) | ||
{ | ||
this(x, y, width, generalStat.getStatLabel(), generalStat.valueText); | ||
} | ||
|
||
public CustomStatElement(int x, int y, int width, @Nullable Text left, @Nullable Text right) | ||
{ | ||
super(x, y, width, HEIGHT); | ||
this.txtLeft = left; | ||
this.txtRight = right; | ||
} | ||
// ================================================== | ||
public final @Nullable Text getLeftText() { return this.txtLeft; } | ||
public final @Nullable Text getRightText() { return this.txtLeft; } | ||
public @Virtual void setLeftText(@Nullable Text left) { this.txtLeft = left; } | ||
public @Virtual void setRightText(@Nullable Text right) { this.txtRight = right; } | ||
// ================================================== | ||
public @Virtual @Override void render(TDrawContext pencil) | ||
{ | ||
pencil.drawTElementTextTH(this.txtLeft, HorizontalAlignment.LEFT); | ||
pencil.drawTElementTextTH(this.txtRight, HorizontalAlignment.RIGHT); | ||
} | ||
// ================================================== | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...20.1/src/main/java/io/github/thecsdev/betterstats/api/util/enumerations/ItemStatType.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 io.github.thecsdev.betterstats.api.util.enumerations; | ||
|
||
import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget.TEXT_STAT_BROKEN; | ||
import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget.TEXT_STAT_CRAFTED; | ||
import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget.TEXT_STAT_DROPPED; | ||
import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget.TEXT_STAT_MINED; | ||
import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget.TEXT_STAT_PICKED_UP; | ||
import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget.TEXT_STAT_USED; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
import io.github.thecsdev.betterstats.api.util.stats.SUItemStat; | ||
import io.github.thecsdev.tcdcommons.api.util.interfaces.ITextProvider; | ||
import net.minecraft.text.Text; | ||
|
||
public enum ItemStatType implements ITextProvider | ||
{ | ||
// ================================================== | ||
MINED(TEXT_STAT_MINED, s -> s.mined), | ||
CRAFTED(TEXT_STAT_CRAFTED, s -> s.crafted), | ||
PICKED_UP(TEXT_STAT_PICKED_UP, s -> s.pickedUp), | ||
DROPPED(TEXT_STAT_DROPPED, s -> s.dropped), | ||
USED(TEXT_STAT_USED, s -> s.used), | ||
BROKEN(TEXT_STAT_BROKEN, s -> s.broken); | ||
// ================================================== | ||
private final Text text; | ||
private final Function<SUItemStat, Integer> statValueSupplier; | ||
// ================================================== | ||
private ItemStatType(Text text, Function<SUItemStat, Integer> statValueSupplier) | ||
{ | ||
this.text = Objects.requireNonNull(text); | ||
this.statValueSupplier = Objects.requireNonNull(statValueSupplier); | ||
} | ||
// ================================================== | ||
public final @Override Text getText() { return this.text; } | ||
public int getStatValue(SUItemStat stat) throws NullPointerException | ||
{ | ||
return this.statValueSupplier.apply(Objects.requireNonNull(stat)); | ||
} | ||
// ================================================== | ||
} |
34 changes: 34 additions & 0 deletions
34
....20.1/src/main/java/io/github/thecsdev/betterstats/api/util/enumerations/MobStatType.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,34 @@ | ||
package io.github.thecsdev.betterstats.api.util.enumerations; | ||
|
||
import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.MobStatWidget.TEXT_STAT_DEATHS; | ||
import static io.github.thecsdev.betterstats.api.client.gui.stats.widget.MobStatWidget.TEXT_STAT_KILLS; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
import io.github.thecsdev.betterstats.api.util.stats.SUMobStat; | ||
import io.github.thecsdev.tcdcommons.api.util.interfaces.ITextProvider; | ||
import net.minecraft.text.Text; | ||
|
||
public enum MobStatType implements ITextProvider | ||
{ | ||
// ================================================== | ||
KILLED(TEXT_STAT_KILLS, s -> s.kills), | ||
KILLED_BY(TEXT_STAT_DEATHS, s -> s.deaths); | ||
// ================================================== | ||
private final Text text; | ||
private final Function<SUMobStat, Integer> statValueSupplier; | ||
// ================================================== | ||
private MobStatType(Text text, Function<SUMobStat, Integer> statValueSupplier) | ||
{ | ||
this.text = Objects.requireNonNull(text); | ||
this.statValueSupplier = Objects.requireNonNull(statValueSupplier); | ||
} | ||
// ================================================== | ||
public final @Override Text getText() { return this.text; } | ||
public int getStatValue(SUMobStat stat) throws NullPointerException | ||
{ | ||
return this.statValueSupplier.apply(Objects.requireNonNull(stat)); | ||
} | ||
// ================================================== | ||
} |
35 changes: 35 additions & 0 deletions
35
.../main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/BetterStatsHudScreen.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,35 @@ | ||
package io.github.thecsdev.betterstats.client.gui.screen.hud; | ||
|
||
import static io.github.thecsdev.betterstats.BetterStats.getModID; | ||
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import io.github.thecsdev.betterstats.BetterStats; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.screen.TWidgetHudScreen; | ||
import io.github.thecsdev.tcdcommons.api.client.util.interfaces.IParentScreenProvider; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
/** | ||
* {@link BetterStats}'s {@link TWidgetHudScreen}. | ||
*/ | ||
public final class BetterStatsHudScreen extends TWidgetHudScreen implements IParentScreenProvider | ||
{ | ||
// ================================================== | ||
public static final Text TEXT_TITLE = translatable("betterstats.client.gui.screen.hud.betterstatshudscreen"); | ||
public static final Identifier HUD_SCREEN_ID = new Identifier(getModID(), "stats_hud"); | ||
// -------------------------------------------------- | ||
private static final BetterStatsHudScreen INSTANCE = new BetterStatsHudScreen(); | ||
// -------------------------------------------------- | ||
private @Nullable Screen parent; | ||
// ================================================== | ||
private BetterStatsHudScreen() { super(TEXT_TITLE, HUD_SCREEN_ID); } | ||
// ================================================== | ||
/** | ||
* Returns the current instance of {@link BetterStatsHudScreen}. | ||
*/ | ||
public static BetterStatsHudScreen getInstance() { return INSTANCE; } | ||
// ================================================== | ||
} |
74 changes: 74 additions & 0 deletions
74
...in/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudItemEntry.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,74 @@ | ||
package io.github.thecsdev.betterstats.client.gui.screen.hud.entry; | ||
|
||
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal; | ||
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; | ||
|
||
import java.util.Objects; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import io.github.thecsdev.betterstats.api.client.gui.stats.widget.CustomStatElement; | ||
import io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget; | ||
import io.github.thecsdev.betterstats.api.util.enumerations.ItemStatType; | ||
import io.github.thecsdev.betterstats.api.util.stats.SUItemStat; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.TElement; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.panel.TPanelElement; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.screen.TWidgetHudScreen; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.util.TDrawContext; | ||
import net.minecraft.text.Text; | ||
|
||
public final class StatsHudItemEntry extends TWidgetHudScreen.WidgetEntry<TElement> | ||
{ | ||
// ================================================== | ||
static final int WIDTH = 150; | ||
// -------------------------------------------------- | ||
protected final SUItemStat stat; | ||
protected ItemStatType mode = ItemStatType.MINED; | ||
// ================================================== | ||
public StatsHudItemEntry(SUItemStat stat) throws NullPointerException | ||
{ | ||
super(0.5, 0.25); | ||
this.stat = Objects.requireNonNull(stat); | ||
} | ||
// ================================================== | ||
public final @Override TElement createWidget() | ||
{ | ||
final var el = new Element(); | ||
el.eContextMenu.register((__, cMenu) -> | ||
{ | ||
for(final var ist : ItemStatType.values()) | ||
{ | ||
cMenu.addButton(ist.getText(), ___ -> | ||
{ | ||
this.mode = ist; | ||
refreshEntry(); | ||
}); | ||
} | ||
cMenu.addSeparator(); | ||
cMenu.addButton(translatable("selectWorld.delete"), ___ -> removeEntry()); | ||
}); | ||
return el; | ||
} | ||
// -------------------------------------------------- | ||
private final CustomStatElement createCustomStatElement() | ||
{ | ||
//collect info | ||
final int i = ItemStatWidget.SIZE; | ||
@Nullable Text left = this.mode.getText(); | ||
@Nullable Text right = literal(Integer.toString(this.mode.getStatValue(this.stat))); | ||
//create and return | ||
return new CustomStatElement(i, 0, WIDTH - i, left, right); | ||
} | ||
// ================================================== | ||
private final class Element extends TElement | ||
{ | ||
public Element() | ||
{ | ||
super(0, 0, WIDTH, CustomStatElement.HEIGHT); | ||
addChild(new ItemStatWidget(0, 0, stat), true); | ||
addChild(createCustomStatElement(), true); | ||
} | ||
public @Override void render(TDrawContext pencil) { pencil.drawTFill(TPanelElement.COLOR_BACKGROUND); } | ||
} | ||
// ================================================== | ||
} |
79 changes: 79 additions & 0 deletions
79
...ain/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.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,79 @@ | ||
package io.github.thecsdev.betterstats.client.gui.screen.hud.entry; | ||
|
||
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal; | ||
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; | ||
|
||
import java.util.Objects; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import io.github.thecsdev.betterstats.api.client.gui.stats.widget.CustomStatElement; | ||
import io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget; | ||
import io.github.thecsdev.betterstats.api.client.gui.stats.widget.MobStatWidget; | ||
import io.github.thecsdev.betterstats.api.util.enumerations.MobStatType; | ||
import io.github.thecsdev.betterstats.api.util.stats.SUMobStat; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.TElement; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.panel.TPanelElement; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.screen.TWidgetHudScreen; | ||
import io.github.thecsdev.tcdcommons.api.client.gui.util.TDrawContext; | ||
import net.minecraft.text.Text; | ||
|
||
public final class StatsHudMobEntry extends TWidgetHudScreen.WidgetEntry<TElement> | ||
{ | ||
// ================================================== | ||
static final int WIDTH = StatsHudItemEntry.WIDTH; | ||
// -------------------------------------------------- | ||
protected final SUMobStat stat; | ||
protected MobStatType mode = MobStatType.KILLED; | ||
// ================================================== | ||
public StatsHudMobEntry(SUMobStat stat) throws NullPointerException | ||
{ | ||
super(0.5, 0.25); | ||
this.stat = Objects.requireNonNull(stat); | ||
} | ||
// ================================================== | ||
public final @Override TElement createWidget() | ||
{ | ||
final var el = new Element(); | ||
el.eContextMenu.register((__, cMenu) -> | ||
{ | ||
for(final var ist : MobStatType.values()) | ||
{ | ||
cMenu.addButton(ist.getText(), ___ -> | ||
{ | ||
this.mode = ist; | ||
refreshEntry(); | ||
}); | ||
} | ||
cMenu.addSeparator(); | ||
cMenu.addButton(translatable("selectWorld.delete"), ___ -> removeEntry()); | ||
}); | ||
return el; | ||
} | ||
// -------------------------------------------------- | ||
private final CustomStatElement createCustomStatElement() | ||
{ | ||
//collect info | ||
final int i = ItemStatWidget.SIZE; | ||
@Nullable Text left = this.mode.getText(); | ||
@Nullable Text right = literal(Integer.toString(this.mode.getStatValue(this.stat))); | ||
//create and return | ||
return new CustomStatElement(i, 0, WIDTH - i, left, right); | ||
} | ||
// ================================================== | ||
private final class Element extends TElement | ||
{ | ||
public Element() | ||
{ | ||
super(0, 0, WIDTH, CustomStatElement.HEIGHT); | ||
|
||
final var ms = new MobStatWidget(0, 0, stat); | ||
ms.setSize(this.height, this.height); | ||
|
||
addChild(ms, true); | ||
addChild(createCustomStatElement(), true); | ||
} | ||
public @Override void render(TDrawContext pencil) { pencil.drawTFill(TPanelElement.COLOR_BACKGROUND); } | ||
} | ||
// ================================================== | ||
} |
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 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
Oops, something went wrong.