forked from BVengo/sound-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllSoundOptionsScreen.java
More file actions
150 lines (122 loc) · 5.32 KB
/
AllSoundOptionsScreen.java
File metadata and controls
150 lines (122 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.bvengo.soundcontroller.gui;
import com.bvengo.soundcontroller.config.VolumeConfig;
import com.bvengo.soundcontroller.gui.buttons.ToggleButtonWidget;
import net.minecraft.client.Options;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.options.OptionsSubScreen;
import net.minecraft.network.chat.CommonComponents;
import java.util.Comparator;
import static com.bvengo.soundcontroller.Translations.SOUND_SCREEN_TITLE;
import static com.bvengo.soundcontroller.Translations.SEARCH_FIELD_TITLE;
import static com.bvengo.soundcontroller.Translations.SEARCH_FIELD_PLACEHOLDER;
import static com.bvengo.soundcontroller.Translations.FILTER_BUTTON_TOOLTIP;
import static com.bvengo.soundcontroller.Translations.SUBTITLES_BUTTON_TOOLTIP;
/**
* Screen that displays all sound options.
*/
public class AllSoundOptionsScreen extends OptionsSubScreen {
VolumeConfig config = VolumeConfig.getInstance();
protected final Screen parent;
private VolumeListWidget volumeListWidget;
private EditBox searchField;
private ToggleButtonWidget filterButton;
private ToggleButtonWidget subtitlesButton;
private boolean showModifiedOnly = false;
public AllSoundOptionsScreen(Screen parent, Options options) {
super(parent, options, SOUND_SCREEN_TITLE);
this.parent = parent;
// Increase header height to make room for search field. Includes 8 extra padding below.
layout.setHeaderHeight(layout.getHeaderHeight() + 28);
}
@Override
protected void init() {
addSearchField();
addFilterButton();
addSubtitlesButton();
addVolumeList();
addDoneButton();
this.setInitialFocus(this.searchField);
}
@Override
protected void addOptions() {}
private void addSearchField() {
// Add search field - x, y, width, height
this.searchField = new EditBox(this.font, 80, 35, this.width - 167, 20,
SEARCH_FIELD_PLACEHOLDER);
this.searchField.setResponder(serverName -> this.loadOptions());
this.addWidget(this.searchField);
}
private void addFilterButton() {
// Add filter button - x, y, width, height, textures, pressAction
this.filterButton = new ToggleButtonWidget("filter",
this.searchField.getRight() + 8, 35, 20, 20,
(button) -> {
showModifiedOnly = !showModifiedOnly;
loadOptions();
},
false
);
this.filterButton.setTooltip(Tooltip.create(FILTER_BUTTON_TOOLTIP));
this.addRenderableWidget(this.filterButton);
}
private void addSubtitlesButton() {
// Add subtitles button - x, y, width, height, textures, pressAction
this.subtitlesButton = new ToggleButtonWidget("subtitles",
this.filterButton.getRight() + 4, 35, 20, 20,
(button) -> {
config.toggleSubtitles();
},
config.areSubtitlesEnabled());
this.subtitlesButton.setTooltip(Tooltip.create(SUBTITLES_BUTTON_TOOLTIP));
this.addRenderableWidget(this.subtitlesButton);
}
private void addVolumeList() {
this.volumeListWidget = new VolumeListWidget(this.minecraft, this.width, this.searchField.getBottom() + 32, this);
loadOptions();
this.addRenderableWidget(this.volumeListWidget);
}
private void addDoneButton() {
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, button -> this.onClose())
.bounds(this.width / 2 - 100, this.height - 27, 200, 20).build());
}
private void loadOptions() {
this.volumeListWidget.clearEntries();
this.volumeListWidget.setScrollAmount(0);
String search = this.searchField.getValue().toLowerCase();
// Update all buttons
config.getVolumes().values().stream()
.filter(volumeData -> volumeData.inFilter(search, showModifiedOnly))
.sorted(Comparator.comparing(v -> v.getId().toString()))
.forEach(volumeData -> {
VolumeWidgetEntry volumeEntry = new VolumeWidgetEntry(volumeData, this, this.options);
this.volumeListWidget.addWidgetEntry(volumeEntry);
});
}
@Override
public void removed() {
config.save();
this.searchField.setValue(""); // Clear search field
}
@Override
public void resize(int width, int height) {
// Cache search before clearing
String search = this.searchField.getValue();
this.width = width;
this.height = height;
this.clearWidgets();
this.clearFocus();
this.init();
this.searchField.setValue(search);
}
@Override
public void extractRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) {
super.extractRenderState(context, mouseX, mouseY, delta);
context.centeredText(this.font, this.title, this.width / 2, 20, 0xFFFFFF);
context.text(this.font, SEARCH_FIELD_TITLE, 32, 40, 0xA0A0A0);
this.searchField.extractRenderState(context, mouseX, mouseY, delta);
}
}