Skip to content

Commit

Permalink
Added client-guiSmoothScroll config property
Browse files Browse the repository at this point in the history
A config property that allows people to turn "smooth scrolling" on or off, for the statistics panel.
  • Loading branch information
TheCSDev committed Feb 23, 2024
1 parent 730036c commit a82e9a2
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 147 deletions.
2 changes: 1 addition & 1 deletion betterstats-3-fabric-1.20.1/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ org.gradle.jvmargs=-Xmx1G
mod_name = Better Statistics Screen
mod_description = Improves the statistics screen and makes it more useful.
mod_author = TheCSDev
mod_version = 3.9+fabric-1.20.1
mod_version = 3.9.1+fabric-1.20.1

mod_contact_homepage = https://github.com/TheCSMods
mod_contact_sources = https://github.com/TheCSMods/mc-better-stats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class BetterStatsConfig extends AutoConfig
*/
public static final @NonSerialized boolean RESTRICTED_MODE;
// --------------------------------------------------
public @SerializedAs("client-guiSmoothScroll") boolean guiSmoothScroll = true;
public @SerializedAs("client-guiMobsFollowCursor") boolean guiMobsFollowCursor = true;
public @SerializedAs("client-trustAllServersBssNet") boolean trustAllServersBssNet = true;
public @SerializedAs("server-registerCommands") boolean registerCommands = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public BetterStatsConfigScreen(@Nullable Screen parent)
contentPane.setZOffset(TCDCommonsClient.MAGIC_ITEM_Z_OFFSET);
addChild(contentPane, false);

final int panelW = (int) ((float)getWidth() / 2.5f);
final int panelW = (int) ((float)getWidth() / 2f);
final int panelX = (getWidth() / 2) - (panelW / 2);
final int panelH = getHeight() - 40;
final int panelY = (getHeight() / 2) - (panelH / 2);
Expand Down Expand Up @@ -99,31 +99,56 @@ public BetterStatsConfigScreen(@Nullable Screen parent)

final var config = BetterStats.getInstance().getConfig();
final var config_builder = TConfigPanelBuilder.builder(panel_config);
config_builder.addLabelB(translatable("tcdcommons.client_side")).setTextColor(0xFFFFFF00);
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.debug_mode"),
BetterStatsConfig.DEBUG_MODE,
checkbox -> BetterStatsConfig.DEBUG_MODE = checkbox.getChecked())
.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_mob_follow_cursor"),
config.guiMobsFollowCursor,
checkbox -> config.guiMobsFollowCursor = checkbox.getChecked())
.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net"),
config.trustAllServersBssNet,
checkbox -> config.trustAllServersBssNet = checkbox.getChecked());
config_builder.getLastAddedElement().setTooltip(
Tooltip.of(translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net.tooltip")));
config_builder.addLabelB(translatable("tcdcommons.server_side")).setTextColor(0xFFFFFF00);
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.register_commands"),
config.registerCommands,
checkbox -> config.registerCommands = checkbox.getChecked())
.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.enable_sas"),
config.enableServerSAS,
checkbox -> config.enableServerSAS = checkbox.getChecked())
.build(() -> { try { config.saveToFile(true); } catch (Exception e) { throw new RuntimeException(e); } });
{
//configs for client-sided features
config_builder.addLabelB(translatable("tcdcommons.client_side")).setTextColor(0xFFFFFF00);
{
//debug mode
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.debug_mode"),
BetterStatsConfig.DEBUG_MODE,
checkbox -> BetterStatsConfig.DEBUG_MODE = checkbox.getChecked());

//gui smooth scroll
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_smooth_scroll"),
config.guiSmoothScroll,
checkbox -> config.guiSmoothScroll = checkbox.getChecked());
config_builder.getLastAddedElement().setTooltip(Tooltip.of(translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_smooth_scroll.tooltip")));

//gui mobs follow cursor
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_mob_follow_cursor"),
config.guiMobsFollowCursor,
checkbox -> config.guiMobsFollowCursor = checkbox.getChecked());

//trust all servers bss network
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net"),
config.trustAllServersBssNet,
checkbox -> config.trustAllServersBssNet = checkbox.getChecked());
config_builder.getLastAddedElement().setTooltip(Tooltip.of(translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net.tooltip")));
}

//configs for server-sided features
config_builder.addLabelB(translatable("tcdcommons.server_side")).setTextColor(0xFFFFFF00);
{
//register commands
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.register_commands"),
config.registerCommands,
checkbox -> config.registerCommands = checkbox.getChecked());

//enable stat announcement system
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.enable_sas"),
config.enableServerSAS,
checkbox -> config.enableServerSAS = checkbox.getChecked());
}

//finally, build the config gui
config_builder.build(() -> { try { config.saveToFile(true); } catch (Exception e) { throw new RuntimeException(e); } });
}

final var btn_actionCancel = new TButtonWidget(
5, 5, (panelW / 2) - 7, 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.jetbrains.annotations.ApiStatus.Internal;
import org.jetbrains.annotations.Nullable;

import io.github.thecsdev.betterstats.BetterStats;
import io.github.thecsdev.betterstats.api.client.gui.panel.BSComponentPanel;
import io.github.thecsdev.betterstats.api.client.gui.widget.ScrollBarWidget;
import io.github.thecsdev.betterstats.api.client.registry.StatsTab;
Expand Down Expand Up @@ -66,7 +67,7 @@ public final double getVerticalScrollBarValue()
this.panel = new TPanelElement(0, 0, getWidth() - 8, getHeight());
this.panel.setScrollFlags(TPanelElement.SCROLL_VERTICAL);
this.panel.setScrollPadding(10);
this.panel.setSmoothScroll(true);
this.panel.setSmoothScroll(BetterStats.getInstance().getConfig().guiSmoothScroll);
this.panel.setBackgroundColor(0);
this.panel.setOutlineColor(0);
addChild(this.panel, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,55 @@ public final class BSConfigTab extends StatsTab
//init config gui
final var config = BetterStats.getInstance().getConfig();
this.config_builder = TConfigPanelBuilder.builder(panel);

//configs for client-sided features
this.config_builder.addLabelB(translatable("tcdcommons.client_side")).setTextColor(0xFFFFFF00);
this.config_builder.addCheckbox(
{
//debug mode
this.config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.debug_mode"),
BetterStatsConfig.DEBUG_MODE,
checkbox -> BetterStatsConfig.DEBUG_MODE = checkbox.getChecked())
.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_mob_follow_cursor"),
config.guiMobsFollowCursor,
checkbox -> config.guiMobsFollowCursor = checkbox.getChecked())
.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net"),
config.trustAllServersBssNet,
checkbox -> config.trustAllServersBssNet = checkbox.getChecked());
this.config_builder.getLastAddedElement().setTooltip(
Tooltip.of(translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net.tooltip")));
checkbox -> BetterStatsConfig.DEBUG_MODE = checkbox.getChecked());

//gui smooth scroll
this.config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_smooth_scroll"),
config.guiSmoothScroll,
checkbox -> config.guiSmoothScroll = checkbox.getChecked());
this.config_builder.getLastAddedElement().setTooltip(Tooltip.of(translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_smooth_scroll.tooltip")));

//gui mobs follow cursor
this.config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_mob_follow_cursor"),
config.guiMobsFollowCursor,
checkbox -> config.guiMobsFollowCursor = checkbox.getChecked());

//trust all servers bss network
this.config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net"),
config.trustAllServersBssNet,
checkbox -> config.trustAllServersBssNet = checkbox.getChecked());
this.config_builder.getLastAddedElement().setTooltip(Tooltip.of(translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net.tooltip")));
}

//configs for server-sided features
this.config_builder.addLabelB(translatable("tcdcommons.server_side")).setTextColor(0xFFFFFF00);
this.config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.register_commands"),
config.registerCommands,
checkbox -> config.registerCommands = checkbox.getChecked())
.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.enable_sas"),
config.enableServerSAS,
checkbox -> config.enableServerSAS = checkbox.getChecked())
.build(() -> { try { config.saveToFile(true); } catch (Exception e) { throw new RuntimeException(e); } });
{
//register commands
this.config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.register_commands"),
config.registerCommands,
checkbox -> config.registerCommands = checkbox.getChecked());

//enable stat announcement system
this.config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.enable_sas"),
config.enableServerSAS,
checkbox -> config.enableServerSAS = checkbox.getChecked());
}

//finally, build the config gui
this.config_builder.build(() -> { try { config.saveToFile(true); } catch (Exception e) { throw new RuntimeException(e); } });
}
// --------------------------------------------------
public final @Override void initFilters(FiltersInitContext initContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"betterstats.client.gui.stats.panel.statstabpanel.seed_sha256": "Seed (SHA-256)",

"betterstats.api.client.gui.screen.betterstatsconfigscreen.debug_mode": "Debug mode",
"betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_smooth_scroll": "Enable GUI smooth-scroll",
"betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_smooth_scroll.tooltip": "When enabled, scrolling the statistics panels will be 'smoothly animated'. Disable this if you play on lower-end devices, or if scrolling via mouse-wheel doesn't work at all for you.",
"betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_mob_follow_cursor": "GUI mobs follow curfollow cursor",
"betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net": "Auto-toggle 'betterstats' network",
"betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net.tooltip": "When this mod is installed on a server, it offers more features. The 'betterstats' network protocol is how a 'betterstats' server communicates with the 'betterstats' client. With this enabled, the client will automatically tell the server it has 'betterstats' installed when applicable. With this disabled, you will have do it manually yourself each time you join a server.",
Expand Down
2 changes: 1 addition & 1 deletion betterstats-3-fabric-1.20.2/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ org.gradle.jvmargs=-Xmx1G
mod_name = Better Statistics Screen
mod_description = Improves the statistics screen and makes it more useful.
mod_author = TheCSDev
mod_version = 3.9+fabric-1.20.2
mod_version = 3.9.1+fabric-1.20.2

mod_contact_homepage = https://github.com/TheCSMods
mod_contact_sources = https://github.com/TheCSMods/mc-better-stats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class BetterStatsConfig extends AutoConfig
*/
public static final @NonSerialized boolean RESTRICTED_MODE;
// --------------------------------------------------
public @SerializedAs("client-guiSmoothScroll") boolean guiSmoothScroll = true;
public @SerializedAs("client-guiMobsFollowCursor") boolean guiMobsFollowCursor = true;
public @SerializedAs("client-trustAllServersBssNet") boolean trustAllServersBssNet = true;
public @SerializedAs("server-registerCommands") boolean registerCommands = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public BetterStatsConfigScreen(@Nullable Screen parent)
contentPane.setZOffset(TCDCommonsClient.MAGIC_ITEM_Z_OFFSET);
addChild(contentPane, false);

final int panelW = (int) ((float)getWidth() / 2.5f);
final int panelW = (int) ((float)getWidth() / 2f);
final int panelX = (getWidth() / 2) - (panelW / 2);
final int panelH = getHeight() - 40;
final int panelY = (getHeight() / 2) - (panelH / 2);
Expand Down Expand Up @@ -99,31 +99,56 @@ public BetterStatsConfigScreen(@Nullable Screen parent)

final var config = BetterStats.getInstance().getConfig();
final var config_builder = TConfigPanelBuilder.builder(panel_config);
config_builder.addLabelB(translatable("tcdcommons.client_side")).setTextColor(0xFFFFFF00);
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.debug_mode"),
BetterStatsConfig.DEBUG_MODE,
checkbox -> BetterStatsConfig.DEBUG_MODE = checkbox.getChecked())
.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_mob_follow_cursor"),
config.guiMobsFollowCursor,
checkbox -> config.guiMobsFollowCursor = checkbox.getChecked())
.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net"),
config.trustAllServersBssNet,
checkbox -> config.trustAllServersBssNet = checkbox.getChecked());
config_builder.getLastAddedElement().setTooltip(
Tooltip.of(translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net.tooltip")));
config_builder.addLabelB(translatable("tcdcommons.server_side")).setTextColor(0xFFFFFF00);
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.register_commands"),
config.registerCommands,
checkbox -> config.registerCommands = checkbox.getChecked())
.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.enable_sas"),
config.enableServerSAS,
checkbox -> config.enableServerSAS = checkbox.getChecked())
.build(() -> { try { config.saveToFile(true); } catch (Exception e) { throw new RuntimeException(e); } });
{
//configs for client-sided features
config_builder.addLabelB(translatable("tcdcommons.client_side")).setTextColor(0xFFFFFF00);
{
//debug mode
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.debug_mode"),
BetterStatsConfig.DEBUG_MODE,
checkbox -> BetterStatsConfig.DEBUG_MODE = checkbox.getChecked());

//gui smooth scroll
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_smooth_scroll"),
config.guiSmoothScroll,
checkbox -> config.guiSmoothScroll = checkbox.getChecked());
config_builder.getLastAddedElement().setTooltip(Tooltip.of(translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_smooth_scroll.tooltip")));

//gui mobs follow cursor
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.gui_mob_follow_cursor"),
config.guiMobsFollowCursor,
checkbox -> config.guiMobsFollowCursor = checkbox.getChecked());

//trust all servers bss network
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net"),
config.trustAllServersBssNet,
checkbox -> config.trustAllServersBssNet = checkbox.getChecked());
config_builder.getLastAddedElement().setTooltip(Tooltip.of(translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.trust_all_servers_bss_net.tooltip")));
}

//configs for server-sided features
config_builder.addLabelB(translatable("tcdcommons.server_side")).setTextColor(0xFFFFFF00);
{
//register commands
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.register_commands"),
config.registerCommands,
checkbox -> config.registerCommands = checkbox.getChecked());

//enable stat announcement system
config_builder.addCheckbox(
translatable("betterstats.api.client.gui.screen.betterstatsconfigscreen.enable_sas"),
config.enableServerSAS,
checkbox -> config.enableServerSAS = checkbox.getChecked());
}

//finally, build the config gui
config_builder.build(() -> { try { config.saveToFile(true); } catch (Exception e) { throw new RuntimeException(e); } });
}

final var btn_actionCancel = new TButtonWidget(
5, 5, (panelW / 2) - 7, 20,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.jetbrains.annotations.ApiStatus.Internal;
import org.jetbrains.annotations.Nullable;

import io.github.thecsdev.betterstats.BetterStats;
import io.github.thecsdev.betterstats.api.client.gui.panel.BSComponentPanel;
import io.github.thecsdev.betterstats.api.client.gui.widget.ScrollBarWidget;
import io.github.thecsdev.betterstats.api.client.registry.StatsTab;
Expand Down Expand Up @@ -66,7 +67,7 @@ public final double getVerticalScrollBarValue()
this.panel = new TPanelElement(0, 0, getWidth() - 8, getHeight());
this.panel.setScrollFlags(TPanelElement.SCROLL_VERTICAL);
this.panel.setScrollPadding(10);
this.panel.setSmoothScroll(true);
this.panel.setSmoothScroll(BetterStats.getInstance().getConfig().guiSmoothScroll);
this.panel.setBackgroundColor(0);
this.panel.setOutlineColor(0);
addChild(this.panel, true);
Expand Down
Loading

0 comments on commit a82e9a2

Please sign in to comment.