Change the human race option to a text link

This commit is contained in:
Sollace 2024-12-23 18:34:36 +01:00
parent b95812c0ba
commit e3f82ab133
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -14,8 +14,11 @@ import com.minelittlepony.unicopia.network.Channel;
import com.minelittlepony.unicopia.network.MsgRequestSpeciesChange; import com.minelittlepony.unicopia.network.MsgRequestSpeciesChange;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.ScreenRect;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Colors;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -68,7 +71,14 @@ public class TribeSelectionScreen extends GameGui implements HidesHud {
this.options.clear(); this.options.clear();
for (Race race : options) { for (Race race : options) {
addOption(race, top); if (race.isHuman()) {
final Race r = race;
addButton(new Link(width / 2, height - getFont().fontHeight - 10).setCentered())
.onClick(s -> selectRace(r))
.getStyle().setText("[Or Play as None of these]");
} else {
addOption(race, top);
}
} }
scroll(SELECTION == -1 ? options.size() / 2 : SELECTION, false); scroll(SELECTION == -1 ? options.size() / 2 : SELECTION, false);
@ -79,21 +89,25 @@ public class TribeSelectionScreen extends GameGui implements HidesHud {
int index = options.size(); int index = options.size();
options.add(addDrawableChild(option)); options.add(addDrawableChild(option));
option.onClick(b -> { option.onClick(b -> {
finished = true;
scroll(index, false); scroll(index, false);
client.setScreen(new TribeConfirmationScreen(result -> { selectRace(race);
finished = false;
if (result) {
Channel.CLIENT_REQUEST_SPECIES_CHANGE.sendToServer(new MsgRequestSpeciesChange(true, race));
finish();
} else {
client.setScreen(this);
}
}, race));
}).setEnabled(allowedRaces.contains(race)); }).setEnabled(allowedRaces.contains(race));
} }
private void selectRace(Race race) {
finished = true;
client.setScreen(new TribeConfirmationScreen(result -> {
finished = false;
if (result) {
Channel.CLIENT_REQUEST_SPECIES_CHANGE.sendToServer(new MsgRequestSpeciesChange(true, race));
finish();
} else {
client.setScreen(this);
}
}, race));
}
@Override @Override
public void tick() { public void tick() {
prevScrollPosition = scrollPosition; prevScrollPosition = scrollPosition;
@ -194,4 +208,32 @@ public class TribeSelectionScreen extends GameGui implements HidesHud {
}); });
} }
} }
static class Link extends Label implements Widget {
public Link(int x, int y) {
super(x, y);
}
@Override
protected boolean isValidClickButton(int button) {
return button == 0;
}
@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return getBounds().contains(mouseX, mouseY);
}
@Override
public ScreenRect getNavigationFocus() {
return new ScreenRect(getX(), getY(), getWidth(), getHeight());
}
@Override
public void renderWidget(DrawContext context, int mouseX, int mouseY, float partialTicks) {
this.hovered = isMouseOver(mouseX, mouseY);
getStyle().setColor(isSelected() ? Colors.ALTERNATE_WHITE : Colors.GRAY);
super.renderWidget(context, mouseX, mouseY, partialTicks);
}
}
} }