forked from VazkiiMods/Botania
-
Notifications
You must be signed in to change notification settings - Fork 44
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 15 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
243 changes: 243 additions & 0 deletions
243
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,243 @@ | ||
package vazkii.botania.client.gui.loki; | ||
|
||
import com.cleanroommc.modularui.api.drawable.IKey; | ||
import com.cleanroommc.modularui.api.value.IStringValue; | ||
import com.cleanroommc.modularui.drawable.AdaptableUITexture; | ||
import com.cleanroommc.modularui.drawable.Rectangle; | ||
import com.cleanroommc.modularui.drawable.UITexture; | ||
import com.cleanroommc.modularui.factory.ClientGUI; | ||
import com.cleanroommc.modularui.screen.CustomModularScreen; | ||
import com.cleanroommc.modularui.screen.ModularPanel; | ||
import com.cleanroommc.modularui.screen.RichTooltip; | ||
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; | ||
import com.cleanroommc.modularui.utils.Alignment; | ||
import com.cleanroommc.modularui.utils.Color; | ||
import com.cleanroommc.modularui.value.sync.InteractionSyncHandler; | ||
import com.cleanroommc.modularui.widget.ParentWidget; | ||
import com.cleanroommc.modularui.widget.ScrollWidget; | ||
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.Row; | ||
import com.cleanroommc.modularui.widgets.textfield.TextFieldWidget; | ||
import cpw.mods.fml.common.Optional; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTBase; | ||
import net.minecraft.util.EnumChatFormatting; | ||
import net.minecraft.util.StatCollector; | ||
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 vazkii.botania.common.network.PacketLokiRenameSchematic; | ||
|
||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class GuiLokiSchematics extends CustomModularScreen { | ||
glowredman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static void open(ItemStack ring) { | ||
GuiLokiSchematics.itemStack = ring; | ||
ClientGUI.open(new GuiLokiSchematics(ring)); | ||
} | ||
|
||
public static ItemStack itemStack; | ||
|
||
public GuiLokiSchematics(ItemStack itemStack) { | ||
this.itemStack = itemStack; | ||
} | ||
|
||
private static Object selectedSchematic; | ||
|
||
private static Object schematicToBeRenamed; | ||
|
||
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; | ||
|
||
@Override | ||
@Optional.Method(modid = "modularui2") | ||
public ModularPanel buildUI(ModularGuiContext context) { | ||
|
||
final UITexture backgroundTexture = AdaptableUITexture | ||
.builder() | ||
.location("botania:textures/gui/croppedPaper") | ||
.imageSize(330, 252) | ||
.adaptable(12) | ||
.build(); | ||
final UITexture checkIcon = UITexture | ||
.builder() | ||
.location("botania:textures/gui/check") | ||
.imageSize(20, 20) | ||
.build(); | ||
final UITexture deleteIcon = UITexture | ||
.builder() | ||
.location("botania:textures/gui/delete") | ||
.imageSize(20, 20) | ||
.build(); | ||
final UITexture renameIcon = UITexture | ||
.builder() | ||
.location("botania:textures/gui/rename") | ||
.imageSize(20, 20) | ||
.build(); | ||
|
||
selectedSchematic = itemStack.getTagCompound().getString(ItemLokiRing.TAG_CURRENT_SCHEMATIC); | ||
|
||
ItemLokiRing ring = (ItemLokiRing) itemStack.getItem(); | ||
ring.schematicNames = Arrays.asList(itemStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).tagMap.keySet().stream().sorted(Comparator.comparing(Object::toString)).toArray()); | ||
|
||
Set<Object> deleted = new HashSet<>(); | ||
|
||
final ScrollWidget<?> scrollWidget = new ScrollWidget<>(new VerticalScrollData()); | ||
scrollWidget.getScrollArea().getScrollY().setScrollSize(ring.schematicNames.size() * (SCROLL_AREA_HEIGHT / 5 + 1)); | ||
int idx = 0; | ||
for(Object key : itemStack.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).tagMap.keySet()) { | ||
scrollWidget.child( | ||
new Row() | ||
.sizeRel(1f, 0.2f) | ||
.pos(0, ring.schematicNames.indexOf(key) * (SCROLL_AREA_HEIGHT / 5 + 1)) | ||
.padding(5, 0, 5, 5) | ||
.setEnabledIf((w) -> !deleted.contains(key)) | ||
.background(new Rectangle() | ||
.setColor(idx % 2 == 0 ? Color.ORANGE.brighter(3) : Color.ORANGE.brighter(2))) | ||
.child( | ||
new TextWidget(key.toString()) | ||
.widthRel(0.72f)) | ||
.child( | ||
new ParentWidget<>() | ||
.tooltip(new RichTooltip(new TextWidget("Activate Schematic"))) | ||
.widthRel(0.083f) | ||
.heightRel(1f) | ||
.setEnabledIf((w) -> !key.equals(selectedSchematic)) | ||
.child( | ||
new ButtonWidget<>() | ||
.onMousePressed(ignored -> { | ||
PacketHandler.INSTANCE.sendToServer(new PacketLokiChangeSchematic(key.toString())); | ||
selectedSchematic = key; | ||
return true; | ||
}) | ||
.background(checkIcon) | ||
.hoverBackground(checkIcon) | ||
.size(20,20) | ||
.center())) | ||
.child( | ||
new ParentWidget<>() | ||
.widthRel(0.083f) | ||
.heightRel(1f) | ||
.child( | ||
new ButtonWidget<>() | ||
.tooltip(new RichTooltip(new TextWidget("Rename Schematic"))) | ||
.onMousePressed(ignored -> { | ||
this.schematicToBeRenamed = key; | ||
ClientGUI.open(new RenameGui()); | ||
return true; | ||
}) | ||
.background(renameIcon) | ||
.hoverBackground(renameIcon) | ||
.size(20, 20) | ||
.center())) | ||
.child( | ||
new ParentWidget<>() | ||
.widthRel(0.083f) | ||
.heightRel(1f) | ||
.child( | ||
new ButtonWidget<>() | ||
.tooltip(new RichTooltip(new TextWidget("Delete Schematic"))) | ||
.onMousePressed(ignored -> { | ||
PacketHandler.INSTANCE.sendToServer(new PacketLokiDeleteSchematic(key.toString())); | ||
deleted.add(key); | ||
if(key.equals(selectedSchematic)) | ||
selectedSchematic = null; | ||
return true; | ||
}) | ||
.background(deleteIcon) | ||
.hoverBackground(deleteIcon) | ||
.size(20, 20) | ||
.center()))); | ||
idx++; | ||
} | ||
|
||
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(backgroundTexture) | ||
.size(WINDOW_WIDTH, WINDOW_HEIGHT); | ||
} | ||
|
||
public static class RenameGui extends CustomModularScreen { | ||
|
||
private String newValue = ""; | ||
|
||
@Override | ||
public void close() { | ||
super.close(); | ||
this.persist(); | ||
} | ||
|
||
@Override | ||
public void close(boolean force) { | ||
super.close(force); | ||
this.persist(); | ||
} | ||
|
||
public void persist() { | ||
PacketHandler.INSTANCE.sendToServer(new PacketLokiRenameSchematic(schematicToBeRenamed.toString(), newValue)); | ||
} | ||
|
||
@Override | ||
public ModularPanel buildUI(ModularGuiContext context) { | ||
final UITexture BACKGROUND = AdaptableUITexture.builder() | ||
.location("botania:textures/gui/croppedPaper") | ||
.imageSize(330, 252) | ||
.adaptable(12) | ||
.build(); | ||
|
||
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(BACKGROUND) | ||
.size(200, 100); | ||
} | ||
} | ||
} |
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.