UIGalleryEventData class

Пакет: com.hypixel.hytale.server.core.command.system.pages

Файл: com/hypixel/hytale/server/core/command/system/pages/UIGalleryPage.java

Поля (5)

МодификаторыТипИмя
public static final BuilderCodec<UIGalleryPage.UIGalleryEventData> CODEC
static final String KEY_CATEGORY
static final String KEY_TOGGLE_CODE
private String category
private String toggleCode

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.command.system.pages;

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.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
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.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.pages.InteractiveCustomUIPage;
class="kw">import com.hypixel.hytale.server.core.ui.Value;
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 it.unimi.dsi.fastutil.ints.IntOpenHashSet;
class="kw">import it.unimi.dsi.fastutil.ints.IntSet;
class="kw">import javax.annotation.Nonnull;

class="kw">public class UIGalleryPage class="kw">extends InteractiveCustomUIPage<UIGalleryPage.UIGalleryEventData> {
   class="kw">private class="kw">static class="kw">final Value<String> CATEGORY_BUTTON_STYLE = Value.ref("Pages/UIGallery/CategoryButton.ui", "LabelStyle");
   class="kw">private class="kw">static class="kw">final Value<String> CATEGORY_BUTTON_SELECTED_STYLE = Value.ref("Pages/UIGallery/CategoryButton.ui", "SelectedLabelStyle");
   class="kw">private UIGalleryPage.Category selectedCategory = UIGalleryPage.Category.BUTTONS;
   class="kw">private class="kw">final IntSet expandedCodeBlocks = new IntOpenHashSet();

   class="kw">public UIGalleryPage(@Nonnull PlayerRef var1) {
      super(var1, CustomPageLifetime.CanDismiss, UIGalleryPage.UIGalleryEventData.CODEC);
   }

   @Override
   class="kw">public void build(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4) {
      var2.append("Pages/UIGallery/UIGalleryPage.ui");
      this.buildCategoryList(var2, var3);
      this.displayCategory(this.selectedCategory, var2, var3);
   }

   class="kw">public void handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull UIGalleryPage.UIGalleryEventData var3) {
      UICommandBuilder var4 = new UICommandBuilder();
      UIEventBuilder var5 = new UIEventBuilder();
      if (var3.category != null) {
         UIGalleryPage.Category var6 = UIGalleryPage.Category.fromId(var3.category);
         if (var6 != this.selectedCategory) {
            int var7 = this.selectedCategory.ordinal();
            var4.set("#CategoryList[" + var7 + "].Style", CATEGORY_BUTTON_STYLE);
            int var8 = var6.ordinal();
            var4.set("#CategoryList[" + var8 + "].Style", CATEGORY_BUTTON_SELECTED_STYLE);
            this.expandedCodeBlocks.clear();
            this.selectedCategory = var6;
            this.displayCategory(this.selectedCategory, var4, var5);
         }

         this.sendUpdate(var4, var5, false);
      } else if (var3.toggleCode != null) {
         try {
            int var10 = Integer.parseInt(var3.toggleCode);
            this.toggleCodeBlock(var10, var4);
            this.sendUpdate(var4, var5, false);
         } catch (NumberFormatException var9) {
         }
      }
   }

   class="kw">private void buildCategoryList(@Nonnull UICommandBuilder var1, @Nonnull UIEventBuilder var2) {
      var1.clear("#CategoryList");

      for (int var3 = 0; var3 < UIGalleryPage.Category.values().length; var3++) {
         UIGalleryPage.Category var4 = UIGalleryPage.Category.values()[var3];
         var1.append("#CategoryList", "Pages/UIGallery/CategoryButton.ui");
         var1.set("#CategoryList[" + var3 + "].TextSpans", Message.translation(var4.getNameKey()));
         if (var4 == this.selectedCategory) {
            var1.set("#CategoryList[" + var3 + "].Style", CATEGORY_BUTTON_SELECTED_STYLE);
         }

         var2.addEventBinding(CustomUIEventBindingType.Activating, "#CategoryList[" + var3 + "]", EventData.of("Category", var4.getId()));
      }
   }

   class="kw">private void displayCategory(@Nonnull UIGalleryPage.Category var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3) {
      var2.set("#CategoryTitle.TextSpans", Message.translation(var1.getNameKey()));
      var2.set("#CategoryDescription.TextSpans", Message.translation(var1.getDescriptionKey()));
      var2.clear("#CategoryContent");
      var2.append("#CategoryContent", var1.getContentPath());

      for (int var4 = 0; var4 < var1.getCodeBlockCount(); var4++) {
         String var5 = "#CategoryContent #Code" + var4 + " #ToggleCode";
         var3.addEventBinding(CustomUIEventBindingType.Activating, var5, EventData.of("ToggleCode", String.valueOf(var4)));
      }
   }

   class="kw">private void toggleCodeBlock(int var1, @Nonnull UICommandBuilder var2) {
      String var3 = "#CategoryContent #Code" + var1 + " #CodeContainer";
      String var4 = "#CategoryContent #Code" + var1 + " #ToggleCode";
      if (this.expandedCodeBlocks.contains(var1)) {
         this.expandedCodeBlocks.remove(var1);
         var2.set(var3 + ".Visible", false);
         var2.set(var4 + ".TextSpans", Message.raw("Show Code"));
      } else {
         this.expandedCodeBlocks.add(var1);
         var2.set(var3 + ".Visible", true);
         var2.set(var4 + ".TextSpans", Message.raw("Hide Code"));
      }
   }

   class="kw">private enum Category {
      BUTTONS(
         "buttons",
         "server.customUI.uiGallery.category.buttons",
         "server.customUI.uiGallery.category.buttons.desc",
         "Pages/UIGallery/Categories/ButtonsContent.ui",
         7
      ),
      INPUTS(
         "inputs",
         "server.customUI.uiGallery.category.inputs",
         "server.customUI.uiGallery.category.inputs.desc",
         "Pages/UIGallery/Categories/InputsContent.ui",
         4
      ),
      SELECTION(
         "selection",
         "server.customUI.uiGallery.category.selection",
         "server.customUI.uiGallery.category.selection.desc",
         "Pages/UIGallery/Categories/SelectionContent.ui",
         4
      ),
      CONTAINERS(
         "containers",
         "server.customUI.uiGallery.category.containers",
         "server.customUI.uiGallery.category.containers.desc",
         "Pages/UIGallery/Categories/ContainersContent.ui",
         7
      ),
      TEXT("text", "server.customUI.uiGallery.category.text", "server.customUI.uiGallery.category.text.desc", "Pages/UIGallery/Categories/TextContent.ui", 3),
      SLIDERS(
         "sliders",
         "server.customUI.uiGallery.category.sliders",
         "server.customUI.uiGallery.category.sliders.desc",
         "Pages/UIGallery/Categories/SlidersContent.ui",
         3
      ),
      PROGRESS(
         "progress",
         "server.customUI.uiGallery.category.progress",
         "server.customUI.uiGallery.category.progress.desc",
         "Pages/UIGallery/Categories/ProgressContent.ui",
         3
      ),
      SCROLLBARS(
         "scrollbars",
         "server.customUI.uiGallery.category.scrollbars",
         "server.customUI.uiGallery.category.scrollbars.desc",
         "Pages/UIGallery/Categories/ScrollbarsContent.ui",
         3
      ),
      NAVIGATION(
         "navigation",
         "server.customUI.uiGallery.category.navigation",
         "server.customUI.uiGallery.category.navigation.desc",
         "Pages/UIGallery/Categories/NavigationContent.ui",
         2
      ),
      TOOLTIPS(
         "tooltips",
         "server.customUI.uiGallery.category.tooltips",
         "server.customUI.uiGallery.category.tooltips.desc",
         "Pages/UIGallery/Categories/TooltipsContent.ui",
         2
      );

      class="kw">private class="kw">final String id;
      class="kw">private class="kw">final String nameKey;
      class="kw">private class="kw">final String descriptionKey;
      class="kw">private class="kw">final String contentPath;
      class="kw">private class="kw">final int codeBlockCount;

      Category(String nullxx, String nullxxx, String nullxxxx, String nullxxxxx, int nullxxxxxx) {
         this.id = nullxx;
         this.nameKey = nullxxx;
         this.descriptionKey = nullxxxx;
         this.contentPath = nullxxxxx;
         this.codeBlockCount = nullxxxxxx;
      }

      class="kw">public String getId() {
         class="kw">return this.id;
      }

      class="kw">public String getNameKey() {
         class="kw">return this.nameKey;
      }

      class="kw">public String getDescriptionKey() {
         class="kw">return this.descriptionKey;
      }

      class="kw">public String getContentPath() {
         class="kw">return this.contentPath;
      }

      class="kw">public int getCodeBlockCount() {
         class="kw">return this.codeBlockCount;
      }

      class="kw">public class="kw">static UIGalleryPage.Category fromId(String var0) {
         for (UIGalleryPage.Category var4 : values()) {
            if (var4.id.equals(var0)) {
               class="kw">return var4;
            }
         }

         class="kw">return BUTTONS;
      }
   }

   class="kw">public class="kw">static class UIGalleryEventData {
      class="kw">static class="kw">final String KEY_CATEGORY = "Category";
      class="kw">static class="kw">final String KEY_TOGGLE_CODE = "ToggleCode";
      class="kw">public class="kw">static class="kw">final BuilderCodec<UIGalleryPage.UIGalleryEventData> CODEC = BuilderCodec.builder(
            UIGalleryPage.UIGalleryEventData.class, UIGalleryPage.UIGalleryEventData::new
         )
         .addField(new KeyedCodec<>("Category", Codec.STRING), (var0, var1) -> var0.category = var1, var0 -> var0.category)
         .addField(new KeyedCodec<>("ToggleCode", Codec.STRING), (var0, var1) -> var0.toggleCode = var1, var0 -> var0.toggleCode)
         .build();
      class="kw">private String category;
      class="kw">private String toggleCode;

      class="kw">public UIGalleryEventData() {
      }
   }
}