Added button to direct connection screen, added feature to disable certain buttons

This commit is contained in:
FlorianMichael 2024-02-17 19:56:05 +01:00
parent 988268ba13
commit 775eb62ded
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
6 changed files with 83 additions and 14 deletions

View File

@ -62,6 +62,11 @@ public abstract class MixinAddServerScreen extends Screen {
@Inject(method = "init", at = @At("RETURN"))
private void addVersionSetterButton(CallbackInfo ci) {
final int buttonPosition = GeneralSettings.global().addServerScreenButtonOrientation.getIndex();
if (buttonPosition == 0) { // Off
return;
}
final ProtocolVersion forcedVersion = ((IServerInfo) server).viaFabricPlus$forcedVersion();
// Restore input if the user cancels the version selection screen (or if the user is editing an existing server)
@ -83,7 +88,7 @@ public abstract class MixinAddServerScreen extends Screen {
}).size(98, 20);
// Set the button's position according to the configured orientation
buttonBuilder = GeneralSettings.withOrientation(buttonBuilder, GeneralSettings.global().addServerScreenButtonOrientation.getIndex(), width, height);
buttonBuilder = GeneralSettings.withOrientation(buttonBuilder, buttonPosition, width, height);
// Add the button to the screen
this.addDrawableChild(buttonBuilder.build());

View File

@ -0,0 +1,57 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.base.integration;
import de.florianmichael.viafabricplus.screen.base.ProtocolSelectionScreen;
import de.florianmichael.viafabricplus.settings.impl.GeneralSettings;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.DirectConnectScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(DirectConnectScreen.class)
public abstract class MixinDirectConnectScreen extends Screen {
public MixinDirectConnectScreen(Text title) {
super(title);
}
@Inject(method = "init", at = @At("RETURN"))
private void addProtocolSelectionButton(CallbackInfo ci) {
final int buttonPosition = GeneralSettings.global().directConnectScreenButtonOrientation.getIndex();
if (buttonPosition == 0) { // Off
return;
}
// Create the button
ButtonWidget.Builder builder = ButtonWidget.builder(Text.literal("ViaFabricPlus"), button -> ProtocolSelectionScreen.INSTANCE.open(this)).size(98, 20);
// Set the button's position according to the configured orientation
builder = GeneralSettings.withOrientation(builder, buttonPosition, width, height);
// Add the button to the screen
this.addDrawableChild(builder.build());
}
}

View File

@ -39,11 +39,16 @@ public abstract class MixinMultiplayerScreen extends Screen {
@Inject(method = "init", at = @At("RETURN"))
private void addProtocolSelectionButton(CallbackInfo ci) {
final int buttonPosition = GeneralSettings.global().multiplayerScreenButtonOrientation.getIndex();
if (buttonPosition == 0) { // Off
return;
}
// Create the button
ButtonWidget.Builder builder = ButtonWidget.builder(Text.literal("ViaFabricPlus"), button -> ProtocolSelectionScreen.INSTANCE.open(this)).size(98, 20);
// Set the button's position according to the configured orientation
builder = GeneralSettings.withOrientation(builder, GeneralSettings.global().multiplayerScreenButtonOrientation.getIndex(), width, height);
builder = GeneralSettings.withOrientation(builder, buttonPosition, width, height);
// Add the button to the screen
this.addDrawableChild(builder.build());

View File

@ -23,24 +23,24 @@ import de.florianmichael.viafabricplus.settings.base.BooleanSetting;
import de.florianmichael.viafabricplus.settings.base.ModeSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
public class GeneralSettings extends SettingGroup {
private static final GeneralSettings INSTANCE = new GeneralSettings();
public final ModeSetting multiplayerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general_settings.viafabricplus.multiplayer_screen_button_orientation"), 1,
private final MutableText[] ORIENTATION_OPTIONS = new MutableText[] {
Text.translatable("base.viafabricplus.off"),
Text.translatable("base.viafabricplus.left_top"),
Text.translatable("base.viafabricplus.right_top"),
Text.translatable("base.viafabricplus.left_bottom"),
Text.translatable("base.viafabricplus.right_bottom")
);
public final ModeSetting addServerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general_settings.viafabricplus.add_server_screen_button_orientation"), 1,
Text.translatable("base.viafabricplus.left_top"),
Text.translatable("base.viafabricplus.right_top"),
Text.translatable("base.viafabricplus.left_bottom"),
Text.translatable("base.viafabricplus.right_bottom")
);
};
public final ModeSetting multiplayerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general_settings.viafabricplus.multiplayer_screen_button_orientation"), 2, ORIENTATION_OPTIONS);
public final ModeSetting addServerScreenButtonOrientation = new ModeSetting(this, Text.translatable("general_settings.viafabricplus.add_server_screen_button_orientation"), 2, ORIENTATION_OPTIONS);
public final ModeSetting directConnectScreenButtonOrientation = new ModeSetting(this, Text.translatable("general_settings.viafabricplus.direct_connect_screen_button_orientation"), 2, ORIENTATION_OPTIONS);
public final ModeSetting removeNotAvailableItemsFromCreativeTab = new ModeSetting(this, Text.translatable("general_settings.viafabricplus.filter_creative_tabs"),
Text.translatable("base.viafabricplus.vanilla_and_modded"),
Text.translatable("base.viafabricplus.vanilla_only"),
@ -65,10 +65,10 @@ public class GeneralSettings extends SettingGroup {
public static ButtonWidget.Builder withOrientation(final ButtonWidget.Builder builder, final int orientationIndex, final int width, final int height) {
return switch (orientationIndex) {
case 0 -> builder.position(5, 5);
case 1 -> builder.position(width - 98 - 5, 5);
case 2 -> builder.position(5, height - 20 - 5);
case 3 -> builder.position(width - 98 - 5, height - 20 - 5);
case 1 -> builder.position(5, 5);
case 2 -> builder.position(width - 98 - 5, 5);
case 3 -> builder.position(5, height - 20 - 5);
case 4 -> builder.position(width - 98 - 5, height - 20 - 5);
default -> builder;
};
}

View File

@ -38,6 +38,7 @@
"general_settings.viafabricplus.show_classic_loading_progress": "Show classic loading progress in connect screen",
"general_settings.viafabricplus.multiplayer_screen_button_orientation": "Multiplayer screen button orientation",
"general_settings.viafabricplus.add_server_screen_button_orientation": "Add server screen button orientation",
"general_settings.viafabricplus.direct_connect_screen_button_orientation": "Direct connect screen button orientation",
"general_settings.viafabricplus.filter_creative_tabs": "Remove not available items from creative tab",
"general_settings.viafabricplus.show_advertised_server_version": "Show advertised/server version in Multiplayer",
"general_settings.viafabricplus.ignore_packet_translation_errors": "Ignore packet translation errors",

View File

@ -14,6 +14,7 @@
"base.integration.MixinChunkTracker",
"base.integration.MixinConnectScreen_1",
"base.integration.MixinDebugHud",
"base.integration.MixinDirectConnectScreen",
"base.integration.MixinDownloadingTerrainScreen",
"base.integration.MixinMinecraftClient",
"base.integration.MixinMultiplayerScreen",