PrefabPage class

Пакет: com.hypixel.hytale.builtin.buildertools.prefablist

Файл: com/hypixel/hytale/builtin/buildertools/prefablist/PrefabPage.java

extends: InteractiveCustomUIPage<FileBrowserEventData>

Поля (58)

МодификаторыТипИмя
final String BASE_PACK_KEY
return
long var1
boolean var10
WorldChunk var11
boolean var11
BlockChunk var12
String var12
int var13
Environment var14
Color var15
String var2
Path var2
UICommandBuilder var2
BuilderToolPrefabPreview var2
Ref var2
UICommandBuilder var2
String var2
boolean var3
boolean var3
Path var3
BlockSelection var3
UIEventBuilder var3
EditorBlocksChange var3
Store var3
UIEventBuilder var3
String[] var3
String var3
List var3
Path var4
String var4
UICommandBuilder var4
World var4
String var4
Path var4
int var4
Path var5
Path var5
var5
String var5
var5
var5
UIEventBuilder var5
Vector3d var5
Player var5
boolean var5
FileBrowserConfig var6
Path var6
int var6
PlayerRef var6
String var7
boolean var7
int var7
BlockSelection var7
int var8
String var8
long var9
String var9

Методы (33)

МодификаторыВозвратСигнатура
private void applyTintFromPlayerPositionvoid applyTintFromPlayerPosition(BuilderToolPrefabPreview var1)
private void buildCurrentPathvoid buildCurrentPath(@Nonnull UICommandBuilder var1)
private void buildFileListvoid buildFileList(@Nonnull UICommandBuilder var1, @Nonnull UIEventBuilder var2)
private void buildLoadButtonvoid buildLoadButton(@Nonnull UICommandBuilder var1, @Nonnull UIEventBuilder var2)
private void buildPersistentBindingsvoid buildPersistentBindings(@Nonnull UIEventBuilder var1)
private void clearPreviewvoid clearPreview()
for for(FileListProvider.FileEntry var7 : var3)
private void handleAssetsNavigationvoid handleAssetsNavigation(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull String var3, boolean var4)
public void handleDataEventvoid handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull FileBrowserEventData var3)
private void handlePrefabSelectionvoid handlePrefabSelection(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull Path var3, @Nonnull String var4)
private void handlePreviewRequestvoid handlePreviewRequest(@Nonnull String var1)
if if(var5 != null)
if if(var4 != null)
if if(var4)
if if(var6 == null)
if if(var2 == null)
if if(var3 != null)
if if(var1 != null)
if if(var2 == null)
if if(var14 != null)
if if(var15 != null)
if if(var7 != null)
if if(var1)
if if(var1 == null)
if if(var10)
if if(var10)
static boolean isTooLargeToPreviewboolean isTooLargeToPreview(@Nonnull Path var0)
private boolean isValidDirboolean isValidDir(@Nullable Path var1, boolean var2)
private void sendListingUpdatevoid sendListingUpdate(boolean var1)
private void sendPreviewPacketvoid sendPreviewPacket(@Nullable BlockSelection var1)
private void sendTooLargePreviewMessagevoid sendTooLargePreviewMessage(@Nonnull Path var1)
private void setCurrentDirvoid setCurrentDir(@Nonnull Path var1)
abstract super super(var1, CustomPageLifetime.CanDismiss, FileBrowserEventData.CODEC)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.buildertools.prefablist;

class="kw">import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
class="kw">import com.hypixel.hytale.builtin.buildertools.prefabeditor.PrefabEditSessionManager;
class="kw">import com.hypixel.hytale.builtin.buildertools.utils.PasteToolUtil;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.protocol.Color;
class="kw">import com.hypixel.hytale.protocol.GameMode;
class="kw">import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolPrefabPreview;
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_.EditorBlocksChange;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.Page;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.asset.type.environment.config.Environment;
class="kw">import com.hypixel.hytale.server.core.asset.util.ColorParseUtil;
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.prefab.PrefabStore;
class="kw">import com.hypixel.hytale.server.core.prefab.selection.standard.BlockSelection;
class="kw">import com.hypixel.hytale.server.core.ui.Value;
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.FileListProvider;
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.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.BlockChunk;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.io.IOException;
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.List;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class PrefabPage class="kw">extends InteractiveCustomUIPage<FileBrowserEventData> {
   class="kw">private class="kw">static class="kw">final String BASE_PACK_KEY = "HytaleAssets";
   @Nonnull
   class="kw">private class="kw">final ServerFileBrowser browser;
   @Nonnull
   class="kw">private class="kw">final BuilderToolsPlugin.BuilderState builderState;
   @Nonnull
   class="kw">private class="kw">final AssetPrefabFileProvider assetProvider;
   @Nonnull
   class="kw">private Path assetsCurrentDir;
   @Nullable
   class="kw">private Path previewedPath;
   @Nullable
   class="kw">private String previewedFileName;
   class="kw">private class="kw">static class="kw">final int PREVIEW_TILT = 23;
   class="kw">private class="kw">static class="kw">final int PREVIEW_SPIN_SPEED = 27;
   class="kw">private class="kw">static class="kw">final int PREVIEW_MAX_SIZE = 100;
   class="kw">private class="kw">static class="kw">final long PREVIEW_MAX_FILE_SIZE_BYTES = 134217728L;
   class="kw">private class="kw">static class="kw">final long PREVIEW_MAX_LPF_FILE_SIZE_BYTES = 13421772L;
   class="kw">private class="kw">static class="kw">final int DEFAULT_BIOME_TINT = ColorParseUtil.colorToARGBInt(PrefabEditSessionManager.DEFAULT_TINT) & 16777215;
   class="kw">private class="kw">static class="kw">final int DEFAULT_WATER_TINT = ColorParseUtil.colorToARGBInt(Environment.getUnknownFor("").getWaterTint()) & 16777215;

   class="kw">public PrefabPage(@Nonnull PlayerRef var1, @Nonnull BuilderToolsPlugin.BuilderState var2) {
      super(var1, CustomPageLifetime.CanDismiss, FileBrowserEventData.CODEC);
      this.builderState = var2;
      this.assetProvider = new AssetPrefabFileProvider();
      boolean var3 = PrefabStore.get().getAllBrowsablePrefabPaths().size() > 1;
      Path var4 = var3 ? Paths.get("") : Paths.get("HytaleAssets");
      Path var5 = var2.getPrefabListPath();
      this.assetsCurrentDir = this.isValidDir(var5, var3) ? var5 : var4;
      FileBrowserConfig var6 = FileBrowserConfig.builder()
         .listElementId("#FileList")
         .searchInputId("#SearchInput")
         .roots(List.of())
         .allowedExtensions(".prefab.json", ".lpf")
         .enableRootSelector(false)
         .enableSearch(true)
         .enableDirectoryNav(true)
         .maxResults(50)
         .build();
      String var7 = var2.getPrefabListSearchQuery();
      this.browser = new ServerFileBrowser(var6, Paths.get("HytaleAssets"), null);
      if (var7 != null && !var7.isEmpty()) {
         this.browser.setSearchQuery(var7);
      }
   }

   @Override
   class="kw">public void build(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4) {
      var2.append("Pages/PrefabListPage.ui");
      this.browser.buildSearchInput(var2, var3);
      this.buildPersistentBindings(var3);
      this.buildCurrentPath(var2);
      this.buildFileList(var2, var3);
      this.buildLoadButton(var2, var3);
   }

   class="kw">private void buildPersistentBindings(@Nonnull UIEventBuilder var1) {
      var1.addEventBinding(CustomUIEventBindingType.Activating, "#HomeButton", EventData.of("File", "~"));
   }

   class="kw">public void handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull FileBrowserEventData var3) {
      if (var3.getSearchQuery() != null) {
         this.browser.handleEvent(var3);
         this.builderState.setPrefabListSearchQuery(this.browser.getSearchQuery());
         this.sendListingUpdate(false);
      } else if (var3.isBrowseRequested()) {
         Path var5 = this.previewedPath;
         if (var3.getPreview() != null) {
            var5 = this.resolvePreviewPath(var3.getPreview());
         }

         if (var5 != null) {
            this.handlePrefabSelection(var1, var2, var5, var5.getFileName().toString());
         }
      } else if (var3.getPreview() != null) {
         this.handlePreviewRequest(var3.getPreview());
      } else {
         String var4 = var3.getSearchResult() != null ? var3.getSearchResult() : var3.getFile();
         if (var4 != null) {
            this.handleAssetsNavigation(var1, var2, var4, var3.getSearchResult() != null);
         }
      }
   }

   class="kw">private void handleAssetsNavigation(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull String var3, boolean var4) {
      if ("~".equals(var3)) {
         boolean var7 = PrefabStore.get().getAllBrowsablePrefabPaths().size() > 1;
         this.setCurrentDir(var7 ? Paths.get("") : Paths.get("HytaleAssets"));
         this.browser.setSearchQuery("");
         this.builderState.setPrefabListSearchQuery(null);
         this.sendListingUpdate(true);
      } else if ("..".equals(var3)) {
         if (this.assetsCurrentDir.getNameCount() > 1) {
            this.setCurrentDir(this.assetsCurrentDir.getParent());
         } else if (this.assetsCurrentDir.getNameCount() == 1) {
            this.setCurrentDir(Paths.get(""));
         }

         this.sendListingUpdate(false);
      } else {
         String var5;
         if (var4) {
            var5 = var3;
         } else {
            var5 = this.assetsCurrentDir.toString().isEmpty() ? var3 : this.assetsCurrentDir.toString().replace('\\', '/') + "/" + var3;
         }

         Path var6 = this.assetProvider.resolveVirtualPath(var5);
         if (var6 == null) {
            this.sendUpdate();
         } else {
            if (Files.isDirectory(var6)) {
               this.setCurrentDir(Paths.get(var5));
               this.sendListingUpdate(false);
            } else {
               this.handlePreviewRequest(var3);
            }
         }
      }
   }

   class="kw">private void buildLoadButton(@Nonnull UICommandBuilder var1, @Nonnull UIEventBuilder var2) {
      boolean var3 = this.previewedPath != null;
      var1.set("#LoadButton.Visible", var3);
      var2.addEventBinding(CustomUIEventBindingType.Activating, "#LoadButton", EventData.of("Browse", "true"));
   }

   @Nullable
   class="kw">private Path resolvePreviewPath(@Nonnull String var1) {
      String var2 = var1.contains("/") ? var1 : this.assetsCurrentDir.toString().replace('\\', '/') + "/" + var1;
      Path var3 = this.assetProvider.resolveVirtualPath(var2);
      class="kw">return var3 != null && Files.isRegularFile(var3) ? var3 : null;
   }

   class="kw">private void handlePreviewRequest(@Nonnull String var1) {
      Path var2 = this.resolvePreviewPath(var1);
      if (var2 == null) {
         this.sendUpdate();
      } else if (var2.equals(this.previewedPath)) {
         this.sendUpdate();
      } else {
         this.previewedFileName = var1;
         if (isTooLargeToPreview(var2)) {
            this.previewedPath = var2;
            this.sendTooLargePreviewMessage(var2);
         } else {
            this.previewedPath = var2;
            BlockSelection var3 = PrefabStore.get().getPrefab(var2);
            if (var3 != null) {
               this.sendPreviewPacket(var3);
               UICommandBuilder var4 = new UICommandBuilder();
               UIEventBuilder var5 = new UIEventBuilder();
               this.buildPersistentBindings(var5);
               this.buildFileList(var4, var5);
               this.buildLoadButton(var4, var5);
               var4.set("#PreviewMessage.Visible", false);
               this.sendUpdate(var4, var5, false);
            }
         }
      }
   }

   class="kw">private void sendTooLargePreviewMessage(@Nonnull Path var1) {
      this.sendPreviewPacket(null);
      UICommandBuilder var2 = new UICommandBuilder();
      UIEventBuilder var3 = new UIEventBuilder();
      this.buildPersistentBindings(var3);
      this.buildFileList(var2, var3);
      this.buildLoadButton(var2, var3);
      var2.set(
         "#PreviewMessage.Text",
         Message.translation("server.builderTools.prefabTooLargeToPreview")
            .param("name", AssetPrefabFileProvider.removeExtension(var1.getFileName().toString()))
      );
      var2.set("#PreviewMessage.Visible", true);
      this.sendUpdate(var2, var3, false);
   }

   class="kw">private class="kw">static boolean isTooLargeToPreview(@Nonnull Path var0) {
      try {
         long var1 = var0.getFileName().toString().endsWith(".lpf") ? 13421772L : 134217728L;
         class="kw">return Files.size(var0) > var1;
      } catch (IOException var3) {
         class="kw">return false;
      }
   }

   class="kw">private void sendPreviewPacket(@Nullable BlockSelection var1) {
      BuilderToolPrefabPreview var2 = new BuilderToolPrefabPreview();
      if (var1 != null) {
         var2.tilt = 23;
         var2.spinSpeed = 27;
         var2.previewScale = 100;
         if (var1.getBlockCount() > 4000000) {
            var2.blocksOmitted = true;
            var2.bounds = var1.toEditorSelectionBounds();
         } else {
            EditorBlocksChange var3 = var1.toPacket();
            var2.blocksChange = var3.blocksChange;
            var2.fluidsChange = var3.fluidsChange;
            var2.entityChanges = var3.entityChanges;
         }

         this.applyTintFromPlayerPosition(var2);
      }

      this.playerRef.getPacketHandler().write(var2);
   }

   class="kw">private void applyTintFromPlayerPosition(BuilderToolPrefabPreview var1) {
      Ref var2 = this.playerRef.getReference();
      if (var2 == null) {
         var1.biomeTint = DEFAULT_BIOME_TINT;
         var1.waterTint = DEFAULT_WATER_TINT;
      } else {
         Store var3 = var2.getStore();
         World var4 = var3.getExternalData().getWorld();
         Vector3d var5 = this.playerRef.getTransform().getPosition();
         int var6 = MathUtil.floor(var5.x);
         int var7 = MathUtil.floor(var5.y);
         int var8 = MathUtil.floor(var5.z);
         long var9 = ChunkUtil.indexChunkFromBlock(var6, var8);
         WorldChunk var11 = var4.getNonTickingChunk(var9);
         if (var11 != null && var11.getBlockChunk() != null) {
            BlockChunk var12 = var11.getBlockChunk();
            var1.biomeTint = var12.getTint(var6, var8);
            int var13 = var12.getEnvironment(var6, var7, var8);
            Environment var14 = Environment.getAssetMap().getAsset(var13);
            if (var14 != null) {
               Color var15 = var14.getWaterTint();
               if (var15 != null) {
                  var1.waterTint = (var15.red & 255) << 16 | (var15.green & 255) << 8 | var15.blue & 255;
                  class="kw">return;
               }
            }

            var1.waterTint = DEFAULT_WATER_TINT;
         } else {
            var1.biomeTint = DEFAULT_BIOME_TINT;
            var1.waterTint = DEFAULT_WATER_TINT;
         }
      }
   }

   class="kw">private void clearPreview() {
      this.previewedPath = null;
      this.previewedFileName = null;
      this.sendPreviewPacket(null);
   }

   class="kw">private void handlePrefabSelection(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull Path var3, @Nonnull String var4) {
      Player var5 = var2.getComponent(var1, Player.getComponentType());
      assert var5 != null;
      if (var5.getGameMode() != GameMode.Creative) {
         var5.getPageManager().setPage(var1, var2, Page.None);
      } else {
         PlayerRef var6 = var2.getComponent(var1, PlayerRef.getComponentType());
         assert var6 != null;
         this.clearPreview();
         var5.getPageManager().setPage(var1, var2, Page.None);
         BlockSelection var7 = PrefabStore.get().getPrefab(var3);
         if (var7 != null) {
            BuilderToolsPlugin.addToQueue(var5, var6, (var2x, var3x, var4x) -> var3x.load(var4, var7, var4x));
            PasteToolUtil.switchToPasteTool(var1, var6, var2);
         }
      }
   }

   class="kw">private void sendListingUpdate(boolean var1) {
      UICommandBuilder var2 = new UICommandBuilder();
      UIEventBuilder var3 = new UIEventBuilder();
      this.buildPersistentBindings(var3);
      if (var1) {
         this.browser.buildSearchInput(var2, var3);
      }

      this.buildCurrentPath(var2);
      this.buildFileList(var2, var3);
      var2.set("#PreviewMessage.Visible", false);
      this.sendUpdate(var2, var3, false);
   }

   class="kw">private void buildCurrentPath(@Nonnull UICommandBuilder var1) {
      String var2 = this.assetsCurrentDir.toString().replace('\\', '/');
      String[] var3 = var2.split("/", 2);
      String var4 = var3.length > 1 ? var3[1] : "/";
      var1.set("#CurrentPath.Text", var4);
   }

   class="kw">private void setCurrentDir(@Nonnull Path var1) {
      this.assetsCurrentDir = var1;
      this.builderState.setPrefabListPath(var1);
   }

   class="kw">private boolean isValidDir(@Nullable Path var1, boolean var2) {
      if (var1 == null) {
         class="kw">return false;
      }

      String var3 = var1.toString().replace('\\', '/');
      if (var3.isEmpty()) {
         class="kw">return var2;
      }

      Path var4 = this.assetProvider.resolveVirtualPath(var3);
      class="kw">return var4 != null && Files.isDirectory(var4);
   }

   class="kw">private void buildFileList(@Nonnull UICommandBuilder var1, @Nonnull UIEventBuilder var2) {
      var1.clear("#FileList");
      List var3 = this.assetProvider.getFiles(this.assetsCurrentDir, this.browser.getSearchQuery());
      int var4 = 0;
      boolean var5 = this.assetsCurrentDir.getNameCount() >= 1 && !this.assetsCurrentDir.toString().isEmpty();
      if (var5 && this.browser.getSearchQuery().isEmpty()) {
         var1.append("#FileList", "Pages/BasicTextButton.ui");
         var1.set("#FileList[0].Text", "../");
         var2.addEventBinding(CustomUIEventBindingType.Activating, "#FileList[0]", EventData.of("File", ".."));
         var4++;
      }

      for (FileListProvider.FileEntry var7 : var3) {
         String var8 = var7.isDirectory() ? var7.displayName() + "/" : var7.displayName();
         String var9 = "#FileList[" + var4 + "]";
         var1.append("#FileList", "Pages/BasicTextButton.ui");
         var1.set(var9 + ".Text", var8);
         boolean var10 = !var7.isDirectory();
         if (var10) {
            boolean var11 = var7.name().equals(this.previewedFileName);
            var1.set(var9 + ".Style", Value.ref("Pages/BasicTextButton.ui", var11 ? "ActiveLabelStyle" : "SelectedLabelStyle"));
         }

         String var12 = !this.browser.getSearchQuery().isEmpty() && var10 ? "SearchResult" : "File";
         if (var10) {
            var2.addEventBinding(CustomUIEventBindingType.Activating, var9, EventData.of("Preview", var7.name()), false);
            var2.addEventBinding(CustomUIEventBindingType.DoubleClicking, var9, EventData.of("Browse", "true").append("Preview", var7.name()));
         } else {
            var2.addEventBinding(CustomUIEventBindingType.Activating, var9, EventData.of(var12, var7.name()));
         }

         var4++;
      }
   }

   @Override
   class="kw">public void onDismiss(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2) {
      this.clearPreview();
   }
}