Rework Settings Menu
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package de.winniepat.parrotmod.ui;
|
||||
|
||||
import icyllis.modernui.animation.ObjectAnimator;
|
||||
import icyllis.modernui.fragment.Fragment;
|
||||
import icyllis.modernui.view.View;
|
||||
import icyllis.modernui.view.ViewGroup;
|
||||
import icyllis.modernui.widget.LinearLayout;
|
||||
import icyllis.modernui.widget.TextView;
|
||||
|
||||
public abstract class BaseTabFragment extends Fragment {
|
||||
|
||||
protected int dp(float dp) {
|
||||
return (int) (dp * getContext().getResources().getDisplayMetrics().density);
|
||||
}
|
||||
|
||||
protected TextView makeLabel(String text) {
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setText(text);
|
||||
tv.setTextSize(14);
|
||||
tv.setTextColor(0xFFEEEEEE);
|
||||
var p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
p.topMargin = dp(12);
|
||||
p.bottomMargin = dp(4);
|
||||
tv.setLayoutParams(p);
|
||||
return tv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, icyllis.modernui.util.DataSet savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
view.setAlpha(0);
|
||||
view.setTranslationY(dp(20));
|
||||
ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1).setDuration(400).start();
|
||||
ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, dp(20), 0).setDuration(400).start();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package de.winniepat.parrotmod.ui;
|
||||
|
||||
import de.winniepat.parrotmod.config.ConfigManager;
|
||||
import icyllis.modernui.fragment.Fragment;
|
||||
import icyllis.modernui.util.DataSet;
|
||||
import icyllis.modernui.view.LayoutInflater;
|
||||
import icyllis.modernui.view.View;
|
||||
@@ -9,68 +8,59 @@ import icyllis.modernui.view.ViewGroup;
|
||||
import icyllis.modernui.widget.LinearLayout;
|
||||
import icyllis.modernui.widget.Switch;
|
||||
import icyllis.modernui.widget.TextView;
|
||||
import icyllis.modernui.view.Gravity;
|
||||
|
||||
public class DiscordTabFragment extends Fragment {
|
||||
public class DiscordTabFragment extends BaseTabFragment {
|
||||
|
||||
@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));
|
||||
layout.setPadding(dp(20), dp(20), dp(20), dp(20));
|
||||
|
||||
layout.addView(makeLabel("Enable DiscordRPC"));
|
||||
Switch toggleDiscordRPC = new Switch(getContext());
|
||||
toggleDiscordRPC.setChecked(ConfigManager.getInstance().enableDiscordRPC);
|
||||
toggleDiscordRPC.setOnCheckedChangeListener((v, checked) -> {
|
||||
addSwitch(layout, "Enable DiscordRPC", ConfigManager.getInstance().enableDiscordRPC, (v, checked) -> {
|
||||
ConfigManager.getInstance().enableDiscordRPC = checked;
|
||||
ConfigManager.save();
|
||||
});
|
||||
layout.addView(toggleDiscordRPC);
|
||||
|
||||
layout.addView(makeLabel("Show Biome in RPC"));
|
||||
Switch toggleBiome = new Switch(getContext());
|
||||
toggleBiome.setChecked(ConfigManager.getInstance().showBiomeInRPC);
|
||||
toggleBiome.setOnCheckedChangeListener((v, checked) -> {
|
||||
addSwitch(layout, "Show Biome in RPC", ConfigManager.getInstance().showBiomeInRPC, (v, checked) -> {
|
||||
ConfigManager.getInstance().showBiomeInRPC = checked;
|
||||
ConfigManager.save();
|
||||
});
|
||||
layout.addView(toggleBiome);
|
||||
|
||||
layout.addView(makeLabel("Show Held Item in RPC"));
|
||||
Switch toggleHeldItem = new Switch(getContext());
|
||||
toggleHeldItem.setChecked(ConfigManager.getInstance().showHeldItemInRPC);
|
||||
toggleHeldItem.setOnCheckedChangeListener((v, checked) -> {
|
||||
addSwitch(layout, "Show Held Item in RPC", ConfigManager.getInstance().showHeldItemInRPC, (v, checked) -> {
|
||||
ConfigManager.getInstance().showHeldItemInRPC = checked;
|
||||
ConfigManager.save();
|
||||
});
|
||||
layout.addView(toggleHeldItem);
|
||||
|
||||
layout.addView(makeLabel("Show Health in RPC"));
|
||||
Switch toggleHealth = new Switch(getContext());
|
||||
toggleHealth.setChecked(ConfigManager.getInstance().showHealthInRPC);
|
||||
toggleHealth.setOnCheckedChangeListener((v, checked) -> {
|
||||
addSwitch(layout, "Show Health in RPC", ConfigManager.getInstance().showHealthInRPC, (v, checked) -> {
|
||||
ConfigManager.getInstance().showHealthInRPC = checked;
|
||||
ConfigManager.save();
|
||||
});
|
||||
layout.addView(toggleHealth);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
private TextView makeLabel(String text) {
|
||||
private void addSwitch(LinearLayout parent, String label, boolean checked, Switch.OnCheckedChangeListener listener) {
|
||||
LinearLayout row = new LinearLayout(getContext());
|
||||
row.setOrientation(LinearLayout.HORIZONTAL);
|
||||
row.setGravity(Gravity.CENTER_VERTICAL);
|
||||
var rowParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
rowParams.bottomMargin = dp(12);
|
||||
row.setLayoutParams(rowParams);
|
||||
|
||||
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;
|
||||
}
|
||||
tv.setText(label);
|
||||
tv.setTextSize(15);
|
||||
tv.setTextColor(0xFFEEEEEE);
|
||||
var labelParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f);
|
||||
row.addView(tv, labelParams);
|
||||
|
||||
private int dp(float dp) {
|
||||
return (int) (dp * getContext().getResources().getDisplayMetrics().density);
|
||||
}
|
||||
Switch s = new Switch(getContext());
|
||||
s.setChecked(checked);
|
||||
s.setOnCheckedChangeListener(listener);
|
||||
row.addView(s);
|
||||
|
||||
parent.addView(row);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
package de.winniepat.parrotmod.ui;
|
||||
|
||||
import de.winniepat.parrotmod.Parrotmod;
|
||||
import de.winniepat.parrotmod.config.ConfigManager;
|
||||
import icyllis.modernui.fragment.Fragment;
|
||||
import icyllis.modernui.util.DataSet;
|
||||
import icyllis.modernui.view.*;
|
||||
import icyllis.modernui.widget.*;
|
||||
import icyllis.modernui.view.LayoutInflater;
|
||||
import icyllis.modernui.view.View;
|
||||
import icyllis.modernui.view.ViewGroup;
|
||||
import icyllis.modernui.widget.Button;
|
||||
import icyllis.modernui.widget.LinearLayout;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class GeneralTabFragment extends Fragment {
|
||||
public class GeneralTabFragment extends BaseTabFragment {
|
||||
|
||||
@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));
|
||||
layout.setPadding(dp(20), dp(20), dp(20), dp(20));
|
||||
|
||||
layout.addView(makeLabel("Minecraft Version: " + Minecraft.getInstance().getLaunchedVersion()));
|
||||
|
||||
@@ -22,30 +23,16 @@ public class GeneralTabFragment extends Fragment {
|
||||
reloadBtn.setText("Reload Config");
|
||||
reloadBtn.setOnClickListener(v -> ConfigManager.load());
|
||||
var p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
p.topMargin = dp(16);
|
||||
p.topMargin = dp(24);
|
||||
layout.addView(reloadBtn, p);
|
||||
|
||||
Button saveBtn = new Button(getContext());
|
||||
saveBtn.setText("Save Config");
|
||||
saveBtn.setOnClickListener(v -> ConfigManager.save());
|
||||
layout.addView(saveBtn, p);
|
||||
var p2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
p2.topMargin = dp(12);
|
||||
layout.addView(saveBtn, p2);
|
||||
|
||||
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,22 +1,20 @@
|
||||
package de.winniepat.parrotmod.ui;
|
||||
|
||||
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 {
|
||||
public class InfoTabFragment extends BaseTabFragment {
|
||||
|
||||
@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));
|
||||
layout.setPadding(dp(20), dp(20), dp(20), dp(20));
|
||||
|
||||
String parrotVersion = FabricLoader.getInstance().getModContainer("parrotmod").orElseThrow().getMetadata().getVersion().getFriendlyString();
|
||||
layout.addView(makeLabel("Parrotmod version: " + parrotVersion));
|
||||
@@ -41,20 +39,4 @@ public class InfoTabFragment extends Fragment {
|
||||
|
||||
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,6 +1,7 @@
|
||||
package de.winniepat.parrotmod.ui;
|
||||
|
||||
import icyllis.modernui.R;
|
||||
import icyllis.modernui.animation.ObjectAnimator;
|
||||
import icyllis.modernui.fragment.Fragment;
|
||||
import icyllis.modernui.util.DataSet;
|
||||
import icyllis.modernui.view.*;
|
||||
@@ -15,19 +16,34 @@ public class SettingsFragment extends Fragment {
|
||||
LinearLayout root = new LinearLayout(getContext());
|
||||
root.setOrientation(LinearLayout.HORIZONTAL);
|
||||
root.setLayoutParams(new FrameLayout.LayoutParams(
|
||||
dp(520), dp(320), Gravity.CENTER));
|
||||
dp(700), dp(450), Gravity.CENTER));
|
||||
|
||||
root.setAlpha(0);
|
||||
root.setScaleX(0.95f);
|
||||
root.setScaleY(0.95f);
|
||||
ObjectAnimator.ofFloat(root, View.ALPHA, 0, 1).setDuration(400).start();
|
||||
ObjectAnimator.ofFloat(root, View.SCALE_X, 0.95f, 1).setDuration(400).start();
|
||||
ObjectAnimator.ofFloat(root, View.SCALE_Y, 0.95f, 1).setDuration(400).start();
|
||||
|
||||
LinearLayout sidebar = new LinearLayout(getContext());
|
||||
sidebar.setOrientation(LinearLayout.VERTICAL);
|
||||
sidebar.setPadding(dp(8), dp(8), dp(8), dp(8));
|
||||
sidebar.setBackground(makeRoundedBg(0xCC1A1A2E));
|
||||
sidebar.setPadding(dp(12), dp(16), dp(12), dp(16));
|
||||
sidebar.setBackground(makeRoundedBg(0xEE161625));
|
||||
|
||||
var sidebarParams = new LinearLayout.LayoutParams(dp(110), ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
TextView title = new TextView(getContext());
|
||||
title.setText("ParrotMod");
|
||||
title.setTextSize(20);
|
||||
title.setGravity(Gravity.CENTER);
|
||||
title.setTextColor(0xFFFFFFFF);
|
||||
title.setPadding(0, 0, 0, dp(20));
|
||||
sidebar.addView(title);
|
||||
|
||||
var sidebarParams = new LinearLayout.LayoutParams(dp(160), ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
root.addView(sidebar, sidebarParams);
|
||||
|
||||
FrameLayout contentArea = new FrameLayout(getContext());
|
||||
contentArea.setId(R.id.content);
|
||||
contentArea.setBackground(makeRoundedBg(0xCC101018));
|
||||
contentArea.setBackground(makeRoundedBg(0xEE101018));
|
||||
|
||||
var contentParams = new LinearLayout.LayoutParams(
|
||||
0, ViewGroup.LayoutParams.MATCH_PARENT, 1f);
|
||||
@@ -49,10 +65,10 @@ public class SettingsFragment extends Fragment {
|
||||
for (int i = 0; i < tabNames.length; i++) {
|
||||
final int index = i;
|
||||
Button tab = new Button(getContext());
|
||||
tab.setText(tabNames[i]);
|
||||
tab.setTextSize(13);
|
||||
tab.setText(tabNames[index]);
|
||||
tab.setTextSize(15);
|
||||
tab.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
|
||||
tab.setPadding(dp(10), dp(6), dp(10), dp(6));
|
||||
tab.setPadding(dp(16), dp(8), dp(16), dp(8));
|
||||
tab.setBackground(null);
|
||||
|
||||
tab.setOnClickListener(v -> {
|
||||
@@ -60,19 +76,27 @@ public class SettingsFragment extends Fragment {
|
||||
.setReorderingAllowed(true)
|
||||
.replace(contentArea.getId(), tabFragments[index])
|
||||
.commit();
|
||||
for (Button b : tabs) b.setTextColor(0xFFAAAAAA);
|
||||
for (Button b : tabs) {
|
||||
b.setTextColor(0xFFAAAAAA);
|
||||
b.setBackground(null);
|
||||
}
|
||||
tab.setTextColor(0xFFFFFFFF);
|
||||
tab.setBackground(makeRoundedBg(0x33FFFFFF));
|
||||
});
|
||||
|
||||
var tabParams = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, dp(32));
|
||||
tabParams.bottomMargin = dp(4);
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, dp(40));
|
||||
tabParams.bottomMargin = dp(8);
|
||||
sidebar.addView(tab, tabParams);
|
||||
tabs[i] = tab;
|
||||
tabs[index] = tab;
|
||||
}
|
||||
|
||||
tabs[0].setTextColor(0xFFFFFFFF);
|
||||
for (int i = 1; i < tabs.length; i++) tabs[i].setTextColor(0xFFAAAAAA);
|
||||
tabs[0].setBackground(makeRoundedBg(0x33FFFFFF));
|
||||
for (int i = 1; i < tabs.length; i++) {
|
||||
tabs[i].setTextColor(0xFFAAAAAA);
|
||||
tabs[i].setBackground(null);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
@@ -83,7 +107,7 @@ public class SettingsFragment extends Fragment {
|
||||
|
||||
private ShapeDrawable makeRoundedBg(int color) {
|
||||
ShapeDrawable d = new ShapeDrawable();
|
||||
d.setCornerRadius(dp(6));
|
||||
d.setCornerRadius(dp(12));
|
||||
d.setColor(color);
|
||||
return d;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user