Skip to content

Commit 5edc60e

Browse files
authored
Merge pull request #30 from WehrWolff/add-timing-options
Add delay and duration options for misc messages (WehrWolff)
2 parents fc6f66e + c96463a commit 5edc60e

18 files changed

Lines changed: 696 additions & 32 deletions

File tree

common/src/main/java/dev/terminalmc/chatnotify/ChatNotify.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import dev.terminalmc.chatnotify.config.Trigger;
2424
import dev.terminalmc.chatnotify.util.ModLogger;
2525
import dev.terminalmc.chatnotify.util.ResponseUtil;
26+
import dev.terminalmc.chatnotify.util.TimingUtil;
2627
import dev.terminalmc.chatnotify.util.text.FormatUtil;
2728
import net.minecraft.ChatFormatting;
2829
import net.minecraft.client.Minecraft;
@@ -80,6 +81,7 @@ public static void onConfigSaved(Config config) {
8081

8182
public static void afterClientTick(Minecraft mc) {
8283
ResponseUtil.tickResponses(mc);
84+
TimingUtil.tickActions();
8385

8486
// Config reset warning toast
8587
if (hasResetConfig && mc.screen instanceof TitleScreen) {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2025 TerminalMC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package dev.terminalmc.chatnotify.command;
18+
19+
import com.mojang.brigadier.Command;
20+
import com.mojang.brigadier.CommandDispatcher;
21+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
22+
import dev.terminalmc.chatnotify.ChatNotify;
23+
import dev.terminalmc.chatnotify.gui.screen.RootScreen;
24+
import net.minecraft.client.Minecraft;
25+
26+
public class ChatNotifyCommand {
27+
28+
private ChatNotifyCommand() {
29+
throw new UnsupportedOperationException("This class cannot be instantiated.");
30+
}
31+
32+
public static <S> void register(CommandDispatcher<S> dispatcher) {
33+
dispatcher.register(LiteralArgumentBuilder.<S>literal(ChatNotify.MOD_ID).executes((ctx) -> {
34+
Minecraft mc = Minecraft.getInstance();
35+
mc.tell(() -> mc.setScreen(new RootScreen(mc.screen)));
36+
37+
return Command.SINGLE_SUCCESS;
38+
}));
39+
}
40+
}

common/src/main/java/dev/terminalmc/chatnotify/config/Config.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import dev.terminalmc.chatnotify.config.util.JsonUtil;
2222
import dev.terminalmc.chatnotify.platform.Services;
2323
import dev.terminalmc.chatnotify.util.ResponseUtil;
24+
import dev.terminalmc.chatnotify.util.TimingUtil;
2425
import net.minecraft.sounds.SoundSource;
2526
import org.jetbrains.annotations.NotNull;
2627
import org.jetbrains.annotations.Nullable;
@@ -366,6 +367,7 @@ public static Config reload() {
366367
instance = null;
367368
get();
368369
ResponseUtil.clear();
370+
TimingUtil.clear();
369371
ChatNotify.updateUsernameNotif(instance);
370372
return instance;
371373
}

common/src/main/java/dev/terminalmc/chatnotify/config/Notification.java

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ public enum CheckOwnMode {
138138
public boolean titleMsgEnabled;
139139
public static final boolean titleMsgEnabledDefault = false;
140140

141+
/**
142+
* Optional message to display in subtitle text.
143+
*/
144+
public String subtitleMsg;
145+
public static final String subtitleMsgDefault = "";
146+
public boolean subtitleMsgEnabled;
147+
public static final boolean subtitleMsgEnabledDefault = false;
148+
141149
/**
142150
* Optional message to display in a toast popup.
143151
*/
@@ -162,6 +170,24 @@ public enum CheckOwnMode {
162170
public boolean clipboardMsgEnabled;
163171
public static final boolean clipboardMsgEnabledDefault = false;
164172

173+
/**
174+
* Optional message timing (status bar, title text or toast popup).
175+
*/
176+
public boolean soundSync;
177+
public static final boolean soundSyncDefault = true;
178+
public int delay;
179+
public static final int timingDelayDefault = 0;
180+
public int titleFadeIn;
181+
public static final int titleFadeInDefault = 10;
182+
public int titleStay;
183+
public static final int titleStayDefault = 70;
184+
public int titleFadeOut;
185+
public static final int titleFadeOutDefault = 20;
186+
public int statusBarStay;
187+
public static final int statusBarStayDefault = 60;
188+
public int toastStay;
189+
public static final int toastStayDefault = 100;
190+
165191
/**
166192
* A list of {@link Trigger} instances, of which any one can trigger this instance.
167193
*/
@@ -212,12 +238,21 @@ public enum CheckOwnMode {
212238
boolean statusBarMsgEnabled,
213239
String titleMsg,
214240
boolean titleMsgEnabled,
241+
String subtitleMsg,
242+
boolean subtitleMsgEnabled,
215243
String toastMsg,
216244
boolean toastMsgEnabled,
217245
String typedMsg,
218246
boolean typedMsgEnabled,
219247
String clipboardMsg,
220248
boolean clipboardMsgEnabled,
249+
boolean soundSync,
250+
int delay,
251+
int titleFadeIn,
252+
int titleStay,
253+
int titleFadeOut,
254+
int statusBarStay,
255+
int toastStay,
221256
List<Trigger> triggers,
222257
List<Trigger> inclusionTriggers,
223258
List<Trigger> exclusionTriggers,
@@ -236,12 +271,21 @@ public enum CheckOwnMode {
236271
this.statusBarMsgEnabled = statusBarMsgEnabled;
237272
this.titleMsg = titleMsg;
238273
this.titleMsgEnabled = titleMsgEnabled;
274+
this.subtitleMsg = subtitleMsg;
275+
this.subtitleMsgEnabled = subtitleMsgEnabled;
239276
this.toastMsg = toastMsg;
240277
this.toastMsgEnabled = toastMsgEnabled;
241278
this.typedMsg = typedMsg;
242279
this.typedMsgEnabled = typedMsgEnabled;
243280
this.clipboardMsg = clipboardMsg;
244281
this.clipboardMsgEnabled = clipboardMsgEnabled;
282+
this.soundSync = soundSync;
283+
this.delay = delay;
284+
this.titleFadeIn = titleFadeIn;
285+
this.titleStay = titleStay;
286+
this.titleFadeOut = titleFadeOut;
287+
this.statusBarStay = statusBarStay;
288+
this.toastStay = toastStay;
245289
this.triggers = triggers;
246290
this.inclusionTriggers = inclusionTriggers;
247291
this.exclusionTriggers = exclusionTriggers;
@@ -267,12 +311,21 @@ static Notification createUser() {
267311
statusBarMsgEnabledDefault,
268312
titleMsgDefault,
269313
titleMsgEnabledDefault,
314+
subtitleMsgDefault,
315+
subtitleMsgEnabledDefault,
270316
toastMsgDefault,
271317
toastMsgEnabledDefault,
272318
typedMsgDefault,
273319
typedMsgEnabledDefault,
274320
clipboardMsgDefault,
275321
clipboardMsgEnabledDefault,
322+
soundSyncDefault,
323+
timingDelayDefault,
324+
titleFadeInDefault,
325+
titleStayDefault,
326+
titleFadeOutDefault,
327+
statusBarStayDefault,
328+
toastStayDefault,
276329
new ArrayList<>(List.of(new Trigger("Profile name"), new Trigger("Display name"))),
277330
inclusionTriggersDefault.get(),
278331
exclusionTriggersDefault.get(),
@@ -298,12 +351,21 @@ static Notification createBlank(Sound sound, TextStyle textStyle) {
298351
statusBarMsgEnabledDefault,
299352
titleMsgDefault,
300353
titleMsgEnabledDefault,
354+
subtitleMsgDefault,
355+
subtitleMsgEnabledDefault,
301356
toastMsgDefault,
302357
toastMsgEnabledDefault,
303358
typedMsgDefault,
304359
typedMsgEnabledDefault,
305360
clipboardMsgDefault,
306361
clipboardMsgEnabledDefault,
362+
soundSyncDefault,
363+
timingDelayDefault,
364+
titleFadeInDefault,
365+
titleStayDefault,
366+
titleFadeOutDefault,
367+
statusBarStayDefault,
368+
toastStayDefault,
307369
new ArrayList<>(List.of(new Trigger(""))),
308370
inclusionTriggersDefault.get(),
309371
exclusionTriggersDefault.get(),
@@ -551,6 +613,20 @@ public Notification deserialize(
551613
silent
552614
);
553615

616+
String subtitleMsg = JsonUtil.getOrDefault(
617+
obj,
618+
"subtitleMsg",
619+
subtitleMsgDefault,
620+
silent
621+
);
622+
623+
boolean subtitleMsgEnabled = JsonUtil.getOrDefault(
624+
obj,
625+
"subtitleMsgEnabled",
626+
subtitleMsgEnabledDefault,
627+
silent
628+
);
629+
554630
String toastMsg = JsonUtil.getOrDefault(
555631
obj,
556632
"toastMsg",
@@ -593,6 +669,55 @@ public Notification deserialize(
593669
silent
594670
);
595671

672+
boolean soundSync = JsonUtil.getOrDefault(
673+
obj,
674+
"soundSync",
675+
soundSyncDefault,
676+
silent
677+
);
678+
679+
int delay = JsonUtil.getOrDefault(
680+
obj,
681+
"delay",
682+
timingDelayDefault,
683+
silent
684+
);
685+
686+
int titleFadeIn = JsonUtil.getOrDefault(
687+
obj,
688+
"titleFadeIn",
689+
titleFadeInDefault,
690+
silent
691+
);
692+
693+
int titleStay = JsonUtil.getOrDefault(
694+
obj,
695+
"titleStay",
696+
titleStayDefault,
697+
silent
698+
);
699+
700+
int titleFadeOut = JsonUtil.getOrDefault(
701+
obj,
702+
"titleFadeOut",
703+
titleFadeOutDefault,
704+
silent
705+
);
706+
707+
int statusBarStay = JsonUtil.getOrDefault(
708+
obj,
709+
"statusBarStay",
710+
statusBarStayDefault,
711+
silent
712+
);
713+
714+
int toastStay = JsonUtil.getOrDefault(
715+
obj,
716+
"toastStay",
717+
toastStayDefault,
718+
silent
719+
);
720+
596721
List<Trigger> triggers = JsonUtil.getOrDefault(
597722
ctx,
598723
obj,
@@ -660,12 +785,21 @@ public Notification deserialize(
660785
statusBarMsgEnabled,
661786
titleMsg,
662787
titleMsgEnabled,
788+
subtitleMsg,
789+
subtitleMsgEnabled,
663790
toastMsg,
664791
toastMsgEnabled,
665792
typedMsg,
666793
typedMsgEnabled,
667794
clipboardMsg,
668795
clipboardMsgEnabled,
796+
soundSync,
797+
delay,
798+
titleFadeIn,
799+
titleStay,
800+
titleFadeOut,
801+
statusBarStay,
802+
toastStay,
669803
triggers,
670804
inclusionTriggers,
671805
exclusionTriggers,

common/src/main/java/dev/terminalmc/chatnotify/gui/toast/NotificationToast.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public class NotificationToast implements Toast {
3232

3333
private static final ResourceLocation BACKGROUND_SPRITE =
3434
ResourceLocation.withDefaultNamespace("toast/advancement");
35-
private static final int DISPLAY_TIME = 5000;
3635
private static final int WIDTH = 160;
3736
private static final int HEIGHT = 32;
3837
private static final int X_MARGIN = 10;
@@ -41,10 +40,12 @@ public class NotificationToast implements Toast {
4140

4241
private final int lineHeight;
4342
private final List<FormattedCharSequence> messageLines;
43+
private final int displayTime;
4444

45-
public NotificationToast(Component message) {
45+
public NotificationToast(Component message, int displayTime) {
4646
this.messageLines = Minecraft.getInstance().font.split(message, WIDTH - X_MARGIN * 2);
4747
this.lineHeight = Minecraft.getInstance().font.lineHeight + LINE_SPACE;
48+
this.displayTime = displayTime;
4849
}
4950

5051
@Override
@@ -110,7 +111,7 @@ public NotificationToast(Component message) {
110111
}
111112
}
112113

113-
return elapsedTime < DISPLAY_TIME * component.getNotificationDisplayTimeMultiplier()
114+
return elapsedTime < displayTime * component.getNotificationDisplayTimeMultiplier()
114115
? Visibility.SHOW
115116
: Visibility.HIDE;
116117
}

0 commit comments

Comments
 (0)