Skip to content

Commit

Permalink
shuffle stuff a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Feb 19, 2023
1 parent 9611f3f commit 055168c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,31 @@ public SwitchScreen(SwitchyDisplayPresets displayPresets) {
return OwoUIAdapter.create(this, Containers::verticalFlow);
}

private Component generatePresetComponent(SwitchyDisplayPreset preset) {
private Component generatePresetComponent(SwitchyDisplayPreset preset, boolean currentPreset) {
// Main Horizontal Flow Panel
HorizontalFlowLayout horizontalFLow = Containers.horizontalFlow(Sizing.fixed(400), Sizing.content());
horizontalFLow.padding(Insets.vertical(4).withLeft(10).withRight(10));
horizontalFLow.gap(2);
horizontalFLow.surface(Surface.DARK_PANEL);
horizontalFLow.verticalAlignment(VerticalAlignment.CENTER);
horizontalFLow.horizontalAlignment(HorizontalAlignment.CENTER);
horizontalFLow.mouseEnter().subscribe(() -> horizontalFLow.surface(Surface.DARK_PANEL.and(Surface.outline(Color.WHITE.argb()))));
horizontalFLow.mouseLeave().subscribe(() -> horizontalFLow.surface(Surface.DARK_PANEL));
horizontalFLow.mouseDown().subscribe((x, y, button) -> {
SwitchyClientNetworking.sendSwitch(preset.presetName);
return true;
});
if (currentPreset) {
horizontalFLow.surface(Surface.DARK_PANEL.and(Surface.outline(Color.BLUE.argb())));
} else {
horizontalFLow.surface(Surface.DARK_PANEL);
horizontalFLow.mouseEnter().subscribe(() -> horizontalFLow.surface(Surface.DARK_PANEL.and(Surface.outline(Color.WHITE.argb()))));
horizontalFLow.mouseLeave().subscribe(() -> horizontalFLow.surface(Surface.DARK_PANEL));
horizontalFLow.mouseDown().subscribe((x, y, button) -> {
SwitchyClientNetworking.sendSwitch(preset.presetName);
return true;
});
}

// Left Side Elements
horizontalFLow.children(sideLeftComponents.values().stream().map((fun) -> fun.apply(preset)).filter(Objects::nonNull).toList());

// Main Elements
HorizontalFlowLayout leftRightFlow = Containers.horizontalFlow(Sizing.content(), Sizing.content());
leftRightFlow.margins(Insets.horizontal(6));
leftRightFlow.gap(4);

VerticalFlowLayout leftAlignedFlow = Containers.verticalFlow(Sizing.content(), Sizing.content());
Expand Down Expand Up @@ -99,7 +104,7 @@ protected void build(FlowLayout rootComponent) {
rootComponent.horizontalAlignment(HorizontalAlignment.CENTER);
rootComponent.verticalAlignment(VerticalAlignment.CENTER);

List<Component> presetFlows = new ArrayList<>(displayPresets.presets.values().stream().map(this::generatePresetComponent).toList());
List<Component> presetFlows = new ArrayList<>(displayPresets.presets.values().stream().map(preset -> generatePresetComponent(preset, Objects.equals(preset.presetName, displayPresets.currentPreset))).toList());

VerticalFlowLayout presetsLayout = Containers.verticalFlow(Sizing.content(), Sizing.content());
presetsLayout.padding(Insets.of(6));
Expand Down Expand Up @@ -133,6 +138,6 @@ protected void build(FlowLayout rootComponent) {
});

// Add base components
registerPresetDisplayComponent(new Identifier(SwitchyClient.ID, "preset_name"), ComponentPosition.LEFT, displayPreset -> Components.label(Text.literal(displayPreset.presetName)));
registerPresetDisplayComponent(new Identifier(SwitchyClient.ID, "preset_name"), ComponentPosition.SIDE_LEFT, displayPreset -> Components.label(Text.literal(displayPreset.presetName)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DrogtorCompatClient {
public static void touch() {}

static {
SwitchyScreenExtensions.registerQuickSwitchDisplayComponent(ID, ComponentPosition.RIGHT, displayPreset -> {
SwitchyScreenExtensions.registerQuickSwitchDisplayComponent(ID, ComponentPosition.LEFT, displayPreset -> {
if (!displayPreset.modules.containsKey(ID)) return null;
NbtCompound nbt = displayPreset.modules.get(ID);
if (!nbt.contains(KEY_NICKNAME)) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class OriginsCompatClient {
public static void touch() {}

static {
SwitchyScreenExtensions.registerQuickSwitchDisplayComponent(ID, SwitchScreen.ComponentPosition.RIGHT, displayPreset -> {
SwitchyScreenExtensions.registerQuickSwitchDisplayComponent(ID, SwitchScreen.ComponentPosition.LEFT, displayPreset -> {
if (!displayPreset.modules.containsKey(ID)) return null;
NbtCompound nbt = displayPreset.modules.get(ID);
if (!nbt.contains(KEY_ORIGINS_LIST, NbtElement.LIST_TYPE)) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class StyledNicknamesCompatClient {
public static void touch() {}

static {
SwitchyScreenExtensions.registerQuickSwitchDisplayComponent(ID, SwitchScreen.ComponentPosition.RIGHT, displayPreset -> {
SwitchyScreenExtensions.registerQuickSwitchDisplayComponent(ID, SwitchScreen.ComponentPosition.LEFT, displayPreset -> {
if (!displayPreset.modules.containsKey(ID)) return null;
NbtCompound nbt = displayPreset.modules.get(ID);
if (!nbt.contains(KEY_NICKNAME)) return null;
Expand Down

0 comments on commit 055168c

Please sign in to comment.