Cleanup
This commit is contained in:
@@ -8,6 +8,7 @@ import com.jagrosh.discordipc.entities.Packet;
|
|||||||
import com.jagrosh.discordipc.entities.RichPresence;
|
import com.jagrosh.discordipc.entities.RichPresence;
|
||||||
import com.jagrosh.discordipc.entities.User;
|
import com.jagrosh.discordipc.entities.User;
|
||||||
import com.jagrosh.discordipc.exceptions.NoDiscordClientException;
|
import com.jagrosh.discordipc.exceptions.NoDiscordClientException;
|
||||||
|
import de.winniepat.parrotmod.ParrotLogger;
|
||||||
import de.winniepat.parrotmod.config.ConfigManager;
|
import de.winniepat.parrotmod.config.ConfigManager;
|
||||||
import net.minecraft.client.player.LocalPlayer;
|
import net.minecraft.client.player.LocalPlayer;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
@@ -49,15 +50,11 @@ public class DiscordRPCManager {
|
|||||||
public static void init() {
|
public static void init() {
|
||||||
ConfigManager.registerListener(cfg -> {
|
ConfigManager.registerListener(cfg -> {
|
||||||
if (cfg.enableDiscordRPC) {
|
if (cfg.enableDiscordRPC) {
|
||||||
if (!connected && client == null) {
|
if (client == null) {
|
||||||
startClient();
|
startClient();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (client != null) {
|
shutdown();
|
||||||
shutdown();
|
|
||||||
client = null;
|
|
||||||
connected = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -189,6 +186,17 @@ public class DiscordRPCManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void shutdown() {
|
public static void shutdown() {
|
||||||
if (client != null) client.close();
|
if (client != null) {
|
||||||
|
try {
|
||||||
|
if (connected) {
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
ParrotLogger.logError(DiscordRPCManager.class, "Error while closing Discord RPC client", e);
|
||||||
|
} finally {
|
||||||
|
client = null;
|
||||||
|
connected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ public abstract class BaseTabFragment extends Fragment {
|
|||||||
tv.setText(title.toUpperCase());
|
tv.setText(title.toUpperCase());
|
||||||
tv.setTextSize(11);
|
tv.setTextSize(11);
|
||||||
tv.setTextColor(COLOR_ACCENT);
|
tv.setTextColor(COLOR_ACCENT);
|
||||||
// Letter spacing might not be available in all ModernUI versions, but let's try if it exists or just skip
|
|
||||||
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(24);
|
p.topMargin = dp(24);
|
||||||
p.bottomMargin = dp(8);
|
p.bottomMargin = dp(8);
|
||||||
|
|||||||
@@ -7,9 +7,13 @@ import icyllis.modernui.view.ViewGroup;
|
|||||||
import icyllis.modernui.widget.LinearLayout;
|
import icyllis.modernui.widget.LinearLayout;
|
||||||
import icyllis.modernui.widget.Switch;
|
import icyllis.modernui.widget.Switch;
|
||||||
import icyllis.modernui.widget.ScrollView;
|
import icyllis.modernui.widget.ScrollView;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DiscordTabFragment extends BaseTabFragment {
|
public class DiscordTabFragment extends BaseTabFragment {
|
||||||
|
|
||||||
|
private final List<View> rpcDetailViews = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, DataSet savedInstanceData) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, DataSet savedInstanceData) {
|
||||||
ScrollView scrollView = new ScrollView(getContext());
|
ScrollView scrollView = new ScrollView(getContext());
|
||||||
@@ -26,37 +30,61 @@ public class DiscordTabFragment extends BaseTabFragment {
|
|||||||
ConfigManager.getInstance().enableDiscordRPC, (v, checked) -> {
|
ConfigManager.getInstance().enableDiscordRPC, (v, checked) -> {
|
||||||
ConfigManager.getInstance().enableDiscordRPC = checked;
|
ConfigManager.getInstance().enableDiscordRPC = checked;
|
||||||
ConfigManager.save();
|
ConfigManager.save();
|
||||||
|
updateRPCDetailsEnabled(checked);
|
||||||
});
|
});
|
||||||
|
|
||||||
addSectionHeader(layout, "RPC Details");
|
addSectionHeader(layout, "RPC Details");
|
||||||
|
|
||||||
addSwitchRow(layout, "Show Biome", "Display current biome in status",
|
rpcDetailViews.add(addSwitchRow(layout, "Show Biome", "Display current biome in status",
|
||||||
ConfigManager.getInstance().showBiomeInRPC, (v, checked) -> {
|
ConfigManager.getInstance().showBiomeInRPC, (v, checked) -> {
|
||||||
ConfigManager.getInstance().showBiomeInRPC = checked;
|
ConfigManager.getInstance().showBiomeInRPC = checked;
|
||||||
ConfigManager.save();
|
ConfigManager.save();
|
||||||
});
|
}));
|
||||||
|
|
||||||
addSwitchRow(layout, "Show Held Item", "Display what you are holding",
|
rpcDetailViews.add(addSwitchRow(layout, "Show Held Item", "Display what you are holding",
|
||||||
ConfigManager.getInstance().showHeldItemInRPC, (v, checked) -> {
|
ConfigManager.getInstance().showHeldItemInRPC, (v, checked) -> {
|
||||||
ConfigManager.getInstance().showHeldItemInRPC = checked;
|
ConfigManager.getInstance().showHeldItemInRPC = checked;
|
||||||
ConfigManager.save();
|
ConfigManager.save();
|
||||||
});
|
}));
|
||||||
|
|
||||||
addSwitchRow(layout, "Show Health", "Display your current HP",
|
rpcDetailViews.add(addSwitchRow(layout, "Show Health", "Display your current HP",
|
||||||
ConfigManager.getInstance().showHealthInRPC, (v, checked) -> {
|
ConfigManager.getInstance().showHealthInRPC, (v, checked) -> {
|
||||||
ConfigManager.getInstance().showHealthInRPC = checked;
|
ConfigManager.getInstance().showHealthInRPC = checked;
|
||||||
ConfigManager.save();
|
ConfigManager.save();
|
||||||
});
|
}));
|
||||||
|
|
||||||
|
updateRPCDetailsEnabled(ConfigManager.getInstance().enableDiscordRPC);
|
||||||
|
|
||||||
return scrollView;
|
return scrollView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSwitchRow(LinearLayout parent, String title, String desc, boolean checked, Switch.OnCheckedChangeListener listener) {
|
private void updateRPCDetailsEnabled(boolean enabled) {
|
||||||
|
for (View v : rpcDetailViews) {
|
||||||
|
v.setEnabled(enabled);
|
||||||
|
v.setAlpha(enabled ? 1.0f : 0.5f);
|
||||||
|
if (v instanceof ViewGroup) {
|
||||||
|
setChildrenEnabled((ViewGroup) v, enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChildrenEnabled(ViewGroup vg, boolean enabled) {
|
||||||
|
for (int i = 0; i < vg.getChildCount(); i++) {
|
||||||
|
View child = vg.getChildAt(i);
|
||||||
|
child.setEnabled(enabled);
|
||||||
|
if (child instanceof ViewGroup) {
|
||||||
|
setChildrenEnabled((ViewGroup) child, enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private View addSwitchRow(LinearLayout parent, String title, String desc, boolean checked, Switch.OnCheckedChangeListener listener) {
|
||||||
LinearLayout card = createSettingCard(title, desc);
|
LinearLayout card = createSettingCard(title, desc);
|
||||||
Switch s = new Switch(getContext());
|
Switch s = new Switch(getContext());
|
||||||
s.setChecked(checked);
|
s.setChecked(checked);
|
||||||
s.setOnCheckedChangeListener(listener);
|
s.setOnCheckedChangeListener(listener);
|
||||||
card.addView(s);
|
card.addView(s);
|
||||||
parent.addView(card);
|
parent.addView(card);
|
||||||
|
return card;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,9 @@ public class SettingsFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, DataSet savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, DataSet savedInstanceState) {
|
||||||
// Main container with shadow/margin if needed, but here it's centering
|
|
||||||
FrameLayout root = new FrameLayout(getContext());
|
FrameLayout root = new FrameLayout(getContext());
|
||||||
root.setLayoutParams(new FrameLayout.LayoutParams(dp(720), dp(480), Gravity.CENTER));
|
root.setLayoutParams(new FrameLayout.LayoutParams(dp(720), dp(480), Gravity.CENTER));
|
||||||
|
|
||||||
// Background
|
|
||||||
View bg = new View(getContext());
|
View bg = new View(getContext());
|
||||||
bg.setBackground(makeRoundedBg(COLOR_BACKGROUND, 16));
|
bg.setBackground(makeRoundedBg(COLOR_BACKGROUND, 16));
|
||||||
root.addView(bg);
|
root.addView(bg);
|
||||||
@@ -32,19 +30,17 @@ public class SettingsFragment extends Fragment {
|
|||||||
layout.setOrientation(LinearLayout.HORIZONTAL);
|
layout.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
root.addView(layout);
|
root.addView(layout);
|
||||||
|
|
||||||
// Sidebar Container
|
|
||||||
FrameLayout sidebarContainer = new FrameLayout(getContext());
|
FrameLayout sidebarContainer = new FrameLayout(getContext());
|
||||||
var sidebarParams = new LinearLayout.LayoutParams(dp(170), ViewGroup.LayoutParams.MATCH_PARENT);
|
var sidebarParams = new LinearLayout.LayoutParams(dp(170), ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
layout.addView(sidebarContainer, sidebarParams);
|
layout.addView(sidebarContainer, sidebarParams);
|
||||||
|
|
||||||
View sidebarBg = new View(getContext());
|
View sidebarBg = new View(getContext());
|
||||||
sidebarBg.setBackground(makeRoundedBg(COLOR_SIDEBAR, 16));
|
sidebarBg.setBackground(makeRoundedBg(COLOR_SIDEBAR, 16));
|
||||||
// We only want right side to be sharp, but for simplicity we just overlap or use a large radius
|
|
||||||
sidebarContainer.addView(sidebarBg);
|
sidebarContainer.addView(sidebarBg);
|
||||||
|
|
||||||
LinearLayout sidebarContent = new LinearLayout(getContext());
|
LinearLayout sidebarContent = new LinearLayout(getContext());
|
||||||
sidebarContent.setOrientation(LinearLayout.VERTICAL);
|
sidebarContent.setOrientation(LinearLayout.VERTICAL);
|
||||||
sidebarContent.setPadding(0, dp(24), 0, dp(16)); // Removed horizontal padding to allow edge indicator
|
sidebarContent.setPadding(0, dp(24), 0, dp(16));
|
||||||
sidebarContainer.addView(sidebarContent, new FrameLayout.LayoutParams(
|
sidebarContainer.addView(sidebarContent, new FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
|
||||||
@@ -53,22 +49,19 @@ public class SettingsFragment extends Fragment {
|
|||||||
title.setTextSize(22);
|
title.setTextSize(22);
|
||||||
title.setGravity(Gravity.CENTER);
|
title.setGravity(Gravity.CENTER);
|
||||||
title.setTextColor(COLOR_ACCENT);
|
title.setTextColor(COLOR_ACCENT);
|
||||||
title.setPadding(dp(16), 0, dp(16), dp(32)); // Added horizontal padding back to title
|
title.setPadding(dp(16), 0, dp(16), dp(32));
|
||||||
sidebarContent.addView(title);
|
sidebarContent.addView(title);
|
||||||
|
|
||||||
// Tabs container
|
|
||||||
FrameLayout tabsContainer = new FrameLayout(getContext());
|
FrameLayout tabsContainer = new FrameLayout(getContext());
|
||||||
sidebarContent.addView(tabsContainer, new LinearLayout.LayoutParams(
|
sidebarContent.addView(tabsContainer, new LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f));
|
ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f));
|
||||||
|
|
||||||
LinearLayout tabsLayout = new LinearLayout(getContext());
|
LinearLayout tabsLayout = new LinearLayout(getContext());
|
||||||
tabsLayout.setOrientation(LinearLayout.VERTICAL);
|
tabsLayout.setOrientation(LinearLayout.VERTICAL);
|
||||||
// Center tabs vertically in available space
|
|
||||||
tabsContainer.addView(tabsLayout, new FrameLayout.LayoutParams(
|
tabsContainer.addView(tabsLayout, new FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
|
||||||
|
|
||||||
|
|
||||||
// Content Area
|
|
||||||
FrameLayout contentArea = new FrameLayout(getContext());
|
FrameLayout contentArea = new FrameLayout(getContext());
|
||||||
contentArea.setId(R.id.content);
|
contentArea.setId(R.id.content);
|
||||||
var contentParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f);
|
var contentParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f);
|
||||||
@@ -112,7 +105,6 @@ public class SettingsFragment extends Fragment {
|
|||||||
tabButtons[index] = tab;
|
tabButtons[index] = tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Footer
|
|
||||||
TextView footer = new TextView(getContext());
|
TextView footer = new TextView(getContext());
|
||||||
String version = FabricLoader.getInstance().getModContainer("parrotmod")
|
String version = FabricLoader.getInstance().getModContainer("parrotmod")
|
||||||
.map(m -> m.getMetadata().getVersion().getFriendlyString()).orElse("?.?.?");
|
.map(m -> m.getMetadata().getVersion().getFriendlyString()).orElse("?.?.?");
|
||||||
@@ -123,7 +115,6 @@ public class SettingsFragment extends Fragment {
|
|||||||
footer.setPadding(dp(16), dp(12), dp(16), dp(12));
|
footer.setPadding(dp(16), dp(12), dp(16), dp(12));
|
||||||
sidebarContent.addView(footer);
|
sidebarContent.addView(footer);
|
||||||
|
|
||||||
// Entrance Animation
|
|
||||||
root.setAlpha(0);
|
root.setAlpha(0);
|
||||||
root.setScaleX(0.96f);
|
root.setScaleX(0.96f);
|
||||||
root.setScaleY(0.96f);
|
root.setScaleY(0.96f);
|
||||||
@@ -131,7 +122,6 @@ public class SettingsFragment extends Fragment {
|
|||||||
ObjectAnimator.ofFloat(root, View.SCALE_X, 0.96f, 1).setDuration(450).start();
|
ObjectAnimator.ofFloat(root, View.SCALE_X, 0.96f, 1).setDuration(450).start();
|
||||||
ObjectAnimator.ofFloat(root, View.SCALE_Y, 0.96f, 1).setDuration(450).start();
|
ObjectAnimator.ofFloat(root, View.SCALE_Y, 0.96f, 1).setDuration(450).start();
|
||||||
|
|
||||||
// Initial tab
|
|
||||||
root.post(() -> {
|
root.post(() -> {
|
||||||
tabButtons[0].callOnClick();
|
tabButtons[0].callOnClick();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"fabricloader": ">=${loader_version}",
|
"fabricloader": ">=${loader_version}",
|
||||||
"fabric-api": "*",
|
"fabric-api": "*",
|
||||||
"minecraft": "${minecraft_version}",
|
"minecraft": "${minecraft_version}",
|
||||||
"modernui": "3.13.0.4",
|
"modernui": ">=3.13.0.4",
|
||||||
"forgeconfigapiport": ">=26.1.0"
|
"forgeconfigapiport": ">=26.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user