|
24 | 24 | package io.github.opencubicchunks.cubicchunks.cubicgen.common.gui; |
25 | 25 |
|
26 | 26 | import com.google.common.base.Converter; |
27 | | -import com.google.common.eventbus.Subscribe; |
28 | 27 | import io.github.opencubicchunks.cubicchunks.cubicgen.CustomCubicMod; |
29 | | -import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UICheckboxNoAutoSize; |
30 | 28 | import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UIRangeSlider; |
31 | | -import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UISliderImproved; |
32 | | -import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.component.UISplitLayout; |
33 | 29 | import io.github.opencubicchunks.cubicchunks.cubicgen.common.gui.converter.Converters; |
34 | | -import net.malisis.core.client.gui.Anchor; |
35 | 30 | import net.malisis.core.client.gui.MalisisGui; |
36 | | -import net.malisis.core.client.gui.component.UIComponent; |
37 | | -import net.malisis.core.client.gui.component.container.UIContainer; |
38 | | -import net.malisis.core.client.gui.component.decoration.UILabel; |
39 | | -import net.malisis.core.client.gui.component.interaction.UICheckBox; |
40 | 31 | import net.malisis.core.client.gui.component.interaction.UISelect; |
41 | | -import net.malisis.core.client.gui.component.interaction.UISlider; |
42 | | -import net.malisis.core.client.gui.component.interaction.UITextField; |
43 | | -import net.malisis.core.client.gui.event.ComponentEvent; |
44 | | -import net.malisis.core.renderer.font.FontOptions; |
45 | 32 | import net.minecraft.client.resources.I18n; |
46 | 33 | import net.minecraft.util.math.MathHelper; |
47 | 34 | import net.minecraft.world.biome.Biome; |
|
55 | 42 | import java.util.function.BiFunction; |
56 | 43 | import java.util.function.BiPredicate; |
57 | 44 | import java.util.function.DoubleSupplier; |
58 | | -import java.util.function.Function; |
59 | | - |
60 | | -import static java.lang.Math.round; |
61 | 45 |
|
62 | 46 | public class MalisisGuiUtils { |
63 | 47 |
|
@@ -132,123 +116,6 @@ public static UISelect<BiomeOption> makeBiomeList(MalisisGui gui, int selectedId |
132 | 116 | return select; |
133 | 117 | } |
134 | 118 |
|
135 | | - public static UIComponent<?> label(MalisisGui gui, String text) { |
136 | | - return wrappedCentered( |
137 | | - gui, new UILabel(gui, text) |
138 | | - .setFontOptions(FontOptions.builder().color(0xFFFFFF).shadow().build()) |
139 | | - ).setSize(0, 15); |
140 | | - } |
141 | | - |
142 | | - // textInput as argument so that it's easy to access it later |
143 | | - // otherwise, to access the value of the text field, it would be necessary to get it out of implementation-specific contaier |
144 | | - public static UIComponent<?> floatInput(ExtraGui gui, String text, UITextField textField, float defaultValue) { |
145 | | - |
146 | | - try { |
147 | | - Function<String, String> filter = newStr -> { |
148 | | - try { |
149 | | - Float.parseFloat(newStr); |
150 | | - return newStr; |
151 | | - } catch (NumberFormatException e1) { |
152 | | - // bug in 6.5.1 where the old text is actually the new text |
153 | | - String str = textField.getText(); |
154 | | - try { |
155 | | - Float.parseFloat(newStr); |
156 | | - return str; // return old text |
157 | | - } catch (NumberFormatException e2) { |
158 | | - // this is ugly... |
159 | | - |
160 | | - // first, is it empty or a single character that doesn't parse? |
161 | | - if (str.length() <= 1) { |
162 | | - return ""; |
163 | | - } |
164 | | - // this should cover all the "user is typing" cases |
165 | | - int length = str.length(); |
166 | | - // iterate end-to-beginning and check if after removing that character, it becomes a valid number |
167 | | - for (int i = length - 1; i >= 0; i--) { |
168 | | - String sub = str.substring(0, i) + str.substring(i + 1); |
169 | | - try { |
170 | | - Float.parseFloat(sub); |
171 | | - return sub; |
172 | | - } catch (NumberFormatException e3) { |
173 | | - } |
174 | | - } |
175 | | - // uh... we still didn't return? |
176 | | - // I don't know what could trigger this, but this is the way we will try to handle it: |
177 | | - // iterate over the characters and remove everything we don't want. |
178 | | - // * up until the dot, remove everything non-digit |
179 | | - // * except 'e' if it's second or later character, then assume there was no dot, and after that, that we are past 'e' |
180 | | - // * if there was no dot, or we are past the dot, remove everything non-digit except 'e' |
181 | | - // * after an 'e', remove everything non-digit |
182 | | - // If it *still* doesn't parse, give up and return empty string |
183 | | - StringBuilder newsb = new StringBuilder(str.length()); |
184 | | - boolean seenFirstDigit = false; |
185 | | - boolean seenDot = false; |
186 | | - boolean seenE = false; |
187 | | - for (char ch : str.toCharArray()) { |
188 | | - if (ch >= '0' && ch <= '9') { |
189 | | - newsb.append(ch); |
190 | | - seenFirstDigit = true; |
191 | | - } else if (ch == 'e' || ch == 'E') { |
192 | | - if (!seenE && seenFirstDigit) { |
193 | | - newsb.append(ch); |
194 | | - seenE = true; |
195 | | - seenDot = true; |
196 | | - } |
197 | | - } else if (ch == '.') { |
198 | | - if (!seenDot) { |
199 | | - newsb.append(ch); |
200 | | - seenDot = true; |
201 | | - } |
202 | | - } |
203 | | - } |
204 | | - str = newsb.toString(); |
205 | | - try { |
206 | | - Float.parseFloat(str); |
207 | | - return str; |
208 | | - } catch (NumberFormatException e3) { |
209 | | - return ""; |
210 | | - } |
211 | | - } |
212 | | - } |
213 | | - }; |
214 | | - textField.setFilter(filter); |
215 | | - // another (imperfect) hack because filter isn't applied when remoing characters |
216 | | - textField.register(new Object() { |
217 | | - @Subscribe |
218 | | - public void onValueChange(ComponentEvent.ValueChange<UITextField, String> change) { |
219 | | - String newText = filter.apply(change.getNewValue()); |
220 | | - if (!newText.equals(change.getNewValue())) { |
221 | | - textField.setText(newText); |
222 | | - } |
223 | | - } |
224 | | - }); |
225 | | - } catch (Throwable t) { |
226 | | - throw new RuntimeException(t); |
227 | | - } |
228 | | - |
229 | | - textField.setEditable(true); |
230 | | - textField.setText(String.format("%.1f", defaultValue)); |
231 | | - textField.setFontOptions(FontOptions.builder().color(0xFFFFFF).build()); |
232 | | - UIComponent<?> label = wrappedMiddle(gui, new UILabel(gui, text).setFontOptions(FontOptions.builder().color(0xFFFFFF).build())); |
233 | | - UISplitLayout<?> split = new UISplitLayout<>(gui, UISplitLayout.Type.SIDE_BY_SIDE, label, textField); |
234 | | - split.setSizeOf(UISplitLayout.Pos.SECOND, 40); |
235 | | - split.autoFitToContent(true); |
236 | | - return split; |
237 | | - } |
238 | | - public static UIContainer<?> wrappedCentered(MalisisGui gui, UIComponent<?> comp) { |
239 | | - comp.setAnchor(Anchor.MIDDLE | Anchor.CENTER); |
240 | | - UIContainer<?> cont = new UIContainer<>(gui); |
241 | | - cont.add(comp); |
242 | | - return cont; |
243 | | - } |
244 | | - |
245 | | - public static UIContainer<?> wrappedMiddle(MalisisGui gui, UIComponent<?> comp) { |
246 | | - comp.setAnchor(Anchor.MIDDLE); |
247 | | - UIContainer<?> cont = new UIContainer<>(gui); |
248 | | - cont.add(comp); |
249 | | - return cont; |
250 | | - } |
251 | | - |
252 | 119 | public static String vanillaText(String name) { |
253 | 120 | String unloc = CustomCubicMod.MODID + ".gui.cubicgen." + name; |
254 | 121 | return unloc; |
|
0 commit comments