Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whoops #169

Merged
merged 1 commit into from Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion common/src/main/java/su/plo/voice/client/VoiceClient.java
Expand Up @@ -131,7 +131,7 @@ public static void disconnect() {
socketUDP.close();
}

recorder.setRunning(false);
recorder.close();
serverConfig = null;

SocketClientUDPQueue.talking.clear();
Expand All @@ -143,6 +143,10 @@ public static boolean isMicrophoneLoopback() {
return Minecraft.getInstance().screen instanceof VoiceSettingsScreen screen && screen.getSource() != null;
}

public static boolean isSettingsOpen() {
return Minecraft.getInstance().screen instanceof VoiceSettingsScreen screen;
}

public static boolean isConnected() {
if (socketUDP == null) {
return false;
Expand Down
Expand Up @@ -3,7 +3,9 @@
import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import su.plo.voice.client.VoiceClient;
import su.plo.voice.client.gui.VoiceSettingsScreen;
import su.plo.voice.client.render.SphereRenderer;
import su.plo.voice.client.socket.SocketClientUDPQueue;
import su.plo.voice.client.sound.AbstractSoundQueue;
Expand Down Expand Up @@ -43,6 +45,8 @@ public ServerSettings(String secret, String ip, int port, boolean hasPriority) {
}

public void update(ConfigPacket config) {
int oldDistance = this.distance;

this.distances = config.getDistances();
Collections.sort(this.distances);
this.minDistance = this.distances.get(0).shortValue();
Expand All @@ -63,13 +67,15 @@ public void update(ConfigPacket config) {
this.distance = serverConfig.distance.get().shortValue();
} else {
this.distance = (short) config.getDefaultDistance();
serverConfig.distance.set((int) this.distance);
}

if(serverConfig.priorityDistance.get() > this.maxDistance &&
serverConfig.priorityDistance.get() < this.maxPriorityDistance) {
this.priorityDistance = serverConfig.priorityDistance.get().shortValue();
} else {
this.priorityDistance = (short) Math.min(this.maxPriorityDistance, this.maxDistance * 2);
serverConfig.priorityDistance.set((int) this.priorityDistance);
}
} else {
this.distance = (short) config.getDefaultDistance();
Expand All @@ -93,7 +99,13 @@ public void update(ConfigPacket config) {
.forEach(AbstractSoundQueue::closeAndKill);
SocketClientUDPQueue.audioChannels.clear();

SphereRenderer.getInstance().setRadius(this.distance + 0.5F, false, false);
if (VoiceClient.isSettingsOpen()) {
((VoiceSettingsScreen) Minecraft.getInstance().screen).updateGeneralTab();
}

SphereRenderer.getInstance().setRadius(this.distance + 0.5F,
this.distance != oldDistance && oldDistance > 0,
false);
}

public void setDistance(short distance) {
Expand Down
Expand Up @@ -33,17 +33,19 @@
import su.plo.voice.client.sound.openal.CustomSource;
import su.plo.voice.client.utils.AudioUtils;

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class VoiceSettingsScreen extends Screen {
private static final int minWidth = 640;
private final Minecraft client = Minecraft.getInstance();

// tabs
private TabWidget aboutWidget;
private Button active;
private int active;
private final List<Button> tabButtons = new ArrayList<>();
private final Map<Button, TabWidget> tabWidgets = new HashMap<>();
private final List<TabWidget> tabWidgets = new ArrayList<>();

// mute mic button
private List<Button> muteMicButtons;
Expand Down Expand Up @@ -181,7 +183,7 @@ protected void init() {
addTab(new TranslatableComponent("gui.plasmo_voice.advanced"), new AdvancedTabWidget(client, this));
addTab(new TranslatableComponent("gui.plasmo_voice.hotkeys"), new KeyBindingsTabWidget(client, this));
aboutWidget = new AboutTabWidget(client, this);
active = tabButtons.get(0);
// active = tabButtons.get(0);

// mute mic
ImageButton muteMicHide = new ImageButton(this.width - 52, 8, 20, 20, 0, 32, 20,
Expand Down Expand Up @@ -270,11 +272,11 @@ protected void init() {
}

public void updateGeneralTab() {
this.tabWidgets.put(tabButtons.get(0), new GeneralTabWidget(client, this));
this.tabWidgets.set(0, new GeneralTabWidget(client, this));
}

public void closeSpeaker() {
for (TabWidget tab : tabWidgets.values()) {
for (TabWidget tab : tabWidgets) {
for (TabWidget.Entry entry : tab.children()) {
if (entry instanceof TabWidget.OptionEntry &&
entry.children().get(0) instanceof MicrophoneThresholdWidget microphoneTest) {
Expand All @@ -286,19 +288,20 @@ public void closeSpeaker() {

private void addTab(Component text, TabWidget drawable) {
int textWidth = font.width(text) + 16;
final int elementIndex = tabWidgets.size();
Button button = new Button(0, 0, textWidth, 20,
text, btn -> {
active = btn;
active = elementIndex;
about = false;
for (TabWidget widget : tabWidgets.values()) {
for (TabWidget widget : tabWidgets) {
widget.onClose();
}
aboutWidget.setScrollAmount(0);

this.closeSpeaker();
});
tabButtons.add(button);
tabWidgets.put(button, drawable);
tabWidgets.add(drawable);
}

public int getHeaderHeight() {
Expand Down Expand Up @@ -379,8 +382,9 @@ public void renderHeader(PoseStack matrices, int mouseX, int mouseY, float delta
buttonY = 8;
}

for (Button button : tabButtons) {
button.active = about || button != active;
for (int i = 0; i < tabButtons.size(); i++) {
Button button = tabButtons.get(i);
button.active = about || i != active;

button.x = buttonX;
buttonX += button.getWidth() + 4;
Expand Down Expand Up @@ -430,8 +434,9 @@ public List<? extends GuiEventListener> children() {

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
for (TabWidget widget : tabWidgets.values()) {
if (keyCode == GLFW.GLFW_KEY_ESCAPE ||
keyCode == GLFW.GLFW_KEY_TAB) {
for (TabWidget widget : tabWidgets) {
if (widget instanceof KeyBindingsTabWidget) {
if (widget.keyPressed(keyCode, scanCode, modifiers)) {
return true;
Expand Down
Expand Up @@ -97,10 +97,10 @@ public AboutTabWidget(Minecraft client, VoiceSettingsScreen parent) {
})
)));
this.addEntry(new ListEntry(ImmutableList.of(
new Button(0, 0, 0, 20, new TextComponent("CurseForge"), button -> {
openLink("https://www.curseforge.com/minecraft/mc-mods/plasmo-voice-client");
new Button(0, 0, 0, 20, new TextComponent("Modrinth"), button -> {
openLink("https://modrinth.com/mod/plasmo-voice");
}, (button, matrices, mouseX, mouseY) -> {
setTooltip(ImmutableList.of(new TextComponent("https://www.curseforge.com/minecraft/mc-mods/plasmo-voice-client")));
setTooltip(ImmutableList.of(new TextComponent("https://modrinth.com/mod/plasmo-voice")));
}),
new Button(0, 0, 0, 20, new TextComponent("Spigot"), button -> {
openLink("https://www.spigotmc.org/resources/plasmo-voice-server.91064/");
Expand Down
Expand Up @@ -102,11 +102,11 @@ public AdvancedTabWidget(Minecraft client, VoiceSettingsScreen parent) {
this.addEntry(new OptionEntry(
new TranslatableComponent("gui.plasmo_voice.advanced.hrtf"),
new ToggleButton(0, 0, 97, 20, config.hrtf,
toggled -> VoiceClient.getSoundEngine().init()),
toggled -> VoiceClient.getSoundEngine().restart()),
config.hrtf,
TextUtils.multiLine("gui.plasmo_voice.advanced.hrtf.tooltip", 7),
(button, element) -> {
VoiceClient.getSoundEngine().init();
VoiceClient.getSoundEngine().restart();
((ToggleButton) element).updateValue();
})
);
Expand Down
Expand Up @@ -38,7 +38,7 @@ public GeneralTabWidget(Minecraft client, VoiceSettingsScreen parent) {
VoiceClient.getClientConfig().save();

// restart sound engine
VoiceClient.getSoundEngine().init();
VoiceClient.getSoundEngine().restart();
}),
VoiceClient.getClientConfig().speaker,
(button, element) -> {
Expand Down
Expand Up @@ -67,6 +67,8 @@ public void handle(ServerConnectPacket packet, Connection connection) throws IOE
VoiceClient.setServerConfig(new ServerSettings(packet.getToken(), ip,
packet.getPort(), packet.hasPriority()));

VoiceClient.getSoundEngine().start();

this.reply(connection, new ClientConnectPacket(packet.getToken(), VoiceClient.PROTOCOL_VERSION));
}

Expand Down
Expand Up @@ -60,7 +60,6 @@ public void run() {
if (!socket.authorized) {
VoiceClient.LOGGER.info("Connected to UDP");
socket.authorized = true;
VoiceClient.recorder.start();

if (client.screen instanceof VoiceNotAvailableScreen) {
client.execute(() ->
Expand Down