-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f05e3a
commit 385b195
Showing
5 changed files
with
210 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/com/lilydev/volubind/ui/ToggleVolumeScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.lilydev.volubind.ui; | ||
|
||
import com.lilydev.volubind.VolubindClient; | ||
import com.lilydev.volubind.VolumeControl; | ||
import com.lilydev.volubind.util.Utils; | ||
import io.wispforest.owo.ui.base.BaseUIModelScreen; | ||
import io.wispforest.owo.ui.component.ButtonComponent; | ||
import io.wispforest.owo.ui.component.Components; | ||
import io.wispforest.owo.ui.component.LabelComponent; | ||
import io.wispforest.owo.ui.container.Containers; | ||
import io.wispforest.owo.ui.container.FlowLayout; | ||
import io.wispforest.owo.ui.container.ScrollContainer; | ||
import io.wispforest.owo.ui.core.Insets; | ||
import io.wispforest.owo.ui.core.Positioning; | ||
import io.wispforest.owo.ui.core.Sizing; | ||
import io.wispforest.owo.ui.core.VerticalAlignment; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.EnumSet; | ||
|
||
public class ToggleVolumeScreen extends BaseUIModelScreen<FlowLayout> { | ||
|
||
Screen parent; | ||
|
||
|
||
public ToggleVolumeScreen(Screen parent) { | ||
super(FlowLayout.class, DataSource.asset(Identifier.of(VolubindClient.MOD_ID, "toggle_volume_screen"))); | ||
this.parent = parent; | ||
} | ||
|
||
private static void toggleVolume(ButtonComponent buttonComponent, SoundCategory category) { | ||
boolean volumeToggled = Utils.getVolumeToggleSupplierByCategory(VolubindClient.CONFIG, category).get(); | ||
|
||
Text toggledVolText = Text.translatable("volubind.screen.toggle_volume.entry.button.toggled"); | ||
Text untoggledVolText = Text.translatable("volubind.screen.toggle_volume.entry.button.untoggled"); | ||
|
||
VolumeControl.toggleVolumeByCategory(VolubindClient.CONFIG, category); | ||
if (volumeToggled) { | ||
buttonComponent.setMessage(untoggledVolText); | ||
} else { | ||
buttonComponent.setMessage(toggledVolText); | ||
} | ||
} | ||
|
||
@Override | ||
protected void build(FlowLayout rootComponent) { | ||
assert this.client != null; | ||
|
||
FlowLayout contentFlow = Containers.verticalFlow(Sizing.content(), Sizing.content()); | ||
contentFlow.id("toggle-volume-content"); | ||
contentFlow.gap(4); | ||
contentFlow.padding(Insets.horizontal(5)); | ||
|
||
ScrollContainer<FlowLayout> pageScroll = Containers.verticalScroll( | ||
Sizing.fixed(360), | ||
Sizing.expand(), | ||
contentFlow | ||
); | ||
|
||
pageScroll.padding(Insets.bottom(20)); | ||
|
||
EnumSet.allOf(SoundCategory.class).forEach(soundCategory -> { | ||
FlowLayout buttonFlow = Containers.horizontalFlow(Sizing.fill(), Sizing.fixed(20)); | ||
buttonFlow.verticalAlignment(VerticalAlignment.CENTER); | ||
|
||
LabelComponent flowLabel = Components.label( | ||
Text.translatable("soundCategory." + soundCategory.getName()) | ||
); | ||
|
||
boolean volumeToggled = Utils.getVolumeToggleSupplierByCategory(VolubindClient.CONFIG, soundCategory).get(); | ||
|
||
Text toggledVolText = Text.translatable("volubind.screen.toggle_volume.entry.button.toggled"); | ||
Text untoggledVolText = Text.translatable("volubind.screen.toggle_volume.entry.button.untoggled"); | ||
|
||
Text buttonText = volumeToggled ? toggledVolText : untoggledVolText; | ||
|
||
ButtonComponent flowButton = Components.button( | ||
buttonText, buttonComponent -> toggleVolume(buttonComponent, soundCategory) | ||
); | ||
|
||
flowButton.horizontalSizing(Sizing.fixed(120)); | ||
flowButton.positioning(Positioning.relative(100, 50)); | ||
|
||
buttonFlow.child(flowLabel); | ||
buttonFlow.child(flowButton); | ||
|
||
contentFlow.child(buttonFlow); | ||
}); | ||
|
||
rootComponent.child(pageScroll); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/resources/assets/volubind/owo_ui/toggle_volume_screen.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<owo-ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/wisp-forest/owo-lib/1.21/owo-ui.xsd"> | ||
<components> | ||
<flow-layout direction="vertical" id="toggle-volume-container"> | ||
<children> | ||
<flow-layout direction="horizontal" id="toggle-volume-title-bar"> | ||
<children> | ||
<label> | ||
<text translate="true">volubind.screen.toggle_volume.title</text> | ||
<margins> | ||
<vertical>10</vertical> | ||
</margins> | ||
</label> | ||
</children> | ||
<vertical-alignment>center</vertical-alignment> | ||
<horizontal-alignment>left</horizontal-alignment> | ||
</flow-layout> | ||
</children> | ||
<vertical-alignment>center</vertical-alignment> | ||
<horizontal-alignment>center</horizontal-alignment> | ||
<surface> | ||
<options-background/> | ||
</surface> | ||
</flow-layout> | ||
</components> | ||
</owo-ui> |