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 2 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
144 changes: 144 additions & 0 deletions
144
src/main/java/vazkii/botania/client/gui/loki/GuiLokiSchematics.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,144 @@ | ||
| package vazkii.botania.client.gui.loki; | ||
|
|
||
| import com.gtnewhorizons.modularui.api.ModularUITextures; | ||
| import com.gtnewhorizons.modularui.api.UIInfos; | ||
| import com.gtnewhorizons.modularui.api.drawable.AdaptableUITexture; | ||
| import com.gtnewhorizons.modularui.api.drawable.IDrawable; | ||
| import com.gtnewhorizons.modularui.api.drawable.Text; | ||
| import com.gtnewhorizons.modularui.api.math.Alignment; | ||
| import com.gtnewhorizons.modularui.api.math.Pos2d; | ||
| import com.gtnewhorizons.modularui.api.math.Size; | ||
| import com.gtnewhorizons.modularui.api.screen.ModularWindow; | ||
| import com.gtnewhorizons.modularui.api.screen.UIBuildContext; | ||
| import com.gtnewhorizons.modularui.api.widget.IWidgetParent; | ||
| import com.gtnewhorizons.modularui.common.widget.ButtonWidget; | ||
| import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; | ||
| import com.gtnewhorizons.modularui.common.widget.Scrollable; | ||
| import com.gtnewhorizons.modularui.common.widget.TextWidget; | ||
| import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; | ||
| import net.minecraft.item.ItemStack; | ||
| import net.minecraft.nbt.NBTBase; | ||
| import net.minecraft.nbt.NBTTagCompound; | ||
| 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 java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| public class GuiLokiSchematics { | ||
|
|
||
| private static final AdaptableUITexture BACKGROUND = AdaptableUITexture | ||
| .of("botania:textures/gui/croppedPaper", 330, 252, 12); | ||
| private static Object selectedSchematic; | ||
| private static final AdaptableUITexture DELETE = AdaptableUITexture | ||
| .of("botania:textures/gui/lokiDelete", 500, 500, 0); | ||
| private static final AdaptableUITexture RENAME = AdaptableUITexture | ||
| .of("botania:textures/gui/lokiRename", 500, 500, 0); | ||
| private static String newSchematicName = ""; | ||
|
|
||
| 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; | ||
|
|
||
| public static ModularWindow getWindow(UIBuildContext buildContext, ItemStack lokiRing) { | ||
| if(lokiRing.getTagCompound().tagMap.containsKey(ItemLokiRing.TAG_CURRENT_SCHEMATIC)) { | ||
| // Substring to remove the leading and ending double quotes | ||
| selectedSchematic = lokiRing.stackTagCompound.getString(ItemLokiRing.TAG_CURRENT_SCHEMATIC).substring(1); | ||
| selectedSchematic = selectedSchematic.toString().substring(0, selectedSchematic.toString().length() - 1); | ||
| } | ||
| ItemLokiRing ring = (ItemLokiRing) lokiRing.getItem(); | ||
| ModularWindow.Builder builder = ModularWindow.builder(WINDOW_WIDTH, WINDOW_HEIGHT); | ||
| buildContext.setShowNEI(false); | ||
| builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); | ||
| Scrollable scrollArea = | ||
| new Scrollable() | ||
| .setVerticalScroll(); | ||
| if(lokiRing.getTagCompound().tagMap.containsKey(ItemLokiRing.TAG_SAVED_SCHEMATICS) && !lokiRing.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).tagMap.keySet().isEmpty()) { | ||
| final AtomicInteger offset = new AtomicInteger(); | ||
| final AtomicInteger disabled = new AtomicInteger(); | ||
| for(Object schematicName : lokiRing.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).tagMap.keySet()) { | ||
| scrollArea = scrollArea.widget(new ButtonWidget() | ||
| .setOnClick((clickData, widget) -> { | ||
| selectedSchematic = schematicName; | ||
| PacketHandler.INSTANCE.sendToServer(new PacketLokiChangeSchematic(schematicName.toString())); | ||
| }) | ||
| .setBackground(() -> new IDrawable[]{new Text(schematicName.toString()).format(selectedSchematic.toString().equals(schematicName.toString()) ? EnumChatFormatting.DARK_GREEN : EnumChatFormatting.BLACK)}) | ||
| .setSize(SCROLL_AREA_WIDTH - 60, SCROLL_AREA_HEIGHT / 10) | ||
| .setEnabled((widget) -> { | ||
| if(lokiRing.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).hasKey(schematicName.toString())) { | ||
| return true; | ||
| } | ||
| disabled.getAndIncrement(); | ||
| return false; | ||
| }) | ||
| .setPosProvider((Size screenSize, ModularWindow window, IWidgetParent parent) -> new Pos2d(0, ring.schematicNames.indexOf(schematicName) * (SCROLL_AREA_HEIGHT / 10 + 1)))); | ||
| scrollArea = scrollArea.widget(new ButtonWidget() | ||
| .setOnClick((clickData, widget) -> { | ||
| UIInfos.openClientUI(buildContext.getPlayer(), (context) -> GuiLokiSchematics.getRenameWindow(context, lokiRing, schematicName)); | ||
| }) | ||
| .setBackground(RENAME) | ||
| .setPosProvider((Size screenSize, ModularWindow window, IWidgetParent parent) -> new Pos2d(SCROLL_AREA_WIDTH - 55, ring.schematicNames.indexOf(schematicName) * (SCROLL_AREA_HEIGHT / 10 + 1))) | ||
| .setEnabled((widget) -> lokiRing.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).hasKey(schematicName.toString())) | ||
| .setSize(20, 20)); | ||
| scrollArea = scrollArea.widget(new ButtonWidget() | ||
| .setOnClick((clickData, widget) -> { | ||
| PacketHandler.INSTANCE.sendToServer(new PacketLokiDeleteSchematic(schematicName.toString())); | ||
| buildContext.setValidator(() -> false); | ||
| }) | ||
| .setBackground(DELETE) | ||
| .setPosProvider((Size screenSize, ModularWindow window, IWidgetParent parent) -> new Pos2d(SCROLL_AREA_WIDTH - 30, ring.schematicNames.indexOf(schematicName) * (SCROLL_AREA_HEIGHT / 10 + 1))) | ||
| .setEnabled((widget) -> lokiRing.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).hasKey(schematicName.toString())) | ||
| .setSize(20, 20)); | ||
| offset.addAndGet((SCROLL_AREA_HEIGHT / 10) + 1); | ||
| } | ||
| } | ||
| scrollArea = scrollArea.widget(new TextWidget("No saved schematics!") | ||
| .setEnabled((widget) -> !lokiRing.getTagCompound().hasKey(ItemLokiRing.TAG_SAVED_SCHEMATICS) || lokiRing.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).tagMap.keySet().isEmpty()) | ||
| .setSize(SCROLL_AREA_WIDTH, SCROLL_AREA_HEIGHT) | ||
| .setPos(0, 0)); | ||
| return builder | ||
| .widget( | ||
| new MultiChildWidget() | ||
| .addChild( | ||
| new TextWidget() | ||
| .setScale(0.5F) | ||
| .setTextSupplier(() -> new Text(selectedSchematic == null ? StatCollector.translateToLocal("botaniamisc.select_schematic") : StatCollector.translateToLocal("botaniamisc.selected_schematic") + " " + selectedSchematic) | ||
| .format(selectedSchematic == null ? EnumChatFormatting.RED : EnumChatFormatting.BLACK) | ||
| .alignment(Alignment.Center)) | ||
| .setSize(SCROLL_AREA_WIDTH, SAVED_SCHEMATICS_HEADER_HEIGHT)) | ||
| .addChild( | ||
| scrollArea | ||
| .setSize(SCROLL_AREA_WIDTH, SCROLL_AREA_HEIGHT - SAVED_SCHEMATICS_HEADER_HEIGHT - Y_PADDING * 2) | ||
| .setPos(0, SAVED_SCHEMATICS_HEADER_HEIGHT)) | ||
| .setPos(WINDOW_WIDTH - SCROLL_AREA_WIDTH - X_PADDING, 0)) | ||
| .setBackground(BACKGROUND) | ||
| .build(); | ||
| } | ||
|
|
||
| public static ModularWindow getRenameWindow(UIBuildContext buildContext, ItemStack lokiRing, Object schematicName) { | ||
| ModularWindow.Builder builder = ModularWindow.builder(200, 100); | ||
|
|
||
| buildContext.addCloseListener(() -> { | ||
| if(lokiRing.getTagCompound().getString(ItemLokiRing.TAG_CURRENT_SCHEMATIC).equals(schematicName)) { | ||
| lokiRing.getTagCompound().setString(ItemLokiRing.TAG_CURRENT_SCHEMATIC, newSchematicName); | ||
| } | ||
| NBTBase nbt = lokiRing.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).getTag(schematicName.toString()); | ||
| lokiRing.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).removeTag(schematicName.toString()); | ||
| lokiRing.getTagCompound().getCompoundTag(ItemLokiRing.TAG_SAVED_SCHEMATICS).setTag(newSchematicName, nbt); | ||
| }); | ||
|
|
||
| return builder | ||
| .widget(new TextWidget() | ||
| .setTextSupplier(() -> new Text("Schematic Name:").format(EnumChatFormatting.BLACK)) | ||
| .setPos(10, 10) | ||
| .setSize(180, 20)) | ||
| .widget(new TextFieldWidget() | ||
| .setGetter(() -> newSchematicName) | ||
| .setSetter((newValue) -> newSchematicName = newValue) | ||
| .setSize(150, 20) | ||
| .setPos(25, 40)) | ||
| .setBackground(BACKGROUND) | ||
| .build(); | ||
| } | ||
| } |
Oops, something went wrong.
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.