-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add chat events * Add powder mining tracker * Add ON_PRICE_UPDATE event and re-calculate profit after prices are updated * Initial config * Add config screens for filtering the shown items * Fix Done button width being only 1 col wide when it's supposed to be 2 * Change to regex because index magic wasn't magic-ing Regex my beloved * Read and write from file and fix incorrect param used in recalculateAll Also a small fix for the regex * Change literal text to translatable * Extract `ON_PRICE_UPDATE` event to a separate class under the `events` package * Simplify switch to use pattern matching * Extract render and chat message lambdas to methods * Add PROFILE_INIT event * Add support for multiple profiles * Re-add ItemPrice#init with additional documentation * Prevent rendering profit if there are no rewards * Format item amounts when rendering * Add more documentation
- Loading branch information
Showing
14 changed files
with
734 additions
and
63 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
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
79 changes: 79 additions & 0 deletions
79
src/main/java/de/hysky/skyblocker/config/screens/powdertracker/ItemTickList.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 de.hysky.skyblocker.config.screens.powdertracker; | ||
|
||
import de.hysky.skyblocker.mixins.accessors.CheckboxWidgetAccessor; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.Element; | ||
import net.minecraft.client.gui.Selectable; | ||
import net.minecraft.client.gui.widget.CheckboxWidget; | ||
import net.minecraft.client.gui.widget.ElementListWidget; | ||
import net.minecraft.text.Text; | ||
|
||
import java.util.List; | ||
|
||
public class ItemTickList extends ElementListWidget<ItemTickList.ItemTickEntry> { | ||
private final List<String> filters; | ||
private final List<String> allItems; | ||
|
||
public ItemTickList(MinecraftClient minecraftClient, int width, int height, int y, int entryHeight, List<String> filters, List<String> allItems) { | ||
super(minecraftClient, width, height, y, entryHeight); | ||
this.filters = filters; | ||
this.allItems = allItems; | ||
} | ||
|
||
public void clearAndInit() { | ||
clearEntries(); | ||
init(); | ||
} | ||
|
||
public ItemTickList init() { | ||
for (String item : allItems) { | ||
ItemTickEntry entry = new ItemTickEntry( | ||
CheckboxWidget.builder(Text.of(item), client.textRenderer) | ||
.checked(!filters.contains(item)) | ||
.callback((checkbox1, checked) -> { | ||
if (checked) filters.remove(item); | ||
else filters.add(item); | ||
}) | ||
.build() | ||
); | ||
addEntry(entry); | ||
} | ||
return this; | ||
} | ||
|
||
public static class ItemTickEntry extends ElementListWidget.Entry<ItemTickEntry> { | ||
private final List<CheckboxWidget> children; | ||
|
||
ItemTickEntry(CheckboxWidget checkboxWidget) { | ||
children = List.of(checkboxWidget); | ||
} | ||
|
||
public void setChecked(boolean checked) { | ||
for (CheckboxWidget child : children) { | ||
((CheckboxWidgetAccessor) child).setChecked(checked); | ||
} | ||
} | ||
|
||
@Override | ||
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { | ||
for (CheckboxWidget child : children) { | ||
child.setX(x); | ||
child.setY(y); | ||
child.setWidth(entryWidth); | ||
child.setHeight(entryHeight); | ||
child.render(context, mouseX, mouseY, tickDelta); | ||
} | ||
} | ||
|
||
@Override | ||
public List<? extends Selectable> selectableChildren() { | ||
return children; | ||
} | ||
|
||
@Override | ||
public List<? extends Element> children() { | ||
return children; | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/de/hysky/skyblocker/config/screens/powdertracker/PowderFilterConfigScreen.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 de.hysky.skyblocker.config.screens.powdertracker; | ||
|
||
import de.hysky.skyblocker.config.SkyblockerConfigManager; | ||
import de.hysky.skyblocker.skyblock.dwarven.PowderMiningTracker; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.gui.widget.ButtonWidget; | ||
import net.minecraft.client.gui.widget.GridWidget; | ||
import net.minecraft.client.gui.widget.SimplePositioningWidget; | ||
import net.minecraft.screen.ScreenTexts; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PowderFilterConfigScreen extends Screen { | ||
@Nullable | ||
private final Screen parent; | ||
private final List<String> filters; | ||
private final List<String> allItems; | ||
|
||
public PowderFilterConfigScreen(@Nullable Screen parent, List<String> allItems) { | ||
super(Text.of("Powder Mining Tracker Filter Config")); | ||
this.parent = parent; | ||
this.filters = new ArrayList<>(SkyblockerConfigManager.get().mining.crystalHollows.powderTrackerFilter); // Copy the list so we can undo changes when necessary | ||
this.allItems = allItems; | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
addDrawable((context, mouseX, mouseY, delta) -> { | ||
assert client != null; | ||
context.drawCenteredTextWithShadow(client.textRenderer, Text.translatable("skyblocker.config.mining.crystalHollows.powderTrackerFilter.screenTitle").formatted(Formatting.BOLD), width / 2, (32 - client.textRenderer.fontHeight) / 2, 0xFFFFFF); | ||
}); | ||
ItemTickList itemTickList = addDrawableChild(new ItemTickList(MinecraftClient.getInstance(), width, height - 96, 32, 24, filters, allItems).init()); | ||
//Grid code gratuitously stolen from WaypointsScreen. Same goes for the y and heights above. | ||
GridWidget gridWidget = new GridWidget(); | ||
gridWidget.getMainPositioner().marginX(5).marginY(2); | ||
GridWidget.Adder adder = gridWidget.createAdder(2); | ||
|
||
adder.add(ButtonWidget.builder(Text.translatable("text.skyblocker.reset"), button -> { | ||
filters.clear(); | ||
itemTickList.clearAndInit(); | ||
}).build()); | ||
adder.add(ButtonWidget.builder(Text.translatable("text.skyblocker.undo"), button -> { | ||
filters.clear(); | ||
filters.addAll(SkyblockerConfigManager.get().mining.crystalHollows.powderTrackerFilter); | ||
itemTickList.clearAndInit(); | ||
}).build()); | ||
adder.add(ButtonWidget.builder(ScreenTexts.DONE, button -> { | ||
saveFilters(); | ||
close(); | ||
}) | ||
.width((ButtonWidget.DEFAULT_WIDTH * 2) + 10) | ||
.build(), 2); | ||
gridWidget.refreshPositions(); | ||
SimplePositioningWidget.setPos(gridWidget, 0, this.height - 64, this.width, 64); | ||
gridWidget.forEachChild(this::addDrawableChild); | ||
} | ||
|
||
public void saveFilters() { | ||
SkyblockerConfigManager.get().mining.crystalHollows.powderTrackerFilter = filters; | ||
SkyblockerConfigManager.save(); | ||
PowderMiningTracker.recalculateAll(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
assert client != null; | ||
client.setScreen(parent); | ||
} | ||
} |
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,46 @@ | ||
package de.hysky.skyblocker.events; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Environment(EnvType.CLIENT) | ||
public class ChatEvents { | ||
/** | ||
* This will be called when a game message is received, cancelled or not. | ||
* | ||
* @implNote Not fired when {@code overlay} is {@code true}. See {@link de.hysky.skyblocker.mixins.MessageHandlerMixin#skyblocker$monitorGameMessage(Text, boolean, CallbackInfo) the mixin} for more information. | ||
*/ | ||
@SuppressWarnings("JavadocReference") | ||
public static final Event<ChatTextEvent> RECEIVE_TEXT = EventFactory.createArrayBacked(ChatTextEvent.class, listeners -> message -> { | ||
for (ChatTextEvent listener : listeners) { | ||
listener.onMessage(message); | ||
} | ||
}); | ||
|
||
/** | ||
* This will be called when a game message is received, cancelled or not. | ||
* This method is called with the result of {@link Text#getString()} to avoid each listener having to call it. | ||
* | ||
* @implNote Not fired when {@code overlay} is {@code true}. See {@link de.hysky.skyblocker.mixins.MessageHandlerMixin#skyblocker$monitorGameMessage(Text, boolean, CallbackInfo) the mixin} for more information. | ||
*/ | ||
@SuppressWarnings("JavadocReference") | ||
public static final Event<ChatStringEvent> RECEIVE_STRING = EventFactory.createArrayBacked(ChatStringEvent.class, listeners -> message -> { | ||
for (ChatStringEvent listener : listeners) { | ||
listener.onMessage(message); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface ChatTextEvent { | ||
void onMessage(Text message); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface ChatStringEvent { | ||
void onMessage(String message); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/de/hysky/skyblocker/events/ItemPriceUpdateEvent.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,21 @@ | ||
package de.hysky.skyblocker.events; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
|
||
@FunctionalInterface | ||
@Environment(EnvType.CLIENT) | ||
public interface ItemPriceUpdateEvent { | ||
void onPriceUpdate(); | ||
|
||
/** | ||
* An event that is fired when all prices are updated. | ||
*/ | ||
Event<ItemPriceUpdateEvent> ON_PRICE_UPDATE = EventFactory.createArrayBacked(ItemPriceUpdateEvent.class, listeners -> () -> { | ||
for (ItemPriceUpdateEvent listener : listeners) { | ||
listener.onPriceUpdate(); | ||
} | ||
}); | ||
} |
Oops, something went wrong.