Origin enum
Пакет: com.hypixel.hytale.builtin.buildertools.imageimport
Файл: com/hypixel/hytale/builtin/buildertools/imageimport/ImageImportPage.java
Поля (1)
| Модификаторы | Тип | Имя |
|---|---|---|
|
BOTTOM_FRONT_LEFT,
BOTTOM_CENTER,
CENTER, |
TOP_CENTER |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.buildertools.imageimport;
class="kw">import com.hypixel.hytale.builtin.buildertools.BlockColorIndex;
class="kw">import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
class="kw">import com.hypixel.hytale.builtin.buildertools.utils.PasteToolUtil;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.common.util.StringUtil;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.CustomPageLifetime;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.Page;
class="kw">import com.hypixel.hytale.server.core.Constants;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.asset.AssetModule;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.pages.InteractiveCustomUIPage;
class="kw">import com.hypixel.hytale.server.core.modules.singleplayer.SingleplayerModule;
class="kw">import com.hypixel.hytale.server.core.prefab.selection.standard.BlockSelection;
class="kw">import com.hypixel.hytale.server.core.ui.DropdownEntryInfo;
class="kw">import com.hypixel.hytale.server.core.ui.LocalizableString;
class="kw">import com.hypixel.hytale.server.core.ui.browser.FileBrowserConfig;
class="kw">import com.hypixel.hytale.server.core.ui.browser.FileBrowserEventData;
class="kw">import com.hypixel.hytale.server.core.ui.browser.ServerFileBrowser;
class="kw">import com.hypixel.hytale.server.core.ui.builder.EventData;
class="kw">import com.hypixel.hytale.server.core.ui.builder.UICommandBuilder;
class="kw">import com.hypixel.hytale.server.core.ui.builder.UIEventBuilder;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.awt.image.BufferedImage;
class="kw">import java.nio.file.Files;
class="kw">import java.nio.file.Path;
class="kw">import java.nio.file.Paths;
class="kw">import java.util.ArrayList;
class="kw">import java.util.List;
class="kw">import java.util.Locale;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import javax.imageio.ImageIO;
class="kw">import org.joml.Vector3i;
class="kw">public class ImageImportPage class="kw">extends InteractiveCustomUIPage<ImageImportPage.PageData> {
class="kw">private class="kw">static class="kw">final int DEFAULT_MAX_SIZE = 128;
class="kw">private class="kw">static class="kw">final int MIN_SIZE = 1;
class="kw">private class="kw">static class="kw">final int MAX_SIZE = 512;
class="kw">private class="kw">static class="kw">final String ASSET_PACK_SUB_PATH = "Server/Imports/Images";
@Nonnull
class="kw">private String imagePath = "";
class="kw">private int maxDimension = 128;
@Nonnull
class="kw">private String orientationStr = "wall_xy";
@Nonnull
class="kw">private ImageImportPage.Orientation orientation = ImageImportPage.Orientation.VERTICAL_XY;
@Nonnull
class="kw">private String originStr = "bottom_center";
@Nonnull
class="kw">private ImageImportPage.Origin origin = ImageImportPage.Origin.BOTTOM_CENTER;
@Nullable
class="kw">private Message statusMessage = null;
class="kw">private boolean isError = false;
class="kw">private boolean isProcessing = false;
class="kw">private boolean showBrowser = false;
@Nonnull
class="kw">private class="kw">final ServerFileBrowser browser;
class="kw">public ImageImportPage(@Nonnull PlayerRef var1) {
super(var1, CustomPageLifetime.CanDismiss, ImageImportPage.PageData.CODEC);
FileBrowserConfig var2 = FileBrowserConfig.builder()
.listElementId("#BrowserPage #FileList")
.searchInputId("#BrowserPage #SearchInput")
.currentPathId("#BrowserPage #CurrentPath")
.allowedExtensions(".png", ".jpg", ".jpeg", ".gif", ".bmp")
.enableRootSelector(false)
.enableSearch(true)
.enableDirectoryNav(true)
.maxResults(50)
.assetPackMode(true, "Server/Imports/Images")
.build();
this.browser = new ServerFileBrowser(var2);
}
@Override
class="kw">public void build(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4) {
var2.append("Pages/ImageImportPage.ui");
var2.set("#ImagePath #Input.Value", this.imagePath);
var2.set("#MaxSizeInput #Input.Value", this.maxDimension);
List var5 = new ArrayList<>();
var5.add(new DropdownEntryInfo(LocalizableString.fromMessageId("server.customUI.imageImport.orientation.wall_xy"), "wall_xy"));
var5.add(new DropdownEntryInfo(LocalizableString.fromMessageId("server.customUI.imageImport.orientation.wall_xz"), "wall_xz"));
var5.add(new DropdownEntryInfo(LocalizableString.fromMessageId("server.customUI.imageImport.orientation.floor"), "floor"));
var2.set("#OrientationInput #Input.Entries", var5);
var2.set("#OrientationInput #Input.Value", this.orientationStr);
List var6 = new ArrayList<>();
var6.add(new DropdownEntryInfo(LocalizableString.fromMessageId("server.customUI.origin.bottom_front_left"), "bottom_front_left"));
var6.add(new DropdownEntryInfo(LocalizableString.fromMessageId("server.customUI.origin.bottom_center"), "bottom_center"));
var6.add(new DropdownEntryInfo(LocalizableString.fromMessageId("server.customUI.origin.center"), "center"));
var6.add(new DropdownEntryInfo(LocalizableString.fromMessageId("server.customUI.origin.top_center"), "top_center"));
var2.set("#OriginInput #Input.Entries", var6);
var2.set("#OriginInput #Input.Value", this.originStr);
this.updateStatus(var2);
var3.addEventBinding(CustomUIEventBindingType.ValueChanged, "#ImagePath #Input", EventData.of("@ImagePath", "#ImagePath #Input.Value"), false);
var3.addEventBinding(CustomUIEventBindingType.ValueChanged, "#MaxSizeInput #Input", EventData.of("@MaxSize", "#MaxSizeInput #Input.Value"), false);
var3.addEventBinding(
CustomUIEventBindingType.ValueChanged, "#OrientationInput #Input", EventData.of("@Orientation", "#OrientationInput #Input.Value"), false
);
var3.addEventBinding(CustomUIEventBindingType.ValueChanged, "#OriginInput #Input", EventData.of("@Origin", "#OriginInput #Input.Value"), false);
var3.addEventBinding(CustomUIEventBindingType.Activating, "#ImportButton", EventData.of("Import", "true"));
var3.addEventBinding(CustomUIEventBindingType.Activating, "#ImagePath #BrowseButton", EventData.of("Browse", "true"));
var2.set("#FormContainer.Visible", !this.showBrowser);
var2.set("#BrowserPage.Visible", this.showBrowser);
if (this.showBrowser) {
this.buildBrowserPage(var2, var3);
}
}
class="kw">private void buildBrowserPage(@Nonnull UICommandBuilder var1, @Nonnull UIEventBuilder var2) {
this.browser.buildSearchInput(var1, var2);
this.browser.buildCurrentPath(var1);
this.browser.buildFileList(var1, var2);
var2.addEventBinding(CustomUIEventBindingType.Activating, "#BrowserPage #SelectButton", EventData.of("BrowserSelect", "true"));
var2.addEventBinding(CustomUIEventBindingType.Activating, "#BrowserPage #CancelButton", EventData.of("BrowserCancel", "true"));
}
class="kw">private void updateStatus(@Nonnull UICommandBuilder var1) {
if (this.statusMessage != null) {
var1.set("#StatusText.Text", this.statusMessage);
var1.set("#StatusText.Visible", true);
var1.set("#StatusText.Style.TextColor", this.isError ? "#e74c3c" : "#cfd8e3");
} else {
var1.set("#StatusText.Visible", false);
}
}
class="kw">private void setError(@Nonnull Message var1) {
this.statusMessage = var1;
this.isError = true;
this.isProcessing = false;
this.rebuild();
}
class="kw">private void setStatus(@Nonnull Message var1) {
this.statusMessage = var1;
this.isError = false;
this.rebuild();
}
class="kw">public void handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull ImageImportPage.PageData var3) {
if (var3.browse != null && var3.browse) {
this.showBrowser = true;
this.rebuild();
} else if (var3.browserCancel != null && var3.browserCancel) {
this.showBrowser = false;
this.rebuild();
} else if (var3.browserSelect != null && var3.browserSelect) {
this.showBrowser = false;
this.rebuild();
} else if (!this.showBrowser || !this.handleBrowserEvent(var3)) {
boolean var4 = false;
if (var3.imagePath != null) {
this.imagePath = StringUtil.stripQuotes(var3.imagePath.trim());
this.statusMessage = null;
var4 = true;
}
if (var3.maxSize != null) {
this.maxDimension = Math.max(1, Math.min(512, var3.maxSize));
var4 = true;
}
if (var3.orientation != null) {
this.orientationStr = var3.orientation.trim().toLowerCase(Locale.ROOT);
this.orientation = class="kw">switch (this.orientationStr) {
case "wall_xz", "xz", "vertical_xz" -> ImageImportPage.Orientation.VERTICAL_XZ;
case "floor", "horizontal", "horizontal_xz" -> ImageImportPage.Orientation.HORIZONTAL_XZ;
class="kw">default -> ImageImportPage.Orientation.VERTICAL_XY;
};
var4 = true;
}
if (var3.origin != null) {
this.originStr = var3.origin.trim().toLowerCase(Locale.ROOT);
this.origin = class="kw">switch (this.originStr) {
case "bottom_front_left" -> ImageImportPage.Origin.BOTTOM_FRONT_LEFT;
case "center" -> ImageImportPage.Origin.CENTER;
case "top_center" -> ImageImportPage.Origin.TOP_CENTER;
class="kw">default -> ImageImportPage.Origin.BOTTOM_CENTER;
};
var4 = true;
}
if (var3.doImport != null && var3.doImport && !this.isProcessing) {
this.performImport(var1, var2);
} else {
if (var4) {
this.sendUpdate();
}
}
}
}
class="kw">private boolean handleBrowserEvent(@Nonnull ImageImportPage.PageData var1) {
if (var1.searchQuery != null) {
this.browser.setSearchQuery(var1.searchQuery.trim().toLowerCase(Locale.ROOT));
this.rebuildBrowser();
class="kw">return true;
}
if (var1.file != null) {
String var2 = var1.file;
if ("..".equals(var2)) {
this.browser.navigateUp();
this.rebuildBrowser();
class="kw">return true;
}
if (this.browser.handleEvent(FileBrowserEventData.file(var2))) {
this.rebuildBrowser();
class="kw">return true;
}
String var3 = this.browser.getAssetPackCurrentPath().isEmpty() ? var2 : this.browser.getAssetPackCurrentPath() + "/" + var2;
Path var4 = this.browser.resolveAssetPackPath(var3);
if (var4 != null && Files.isRegularFile(var4)) {
this.imagePath = var4.toString();
this.showBrowser = false;
this.rebuild();
class="kw">return true;
}
}
if (var1.searchResult != null) {
Path var5 = this.browser.resolveAssetPackPath(var1.searchResult);
if (var5 != null && Files.isRegularFile(var5)) {
this.imagePath = var5.toString();
this.showBrowser = false;
this.rebuild();
class="kw">return true;
}
}
class="kw">return false;
}
class="kw">private void rebuildBrowser() {
UICommandBuilder var1 = new UICommandBuilder();
UIEventBuilder var2 = new UIEventBuilder();
this.browser.buildFileList(var1, var2);
this.browser.buildCurrentPath(var1);
this.sendUpdate(var1, var2, false);
}
class="kw">private void performImport(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2) {
if (this.imagePath.isEmpty()) {
this.setError(Message.translation("server.builderTools.imageImport.emptyPath"));
} else {
Path var3 = Paths.get(this.imagePath);
boolean var4 = Constants.SINGLEPLAYER && SingleplayerModule.isOwner(this.playerRef);
if (!var4 && !AssetModule.get().isWithinPackSubDir(var3, "Server/Imports/Images")) {
this.setError(Message.translation("server.builderTools.imageImport.notInImportsDir"));
} else if (!Files.exists(var3)) {
this.setError(Message.translation("server.builderTools.imageImport.fileNotFound").param("path", this.imagePath));
} else {
this.isProcessing = true;
this.setStatus(Message.translation("server.builderTools.imageImport.processing"));
Player var5 = var2.getComponent(var1, Player.getComponentType());
PlayerRef var6 = var2.getComponent(var1, PlayerRef.getComponentType());
if (var5 != null && var6 != null) {
String var7 = this.imagePath;
int var8 = this.maxDimension;
ImageImportPage.Orientation var9 = this.orientation;
ImageImportPage.Origin var10 = this.origin;
BuilderToolsPlugin.addToQueue(
var5,
var6,
(var8x, var9x, var10x) -> {
try {
BufferedImage var11 = null;
try {
var11 = ImageIO.read(Paths.get(var7).toFile());
} catch (Exception var38) {
}
if (var11 == null) {
this.setError(Message.translation("server.builderTools.imageImport.unreadableImage"));
class="kw">return;
}
int var12 = var11.getWidth();
int var13 = var11.getHeight();
float var14 = 1.0F;
if (var12 > var8 || var13 > var8) {
var14 = (float)var8 / Math.max(var12, var13);
var12 = Math.round(var12 * var14);
var13 = Math.round(var13 * var14);
}
BlockColorIndex var15 = BuilderToolsPlugin.get().getBlockColorIndex();
if (var15.isEmpty()) {
this.setError(Message.translation("server.builderTools.imageImport.colorIndexEmpty"));
class="kw">return;
}
int var16;
int var17;
int var18;
class="kw">switch (var9) {
case VERTICAL_XY:
var16 = var12;
var17 = var13;
var18 = 1;
break;
case VERTICAL_XZ:
var16 = var12;
var17 = 1;
var18 = var13;
break;
case HORIZONTAL_XZ:
var16 = var12;
var17 = 1;
var18 = var13;
break;
class="kw">default:
var16 = var12;
var17 = var13;
var18 = 1;
}
int var19 = 0;
int var20 = 0;
int var21 = 0;
class="kw">switch (var10) {
case BOTTOM_FRONT_LEFT:
class="kw">default:
break;
case BOTTOM_CENTER:
var19 = -var16 / 2;
var21 = -var18 / 2;
break;
case CENTER:
var19 = -var16 / 2;
var20 = -var17 / 2;
var21 = -var18 / 2;
break;
case TOP_CENTER:
var19 = -var16 / 2;
var20 = -var17;
var21 = -var18 / 2;
}
BlockSelection var22 = new BlockSelection(var12 * var13, 0);
var22.setPosition(0, 0, 0);
int var23 = 0;
float var24 = var14;
for (int var25 = 0; var25 < var13; var25++) {
for (int var26 = 0; var26 < var12; var26++) {
int var27 = Math.min((int)(var26 / var24), var11.getWidth() - 1);
int var28 = Math.min((int)(var25 / var24), var11.getHeight() - 1);
int var29 = var11.getRGB(var27, var28);
int var30 = var29 >> 24 & 0xFF;
if (var30 >= 128) {
int var31 = var29 >> 16 & 0xFF;
int var32 = var29 >> 8 & 0xFF;
int var33 = var29 & 0xFF;
int var34 = var15.findClosestBlock(var31, var32, var33);
if (var34 > 0) {
int var35;
int var36;
int var37;
class="kw">switch (var9) {
case VERTICAL_XY:
var35 = var26;
var36 = var13 - 1 - var25;
var37 = 0;
break;
case VERTICAL_XZ:
var35 = var26;
var36 = 0;
var37 = var13 - 1 - var25;
break;
case HORIZONTAL_XZ:
var35 = var26;
var36 = 0;
var37 = var25;
break;
class="kw">default:
var35 = var26;
var36 = var13 - 1 - var25;
var37 = 0;
}
var22.addBlockAtLocalPos(var35 + var19, var36 + var20, var37 + var21, var34, 0, 0, 0);
var23++;
}
}
}
}
var22.setSelectionArea(new Vector3i(var19, var20, var21), new Vector3i(var16 - 1 + var19, var17 - 1 + var20, var18 - 1 + var21));
var9x.setSelection(var22);
var9x.sendSelectionToClient();
this.statusMessage = Message.translation("server.builderTools.imageImport.success")
.param("count", var23)
.param("width", var16)
.param("height", var17)
.param("depth", var18);
this.isProcessing = false;
var6.sendMessage(
Message.translation("server.builderTools.imageImport.success")
.param("count", var23)
.param("width", var16)
.param("height", var17)
.param("depth", var18)
);
var5.getPageManager().setPage(var8x, var2, Page.None);
PasteToolUtil.switchToPasteTool(var8x, var6, var10x);
} catch (Exception var39) {
((HytaleLogger.Api)BuilderToolsPlugin.get().getLogger().at(Level.WARNING).withCause(var39)).log("Image class="kw">import error");
this.setError(Message.translation("server.builderTools.imageImport.error").param("message", var39.getMessage()));
}
}
);
} else {
this.setError(Message.translation("server.builderTools.imageImport.playerNotFound"));
}
}
}
}
class="kw">public enum Orientation {
VERTICAL_XY,
VERTICAL_XZ,
HORIZONTAL_XZ;
Orientation() {
}
}
class="kw">public enum Origin {
BOTTOM_FRONT_LEFT,
BOTTOM_CENTER,
CENTER,
TOP_CENTER;
Origin() {
}
}
class="kw">public class="kw">static class PageData {
class="kw">static class="kw">final String KEY_IMAGE_PATH = "@ImagePath";
class="kw">static class="kw">final String KEY_MAX_SIZE = "@MaxSize";
class="kw">static class="kw">final String KEY_ORIENTATION = "@Orientation";
class="kw">static class="kw">final String KEY_ORIGIN = "@Origin";
class="kw">static class="kw">final String KEY_IMPORT = "Import";
class="kw">static class="kw">final String KEY_BROWSE = "Browse";
class="kw">static class="kw">final String KEY_BROWSER_SELECT = "BrowserSelect";
class="kw">static class="kw">final String KEY_BROWSER_CANCEL = "BrowserCancel";
class="kw">public class="kw">static class="kw">final BuilderCodec<ImageImportPage.PageData> CODEC = BuilderCodec.builder(ImageImportPage.PageData.class, ImageImportPage.PageData::new)
.append(new KeyedCodec<>("@ImagePath", Codec.STRING), (var0, var1) -> var0.imagePath = var1, var0 -> var0.imagePath)
.add()
.append(new KeyedCodec<>("@MaxSize", Codec.INTEGER), (var0, var1) -> var0.maxSize = var1, var0 -> var0.maxSize)
.add()
.append(new KeyedCodec<>("@Orientation", Codec.STRING), (var0, var1) -> var0.orientation = var1, var0 -> var0.orientation)
.add()
.append(new KeyedCodec<>("@Origin", Codec.STRING), (var0, var1) -> var0.origin = var1, var0 -> var0.origin)
.add()
.append(
new KeyedCodec<>("Import", Codec.STRING),
(var0, var1) -> var0.doImport = "true".equalsIgnoreCase(var1),
var0 -> var0.doImport != null && var0.doImport ? "true" : null
)
.add()
.append(
new KeyedCodec<>("Browse", Codec.STRING),
(var0, var1) -> var0.browse = "true".equalsIgnoreCase(var1),
var0 -> var0.browse != null && var0.browse ? "true" : null
)
.add()
.append(
new KeyedCodec<>("BrowserSelect", Codec.STRING),
(var0, var1) -> var0.browserSelect = "true".equalsIgnoreCase(var1),
var0 -> var0.browserSelect != null && var0.browserSelect ? "true" : null
)
.add()
.append(
new KeyedCodec<>("BrowserCancel", Codec.STRING),
(var0, var1) -> var0.browserCancel = "true".equalsIgnoreCase(var1),
var0 -> var0.browserCancel != null && var0.browserCancel ? "true" : null
)
.add()
.append(new KeyedCodec<>("File", Codec.STRING), (var0, var1) -> var0.file = var1, var0 -> var0.file)
.add()
.append(new KeyedCodec<>("@SearchQuery", Codec.STRING), (var0, var1) -> var0.searchQuery = var1, var0 -> var0.searchQuery)
.add()
.append(new KeyedCodec<>("SearchResult", Codec.STRING), (var0, var1) -> var0.searchResult = var1, var0 -> var0.searchResult)
.add()
.build();
@Nullable
class="kw">private String imagePath;
@Nullable
class="kw">private Integer maxSize;
@Nullable
class="kw">private String orientation;
@Nullable
class="kw">private String origin;
@Nullable
class="kw">private Boolean doImport;
@Nullable
class="kw">private Boolean browse;
@Nullable
class="kw">private Boolean browserSelect;
@Nullable
class="kw">private Boolean browserCancel;
@Nullable
class="kw">private String file;
@Nullable
class="kw">private String searchQuery;
@Nullable
class="kw">private String searchResult;
class="kw">public PageData() {
}
}
}