-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename and ExplorerGUI, Compatible Utils, Kyoyu Placement Fields stuff
- Loading branch information
1 parent
20d511b
commit 7f123af
Showing
14 changed files
with
495 additions
and
17 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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/vulpeus/kyoyu/client/gui/Explorer_GuiList.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,38 @@ | ||
package com.vulpeus.kyoyu.client.gui; | ||
|
||
//? if client { | ||
import com.vulpeus.kyoyu.Kyoyu; | ||
import com.vulpeus.kyoyu.placement.KyoyuPlacement; | ||
import fi.dy.masa.malilib.gui.GuiListBase; | ||
import fi.dy.masa.malilib.util.StringUtils; | ||
import net.minecraft.client.gui.screen.Screen; | ||
|
||
import java.util.List; | ||
|
||
public class Explorer_GuiList extends GuiListBase<KyoyuPlacement, Explorer_WidgetListEntry, Explorer_WidgetList> { | ||
|
||
public final List<KyoyuPlacement> kyoyuPlacementList; | ||
|
||
public Explorer_GuiList(Screen parentGui, List<KyoyuPlacement> kyoyuPlacementList) { | ||
super(12, 30); | ||
this.setParent(parentGui); | ||
this.setTitle(StringUtils.translate("kyoyu.gui.title.title", Kyoyu.MOD_VERSION)); | ||
this.kyoyuPlacementList = kyoyuPlacementList; | ||
} | ||
|
||
@Override | ||
protected Explorer_WidgetList createListWidget(int x, int y) { | ||
return new Explorer_WidgetList(x, y, this.width - 20, this.height - 20, null, kyoyuPlacementList); | ||
} | ||
|
||
@Override | ||
protected int getBrowserWidth() { | ||
return this.width; | ||
} | ||
|
||
@Override | ||
protected int getBrowserHeight() { | ||
return this.height; | ||
} | ||
} | ||
//?} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/vulpeus/kyoyu/client/gui/Explorer_WidgetList.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,71 @@ | ||
package com.vulpeus.kyoyu.client.gui; | ||
|
||
//? if client { | ||
import com.vulpeus.kyoyu.Kyoyu; | ||
import com.vulpeus.kyoyu.placement.KyoyuPlacement; | ||
import fi.dy.masa.malilib.gui.GuiBase; | ||
import fi.dy.masa.malilib.gui.interfaces.ISelectionListener; | ||
import fi.dy.masa.malilib.gui.widgets.WidgetListBase; | ||
import fi.dy.masa.malilib.render.RenderUtils; | ||
|
||
//? if >=1.20 { | ||
import net.minecraft.client.gui.DrawContext; | ||
//?} elif >=1.16 { | ||
/* import net.minecraft.client.util.math.MatrixStack; */ | ||
//?} | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class Explorer_WidgetList extends WidgetListBase<KyoyuPlacement, Explorer_WidgetListEntry> { | ||
|
||
private final List<KyoyuPlacement> kyoyuPlacement; | ||
|
||
public Explorer_WidgetList(int x, int y, int width, int height, ISelectionListener<KyoyuPlacement> selectionListener, List<KyoyuPlacement> kyoyuPlacement) { | ||
super(x, y, width, height, selectionListener); | ||
this.browserEntryHeight = 22; | ||
this.kyoyuPlacement = kyoyuPlacement; | ||
Kyoyu.LOGGER.info("{}", getAllEntries()); | ||
setSize(width, height); | ||
} | ||
|
||
@Override | ||
public void setSize(int width, int height) { | ||
super.setSize(width, height); | ||
|
||
this.browserWidth = width - 20; | ||
this.browserHeight = height - posY - 20; | ||
this.browserEntryWidth = browserWidth - 5; | ||
} | ||
|
||
@Override | ||
protected Explorer_WidgetListEntry createListEntryWidget(int x, int y, int listIndex, boolean isOdd, KyoyuPlacement kyoyuPlacement) { | ||
return new Explorer_WidgetListEntry(x, y, browserEntryWidth, getBrowserEntryHeightFor(kyoyuPlacement), kyoyuPlacement, listIndex, isOdd); | ||
} | ||
|
||
@Override | ||
protected Collection<KyoyuPlacement> getAllEntries() { | ||
Kyoyu.LOGGER.info("{}", this.kyoyuPlacement); | ||
return this.kyoyuPlacement; | ||
} | ||
|
||
@Override | ||
//? if >=1.20 { | ||
public void drawContents(DrawContext drawContext, int mouseX, int mouseY, float partialTicks) { | ||
//?} elif >=1.16 { | ||
/* public void drawContents(MatrixStack drawContext, int mouseX, int mouseY, float partialTicks) { */ | ||
//?} else { | ||
/* public void drawContents(int mouseX, int mouseY, float partialTicks) { */ | ||
//?} | ||
|
||
// Draw an outline around the entire widget | ||
RenderUtils.drawOutlinedBox(posX, posY, browserWidth, browserHeight, 0xB0000000, GuiBase.COLOR_HORIZONTAL_BAR); | ||
|
||
//? if >=1.16 { | ||
super.drawContents(drawContext, mouseX, mouseY, partialTicks); | ||
//?} else { | ||
/* super.drawContents(mouseX, mouseY, partialTicks); */ | ||
//?} | ||
} | ||
} | ||
//?} |
215 changes: 215 additions & 0 deletions
215
src/main/java/com/vulpeus/kyoyu/client/gui/Explorer_WidgetListEntry.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,215 @@ | ||
package com.vulpeus.kyoyu.client.gui; | ||
|
||
//? if client { | ||
import com.vulpeus.kyoyu.Kyoyu; | ||
import com.vulpeus.kyoyu.placement.KyoyuPlacement; | ||
import com.vulpeus.kyoyu.placement.KyoyuRegion; | ||
import fi.dy.masa.litematica.data.DataManager; | ||
import fi.dy.masa.litematica.data.SchematicHolder; | ||
import fi.dy.masa.litematica.gui.GuiMaterialList; | ||
import fi.dy.masa.litematica.materials.MaterialListSchematic; | ||
import fi.dy.masa.litematica.schematic.LitematicaSchematic; | ||
import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; | ||
import fi.dy.masa.malilib.gui.GuiBase; | ||
import fi.dy.masa.malilib.gui.button.ButtonBase; | ||
import fi.dy.masa.malilib.gui.button.ButtonGeneric; | ||
import fi.dy.masa.malilib.gui.button.IButtonActionListener; | ||
import fi.dy.masa.malilib.gui.widgets.WidgetListEntryBase; | ||
import fi.dy.masa.malilib.render.RenderUtils; | ||
import fi.dy.masa.malilib.util.GuiUtils; | ||
import fi.dy.masa.malilib.util.StringUtils; | ||
import net.minecraft.util.BlockMirror; | ||
import net.minecraft.util.BlockRotation; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
//? if >=1.20 { | ||
import net.minecraft.client.gui.DrawContext; | ||
//?} elif >=1.16 { | ||
/* import net.minecraft.client.util.math.MatrixStack; */ | ||
//?} | ||
|
||
import java.util.Set; | ||
|
||
public class Explorer_WidgetListEntry extends WidgetListEntryBase<KyoyuPlacement> { | ||
|
||
private final KyoyuPlacement kyoyuPlacement; | ||
private final boolean isOdd; | ||
|
||
public Explorer_WidgetListEntry(int x, int y, int width, int height, KyoyuPlacement entry, int listIndex, boolean isOdd) { | ||
super(x, y, width, height, entry, listIndex); | ||
this.kyoyuPlacement = entry; | ||
this.isOdd = isOdd; | ||
|
||
int buttonHeight = 20; | ||
int buttonY = (height - buttonHeight)/2 + y; | ||
int endX = width - 2; | ||
String text; | ||
int textWidth; | ||
ButtonGeneric button; | ||
ButtonListener listener; | ||
|
||
// REMOVE | ||
text = StringUtils.translate("kyoyu.gui.button.remove_litematic"); | ||
textWidth = getStringWidth(text) + 10; | ||
endX -= textWidth + 2; | ||
button = new ButtonGeneric(endX, buttonY, textWidth, buttonHeight, text); | ||
button.setEnabled(true); | ||
listener = new ButtonListener(ButtonListener.Type.REMOVE, this); | ||
addButton(button, listener); | ||
|
||
|
||
// DOWNLOAD | ||
text = StringUtils.translate("kyoyu.gui.button.download_litematic"); | ||
textWidth = getStringWidth(text) + 10; | ||
endX -= textWidth + 2; | ||
button = new ButtonGeneric(endX, buttonY, textWidth, buttonHeight, text); | ||
// TODO | ||
// button.setEnabled(!kyoyuPlacement.existFile()); | ||
listener = new ButtonListener(ButtonListener.Type.DOWNLOAD, this); | ||
addButton(button, listener); | ||
|
||
|
||
// LOAD | ||
text = StringUtils.translate("kyoyu.gui.button.load_litematic"); | ||
textWidth = getStringWidth(text) + 10; | ||
endX -= textWidth + 2; | ||
button = new ButtonGeneric(endX, buttonY, textWidth, buttonHeight, text); | ||
// TODO | ||
// button.setEnabled(kyoyuPlacement.existFile() && !getClient().isLoadedKyoyuPlacement(kyoyuPlacement)); | ||
listener = new ButtonListener(ButtonListener.Type.LOAD, this); | ||
addButton(button, listener); | ||
|
||
|
||
// MATERIAL_LIST | ||
text = StringUtils.translate("kyoyu.gui.button.material_list"); | ||
textWidth = getStringWidth(text) + 10; | ||
endX -= textWidth + 2; | ||
button = new ButtonGeneric(endX, buttonY, textWidth, buttonHeight, text); | ||
// TODO | ||
// button.setEnabled(kyoyuPlacement.existFile()); | ||
listener = new ButtonListener(ButtonListener.Type.MATERIAL_LIST, this); | ||
addButton(button, listener); | ||
} | ||
|
||
@Override | ||
//? if >=1.20 { | ||
public void render(int mouseX, int mouseY, boolean selected, DrawContext drawContext) { | ||
//?} elif >=1.16 { | ||
/* public void render(int mouseX, int mouseY, boolean selected, MatrixStack drawContext) { */ | ||
//?} else { | ||
/* public void render(int mouseX, int mouseY, boolean selected) { */ | ||
//?} | ||
|
||
// Source: WidgetSchematicEntry | ||
RenderUtils.color(1f, 1f, 1f, 1f); | ||
|
||
// Draw a lighter background for the hovered and the selected entry | ||
if (selected || isMouseOver(mouseX, mouseY)) { | ||
RenderUtils.drawRect(x, y, width, height, 0x70FFFFFF); | ||
} else if (isOdd) { | ||
RenderUtils.drawRect(x, y, width, height, 0x20FFFFFF); | ||
} | ||
// Draw a slightly lighter background for even entries | ||
else { | ||
RenderUtils.drawRect(x, y, width, height, 0x50FFFFFF); | ||
} | ||
|
||
String schematicName = kyoyuPlacement.getName(); | ||
|
||
//? if >=1.16 { | ||
drawString(x + 20, y + 7, 0xFFFFFFFF, schematicName, drawContext); | ||
drawSubWidgets(mouseX, mouseY, drawContext); | ||
//?} else { | ||
/* drawSubWidgets(mouseX, mouseY); */ | ||
//?} | ||
} | ||
|
||
private static class ButtonListener implements IButtonActionListener { | ||
|
||
private final Type type; | ||
private final Explorer_WidgetListEntry entry; | ||
|
||
public ButtonListener(Type type, Explorer_WidgetListEntry entry) { | ||
this.type = type; | ||
this.entry = entry; | ||
} | ||
|
||
@Override | ||
public void actionPerformedWithButton(ButtonBase button, int arg1) { | ||
if (type == null) { | ||
return; | ||
} | ||
button.setEnabled(false); | ||
Kyoyu.LOGGER.info("{} on click {}", entry.kyoyuPlacement.getName(), type.name()); | ||
this.type.onAction(entry); | ||
} | ||
|
||
public enum Type { | ||
MATERIAL_LIST() { | ||
@Override | ||
void onAction(Explorer_WidgetListEntry entry) { | ||
LitematicaSchematic schematic = SchematicHolder.getInstance().getOrLoad(entry.kyoyuPlacement.getFile()); | ||
Set<String> regionNames= schematic.getAreas().keySet(); | ||
MaterialListSchematic materialList = new MaterialListSchematic(schematic, regionNames, true); | ||
DataManager.setMaterialList(materialList); | ||
GuiBase gui = new GuiMaterialList(materialList); | ||
|
||
gui.setTitle(StringUtils.translate("litematica.gui.title.material_list.select_schematic_regions", schematic.getMetadata().getName())); | ||
gui.setParent(GuiUtils.getCurrentScreen()); | ||
GuiBase.openGui(gui); | ||
} | ||
}, | ||
LOAD() { | ||
@Override | ||
void onAction(Explorer_WidgetListEntry entry) { | ||
String name = entry.kyoyuPlacement.getName(); | ||
BlockPos pos = entry.kyoyuPlacement.getRegion().getPos(); | ||
BlockMirror mirror = entry.kyoyuPlacement.getRegion().getMirror().get(); | ||
BlockRotation rotation = entry.kyoyuPlacement.getRegion().getRotation().get(); | ||
|
||
LitematicaSchematic schematic = SchematicHolder.getInstance().getOrLoad(entry.kyoyuPlacement.getFile()); | ||
SchematicPlacement placement = SchematicPlacement.createFor(schematic, pos, name, true, true); | ||
|
||
if (placement.isLocked()) { | ||
placement.toggleLocked(); | ||
} | ||
|
||
placement.setMirror(mirror, null); | ||
placement.setRotation(rotation, null); | ||
for (KyoyuRegion subRegion: entry.kyoyuPlacement.getSubRegions()) { | ||
String subRegionName = subRegion.getName(); | ||
|
||
placement.moveSubRegionTo(subRegionName, subRegion.getPos(), null); | ||
placement.setSubRegionMirror(subRegionName, subRegion.getMirror().get(), null); | ||
placement.setSubRegionRotation(subRegionName, subRegion.getRotation().get(), null); | ||
} | ||
placement.toggleLocked(); | ||
|
||
DataManager.getSchematicPlacementManager().addSchematicPlacement(placement, true); | ||
// TODO | ||
// getClient().add(entry.kyoyuPlacement, placement); | ||
} | ||
}, | ||
DOWNLOAD() { | ||
@Override | ||
void onAction(Explorer_WidgetListEntry entry) { | ||
// TODO | ||
// Packet Process on Download | ||
// REQUEST Download File | ||
} | ||
}, | ||
REMOVE() { | ||
@Override | ||
void onAction(Explorer_WidgetListEntry entry) { | ||
// TODO | ||
// Packet Process on Remove | ||
// REQUEST Remove KyoyuPlacement | ||
} | ||
}; | ||
|
||
abstract void onAction(Explorer_WidgetListEntry entry); | ||
} | ||
|
||
} | ||
} | ||
//?} |
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
Oops, something went wrong.