Skip to content

Commit

Permalink
feat: Bomb Bell Overlay (#2409)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowCat117 authored and kristofbolyai committed May 5, 2024
1 parent 4d023bf commit 460dc41
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import com.wynntils.features.map.MinimapFeature;
import com.wynntils.features.map.WorldWaypointDistanceFeature;
import com.wynntils.features.overlays.ArrowShieldTrackerOverlayFeature;
import com.wynntils.features.overlays.BombBellOverlayFeature;
import com.wynntils.features.overlays.CombatExperienceOverlayFeature;
import com.wynntils.features.overlays.ContentTrackerOverlayFeature;
import com.wynntils.features.overlays.CustomBarsOverlayFeature;
Expand Down Expand Up @@ -267,6 +268,7 @@ public void init() {

// region overlays
registerFeature(new ArrowShieldTrackerOverlayFeature());
registerFeature(new BombBellOverlayFeature());
registerFeature(new CombatExperienceOverlayFeature());
registerFeature(new ContentTrackerOverlayFeature());
registerFeature(new CustomBarsOverlayFeature());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright © Wynntils 2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.features.overlays;

import com.wynntils.core.consumers.features.Feature;
import com.wynntils.core.consumers.overlays.annotations.OverlayInfo;
import com.wynntils.core.persisted.config.Category;
import com.wynntils.core.persisted.config.ConfigCategory;
import com.wynntils.mc.event.RenderEvent;
import com.wynntils.overlays.BombBellOverlay;

@ConfigCategory(Category.OVERLAYS)
public class BombBellOverlayFeature extends Feature {
@OverlayInfo(renderType = RenderEvent.ElementType.GUI)
public final BombBellOverlay bombBellOverlay = new BombBellOverlay();
}
14 changes: 12 additions & 2 deletions common/src/main/java/com/wynntils/models/worlds/type/BombInfo.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
/*
* Copyright © Wynntils 2022-2023.
* Copyright © Wynntils 2022-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.models.worlds.type;

import java.util.concurrent.TimeUnit;
import net.minecraft.ChatFormatting;

public record BombInfo(String user, BombType bomb, String server, long startTime, float length) {
// mm:ss format
public String getRemainingString() {
long millis = startTime + getLength() - System.currentTimeMillis();
long millis = getRemainingLong();
return String.format(
"%02dm %02ds",
TimeUnit.MILLISECONDS.toMinutes(millis),
TimeUnit.MILLISECONDS.toSeconds(millis)
- TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
}

public long getRemainingLong() {
return startTime + getLength() - System.currentTimeMillis();
}

public String asString() {
return ChatFormatting.GOLD + bomb.getName() + ChatFormatting.GRAY + " on " + ChatFormatting.WHITE + server
+ ChatFormatting.GOLD + " (" + getRemainingString() + ")";
}

@Override
public boolean equals(Object o) {
if (!(o instanceof BombInfo bombInfo)) return false;
Expand Down
131 changes: 131 additions & 0 deletions common/src/main/java/com/wynntils/overlays/BombBellOverlay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright © Wynntils 2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.overlays;

import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.vertex.PoseStack;
import com.wynntils.core.components.Models;
import com.wynntils.core.consumers.overlays.Overlay;
import com.wynntils.core.consumers.overlays.OverlayPosition;
import com.wynntils.core.consumers.overlays.OverlaySize;
import com.wynntils.core.persisted.Persisted;
import com.wynntils.core.persisted.config.Config;
import com.wynntils.core.text.StyledText;
import com.wynntils.models.worlds.type.BombInfo;
import com.wynntils.models.worlds.type.BombType;
import com.wynntils.utils.render.TextRenderSetting;
import com.wynntils.utils.render.TextRenderTask;
import com.wynntils.utils.render.buffered.BufferedFontRenderer;
import com.wynntils.utils.render.type.HorizontalAlignment;
import com.wynntils.utils.render.type.TextShadow;
import com.wynntils.utils.render.type.VerticalAlignment;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import net.minecraft.client.renderer.MultiBufferSource;

public class BombBellOverlay extends Overlay {
@Persisted
public final Config<TextShadow> textShadow = new Config<>(TextShadow.OUTLINE);

@Persisted
public final Config<Float> fontScale = new Config<>(1.0f);

@Persisted
public final Config<Boolean> showCombatBombs = new Config<>(true);

@Persisted
public final Config<Boolean> showDungeonBombs = new Config<>(true);

@Persisted
public final Config<Boolean> showLootBombs = new Config<>(true);

@Persisted
public final Config<Boolean> showProfessionXpBombs = new Config<>(true);

@Persisted
public final Config<Boolean> showProfessionSpeedBombs = new Config<>(true);

private final Map<BombType, Supplier<Boolean>> bombTypeMap = Map.ofEntries(
Map.entry(BombType.COMBAT_XP, showCombatBombs::get),
Map.entry(BombType.DUNGEON, showDungeonBombs::get),
Map.entry(BombType.LOOT, showLootBombs::get),
Map.entry(BombType.PROFESSION_XP, showProfessionXpBombs::get),
Map.entry(BombType.PROFESSION_SPEED, showProfessionSpeedBombs::get));

private TextRenderSetting textRenderSetting;

public BombBellOverlay() {
super(
new OverlayPosition(
130,
-5,
VerticalAlignment.TOP,
HorizontalAlignment.RIGHT,
OverlayPosition.AnchorSection.TOP_RIGHT),
new OverlaySize(200, 110));

updateTextRenderSetting();
}

@Override
public void render(PoseStack poseStack, MultiBufferSource bufferSource, float partialTicks, Window window) {
BufferedFontRenderer.getInstance()
.renderTextsWithAlignment(
poseStack,
bufferSource,
this.getRenderX(),
this.getRenderY(),
Models.Bomb.getBombBells().stream()
.sorted(Comparator.comparing(BombInfo::getRemainingLong)
.reversed())
.filter(bombInfo -> {
BombType bombType = bombInfo.bomb();
Supplier<Boolean> bombTypeSupplier = bombTypeMap.get(bombType);
return bombTypeSupplier != null && bombTypeSupplier.get();
})
.map(bombInfo -> new TextRenderTask(bombInfo.asString(), textRenderSetting))
.toList(),
this.getWidth(),
this.getHeight(),
this.getRenderHorizontalAlignment(),
this.getRenderVerticalAlignment());
}

@Override
public void renderPreview(PoseStack poseStack, MultiBufferSource bufferSource, float partialTicks, Window window) {
BufferedFontRenderer.getInstance()
.renderTextsWithAlignment(
poseStack,
bufferSource,
this.getRenderX(),
this.getRenderY(),
List.of(
new TextRenderTask(
StyledText.fromString("§6Combat XP§7 on §fWC32 §6(16m 35s)"),
textRenderSetting),
new TextRenderTask(
StyledText.fromString("§6Profession Speed§7 on §fWC1 §6(3m 12s)"),
textRenderSetting)),
this.getWidth(),
this.getHeight(),
this.getRenderHorizontalAlignment(),
this.getRenderVerticalAlignment(),
fontScale.get());
}

@Override
protected void onConfigUpdate(Config<?> config) {
updateTextRenderSetting();
}

private void updateTextRenderSetting() {
textRenderSetting = TextRenderSetting.DEFAULT
.withMaxWidth(this.getWidth())
.withHorizontalAlignment(this.getRenderHorizontalAlignment())
.withTextShadow(textShadow.get());
}
}
17 changes: 17 additions & 0 deletions common/src/main/resources/assets/wynntils/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@
"feature.wynntils.betaWarning.name": "Beta Warning",
"feature.wynntils.blacksmithRedirect.description": "Adds the ability to redirect blacksmith messages to the game update overlay.",
"feature.wynntils.blacksmithRedirect.name": "Blacksmith Messages",
"feature.wynntils.bombBellOverlay.description": "Adds an overlay to see active bombs.",
"feature.wynntils.bombBellOverlay.name": "Bomb Bell",
"feature.wynntils.bombBellOverlay.overlay.bombBell.fontScale.description": "How large should the bomb bell text be?",
"feature.wynntils.bombBellOverlay.overlay.bombBell.fontScale.name": "Font Scale",
"feature.wynntils.bombBellOverlay.overlay.bombBell.name": "Bomb Bell Overlay",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showCombatBombs.description": "Should Combat XP bombs be shown on the overlay?",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showCombatBombs.name": "Show Combat XP Bombs",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showDungeonBombs.description": "Should Dungeon bombs be shown on the overlay?",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showDungeonBombs.name": "Show Dungeon Bombs",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showLootBombs.description": "Should Loot bombs be shown on the overlay?",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showLootBombs.name": "Show Loot Bombs",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showProfessionSpeedBombs.description": "Should Profession Speed bombs be shown on the overlay?",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showProfessionSpeedBombs.name": "Show Profession Speed Bombs",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showProfessionXpBombs.description": "Should Profession XP bombs be shown on the overlay?",
"feature.wynntils.bombBellOverlay.overlay.bombBell.showProfessionXpBombs.name": "Show Profession XP Bombs",
"feature.wynntils.bombBellOverlay.overlay.bombBell.textShadow.description": "What should the text shadow look like?",
"feature.wynntils.bombBellOverlay.overlay.bombBell.textShadow.name": "Text Shadow",
"feature.wynntils.bombBellRelay.description": "Adds the ability to relay bomb bell messages to your party or guild with a keybind.",
"feature.wynntils.bombBellRelay.name": "Bomb Bell Relay",
"feature.wynntils.bombBellRelay.noKnownBombs": "No known bomb bells to relay.",
Expand Down

0 comments on commit 460dc41

Please sign in to comment.