New Info stuff
This commit is contained in:
@@ -4,6 +4,8 @@ import net.fabricmc.api.ModInitializer;
|
||||
|
||||
public class Parrotmod implements ModInitializer {
|
||||
|
||||
public static String BUILD = "1";
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
||||
|
||||
@@ -1,48 +1,21 @@
|
||||
package de.winniepat.parrotmod.ui;
|
||||
|
||||
import de.winniepat.parrotmod.Parrotmod;
|
||||
import icyllis.modernui.fragment.Fragment;
|
||||
import icyllis.modernui.util.DataSet;
|
||||
import icyllis.modernui.view.*;
|
||||
import icyllis.modernui.widget.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class GeneralTabFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, DataSet savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, DataSet savedInstanceData) {
|
||||
LinearLayout layout = new LinearLayout(getContext());
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
layout.setPadding(dp(12), dp(12), dp(12), dp(12));
|
||||
|
||||
// --- A toggle/switch setting ---
|
||||
layout.addView(makeLabel("Enable feature X"));
|
||||
Switch toggleX = new Switch(getContext());
|
||||
toggleX.setChecked(true); // load from your config
|
||||
toggleX.setOnCheckedChangeListener((v, checked) -> {
|
||||
// save to config
|
||||
MyConfig.enableFeatureX = checked;
|
||||
});
|
||||
layout.addView(toggleX, rowParams());
|
||||
|
||||
// --- Another toggle ---
|
||||
layout.addView(makeLabel("Show HUD overlay"));
|
||||
Switch toggleHUD = new Switch(getContext());
|
||||
toggleHUD.setChecked(MyConfig.showHud);
|
||||
toggleHUD.setOnCheckedChangeListener((v, checked) -> MyConfig.showHud = checked);
|
||||
layout.addView(toggleHUD, rowParams());
|
||||
|
||||
// --- A slider ---
|
||||
layout.addView(makeLabel("Opacity"));
|
||||
SeekBar slider = new SeekBar(getContext());
|
||||
slider.setMax(100);
|
||||
slider.setProgress((int)(MyConfig.opacity * 100));
|
||||
slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) {
|
||||
if (fromUser) MyConfig.opacity = progress / 100f;
|
||||
}
|
||||
public void onStartTrackingTouch(SeekBar bar) {}
|
||||
public void onStopTrackingTouch(SeekBar bar) {}
|
||||
});
|
||||
layout.addView(slider, rowParams());
|
||||
layout.addView(makeLabel("Minecraft Version: " + Minecraft.getInstance().getLaunchedVersion()));
|
||||
|
||||
return layout;
|
||||
}
|
||||
@@ -52,19 +25,13 @@ public class GeneralTabFragment extends Fragment {
|
||||
tv.setText(text);
|
||||
tv.setTextSize(12);
|
||||
tv.setTextColor(0xFFCCCCCC);
|
||||
var p = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
var p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
p.topMargin = dp(8);
|
||||
p.bottomMargin = dp(2);
|
||||
tv.setLayoutParams(p);
|
||||
return tv;
|
||||
}
|
||||
|
||||
private LinearLayout.LayoutParams rowParams() {
|
||||
return new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, dp(28));
|
||||
}
|
||||
|
||||
private int dp(float dp) {
|
||||
return (int) (dp * getContext().getResources().getDisplayMetrics().density);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package de.winniepat.parrotmod.ui;
|
||||
|
||||
import de.winniepat.parrotmod.Parrotmod;
|
||||
import icyllis.modernui.fragment.Fragment;
|
||||
import icyllis.modernui.util.DataSet;
|
||||
import icyllis.modernui.view.LayoutInflater;
|
||||
import icyllis.modernui.view.View;
|
||||
import icyllis.modernui.view.ViewGroup;
|
||||
import icyllis.modernui.widget.LinearLayout;
|
||||
import icyllis.modernui.widget.TextView;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class InfoTabFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, DataSet savedInstanceData) {
|
||||
LinearLayout layout = new LinearLayout(getContext());
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
layout.setPadding(dp(12), dp(12), dp(12), dp(12));
|
||||
|
||||
String parrotVersion = FabricLoader.getInstance().getModContainer("parrotmod").orElseThrow().getMetadata().getVersion().getFriendlyString();
|
||||
layout.addView(makeLabel("Parrotmod version: " + parrotVersion + " (Build " + Parrotmod.BUILD + ")"));
|
||||
|
||||
String mcVersion = FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion().getFriendlyString();
|
||||
layout.addView(makeLabel("Minecraft Version: " + Minecraft.getInstance().getLaunchedVersion() + " (" + mcVersion + ")"));
|
||||
|
||||
String loaderVersion = FabricLoader.getInstance().getModContainer("fabricloader").orElseThrow().getMetadata().getVersion().getFriendlyString();
|
||||
layout.addView(makeLabel("Fabric Loader Version: " + loaderVersion));
|
||||
|
||||
int modCount = FabricLoader.getInstance().getAllMods().size();
|
||||
layout.addView(makeLabel("Loaded Mods: " + modCount));
|
||||
|
||||
layout.addView(makeLabel("Java Version: " + System.getProperty("java.version") + " (" + System.getProperty("os.arch") + ")"));
|
||||
layout.addView(makeLabel("OS: " + System.getProperty("os.name") + " (" + System.getProperty("os.version") + ")"));
|
||||
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
long totalMemory = Runtime.getRuntime().totalMemory();
|
||||
long freeMemory = Runtime.getRuntime().freeMemory();
|
||||
long usedMemory = totalMemory - freeMemory;
|
||||
layout.addView(makeLabel(String.format("Memory: %dMB / %dMB", usedMemory / 1024 / 1024, maxMemory / 1024 / 1024)));
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
private TextView makeLabel(String text) {
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setText(text);
|
||||
tv.setTextSize(12);
|
||||
tv.setTextColor(0xFFCCCCCC);
|
||||
var p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
p.topMargin = dp(8);
|
||||
p.bottomMargin = dp(2);
|
||||
tv.setLayoutParams(p);
|
||||
return tv;
|
||||
}
|
||||
|
||||
private int dp(float dp) {
|
||||
return (int) (dp * getContext().getResources().getDisplayMetrics().density);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package de.winniepat.parrotmod.ui;
|
||||
|
||||
public class MyConfig {
|
||||
public static boolean enableFeatureX = true;
|
||||
public static boolean showHud = true;
|
||||
public static float opacity = 0.5f;
|
||||
}
|
||||
@@ -37,8 +37,9 @@ public class SettingsFragment extends Fragment {
|
||||
contentParams.leftMargin = dp(6);
|
||||
root.addView(contentArea, contentParams);
|
||||
|
||||
String[] tabNames = {"General", "Graphics", "Audio", "Keybinds"};
|
||||
String[] tabNames = {"Info", "General"};
|
||||
Fragment[] tabFragments = {
|
||||
new InfoTabFragment(),
|
||||
new GeneralTabFragment()
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user