Skip to content

Commit

Permalink
Almost all done
Browse files Browse the repository at this point in the history
Got some extra bugs to fix first.
  • Loading branch information
TheCSDev committed Sep 30, 2023
1 parent 5263a16 commit a261829
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.github.thecsdev.betterstats.client.gui.stats.panel;

import static io.github.thecsdev.betterstats.client.network.BetterStatsClientNetworkHandler.c2s_liveStats;
import static io.github.thecsdev.betterstats.client.network.BetterStatsClientNetworkHandler.serverHasBSS;
import static io.github.thecsdev.betterstats.BetterStatsConfig.LEGAL_NET_CONSENT;
import static io.github.thecsdev.betterstats.client.BetterStatsClient.MC_CLIENT;
import static io.github.thecsdev.betterstats.client.network.BetterStatsClientNetworkHandler.c2s_liveStats;
import static io.github.thecsdev.betterstats.client.network.BetterStatsClientNetworkHandler.serverHasBSS;
import static io.github.thecsdev.betterstats.network.BetterStatsNetworkHandler.TXT_CONSENT_WARNING;
import static io.github.thecsdev.betterstats.network.BetterStatsNetworkHandler.TXT_TOGGLE_TOOLTIP;
import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable;

import java.awt.Rectangle;
Expand All @@ -15,6 +17,8 @@
import io.github.thecsdev.tcdcommons.api.client.gui.util.UITexture;
import io.github.thecsdev.tcdcommons.api.client.gui.widget.TButtonWidget;
import io.github.thecsdev.tcdcommons.api.client.util.interfaces.IParentScreenProvider;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;

Expand Down Expand Up @@ -56,24 +60,30 @@ public ActionBarPanel(int x, int y, int width, ActionBarPanelProxy proxy) throws

//bss network button
final var btn_bssNet = new TButtonWidget(btn_options.getX() - 21, btn_options.getY(), 20, 20);
btn_bssNet.setTooltip(Tooltip.of(translatable("TODO - Tooltip"))); //FIXME - BSS NET tooltip
btn_bssNet.setTooltip(Tooltip.of(TXT_TOGGLE_TOOLTIP));
btn_bssNet.setIcon(LEGAL_NET_CONSENT ?
new UITexture(BS_WIDGETS_TEXTURE, new Rectangle(20, 80, 20, 20)) :
new UITexture(BS_WIDGETS_TEXTURE, new Rectangle(0, 80, 20, 20)));
btn_bssNet.setOnClick(__ ->
{
//FIXME - Implement BSS NET consent screen!
//if enabled, and turning off, do not do any more live updates
if(LEGAL_NET_CONSENT) c2s_liveStats(false);

//toggle
LEGAL_NET_CONSENT = !LEGAL_NET_CONSENT;

//if just turned on, send live updates preference packet
if(LEGAL_NET_CONSENT) c2s_liveStats();
//if turning off, send a packet indicating no more live updates
if(LEGAL_NET_CONSENT)
{
c2s_liveStats(false);
LEGAL_NET_CONSENT = false;
refresh();
return;
}

//finally, refresh the panel
refresh();
//else if turning on, go through a consent screen
final var currentScreen = MC_CLIENT.currentScreen;
final BooleanConsumer confirmScreenCallback = (accepted) ->
{
LEGAL_NET_CONSENT = accepted;
MC_CLIENT.setScreen(currentScreen);
if(LEGAL_NET_CONSENT) c2s_liveStats();
};
MC_CLIENT.setScreen(new ConfirmScreen(confirmScreenCallback, TXT_TOGGLE_TOOLTIP, TXT_CONSENT_WARNING));
});
btn_bssNet.setEnabled(serverHasBSS() && !MC_CLIENT.isInSingleplayer());
addChild(btn_bssNet, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public static void init() {}
LOGGER.info("Clearing '" + BetterStatsClientNetworkHandler.class.getSimpleName() + "' flags.");
serverHasBSS = false;
LEGAL_NET_CONSENT = false;

//also clear the HUD, as it now references an outdated stats-provider
BetterStatsHudScreen.getInstance().clearEntries();
});

//initialize network handlers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thecsdev.betterstats.network;

import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable;
import java.util.WeakHashMap;

import org.jetbrains.annotations.ApiStatus.Internal;
Expand All @@ -12,6 +13,7 @@
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

/**
Expand All @@ -22,6 +24,9 @@
// ==================================================
private BetterStatsNetworkHandler() {}
// --------------------------------------------------
public static final Text TXT_TOGGLE_TOOLTIP = translatable("betterstats.network.betterstatsnetworkhandler.toggle_tooltip");
public static final Text TXT_CONSENT_WARNING = translatable("betterstats.network.betterstatsnetworkhandler.consent_warning");
//
public static final int NETWORK_VERSION = 1;
//
public static final Identifier S2C_I_HAVE_BSS;
Expand Down Expand Up @@ -77,7 +82,7 @@ public static void s2c_liveStats(ServerPlayerEntity player)
//obtain prefs
if(player == null) return;
final var prefs = PlayerPrefs.get(player);
if(prefs == null) return; //shouldn't happen at all, but just in case
if(prefs == null || !prefs.liveStats) return;

//check last update time, and avoid packet spam
final long currentTime = System.currentTimeMillis();
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@


"betterstats.client.gui.screen.hud.betterstatshudscreen": "Statistics hud",
"betterstats.client.gui.screen.hud.betterstatshudscreen.pin_stat": "Pin to HUD"
"betterstats.client.gui.screen.hud.betterstatshudscreen.pin_stat": "Pin to HUD",

"betterstats.network.betterstatsnetworkhandler.toggle_tooltip": "Toggle 'betterstats' server connection",
"betterstats.network.betterstatsnetworkhandler.consent_warning": "IMPORTANT:\nBy enabling this feature, the server will find out that you are using a modified client with 'betterstats' installed. To protect your privacy, do not use this feature on servers that may not allow modified clients or this mod.\n\nEnabling this feature adds some extra features that are available when the mod is installed on the server as well."
}

0 comments on commit a261829

Please sign in to comment.