-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Showing
18 changed files
with
523 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
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
44 changes: 44 additions & 0 deletions
44
...main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigEntriesListWidget.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,44 @@ | ||
/* | ||
* This file is licensed under the MIT License, part of Roughly Enough Items. | ||
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package me.shedaniel.rei.impl.client.gui.config.components; | ||
|
||
import me.shedaniel.math.Rectangle; | ||
import me.shedaniel.rei.api.client.gui.widgets.Widget; | ||
import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; | ||
import me.shedaniel.rei.impl.client.gui.config.options.OptionGroup; | ||
import me.shedaniel.rei.impl.client.gui.widget.ListWidget; | ||
import me.shedaniel.rei.impl.client.gui.widget.ScrollableViewWidget; | ||
import me.shedaniel.rei.impl.common.util.RectangleUtils; | ||
|
||
import java.util.List; | ||
|
||
public class ConfigEntriesListWidget { | ||
public static Widget create(Rectangle bounds, List<OptionGroup> groups) { | ||
WidgetWithBounds list = ListWidget.builderOf(RectangleUtils.inset(bounds, 6, 6), groups, | ||
(index, entry) -> ConfigGroupWidget.create(entry, bounds.width - 12 - 6)) | ||
.gap(7) | ||
.build(); | ||
return ScrollableViewWidget.create(bounds, list.withPadding(0, 5), true); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...e/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.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,67 @@ | ||
/* | ||
* This file is licensed under the MIT License, part of Roughly Enough Items. | ||
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package me.shedaniel.rei.impl.client.gui.config.components; | ||
|
||
import me.shedaniel.math.Point; | ||
import me.shedaniel.math.Rectangle; | ||
import me.shedaniel.rei.api.client.gui.widgets.Widget; | ||
import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; | ||
import me.shedaniel.rei.api.client.gui.widgets.Widgets; | ||
import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption; | ||
import me.shedaniel.rei.impl.client.gui.config.options.OptionGroup; | ||
import net.minecraft.client.gui.GuiComponent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ConfigGroupWidget { | ||
public static WidgetWithBounds create(OptionGroup entry, int width) { | ||
List<Widget> widgets = new ArrayList<>(); | ||
int height = 0; | ||
WidgetWithBounds groupTitle = Widgets.createLabel(new Point(0, 3), entry.getGroupName().copy().withStyle(style -> style.withColor(0xFFC0C0C0).withUnderlined(true))) | ||
.leftAligned(); | ||
groupTitle = groupTitle.withPadding(0, 0, 0, 6); | ||
widgets.add(groupTitle); | ||
height = Math.max(height, groupTitle.getBounds().getMaxY()); | ||
|
||
for (CompositeOption<?> option : entry.getOptions()) { | ||
WidgetWithBounds widget = ConfigOptionWidget.create(option, width); | ||
widgets.add(Widgets.withTranslate(widget, 0, height, 0)); | ||
height = Math.max(height, height + widget.getBounds().getMaxY()); | ||
|
||
if (entry.getOptions().get(entry.getOptions().size() - 1) != option) { | ||
int y = height; | ||
widgets.add(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { | ||
for (int x = 0; x <= width; x += 4) { | ||
GuiComponent.fill(matrices, x, y + 1, x + 2, y + 2, 0xFF757575); | ||
} | ||
})); | ||
height += 7; | ||
} | ||
} | ||
|
||
Rectangle bounds = new Rectangle(0, 0, width, height); | ||
return Widgets.concatWithBounds(bounds, widgets); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionValueWidget.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,94 @@ | ||
/* | ||
* This file is licensed under the MIT License, part of Roughly Enough Items. | ||
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package me.shedaniel.rei.impl.client.gui.config.components; | ||
|
||
import com.mojang.math.Matrix4f; | ||
import me.shedaniel.math.Point; | ||
import me.shedaniel.math.Rectangle; | ||
import me.shedaniel.rei.api.client.gui.widgets.Label; | ||
import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; | ||
import me.shedaniel.rei.api.client.gui.widgets.Widgets; | ||
import me.shedaniel.rei.api.client.util.MatrixUtils; | ||
import me.shedaniel.rei.api.common.util.CollectionUtils; | ||
import me.shedaniel.rei.impl.client.gui.config.REIConfigScreen; | ||
import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption; | ||
import me.shedaniel.rei.impl.client.gui.config.options.OptionValueEntry; | ||
import me.shedaniel.rei.impl.client.gui.modules.Menu; | ||
import me.shedaniel.rei.impl.client.gui.modules.entries.ToggleMenuEntry; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.Map; | ||
|
||
import static me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils.literal; | ||
|
||
public class ConfigOptionValueWidget { | ||
public static <T> WidgetWithBounds create(CompositeOption<T> option) { | ||
Map<CompositeOption<?>, ?> options = ((REIConfigScreen) Minecraft.getInstance().screen).getOptions(); | ||
OptionValueEntry<T> entry = option.getEntry(); | ||
T value = (T) options.get(option); | ||
Component text; | ||
|
||
if (entry instanceof OptionValueEntry.Selection<T> selection) { | ||
text = selection.getOption(value); | ||
} else { | ||
text = literal(value.toString()); | ||
} | ||
|
||
Label label = Widgets.createLabel(new Point(), text).rightAligned() | ||
.color(0xFFE0E0E0) | ||
.hoveredColor(0xFFE0E0E0); | ||
Matrix4f[] matrix = {new Matrix4f()}; | ||
|
||
if (entry instanceof OptionValueEntry.Selection<T> selection) { | ||
int noOfOptions = selection.getOptions().size(); | ||
if (noOfOptions == 2) { | ||
label.clickable().onClick($ -> { | ||
((Map<CompositeOption<?>, Object>) options).put(option, selection.getOptions().get((selection.getOptions().indexOf((T) options.get(option)) + 1) % 2)); | ||
label.setMessage(selection.getOption((T) options.get(option))); | ||
}); | ||
} else if (noOfOptions >= 2) { | ||
label.clickable().onClick($ -> { | ||
Menu menu = new Menu(MatrixUtils.transform(matrix[0], label.getBounds()), CollectionUtils.map(selection.getOptions(), | ||
opt -> ToggleMenuEntry.of(selection.getOption(opt), () -> false, o -> { | ||
((REIConfigScreen) Minecraft.getInstance().screen).closeMenu(); | ||
((Map<CompositeOption<?>, Object>) options).put(option, opt); | ||
label.setMessage(selection.getOption(opt)); | ||
}) | ||
.withActive(() -> true)), false); | ||
((REIConfigScreen) Minecraft.getInstance().screen).closeMenu(); | ||
((REIConfigScreen) Minecraft.getInstance().screen).openMenu(menu); | ||
}); | ||
} | ||
} | ||
|
||
return Widgets.concatWithBounds(() -> new Rectangle(-label.getBounds().width, 0, label.getBounds().width + 8, 14), | ||
label, | ||
Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> matrix[0] = matrices.last().pose()), | ||
Widgets.withTranslate(Widgets.createTexturedWidget(new ResourceLocation("roughlyenoughitems:textures/gui/config/selector.png"), | ||
new Rectangle(1, 1, 4, 6), 0, 0, 1, 1, 1, 1), 0, 0.5, 0) | ||
); | ||
} | ||
} |
Oops, something went wrong.