forked from VazkiiMods/Botania
-
Notifications
You must be signed in to change notification settings - Fork 45
Added Saveable Schematics for the Ring of Loki #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ReignOfFROZE
wants to merge
28
commits into
GTNewHorizons:master
Choose a base branch
from
ReignOfFROZE:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
79be44e
Added loki config switching
ReignOfFROZE f601f77
Remove CT dep
ReignOfFROZE fc21641
Made ModularUI an optional dependency
ReignOfFROZE 8c6fb51
Update to MUI2
ReignOfFROZE ff38e8e
Remove unused files
ReignOfFROZE da5cbb6
not sure why the pencil was big
ReignOfFROZE 3620cf9
Added new icons and adjusted GUI scale
ReignOfFROZE 2b59c48
Adjust header text scale
ReignOfFROZE 3bcfb45
Remove useless annotation
ReignOfFROZE 29fe5f0
Organize imports
ReignOfFROZE 055aa62
Added a little bit of polish
ReignOfFROZE dcfa71c
Remove runtime dependency on MUI2
ReignOfFROZE a3d8aa9
Merge upstream/master to master
ReignOfFROZE 82771d4
Don't use wildcard imports
glowredman ba99165
Added packet for renaming and check if the ring is null before trying…
ReignOfFROZE 3aaf74a
Cleanup pass
YannickMG a6445da
Fix deleting schematics leaving holes
YannickMG 46c88f4
Replace Baubles with Baubles Expanded (#81)
Caedis 070e6a7
update
Dream-Master 7ad708e
Add configurable F3 Debug (#78)
brandyyn 83512d4
update
serenibyss c8fe3c8
update
Dream-Master 7fd1bcb
update
Dream-Master 5325153
Add missing equals sign (#83)
Nikolay-Sitnikov 4bbb0e9
Fix the rest of the lang file mistakes in Botania (#84)
Nikolay-Sitnikov 04345bb
Rebase & comments pt 1
ReignOfFROZE 294abf4
Merge branch 'master' into master
Dream-Master 0fda050
Merge branch 'master' into master
Dream-Master File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
146 changes: 146 additions & 0 deletions
146
src/main/java/vazkii/botania/client/gui/loki/GuiLokiSchematics.java
YannickMG marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,146 @@ | ||
package vazkii.botania.client.gui.loki; | ||
|
||
import com.cleanroommc.modularui.api.drawable.IKey; | ||
import com.cleanroommc.modularui.drawable.Rectangle; | ||
import com.cleanroommc.modularui.factory.ClientGUI; | ||
import com.cleanroommc.modularui.screen.ModularPanel; | ||
import com.cleanroommc.modularui.screen.ModularScreen; | ||
import com.cleanroommc.modularui.screen.RichTooltip; | ||
import com.cleanroommc.modularui.utils.Alignment; | ||
import com.cleanroommc.modularui.utils.Color; | ||
import com.cleanroommc.modularui.widget.ParentWidget; | ||
import com.cleanroommc.modularui.widget.ScrollWidget; | ||
import com.cleanroommc.modularui.widget.scroll.ScrollArea; | ||
import com.cleanroommc.modularui.widget.scroll.VerticalScrollData; | ||
import com.cleanroommc.modularui.widgets.ButtonWidget; | ||
import com.cleanroommc.modularui.widgets.TextWidget; | ||
import com.cleanroommc.modularui.widgets.layout.Flow; | ||
import com.cleanroommc.modularui.widgets.layout.Row; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.StatCollector; | ||
import vazkii.botania.client.gui.mui2.Textures; | ||
import vazkii.botania.common.item.relic.ItemLokiRing; | ||
import vazkii.botania.common.network.PacketHandler; | ||
import vazkii.botania.common.network.PacketLokiChangeSchematic; | ||
import vazkii.botania.common.network.PacketLokiDeleteSchematic; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class GuiLokiSchematics { | ||
|
||
private static final int WINDOW_WIDTH = 350, WINDOW_HEIGHT = 225, SCROLL_AREA_WIDTH = 350, SCROLL_AREA_HEIGHT = 200, SAVED_SCHEMATICS_HEADER_HEIGHT = 25, X_PADDING = 5, Y_PADDING = 5; | ||
private ArrayList<String> schematicNames; | ||
|
||
public static void open(ItemStack ring) { | ||
ClientGUI.open(new ModularScreen(new GuiLokiSchematics().buildUI(ring))); | ||
} | ||
|
||
private String selectedSchematic; | ||
|
||
private GuiLokiSchematics() { | ||
} | ||
|
||
public ModularPanel buildUI(ItemStack itemStack) { | ||
if (! ItemLokiRing.isLokiRing(itemStack)) { | ||
return null; | ||
} | ||
|
||
selectedSchematic = ItemLokiRing.getSelectedSchematic(itemStack); | ||
schematicNames = new ArrayList<>(ItemLokiRing.getSchematicNames(itemStack)); | ||
|
||
final ScrollWidget<?> scrollWidget = new ScrollWidget<>(new VerticalScrollData()); | ||
setScrollArea(scrollWidget.getScrollArea()); | ||
for (int i = 0; i < schematicNames.size(); i++) { | ||
// Final value that can be captured by lambdas | ||
final int rowId = i; | ||
Flow row = new Row(); | ||
row.sizeRel(1f, 0.2f) | ||
.pos(0, rowId * (SCROLL_AREA_HEIGHT / 5 + 1)) | ||
.padding(5, 0, 5, 5) | ||
.setEnabledIf((w) -> rowId < schematicNames.size()) | ||
.background(new Rectangle() | ||
.setColor(i % 2 == 0 ? Color.ORANGE.brighter(3) : Color.ORANGE.brighter(2))) | ||
.child( | ||
new TextWidget(IKey.dynamic(()-> rowId < schematicNames.size() ? schematicNames.get(rowId) : "")) | ||
.widthRel(0.72f)) | ||
.child( | ||
new ParentWidget<>() | ||
.tooltip(new RichTooltip() | ||
.add("Activate Schematic")) | ||
.widthRel(0.083f) | ||
.heightRel(1f) | ||
.setEnabledIf((w) -> rowId < schematicNames.size() && !schematicNames.get(rowId).equals(selectedSchematic)) | ||
.child( | ||
new ButtonWidget<>() | ||
.onMousePressed(ignored -> { | ||
String key = schematicNames.get(rowId); | ||
PacketHandler.INSTANCE.sendToServer(new PacketLokiChangeSchematic(key)); | ||
selectedSchematic = key; | ||
return true; | ||
}) | ||
.background(Textures.CHECK_ICON) | ||
.hoverBackground(Textures.CHECK_ICON) | ||
.size(20, 20) | ||
.center())) | ||
.child( | ||
new ParentWidget<>() | ||
.widthRel(0.083f) | ||
.heightRel(1f) | ||
.child( | ||
new ButtonWidget<>() | ||
.tooltip(new RichTooltip() | ||
.add("Rename Schematic")) | ||
.onMousePressed(ignored -> { | ||
ClientGUI.open(new RenameGui(schematicNames.get(rowId))); | ||
return true; | ||
}) | ||
.background(Textures.RENAME_ICON) | ||
.hoverBackground(Textures.RENAME_ICON) | ||
.size(20, 20) | ||
.center())) | ||
.child( | ||
new ParentWidget<>() | ||
.widthRel(0.083f) | ||
.heightRel(1f) | ||
.child( | ||
new ButtonWidget<>() | ||
.tooltip(new RichTooltip() | ||
.add("Delete Schematic")) | ||
.onMousePressed(ignored -> { | ||
String key = schematicNames.get(rowId); | ||
PacketHandler.INSTANCE.sendToServer(new PacketLokiDeleteSchematic(key)); | ||
schematicNames.remove(rowId); | ||
setScrollArea(scrollWidget.getScrollArea()); | ||
if(key.equals(selectedSchematic)) | ||
selectedSchematic = null; | ||
return true; | ||
}) | ||
.background(Textures.DELETE_ICON) | ||
.hoverBackground(Textures.DELETE_ICON) | ||
.size(20, 20) | ||
.center())); | ||
scrollWidget.child( | ||
row); | ||
} | ||
|
||
return ModularPanel.defaultPanel("lokiSchematics") | ||
.child( | ||
new TextWidget(IKey.dynamic(() -> selectedSchematic == null ? StatCollector.translateToLocal("botaniamisc.select_schematic") : StatCollector.translateToLocal("botaniamisc.selected_schematic") + " " + selectedSchematic)) | ||
.align(Alignment.TopCenter) | ||
.marginTop(8) | ||
.scale(0.5f)) | ||
.child( | ||
scrollWidget | ||
.pos(10, 20) | ||
.widthRel(SCROLL_AREA_WIDTH - 20) | ||
.margin(10, 0) | ||
.height(SCROLL_AREA_HEIGHT - 10)) | ||
.background(Textures.BACKGROUND_TEXTURE) | ||
.size(WINDOW_WIDTH, WINDOW_HEIGHT); | ||
} | ||
|
||
private void setScrollArea(ScrollArea scrollWidget) { | ||
scrollWidget.getScrollY().setScrollSize(schematicNames.size() * (SCROLL_AREA_HEIGHT / 5 + 1)); | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/vazkii/botania/client/gui/loki/RenameGui.java
This file contains hidden or 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,80 @@ | ||
package vazkii.botania.client.gui.loki; | ||
|
||
import com.cleanroommc.modularui.api.value.IStringValue; | ||
import com.cleanroommc.modularui.screen.CustomModularScreen; | ||
import com.cleanroommc.modularui.screen.ModularPanel; | ||
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; | ||
import com.cleanroommc.modularui.value.sync.InteractionSyncHandler; | ||
import com.cleanroommc.modularui.widgets.TextWidget; | ||
import com.cleanroommc.modularui.widgets.textfield.TextFieldWidget; | ||
import vazkii.botania.client.gui.mui2.Textures; | ||
import vazkii.botania.common.network.PacketHandler; | ||
import vazkii.botania.common.network.PacketLokiRenameSchematic; | ||
|
||
class RenameGui extends CustomModularScreen { | ||
|
||
private final String schematicToBeRenamed; | ||
|
||
public RenameGui(String schematicToBeRenamed) { | ||
this.schematicToBeRenamed = schematicToBeRenamed; | ||
} | ||
|
||
private String newValue = ""; | ||
|
||
@Override | ||
public void close() { | ||
close(false); | ||
} | ||
|
||
@Override | ||
public void close(boolean force) { | ||
super.close(force); | ||
this.persist(); | ||
} | ||
|
||
public void persist() { | ||
PacketHandler.INSTANCE.sendToServer(new PacketLokiRenameSchematic(schematicToBeRenamed, newValue)); | ||
} | ||
|
||
@Override | ||
public ModularPanel buildUI(ModularGuiContext context) { | ||
|
||
InteractionSyncHandler handler = new InteractionSyncHandler(); | ||
|
||
handler.setOnKeyPressed((key) -> { | ||
System.out.println(key.character); | ||
}); | ||
|
||
return ModularPanel.defaultPanel("rename") | ||
.child(new TextWidget("Schematic Name:") | ||
.pos(10, 10) | ||
.size(180, 20)) | ||
.child(new TextFieldWidget() | ||
.value(new IStringValue<String>() { | ||
@Override | ||
public String getStringValue() { | ||
return newValue; | ||
} | ||
|
||
@Override | ||
public void setStringValue(String val) { | ||
newValue = val; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return newValue; | ||
} | ||
|
||
@Override | ||
public void setValue(String value) { | ||
newValue = value; | ||
} | ||
}) | ||
.disableHoverBackground() | ||
.size(150, 20) | ||
.pos(25, 40)) | ||
.background(Textures.BACKGROUND_TEXTURE) | ||
.size(200, 100); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/vazkii/botania/client/gui/mui2/Textures.java
This file contains hidden or 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,28 @@ | ||
package vazkii.botania.client.gui.mui2; | ||
|
||
import com.cleanroommc.modularui.drawable.AdaptableUITexture; | ||
import com.cleanroommc.modularui.drawable.UITexture; | ||
|
||
public class Textures { | ||
public static final UITexture BACKGROUND_TEXTURE = AdaptableUITexture | ||
.builder() | ||
.location("botania:textures/gui/croppedPaper") | ||
.imageSize(330, 252) | ||
.adaptable(12) | ||
.build(); | ||
public static final UITexture CHECK_ICON = UITexture | ||
.builder() | ||
.location("botania:textures/gui/check") | ||
.imageSize(20, 20) | ||
.build(); | ||
public static final UITexture DELETE_ICON = UITexture | ||
.builder() | ||
.location("botania:textures/gui/delete") | ||
.imageSize(20, 20) | ||
.build(); | ||
public static final UITexture RENAME_ICON = UITexture | ||
.builder() | ||
.location("botania:textures/gui/rename") | ||
.imageSize(20, 20) | ||
.build(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.