ChangeModelPage class
Пакет: com.hypixel.hytale.builtin.model.pages
Файл: com/hypixel/hytale/builtin/model/pages/ChangeModelPage.java
extends: InteractiveCustomUIPage<ChangeModelPage.PageEventData>
Поля (38)
| Модификаторы | Тип | Имя |
|---|---|---|
|
public static final BuilderCodec<ChangeModelPage.PageEventData> |
CODEC |
|
static final String |
KEY_MODEL |
|
static final String |
KEY_SCALE |
|
static final String |
KEY_SEARCH_QUERY |
|
static final String |
KEY_TYPE |
|
|
break |
|
|
break |
|
|
break |
|
private String |
model |
|
|
return |
|
private float |
scale |
|
private String |
searchQuery |
|
private String |
type |
|
int |
var10 |
|
Vector3d |
var10 |
|
Model |
var11 |
|
Vector3d |
var11 |
|
UICommandBuilder |
var12 |
|
String |
var12 |
|
Rotation3f |
var12 |
|
String |
var13 |
|
Holder |
var13 |
|
ModelAsset |
var2 |
|
UICommandBuilder |
var4 |
|
UIEventBuilder |
var5 |
|
Set |
var5 |
|
TransformComponent |
var5 |
|
PlayerSkinComponent |
var6 |
|
Object2IntMap |
var6 |
|
HeadRotation |
var6 |
|
PlayerSkinComponent |
var7 |
|
Vector3d |
var7 |
|
Model |
var8 |
|
Rotation3f |
var8 |
|
int |
var9 |
|
Vector3d |
var9 |
|
|
var9 |
|
|
var9 |
Методы (16)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
public |
PageEventDatapublic PageEventData() |
private |
void |
buildModelListvoid buildModelList(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull UICommandBuilder var3, @Nonnull UIEventBuilder var4) |
|
|
for for(String var8 : var5) |
abstract |
|
for for(int var11 = this.models.size() |
public |
void |
handleDataEventvoid handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull ChangeModelPage.PageEventData var3) |
|
|
if if(var3.searchQuery != null) |
|
|
if if(var3.model != null) |
|
|
if if(var3.scale > 0.0F) |
|
|
if if(this.selectedModel != null) |
|
|
if if(var6 == null) |
|
|
if if(var9 > 0) |
|
|
if if(var9 == null) |
|
|
if if(var10 != null) |
private |
void |
selectModelvoid selectModel(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull String var3, @Nonnull UICommandBuilder var4) |
abstract |
|
super super(var1, CustomPageLifetime.CanDismiss, ChangeModelPage.PageEventData.CODEC) |
|
|
switch switch(var3.type) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.model.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.common.util.StringCompareUtil;
class="kw">import com.hypixel.hytale.component.AddReason;
class="kw">import com.hypixel.hytale.component.Holder;
class="kw">import com.hypixel.hytale.component.NonSerialized;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.RemoveReason;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.math.vector.Transform;
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.asset.type.model.config.Model;
class="kw">import com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset;
class="kw">import com.hypixel.hytale.server.core.cosmetics.CosmeticsModule;
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.entity.component.HeadRotation;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.player.PlayerSkinComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId;
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 com.hypixel.hytale.server.core.util.TargetUtil;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntMap;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
class="kw">import java.util.Comparator;
class="kw">import java.util.List;
class="kw">import java.util.Locale;
class="kw">import java.util.Set;
class="kw">import java.util.stream.Collectors;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">public class ChangeModelPage class="kw">extends InteractiveCustomUIPage<ChangeModelPage.PageEventData> {
@Nonnull
class="kw">private class="kw">static class="kw">final String COMMON_TEXT_BUTTON_DOCUMENT = "Common/TextButton.ui";
@Nonnull
class="kw">private class="kw">static class="kw">final Value<String> BUTTON_LABEL_STYLE = Value.ref("Common/TextButton.ui", "LabelStyle");
@Nonnull
class="kw">private class="kw">static class="kw">final Value<String> BUTTON_LABEL_STYLE_SELECTED = Value.ref("Common/TextButton.ui", "SelectedLabelStyle");
@Nonnull
class="kw">private String searchQuery = "";
class="kw">private List<String> models;
@Nullable
class="kw">private String selectedModel;
@Nullable
class="kw">private Ref<EntityStore> modelPreview;
class="kw">private Vector3d position;
class="kw">private Rotation3f rotation;
class="kw">private float scale = 1.0F;
class="kw">public ChangeModelPage(@Nonnull PlayerRef var1) {
super(var1, CustomPageLifetime.CanDismiss, ChangeModelPage.PageEventData.CODEC);
}
@Override
class="kw">public void build(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4) {
var2.append("Pages/ChangeModelPage.ui");
var3.addEventBinding(CustomUIEventBindingType.ValueChanged, "#SearchInput", EventData.of("@SearchQuery", "#SearchInput.Value"), false);
var3.addEventBinding(
CustomUIEventBindingType.ValueChanged, "#Scale", new EventData().append("Type", "UpdateScale").append("@Scale", "#Scale.Value"), false
);
var3.addEventBinding(CustomUIEventBindingType.Activating, "#ChangeModel", new EventData().append("Type", "ChangeModel"), false);
var3.addEventBinding(CustomUIEventBindingType.Activating, "#ResetModel", new EventData().append("Type", "ResetModel"), false);
this.buildModelList(var1, var4, var2, var3);
}
class="kw">public void handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull ChangeModelPage.PageEventData var3) {
if (var3.searchQuery != null) {
this.searchQuery = var3.searchQuery.trim().toLowerCase(Locale.ROOT);
UICommandBuilder var4 = new UICommandBuilder();
UIEventBuilder var5 = new UIEventBuilder();
this.buildModelList(var1, var2, var4, var5);
this.sendUpdate(var4, var5, false);
} else if (var3.type != null) {
class="kw">switch (var3.type) {
case "Select":
if (var3.model != null) {
UICommandBuilder var12 = new UICommandBuilder();
this.selectModel(var1, var2, var3.model, var12);
this.sendUpdate(var12, null, false);
}
break;
case "UpdateScale":
if (var3.scale > 0.0F) {
this.scale = var3.scale;
if (this.modelPreview != null && this.modelPreview.isValid()) {
var2.putComponent(this.modelPreview, ModelComponent.getComponentType(), new ModelComponent(this.getModel(this.scale)));
}
}
break;
case "ChangeModel":
if (this.selectedModel != null) {
if (this.modelPreview.isValid()) {
var2.removeEntity(this.modelPreview, RemoveReason.REMOVE);
}
Model var11 = this.getModel(this.scale);
var2.putComponent(var1, ModelComponent.getComponentType(), new ModelComponent(var11));
var2.getComponent(var1, Player.getComponentType()).getPageManager().setPage(var1, var2, Page.None);
}
break;
case "ResetModel":
PlayerSkinComponent var6 = var2.getComponent(var1, PlayerSkinComponent.getComponentType());
if (var6 == null) {
class="kw">return;
}
PlayerSkinComponent var7 = var2.getComponent(var1, PlayerSkinComponent.getComponentType());
Model var8 = CosmeticsModule.get().createModel(var7.getPlayerSkin());
var2.putComponent(var1, ModelComponent.getComponentType(), new ModelComponent(var8));
var7.setNetworkOutdated();
}
}
}
@Override
class="kw">public void onDismiss(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2) {
if (this.modelPreview != null && this.modelPreview.isValid()) {
var2.removeEntity(this.modelPreview, RemoveReason.REMOVE);
}
}
class="kw">private void buildModelList(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull UICommandBuilder var3, @Nonnull UIEventBuilder var4) {
var3.clear("#ModelList");
Set var5 = ModelAsset.getAssetMap().getAssetMap().keySet();
if (!this.searchQuery.isEmpty()) {
Object2IntMap var6 = new Object2IntOpenHashMap(var5.size());
for (String var8 : var5) {
int var9 = StringCompareUtil.getFuzzyDistance(var8, this.searchQuery, Locale.ENGLISH);
if (var9 > 0) {
var6.put(var8, var9);
}
}
this.models = var6.keySet().stream().sorted().sorted(Comparator.comparingInt(var6::getInt).reversed()).limit(20L).collect(Collectors.toList());
} else {
this.models = var5.stream().sorted().sorted(String::compareTo).collect(Collectors.toList());
}
int var10 = 0;
for (int var11 = this.models.size(); var10 < var11; var10++) {
String var12 = this.models.get(var10);
String var13 = "#ModelList[" + var10 + "]";
var3.append("#ModelList", "Common/TextButton.ui");
var3.set(var13 + " #Button.Text", var12);
var4.addEventBinding(CustomUIEventBindingType.Activating, var13 + " #Button", new EventData().append("Type", "Select").append("Model", var12), false);
}
if (!this.models.isEmpty()) {
if (!this.models.contains(this.selectedModel)) {
this.selectModel(var1, var2, this.models.getFirst(), var3);
} else if (this.selectedModel != null) {
this.selectModel(var1, var2, this.selectedModel, var3);
}
}
}
class="kw">private void selectModel(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull String var3, @Nonnull UICommandBuilder var4) {
if (this.selectedModel != null && this.models.contains(this.selectedModel)) {
var4.set("#ModelList[" + this.models.indexOf(this.selectedModel) + "] #Button.Style", BUTTON_LABEL_STYLE);
}
var4.set("#ModelList[" + this.models.indexOf(var3) + "] #Button.Style", BUTTON_LABEL_STYLE_SELECTED);
var4.set("#ModelName.Text", var3);
this.selectedModel = var3;
if (this.modelPreview == null || !this.modelPreview.isValid()) {
TransformComponent var5 = var2.getComponent(var1, TransformComponent.getComponentType());
assert var5 != null;
HeadRotation var6 = var2.getComponent(var1, HeadRotation.getComponentType());
assert var6 != null;
Vector3d var7 = var5.getPosition();
Rotation3f var8 = var6.getRotation();
Vector3d var9 = TargetUtil.getTargetLocation(var1, 8.0, var2);
if (var9 == null) {
var9 = new Vector3d(var7).add(Transform.getDirection(var8.pitch(), var8.yaw()).mul(4.0));
}
Vector3d var10 = TargetUtil.getTargetLocation(var2.getExternalData().getWorld(), var0 -> var0 != 0, var9.x, var9.y, var9.z, 0.0, -1.0, 0.0, 8.0);
if (var10 != null) {
var9 = var10;
}
Vector3d var11 = new Vector3d(var7).sub(var9);
var11.y = 0.0;
Rotation3f var12 = Rotation3f.lookAt(var11);
this.position = var9;
this.rotation = var12;
Holder var13 = var2.getRegistry().newHolder();
var13.addComponent(NetworkId.getComponentType(), new NetworkId(var2.getExternalData().takeNextNetworkId()));
var13.addComponent(EntityStore.REGISTRY.getNonSerializedComponentType(), NonSerialized.get());
var13.addComponent(TransformComponent.getComponentType(), new TransformComponent(var9, var12));
var13.addComponent(ModelComponent.getComponentType(), new ModelComponent(this.getModel(this.scale)));
var13.addComponent(HeadRotation.getComponentType(), new HeadRotation(var12));
this.modelPreview = var2.addEntity(var13, AddReason.SPAWN);
} else if (this.modelPreview != null && this.modelPreview.isValid()) {
var2.putComponent(this.modelPreview, ModelComponent.getComponentType(), new ModelComponent(this.getModel(1.0F)));
}
}
@Nullable
class="kw">private Model getModel(float var1) {
ModelAsset var2 = ModelAsset.getAssetMap().getAsset(this.selectedModel);
class="kw">return Model.createScaledModel(var2, var1);
}
class="kw">public class="kw">static class PageEventData {
@Nonnull
class="kw">static class="kw">final String KEY_MODEL = "Model";
@Nonnull
class="kw">static class="kw">final String KEY_TYPE = "Type";
@Nonnull
class="kw">static class="kw">final String KEY_SEARCH_QUERY = "@SearchQuery";
@Nonnull
class="kw">static class="kw">final String KEY_SCALE = "@Scale";
@Nonnull
class="kw">public class="kw">static class="kw">final BuilderCodec<ChangeModelPage.PageEventData> CODEC = BuilderCodec.builder(
ChangeModelPage.PageEventData.class, ChangeModelPage.PageEventData::new
)
.append(new KeyedCodec<>("Model", Codec.STRING), (var0, var1) -> var0.model = var1, var0 -> var0.model)
.add()
.append(new KeyedCodec<>("Type", Codec.STRING), (var0, var1) -> var0.type = var1, var0 -> var0.type)
.add()
.append(new KeyedCodec<>("@SearchQuery", Codec.STRING), (var0, var1) -> var0.searchQuery = var1, var0 -> var0.searchQuery)
.add()
.append(new KeyedCodec<>("@Scale", Codec.FLOAT), (var0, var1) -> var0.scale = var1, var0 -> var0.scale)
.add()
.build();
class="kw">private String model;
class="kw">private String type;
class="kw">private String searchQuery;
class="kw">private float scale;
class="kw">public PageEventData() {
}
}
}