Added Quests and Real Settings (yay)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package de.fullrisk.citrusDev.UI;
|
||||
|
||||
import io.wispforest.owo.ui.component.LabelComponent;
|
||||
import io.wispforest.owo.ui.component.UIComponents;
|
||||
import io.wispforest.owo.ui.container.FlowLayout;
|
||||
import io.wispforest.owo.ui.container.UIContainers;
|
||||
@@ -7,12 +8,15 @@ import io.wispforest.owo.ui.core.*;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FontDescription;
|
||||
import de.fullrisk.citrusDev.client.PlaytimeTracker;
|
||||
import de.fullrisk.citrusDev.UIHelper.CitrusToast;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class QuestsPanel {
|
||||
|
||||
private static final int ACCENT = 0xbaff86;
|
||||
private static final int ACCENT = 0x64de4b;
|
||||
|
||||
private record QuestData(String title, String description, int requiredPlaytime) {
|
||||
boolean isUnlocked() {
|
||||
@@ -20,7 +24,50 @@ public class QuestsPanel {
|
||||
}
|
||||
}
|
||||
|
||||
public static void build(FlowLayout content, int contentWidth, int contentHeight) {
|
||||
public static class Handle {
|
||||
private final LabelComponent playtimeLabel;
|
||||
private final LabelComponent percentLabel;
|
||||
private final FlowLayout barFill;
|
||||
private final int barWidth;
|
||||
private final List<QuestData> quests;
|
||||
private final Set<String> notifiedTitles = new HashSet<>();
|
||||
|
||||
private Handle(LabelComponent playtimeLabel, LabelComponent percentLabel, FlowLayout barFill, int barWidth, List<QuestData> quests) {
|
||||
this.playtimeLabel = playtimeLabel;
|
||||
this.percentLabel = percentLabel;
|
||||
this.barFill = barFill;
|
||||
this.barWidth = barWidth;
|
||||
this.quests = quests;
|
||||
|
||||
// seed with whatever's already unlocked on open, so we don't spam
|
||||
// toasts for quests the player unlocked before opening this screen
|
||||
for (QuestData quest : quests) {
|
||||
if (quest.isUnlocked()) {
|
||||
notifiedTitles.add(quest.title());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
int playtime = PlaytimeTracker.getCurrentPlaytimeSeconds();
|
||||
int maxPlaytime = 360;
|
||||
int progress = Math.min(playtime * 100 / maxPlaytime, 100);
|
||||
|
||||
playtimeLabel.text(Component.literal(formatPlaytime(playtime)));
|
||||
percentLabel.text(Component.literal(progress + "%"));
|
||||
|
||||
int fillWidth = Math.max(barWidth * progress / 100, progress > 0 ? 2 : 0);
|
||||
barFill.horizontalSizing(Sizing.fixed(fillWidth));
|
||||
|
||||
for (QuestData quest : quests) {
|
||||
if (quest.isUnlocked() && notifiedTitles.add(quest.title())) {
|
||||
CitrusToast.show("Quest Unlocked", quest.title());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Handle build(FlowLayout content, int contentWidth, int contentHeight) {
|
||||
List<QuestData> quests = quests();
|
||||
int playtime = PlaytimeTracker.getCurrentPlaytimeSeconds();
|
||||
int maxPlaytime = 360;
|
||||
@@ -28,7 +75,6 @@ public class QuestsPanel {
|
||||
int barWidth = contentWidth - 8;
|
||||
long unlockedCount = quests.stream().filter(QuestData::isUnlocked).count();
|
||||
|
||||
// --- status row: playtime + percentage ---
|
||||
FlowLayout statusBar = UIContainers.horizontalFlow(Sizing.fixed(barWidth), Sizing.fixed(20));
|
||||
statusBar.gap(4);
|
||||
statusBar.padding(Insets.of(4));
|
||||
@@ -36,15 +82,17 @@ public class QuestsPanel {
|
||||
statusBar.horizontalAlignment(HorizontalAlignment.LEFT);
|
||||
statusBar.surface(MyScreen.GLASS_PANEL);
|
||||
|
||||
statusBar.child(UIComponents.label(Component.literal("Playtime: " + formatPlaytime(playtime)))
|
||||
.color(Color.ofRgb(0xFFFFFF)));
|
||||
LabelComponent playtimeLabel = UIComponents.label(Component.literal(formatPlaytime(playtime)));
|
||||
playtimeLabel.color(Color.ofRgb(0xFFFFFF));
|
||||
statusBar.child(playtimeLabel);
|
||||
statusBar.child(UIComponents.spacer());
|
||||
statusBar.child(UIComponents.label(Component.literal(progress + "%"))
|
||||
.color(Color.ofRgb(ACCENT)));
|
||||
|
||||
LabelComponent percentLabel = UIComponents.label(Component.literal(progress + "%"));
|
||||
percentLabel.color(Color.ofRgb(ACCENT));
|
||||
statusBar.child(percentLabel);
|
||||
|
||||
content.child(statusBar);
|
||||
|
||||
// --- progress bar ---
|
||||
FlowLayout barBg = UIContainers.horizontalFlow(Sizing.fixed(barWidth), Sizing.fixed(6));
|
||||
barBg.surface(Surface.flat(0x30FFFFFF).and(Surface.outline(0x30FFFFFF)));
|
||||
barBg.horizontalAlignment(HorizontalAlignment.LEFT);
|
||||
@@ -58,7 +106,6 @@ public class QuestsPanel {
|
||||
|
||||
content.child(barBg);
|
||||
|
||||
// --- unlocked count summary ---
|
||||
FlowLayout summaryRow = UIContainers.horizontalFlow(Sizing.fixed(barWidth), Sizing.content());
|
||||
summaryRow.padding(Insets.of(3, 0, 2, 2));
|
||||
|
||||
@@ -69,7 +116,6 @@ public class QuestsPanel {
|
||||
|
||||
content.child(summaryRow);
|
||||
|
||||
// --- quest list (scrollable) ---
|
||||
FlowLayout questList = UIContainers.verticalFlow(Sizing.fixed(barWidth), Sizing.content());
|
||||
questList.gap(3);
|
||||
questList.padding(Insets.of(2, 0, 2, 2));
|
||||
@@ -78,7 +124,7 @@ public class QuestsPanel {
|
||||
questList.child(buildQuestEntry(quest, contentWidth));
|
||||
}
|
||||
|
||||
int usedHeight = 20 + 6 + 18 + 6; // statusBar + barBg + summaryRow + gaps
|
||||
int usedHeight = 20 + 6 + 18 + 6;
|
||||
int scrollHeight = contentHeight - usedHeight;
|
||||
|
||||
var scrollArea = UIContainers.verticalScroll(
|
||||
@@ -87,6 +133,8 @@ public class QuestsPanel {
|
||||
questList
|
||||
);
|
||||
content.child(scrollArea);
|
||||
|
||||
return new Handle(playtimeLabel, percentLabel, barFill, barWidth, quests);
|
||||
}
|
||||
|
||||
private static String formatPlaytime(int seconds) {
|
||||
@@ -130,7 +178,7 @@ public class QuestsPanel {
|
||||
: Surface.flat(0x40FFFFFF));
|
||||
iconBox.horizontalAlignment(HorizontalAlignment.CENTER);
|
||||
iconBox.verticalAlignment(VerticalAlignment.CENTER);
|
||||
iconBox.child(UIComponents.label(Component.literal(unlocked ? "✓" : ""))
|
||||
iconBox.child(UIComponents.label(Component.literal(""))
|
||||
.color(Color.ofRgb(0x1c1c1c)));
|
||||
row.child(iconBox);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user