PlaySoundPageEventData class
Пакет: com.hypixel.hytale.server.core.entity.entities.player.pages.audio
Файл: com/hypixel/hytale/server/core/entity/entities/player/pages/audio/PlaySoundPage.java
Поля (11)
| Модификаторы | Тип | Имя |
|---|---|---|
|
public static final BuilderCodec<PlaySoundPage.PlaySoundPageEventData> |
CODEC |
|
static final String |
KEY_PITCH |
|
static final String |
KEY_SEARCH_QUERY |
|
static final String |
KEY_SOUND_EVENT |
|
static final String |
KEY_TYPE |
|
static final String |
KEY_VOLUME |
|
private Float |
pitch |
|
private String |
searchQuery |
|
private String |
soundEvent |
|
private String |
type |
|
private Float |
volume |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.entity.entities.player.pages.audio;
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.AudioUtil;
class="kw">import com.hypixel.hytale.common.util.StringCompareUtil;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.protocol.SoundCategory;
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.asset.type.soundevent.config.SoundEvent;
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.SoundUtil;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
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.stream.Collectors;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class PlaySoundPage class="kw">extends InteractiveCustomUIPage<PlaySoundPage.PlaySoundPageEventData> {
class="kw">private class="kw">static class="kw">final String COMMON_TEXT_BUTTON_DOCUMENT = "Common/TextButton.ui";
class="kw">private class="kw">static class="kw">final Value<String> BUTTON_LABEL_STYLE = Value.ref("Common/TextButton.ui", "LabelStyle");
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> soundEvents;
@Nullable
class="kw">private String selectedSoundEvent;
class="kw">private float volumeDecibels = 0.0F;
class="kw">private float pitchSemitones = 0.0F;
class="kw">public PlaySoundPage(@Nonnull PlayerRef var1) {
super(var1, CustomPageLifetime.CanDismiss, PlaySoundPage.PlaySoundPageEventData.CODEC);
}
@Override
class="kw">public void build(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4) {
var2.append("Pages/PlaySoundPage.ui");
var3.addEventBinding(CustomUIEventBindingType.ValueChanged, "#SearchInput", EventData.of("@SearchQuery", "#SearchInput.Value"), false);
var3.addEventBinding(CustomUIEventBindingType.ValueChanged, "#VolumeSlider", EventData.of("@Volume", "#VolumeSlider.Value"), false);
var3.addEventBinding(CustomUIEventBindingType.ValueChanged, "#PitchSlider", EventData.of("@Pitch", "#PitchSlider.Value"), false);
var3.addEventBinding(CustomUIEventBindingType.Activating, "#Play", new EventData().append("Type", "Play"), false);
this.buildSoundEventList(var1, var2, var3, var4);
}
class="kw">public void handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull PlaySoundPage.PlaySoundPageEventData var3) {
if (var3.searchQuery != null) {
this.searchQuery = var3.searchQuery.trim().toLowerCase(Locale.ROOT);
UICommandBuilder var4 = new UICommandBuilder();
UIEventBuilder var5 = new UIEventBuilder();
this.buildSoundEventList(var1, var4, var5, var2);
this.sendUpdate(var4, var5, false);
} else if (var3.volume != null) {
this.volumeDecibels = var3.volume;
UICommandBuilder var9 = new UICommandBuilder();
var9.set("#VolumeValue.Text", String.valueOf((int)this.volumeDecibels));
this.sendUpdate(var9, null, false);
} else if (var3.pitch != null) {
this.pitchSemitones = var3.pitch;
UICommandBuilder var10 = new UICommandBuilder();
var10.set("#PitchValue.Text", String.valueOf(this.pitchSemitones));
this.sendUpdate(var10, null, false);
} else {
class="kw">switch (var3.type) {
case "Select":
if (var3.soundEvent != null) {
UICommandBuilder var13 = new UICommandBuilder();
this.selectSoundEvent(var1, var3.soundEvent, var13, var2);
this.sendUpdate(var13, null, false);
}
break;
case "Play":
if (this.selectedSoundEvent != null) {
int var6 = SoundEvent.getAssetMap().getIndex(this.selectedSoundEvent);
float var7 = AudioUtil.decibelsToLinearGain(this.volumeDecibels);
float var8 = AudioUtil.semitonesToLinearPitch(this.pitchSemitones);
SoundUtil.playSoundEvent2d(var1, var6, SoundCategory.SFX, var7, var8, var2);
}
}
}
}
class="kw">private void buildSoundEventList(
@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull ComponentAccessor<EntityStore> var4
) {
var2.clear("#SoundList");
int var5 = SoundEvent.getAssetMap().getAssetMap().size();
if (!this.searchQuery.isEmpty()) {
Object2IntMap var6 = new Object2IntOpenHashMap(var5);
for (String var8 : SoundEvent.getAssetMap().getAssetMap().keySet()) {
int var9 = StringCompareUtil.getFuzzyDistance(var8, this.searchQuery, Locale.ENGLISH);
if (var9 > 0) {
var6.put(var8, var9);
}
}
this.soundEvents = var6.keySet().stream().sorted(Comparator.comparingInt(var6::getInt).reversed()).limit(20L).collect(Collectors.toList());
} else {
this.soundEvents = SoundEvent.getAssetMap().getAssetMap().keySet().stream().sorted(String::compareTo).collect(Collectors.toList());
}
int var10 = 0;
for (int var11 = this.soundEvents.size(); var10 < var11; var10++) {
String var12 = this.soundEvents.get(var10);
String var13 = "#SoundList[" + var10 + "]";
var2.append("#SoundList", "Common/TextButton.ui");
var2.set(var13 + " #Button.Text", var12);
var3.addEventBinding(
CustomUIEventBindingType.Activating, var13 + " #Button", new EventData().append("Type", "Select").append("SoundEvent", var12), false
);
}
if (!this.soundEvents.isEmpty()) {
if (!this.soundEvents.contains(this.selectedSoundEvent)) {
this.selectSoundEvent(var1, this.soundEvents.getFirst(), var2, var4);
} else if (this.selectedSoundEvent != null) {
this.selectSoundEvent(var1, this.selectedSoundEvent, var2, var4);
}
}
}
class="kw">private void selectSoundEvent(
@Nonnull Ref<EntityStore> var1, @Nonnull String var2, @Nonnull UICommandBuilder var3, @Nonnull ComponentAccessor<EntityStore> var4
) {
if (this.selectedSoundEvent != null && this.soundEvents.contains(this.selectedSoundEvent)) {
var3.set("#SoundList[" + this.soundEvents.indexOf(this.selectedSoundEvent) + "] #Button.Style", BUTTON_LABEL_STYLE);
}
var3.set("#SoundList[" + this.soundEvents.indexOf(var2) + "] #Button.Style", BUTTON_LABEL_STYLE_SELECTED);
var3.set("#SoundName.Text", var2);
this.selectedSoundEvent = var2;
}
class="kw">public class="kw">static class PlaySoundPageEventData {
class="kw">static class="kw">final String KEY_SOUND_EVENT = "SoundEvent";
class="kw">static class="kw">final String KEY_TYPE = "Type";
class="kw">static class="kw">final String KEY_SEARCH_QUERY = "@SearchQuery";
class="kw">static class="kw">final String KEY_VOLUME = "@Volume";
class="kw">static class="kw">final String KEY_PITCH = "@Pitch";
class="kw">public class="kw">static class="kw">final BuilderCodec<PlaySoundPage.PlaySoundPageEventData> CODEC = BuilderCodec.builder(
PlaySoundPage.PlaySoundPageEventData.class, PlaySoundPage.PlaySoundPageEventData::new
)
.append(new KeyedCodec<>("SoundEvent", Codec.STRING), (var0, var1) -> var0.soundEvent = var1, var0 -> var0.soundEvent)
.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<>("@Volume", Codec.FLOAT), (var0, var1) -> var0.volume = var1, var0 -> var0.volume)
.add()
.append(new KeyedCodec<>("@Pitch", Codec.FLOAT), (var0, var1) -> var0.pitch = var1, var0 -> var0.pitch)
.add()
.build();
class="kw">private String soundEvent;
class="kw">private String type;
class="kw">private String searchQuery;
class="kw">private Float volume;
class="kw">private Float pitch;
class="kw">public PlaySoundPageEventData() {
}
}
}