mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-11-24 09:08:53 -05:00
Compare commits
33
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33e0f433a7 | ||
|
|
411a02933b | ||
|
|
854d7827bb | ||
|
|
8e3228419a | ||
|
|
cb8a80f68d | ||
|
|
71342623c6 | ||
|
|
b0c37ac216 | ||
|
|
86ab0e5615 | ||
|
|
2783d29552 | ||
|
|
05323d952f | ||
|
|
a014334f21 | ||
|
|
2e80924c68 | ||
|
|
6749b39142 | ||
|
|
ff25416b07 | ||
|
|
bb81a44a11 | ||
|
|
40dfca2294 | ||
|
|
5a40ced96b | ||
|
|
3eb97b29a1 | ||
|
|
d88de0b072 | ||
|
|
460c44248c | ||
|
|
a16668695c | ||
|
|
fe5ebb5444 | ||
|
|
c34e4c8bbc | ||
|
|
84e76a0a6d | ||
|
|
be70c1e8de | ||
|
|
fba40387bb | ||
|
|
1217e6d101 | ||
|
|
905c410aee | ||
|
|
cea0c826c6 | ||
|
|
dc3b17df3b | ||
|
|
5602dee9ac | ||
|
|
9e4137cc20 | ||
|
|
c92248f6e9 |
No files matched your search
@@ -1,76 +1,4 @@
|
||||
# Changelog
|
||||
## [1.7.2 (January 25th, 2026)](#1-7-2)
|
||||
|
||||
### Additions
|
||||
- Added Saccharine wood furniture for Adorn.
|
||||
- Added the Partner Mark, which party Pokémon have a very small chance to earn as the player walks, provided they have enough friendship.
|
||||
- Added trades for Saccharine Saplings, Hearty Grains, Chipped Pot, and Masterpiece Teacup to the Wandering Trader.
|
||||
- Added brewing recipe for Throat Spray.
|
||||
- Added official Controlify Support
|
||||
- Added new effects
|
||||
- Mental Restoration: Reduces "Time Since Last Rest" statistic, which controls Insomnia, by half a minute per second per effect level
|
||||
- Negative Effect Cleanse: Removes all negative effects
|
||||
- Effect Cleanse: Removes all effects
|
||||
- Added more seasonings for sinister tea
|
||||
- Mental Herb - Mental Restoration I for 10 seconds
|
||||
- White Herb - Negative Effect Cleanse
|
||||
- Milk - Effect Cleanse
|
||||
- Moomoo Milk - Effect Cleanse
|
||||
- Added decorative block models for existing items: Potion, Super Potion, Hyper Potion, Max Potion, Full Restore, Antidote, Awakening, Burn Heal, Ice Heal, Paralyze Heal, Full Heal, Ether, Elixir, Max Ether, Max Elixir, X Accuracy, X Attack, X Defence, X Special Attack, X Special Defence, X Speed, Dire Hit, Guard Spec, Weakness Policy, Blunder Policy, Cleanse Tag, and Spell Tag.
|
||||
- Added decorative sign blocks called Plaques.
|
||||
- Added ride style labels to ride stats in Pokédex, as well as ride style icons in the summary GUI.
|
||||
- Added more seasonings for sinister tea:
|
||||
- Mental Herb - Mental Restoration I for 10 seconds, which staves off Insomnia.
|
||||
- White Herb - Removes negative effects.
|
||||
- Milk, Moomoo Milk - Removes effects.
|
||||
- Added dispenser support for:
|
||||
- Applying a Honey Bottle to Saccharine Logs.
|
||||
- Washing honey off of Saccharine Slathered Logs.
|
||||
- Applying and removing honey on Saccharine Leaves.
|
||||
- Added riding statistics: `Distance by Pokémon on Land`, `Distance by Pokémon in Air` and `Distance by Pokémon in Liquid`.
|
||||
|
||||
### New rideable Pokémon
|
||||
- Honchkrow
|
||||
- Mantine
|
||||
|
||||
### Pokémon Added
|
||||
|
||||
#### Gen 5
|
||||
- Throh
|
||||
- Sawk
|
||||
|
||||
#### Gen 6
|
||||
- Litleo
|
||||
- Pyroar
|
||||
- Spritzee
|
||||
- Aromatisse
|
||||
- Swirlix
|
||||
- Slurpuff
|
||||
|
||||
### Model updates for the following Pokémon
|
||||
- Falinks
|
||||
- Cottonee
|
||||
- Whimsicott
|
||||
- Ferroseed
|
||||
- Ferrothorn
|
||||
- Chingling
|
||||
- Chimecho
|
||||
|
||||
### Animation updates for the following Pokémon
|
||||
- Mantine (ride animations)
|
||||
- Flygon (ride jump animation)
|
||||
- Honchkrow (ride animations)
|
||||
- Croagunk
|
||||
- Toxicroak
|
||||
|
||||
### Changes
|
||||
- Added a new config option, `Enable In-Flight Dismounting` (default: off), which lets you dismount while riding a Pokémon in the air. This is the textbook definition of caveat emptor.
|
||||
- Ride sounds have been separated into stereo for passengers and mono for other players. Riding will now sound more spacious.
|
||||
- Battle AI now uses a smarter threshold for switching, reducing unnecessary switches.
|
||||
- AI will always use the most damaging move when at low HP and when it is not switching, improving endgame decision-making.
|
||||
- Items given from interacting with Saccharine Leaves are placed in the active hotbar slot if possible.
|
||||
- Added `label` as an alternate key to the `tag` property.
|
||||
## [1.7.3 (January 31st, 2026)](#1-7-3)
|
||||
## [1.8.0 (MONTH Xth, 2026)](#1-8-0)
|
||||
|
||||
### Additions
|
||||
@@ -468,7 +396,6 @@
|
||||
- Fixed `/giveallpokemon` not respecting the min and max parameters
|
||||
- Fixed the choose starter toast not disappearing when capturing a Pokémon instead of opening the starter selection screen
|
||||
- Fixed an issue where certain Sinister Tea seasonings were only applying as instant effects and would not apply over time
|
||||
- Long config option labels now scroll instead of overflowing
|
||||
|
||||
### Developer
|
||||
- Added `PokeSnackSpawnerFactory` which allows influence registration on PokeSnack encounters
|
||||
|
||||
@@ -32,10 +32,6 @@ repositories {
|
||||
maven(url = "https://api.modrinth.com/maven")
|
||||
maven(url = "https://maven.neoforged.net/releases")
|
||||
maven(url = "https://maven.gegy.dev")
|
||||
exclusiveContent {
|
||||
forRepository { maven(url = "https://maven.isxander.dev/releases") }
|
||||
filter { includeGroup("dev.isxander") }
|
||||
}
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
@@ -66,11 +62,6 @@ dependencies {
|
||||
|
||||
// Unit Testing
|
||||
testImplementation(libs.bundles.unitTesting)
|
||||
|
||||
// Controlify Compat, same as flywheel so we pick one and only use the api
|
||||
modCompileOnlyApi("dev.isxander:controlify:2.4.3+1.21.1-fabric") {
|
||||
isTransitive = false
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
|
||||
@@ -32,6 +32,6 @@ final class ParticleManagerMixin {
|
||||
@Inject(at = @At("RETURN"), method = "<clinit>")
|
||||
private static void lodestone$addTypes(CallbackInfo ci) {
|
||||
RENDER_ORDER = ImmutableList.<ParticleRenderType>builder().addAll(RENDER_ORDER)
|
||||
.add(ParticleMaterials.INSTANCE.getADD(), ParticleMaterials.INSTANCE.getALPHA(), ParticleMaterials.INSTANCE.getBLEND(), ParticleMaterials.INSTANCE.getOPAQUE()).build();
|
||||
.add(ParticleMaterials.INSTANCE.getXRAY(), ParticleMaterials.INSTANCE.getADD(), ParticleMaterials.INSTANCE.getALPHA(), ParticleMaterials.INSTANCE.getBLEND(), ParticleMaterials.INSTANCE.getOPAQUE()).build();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import com.cobblemon.mod.common.Cobblemon;
|
||||
import com.cobblemon.mod.common.OrientationControllable;
|
||||
import com.cobblemon.mod.common.api.orientation.OrientationController;
|
||||
import com.cobblemon.mod.common.client.CobblemonClient;
|
||||
import com.cobblemon.mod.common.client.gui.interact.wheel.InteractWheelGuiFactoryKt;
|
||||
import com.cobblemon.mod.common.client.keybind.keybinds.PartySendBinding;
|
||||
import com.cobblemon.mod.common.client.keybind.keybinds.RidingFreelookBinding;
|
||||
import com.cobblemon.mod.common.duck.RidePassenger;
|
||||
@@ -21,14 +22,12 @@ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.mojang.blaze3d.Blaze3D;
|
||||
import kotlin.Pair;
|
||||
import kotlin.jvm.functions.Function4;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.SmoothDouble;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.joml.Vector2d;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -69,6 +68,39 @@ public abstract class MouseHandlerMixin {
|
||||
|
||||
@Unique private double cobblemon$timeDelta;
|
||||
|
||||
@Inject(
|
||||
method = "onPress",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
public void cobblemon$pokeskillGuiControl(long windowPointer, int button, int action, int modifiers, CallbackInfo ci) {
|
||||
if (button == 0 && action == 1) {
|
||||
|
||||
// Make sure no menus are open already
|
||||
if (this.minecraft.screen == null && this.minecraft.getOverlay() == null) {
|
||||
// Check to see if party key is held
|
||||
if (PartySendBinding.INSTANCE.getWasDown()) {
|
||||
|
||||
// Don't want to send out a pokemon if we let go of the key
|
||||
PartySendBinding.INSTANCE.actioned();
|
||||
|
||||
//Open the actual gui
|
||||
var player = Minecraft.getInstance().player;
|
||||
var storage = CobblemonClient.INSTANCE.getStorage();
|
||||
var selectedPokemon = storage.getParty().get(storage.getSelectedSlot());
|
||||
if (selectedPokemon != null && player != null) {
|
||||
//canApplyChange = false
|
||||
var gui = InteractWheelGuiFactoryKt.createPokeSkillGui(player, selectedPokemon);
|
||||
Minecraft.getInstance().setScreen(gui);
|
||||
}
|
||||
|
||||
// Stop the rest of minecraft click logic like punching and using items
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "onScroll",
|
||||
at = @At(
|
||||
@@ -151,12 +183,6 @@ public abstract class MouseHandlerMixin {
|
||||
pokeVehicle.clampPassengerRotation(player);
|
||||
}
|
||||
|
||||
for(Function4<LocalPlayer, Double, Double, Double, Vector2d> rideFun : CobblemonClient.INSTANCE.getRidingTurnInputHandler().values()) {
|
||||
Vector2d vec = rideFun.invoke(player, cursorDeltaX, cursorDeltaY, d);
|
||||
cursorDeltaX = vec.x;
|
||||
cursorDeltaY = vec.y;
|
||||
}
|
||||
|
||||
// If the ride is not orientation controllable then return and perform the normal turnPlayer logic
|
||||
if (!(vehicle instanceof OrientationControllable controllableVehicle) || !controllableVehicle.getOrientationController().isActive()) {
|
||||
xMouseSmoother.reset();
|
||||
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin.integration.controlify;
|
||||
|
||||
import com.cobblemon.mod.common.client.CobblemonClient;
|
||||
import com.cobblemon.mod.common.client.integration.controlify.CobblemonControlifyEntrypoint;
|
||||
import com.cobblemon.mod.common.client.keybind.keybinds.PartySendBinding;
|
||||
import com.cobblemon.mod.common.pokedex.scanner.PokedexUsageContext;
|
||||
import dev.isxander.controlify.controller.ControllerEntity;
|
||||
import dev.isxander.controlify.ingame.InGameInputHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(InGameInputHandler.class)
|
||||
public class InGameInputHandlerMixin {
|
||||
@Shadow @Final private ControllerEntity controller;
|
||||
|
||||
@Redirect(
|
||||
method = "handleKeybinds()V",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/entity/player/Inventory;swapPaint(D)V"
|
||||
)
|
||||
)
|
||||
public void cobblemon$onHotbarSwitch(Inventory instance, double direction) {
|
||||
PokedexUsageContext usageContext = CobblemonClient.INSTANCE.getPokedexUsageContext();
|
||||
if (usageContext.getScanningGuiOpen()) {
|
||||
usageContext.adjustZoom(direction);
|
||||
return;
|
||||
}
|
||||
|
||||
if (CobblemonControlifyEntrypoint.Companion.getSEND_OUT_POKEMON().on(controller).digitalNow()) {
|
||||
CobblemonClient.INSTANCE.getStorage().shiftSelected(direction < 0);
|
||||
PartySendBinding.INSTANCE.actioned();
|
||||
return;
|
||||
}
|
||||
|
||||
instance.swapPaint(direction);
|
||||
}
|
||||
}
|
||||
@@ -24,27 +24,13 @@ import com.cobblemon.mod.common.client.net.data.RideSettingsSyncHandler
|
||||
import com.cobblemon.mod.common.client.net.debug.OpenRidingStatsDebugGUIHandler
|
||||
import com.cobblemon.mod.common.client.net.dialogue.DialogueClosedHandler
|
||||
import com.cobblemon.mod.common.client.net.dialogue.DialogueOpenedHandler
|
||||
import com.cobblemon.mod.common.client.net.effect.PokeSnackBlockParticlesHandler
|
||||
import com.cobblemon.mod.common.client.net.effect.RunPosableMoLangHandler
|
||||
import com.cobblemon.mod.common.client.net.effect.SaccharineLogBlockParticlesHandler
|
||||
import com.cobblemon.mod.common.client.net.effect.SpawnSnowstormEntityParticleHandler
|
||||
import com.cobblemon.mod.common.client.net.effect.SpawnSnowstormParticleHandler
|
||||
import com.cobblemon.mod.common.client.net.gui.ExpGainedDataPacketHandler
|
||||
import com.cobblemon.mod.common.client.net.gui.InteractPokemonUIPacketHandler
|
||||
import com.cobblemon.mod.common.client.net.gui.PokedexUIPacketHandler
|
||||
import com.cobblemon.mod.common.client.net.gui.SetActiveTMPacketHandler
|
||||
import com.cobblemon.mod.common.client.net.gui.SetTMMachineContainerDataPacketHandler
|
||||
import com.cobblemon.mod.common.client.net.gui.SummaryUIPacketHandler
|
||||
import com.cobblemon.mod.common.client.net.gui.SynchronizeActiveTMHandler
|
||||
import com.cobblemon.mod.common.client.net.effect.*
|
||||
import com.cobblemon.mod.common.client.net.gui.*
|
||||
import com.cobblemon.mod.common.client.net.habitat.OpenHabitatBlockEditorHandler
|
||||
import com.cobblemon.mod.common.client.net.npc.CloseNPCEditorHandler
|
||||
import com.cobblemon.mod.common.client.net.npc.OpenNPCEditorHandler
|
||||
import com.cobblemon.mod.common.client.net.orientation.ClientboundUpdateOrientationHandler
|
||||
import com.cobblemon.mod.common.client.net.pasture.ClosePastureHandler
|
||||
import com.cobblemon.mod.common.client.net.pasture.OpenPastureHandler
|
||||
import com.cobblemon.mod.common.client.net.pasture.PokemonPasturedHandler
|
||||
import com.cobblemon.mod.common.client.net.pasture.PokemonUnpasturedHandler
|
||||
import com.cobblemon.mod.common.client.net.pasture.UpdatePastureConflictFlagHandler
|
||||
import com.cobblemon.mod.common.client.net.pasture.*
|
||||
import com.cobblemon.mod.common.client.net.pokedex.ServerConfirmedRegisterHandler
|
||||
import com.cobblemon.mod.common.client.net.pokemon.update.ClientboundSeatAssignmentPacketHandler
|
||||
import com.cobblemon.mod.common.client.net.pokemon.update.ClientboundUpdateRidingStateHandler
|
||||
@@ -63,14 +49,7 @@ import com.cobblemon.mod.common.client.net.storage.party.SetPartyPokemonHandler
|
||||
import com.cobblemon.mod.common.client.net.storage.party.SetPartyReferenceHandler
|
||||
import com.cobblemon.mod.common.client.net.storage.pc.*
|
||||
import com.cobblemon.mod.common.client.net.toast.ToastPacketHandler
|
||||
import com.cobblemon.mod.common.client.net.trade.TradeAcceptanceChangedHandler
|
||||
import com.cobblemon.mod.common.client.net.trade.TradeCancelledHandler
|
||||
import com.cobblemon.mod.common.client.net.trade.TradeCompletedHandler
|
||||
import com.cobblemon.mod.common.client.net.trade.TradeOfferExpiredHandler
|
||||
import com.cobblemon.mod.common.client.net.trade.TradeOfferNotificationHandler
|
||||
import com.cobblemon.mod.common.client.net.trade.TradeProcessStartedHandler
|
||||
import com.cobblemon.mod.common.client.net.trade.TradeStartedHandler
|
||||
import com.cobblemon.mod.common.client.net.trade.TradeUpdatedHandler
|
||||
import com.cobblemon.mod.common.client.net.trade.*
|
||||
import com.cobblemon.mod.common.net.PacketRegisterInfo
|
||||
import com.cobblemon.mod.common.net.messages.client.OpenBehaviourEditorPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.PlayerInteractOptionsPacket
|
||||
@@ -86,21 +65,13 @@ import com.cobblemon.mod.common.net.messages.client.data.*
|
||||
import com.cobblemon.mod.common.net.messages.client.debug.RequestOpenRidingStatsDebugGUIPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.dialogue.DialogueClosedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.dialogue.DialogueOpenedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.PokeSnackBlockParticlesPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.RunPosableMoLangPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.SaccharineLogBlockParticlesPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.SpawnSnowstormEntityParticlePacket
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.SpawnSnowstormParticlePacket
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.*
|
||||
import com.cobblemon.mod.common.net.messages.client.habitat.OpenHabitatBlockEditorPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.npc.CloseNPCEditorPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.npc.OpenNPCEditorPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.orientation.ClientboundUpdateDriverInputPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.orientation.ClientboundUpdateOrientationPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.pasture.ClosePasturePacket
|
||||
import com.cobblemon.mod.common.net.messages.client.pasture.OpenPasturePacket
|
||||
import com.cobblemon.mod.common.net.messages.client.pasture.PokemonPasturedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.pasture.PokemonUnpasturedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.pasture.UpdatePastureConflictFlagPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.pasture.*
|
||||
import com.cobblemon.mod.common.net.messages.client.pokedex.ServerConfirmedRegisterPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.pokemon.update.*
|
||||
import com.cobblemon.mod.common.net.messages.client.pokemon.update.evolution.AddEvolutionPacket
|
||||
@@ -121,47 +92,17 @@ import com.cobblemon.mod.common.net.messages.client.storage.party.InitializePart
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.party.MoveClientPartyPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.party.SetPartyPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.party.SetPartyReferencePacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.ClosePCPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.InitializePCPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.MoveClientPCPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.OpenPCPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.RenamePCBoxPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.SetPCBoxPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.SetPCPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.*
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.ChangePCBoxWallpaperPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.RequestPCBoxWallpapersPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.SetPCBoxWallpapersPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.storage.pc.wallpaper.UnlockPCBoxWallpaperPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.tms.TechnicalMachineRegistrySyncPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.toast.ToastPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeAcceptanceChangedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeCancelledPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeCompletedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeOfferExpiredPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeOfferNotificationPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeProcessStartedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeStartedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.TradeUpdatedPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.ui.ExpGainedDataPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.ui.InteractPokemonUIPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.ui.PokedexUIPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.ui.SetActiveTMPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.ui.SetTMMachineContainerDataPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.ui.SummaryUIPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.ui.SynchronizeActiveTMPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.BattleChallengePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.BattleChallengeResponsePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.BenchMovePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.RequestMoveSwapPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.RequestPlayerInteractionsPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.SelectStarterPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.SendOutPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.battle.BattleSelectActionsPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.battle.BattleTeamLeavePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.battle.BattleTeamRequestPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.battle.BattleTeamResponsePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.battle.RemoveSpectatorPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.battle.SpectateBattlePacket
|
||||
import com.cobblemon.mod.common.net.messages.client.trade.*
|
||||
import com.cobblemon.mod.common.net.messages.client.ui.*
|
||||
import com.cobblemon.mod.common.net.messages.server.*
|
||||
import com.cobblemon.mod.common.net.messages.server.battle.*
|
||||
import com.cobblemon.mod.common.net.messages.server.behaviour.DamageOnCollisionPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.behaviour.SetEntityBehaviourPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.block.AdjustBlockEntityViewerCountPacket
|
||||
@@ -188,11 +129,7 @@ import com.cobblemon.mod.common.net.messages.server.pasture.UnpasturePokemonPack
|
||||
import com.cobblemon.mod.common.net.messages.server.pokedex.scanner.FinishScanningPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokedex.scanner.StartScanningPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.interact.InteractPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.ServerboundUpdateRidingStatePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetActiveMarkPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetItemHiddenPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetMarkingsPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetNicknamePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.*
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.evolution.AcceptEvolutionPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.riding.DismountPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.riding.ServerboundUpdateDriverInputPacket
|
||||
@@ -205,21 +142,12 @@ import com.cobblemon.mod.common.net.messages.server.storage.party.PartyTutorialP
|
||||
import com.cobblemon.mod.common.net.messages.server.storage.party.ReleasePartyPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.storage.party.SwapPartyPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.storage.pc.*
|
||||
import com.cobblemon.mod.common.net.messages.server.trade.AcceptTradeRequestPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.trade.CancelTradePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.trade.ChangeTradeAcceptancePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.trade.OfferTradePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.trade.PerformTradePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.trade.UpdateTradeOfferPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.trade.*
|
||||
import com.cobblemon.mod.common.net.serverhandling.ChallengeHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.ChallengeResponseHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.RequestInteractionsHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.battle.BattleSelectActionsHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.battle.RemoveSpectatorHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.battle.SpectateBattleHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.battle.TeamLeaveHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.battle.TeamRequestHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.battle.TeamRequestResponseHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.UsePokeSkillHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.battle.*
|
||||
import com.cobblemon.mod.common.net.serverhandling.behaviour.DamageOnCollisionPacketHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.behaviour.SetEntityBehaviourHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.block.AdjustBlockEntityViewerCountHandler
|
||||
@@ -247,11 +175,7 @@ import com.cobblemon.mod.common.net.serverhandling.pasture.UnpasturePokemonHandl
|
||||
import com.cobblemon.mod.common.net.serverhandling.pokedex.scanner.FinishScanningHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.pokedex.scanner.StartScanningHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.interact.InteractPokemonHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.ServerboundUpdateRidingStateHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetActiveMarkHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetItemHiddenHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetMarkingsHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.SetNicknameHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.pokemon.update.*
|
||||
import com.cobblemon.mod.common.net.serverhandling.riding.DismountPokemonPacketHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.riding.DriverInputPacketHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.riding.ServerboundUpdatePassengerPositionHandler
|
||||
@@ -267,12 +191,7 @@ import com.cobblemon.mod.common.net.serverhandling.storage.party.PartyTutorialPa
|
||||
import com.cobblemon.mod.common.net.serverhandling.storage.party.ReleasePCPokemonHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.storage.party.SwapPartyPokemonHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.storage.pc.*
|
||||
import com.cobblemon.mod.common.net.serverhandling.trade.AcceptTradeRequestHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.trade.CancelTradeHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.trade.ChangeTradeAcceptanceHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.trade.OfferTradeHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.trade.PerformTradeHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.trade.UpdateTradeOfferHandler
|
||||
import com.cobblemon.mod.common.net.serverhandling.trade.*
|
||||
import com.cobblemon.mod.common.util.server
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
|
||||
@@ -342,6 +261,7 @@ object CobblemonNetwork {
|
||||
list.add(PacketRegisterInfo(MarkingsUpdatePacket.ID, MarkingsUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||
list.add(PacketRegisterInfo(RideBoostsUpdatePacket.ID, RideBoostsUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||
list.add(PacketRegisterInfo(RideStaminaUpdatePacket.ID, RideStaminaUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||
list.add(PacketRegisterInfo(SkillCooldownsUpdatePacket.ID, SkillCooldownsUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||
list.add(PacketRegisterInfo(AlphaUpdatePacket.ID, AlphaUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||
list.add(PacketRegisterInfo(ScaleModifierUpdatePacket.ID, ScaleModifierUpdatePacket::decode, PokemonUpdatePacketHandler()))
|
||||
|
||||
@@ -443,6 +363,7 @@ object CobblemonNetwork {
|
||||
list.add(PacketRegisterInfo(BehaviourSyncPacket.ID, BehaviourSyncPacket::decode, DataRegistrySyncPacketHandler()))
|
||||
list.add(PacketRegisterInfo(MarkRegistrySyncPacket.ID, MarkRegistrySyncPacket::decode, DataRegistrySyncPacketHandler()))
|
||||
list.add(PacketRegisterInfo(RideSettingsSyncPacket.ID, RideSettingsSyncPacket::decode, RideSettingsSyncHandler))
|
||||
list.add(PacketRegisterInfo(PokeSkillsRegistrySyncPacket.ID, PokeSkillsRegistrySyncPacket::decode, DataRegistrySyncPacketHandler()))
|
||||
list.add(PacketRegisterInfo(TechnicalMachineRegistrySyncPacket.ID, TechnicalMachineRegistrySyncPacket::decode, DataRegistrySyncPacketHandler()))
|
||||
|
||||
// Effects
|
||||
@@ -535,6 +456,7 @@ object CobblemonNetwork {
|
||||
// Interaction Packets
|
||||
list.add(PacketRegisterInfo(InteractPokemonPacket.ID, InteractPokemonPacket::decode, InteractPokemonHandler))
|
||||
list.add(PacketRegisterInfo(RequestPlayerInteractionsPacket.ID, RequestPlayerInteractionsPacket::decode, RequestInteractionsHandler))
|
||||
list.add(PacketRegisterInfo(UsePokeSkillPacket.ID, UsePokeSkillPacket::decode, UsePokeSkillHandler))
|
||||
|
||||
// Storage Packets
|
||||
list.add(PacketRegisterInfo(SendOutPokemonPacket.ID, SendOutPokemonPacket::decode, SendOutPokemonHandler))
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonNetwork.sendPacket
|
||||
import com.cobblemon.mod.common.api.data.JsonDataRegistry
|
||||
import com.cobblemon.mod.common.api.molang.ExpressionLike
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectTimeline
|
||||
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
||||
import com.cobblemon.mod.common.entity.pokemon.pokeskills.PokeSkill
|
||||
import com.cobblemon.mod.common.entity.pokemon.pokeskills.PokeSkillTier
|
||||
import com.cobblemon.mod.common.net.messages.client.data.PokeSkillsRegistrySyncPacket
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import com.cobblemon.mod.common.util.adapters.ActionEffectTimelineAdapter
|
||||
import com.cobblemon.mod.common.util.adapters.ExpressionLikeAdapter
|
||||
import com.cobblemon.mod.common.util.adapters.IdentifierAdapter
|
||||
import com.cobblemon.mod.common.util.adapters.TextAdapter
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.server.packs.PackType
|
||||
import net.minecraft.world.entity.player.Player
|
||||
|
||||
/**
|
||||
* The JSON data registry for all the possible [PokeSkill]s.
|
||||
*
|
||||
* @author Hiroku
|
||||
* @since August 31st, 2025
|
||||
*/
|
||||
object CobblemonPokeSkills : JsonDataRegistry<PokeSkill> {
|
||||
override val id = cobblemonResource("poke_skills")
|
||||
override val type = PackType.SERVER_DATA
|
||||
override val observable = SimpleObservable<CobblemonPokeSkills>()
|
||||
override val typeToken = TypeToken.get(PokeSkill::class.java)
|
||||
override val resourcePath = "poke_skills"
|
||||
override val gson = GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.registerTypeAdapter(ExpressionLike::class.java, ExpressionLikeAdapter)
|
||||
.registerTypeAdapter(ActionEffectTimeline::class.java, ActionEffectTimelineAdapter)
|
||||
.registerTypeAdapter(ResourceLocation::class.java, IdentifierAdapter)
|
||||
.registerTypeAdapter(Component::class.java, TextAdapter)
|
||||
.create()
|
||||
|
||||
var skills = mapOf<ResourceLocation, PokeSkill>()
|
||||
|
||||
fun getAccessiblePokeSkillTiers(player: Player, pokemon: Pokemon): List<PokeSkillTier> {
|
||||
return skills.values.mapNotNull { skill ->
|
||||
skill.tiers.lastOrNull { tier ->
|
||||
tier.canAccess(player, pokemon)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun reload(data: Map<ResourceLocation, PokeSkill>) {
|
||||
data.forEach { (id, skill) -> skill.id = id }
|
||||
|
||||
skills = data
|
||||
skills.values.forEach { skill ->
|
||||
skill.tiers.forEachIndexed { index, tier ->
|
||||
tier.initialize(skill, index + 1)
|
||||
}
|
||||
}
|
||||
|
||||
observable.emit(this)
|
||||
|
||||
val tiersCount = skills.values.sumOf { it.tiers.size }
|
||||
Cobblemon.LOGGER.info("Loaded ${skills.size} PokéSkills with $tiersCount tiers")
|
||||
}
|
||||
|
||||
override fun sync(player: ServerPlayer) {
|
||||
player.sendPacket(PokeSkillsRegistrySyncPacket(skills.values.toList()))
|
||||
}
|
||||
}
|
||||
@@ -286,6 +286,15 @@ object MoLangFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
fun Any.asMostSpecificMoLangValue(): MoValue {
|
||||
return when (this) {
|
||||
is Number -> DoubleValue(this.toDouble())
|
||||
is String -> StringValue(this)
|
||||
is Boolean -> DoubleValue(if (this) 1.0 else 0.0)
|
||||
else -> StringValue(toString())
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Holder<T>.asMoLangValue(key: ResourceKey<Registry<T>>): ObjectValue<Holder<T>> {
|
||||
val value = ObjectValue(
|
||||
obj = this,
|
||||
@@ -293,11 +302,11 @@ object MoLangFunctions {
|
||||
)
|
||||
value.functions["is_in"] = Function put@{ params: MoParams ->
|
||||
val tag = TagKey.create(key, ResourceLocation.parse(params.getString(0).replace("#", "")))
|
||||
return@put DoubleValue(if (value.obj.`is`(tag)) 1.0 else 0.0)
|
||||
return@put DoubleValue(value.obj.`is`(tag))
|
||||
}
|
||||
value.functions["is_of"] = Function put@{ params: MoParams ->
|
||||
val identifier = ResourceLocation.parse(params.getString(0))
|
||||
return@put DoubleValue(if (value.obj.`is`(identifier)) 1.0 else 0.0)
|
||||
return@put DoubleValue(value.obj.`is`(identifier))
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ object DropEntryMoLangFunctions : AbstractMoLangFunctionHolder<DropEntry>() {
|
||||
map["max_selectable_times"] = { DoubleValue(drop.maxSelectableTimes.toDouble()) }
|
||||
map["can_drop"] = { params ->
|
||||
val pokemon = params.getOrNull<ObjectValue<Pokemon>>(0)?.obj
|
||||
DoubleValue(if (drop.canDrop(pokemon)) 1.0 else 0.0)
|
||||
DoubleValue(drop.canDrop(pokemon))
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
+83
-40
@@ -25,22 +25,8 @@ import com.cobblemon.mod.common.entity.MoLangScriptingEntity
|
||||
import com.cobblemon.mod.common.entity.PosableEntity
|
||||
import com.cobblemon.mod.common.net.messages.client.animation.PlayPosableAnimationPacket
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.SpawnSnowstormEntityParticlePacket
|
||||
import com.cobblemon.mod.common.util.asArrayValue
|
||||
import com.cobblemon.mod.common.util.asExpressionLike
|
||||
import com.cobblemon.mod.common.util.asIdentifierDefaultingNamespace
|
||||
import com.cobblemon.mod.common.util.asResource
|
||||
import com.cobblemon.mod.common.util.asUUID
|
||||
import com.cobblemon.mod.common.util.cloneFrom
|
||||
import com.cobblemon.mod.common.util.effectiveName
|
||||
import com.cobblemon.mod.common.util.getBlockStatesWithPos
|
||||
import com.cobblemon.mod.common.util.getBooleanOrNull
|
||||
import com.cobblemon.mod.common.util.getDoubleOrNull
|
||||
import com.cobblemon.mod.common.util.getIsSubmerged
|
||||
import com.cobblemon.mod.common.util.getOrNull
|
||||
import com.cobblemon.mod.common.util.getStringOrNull
|
||||
import com.cobblemon.mod.common.util.isStandingOn
|
||||
import com.cobblemon.mod.common.util.resolve
|
||||
import com.cobblemon.mod.common.util.worldRegistry
|
||||
import com.cobblemon.mod.common.util.*
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
@@ -48,10 +34,13 @@ import net.minecraft.tags.TagKey
|
||||
import net.minecraft.world.damagesource.DamageSource
|
||||
import net.minecraft.world.damagesource.DamageTypes
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.TamableAnimal
|
||||
import net.minecraft.world.level.block.BonemealableBlock
|
||||
import net.minecraft.world.level.block.CropBlock
|
||||
import net.minecraft.world.phys.AABB
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import java.util.UUID
|
||||
import java.util.*
|
||||
import kotlin.math.sqrt
|
||||
|
||||
object EntityMoLangFunctions : AbstractMoLangFunctionHolder<Entity>() {
|
||||
@@ -78,8 +67,13 @@ object EntityMoLangFunctions : AbstractMoLangFunctionHolder<Entity>() {
|
||||
"vertical_velocity" to { DoubleValue(thisEntity.deltaMovement.y) },
|
||||
"is_on_ground" to { _ -> DoubleValue(thisEntity.onGround()) },
|
||||
"world" to { _ -> thisEntity.level().worldRegistry.wrapAsHolder(thisEntity.level()).asWorldMoLangValue() },
|
||||
"dimension" to { StringValue(thisEntity.level().dimension().location().toString()) },
|
||||
"biome" to { _ -> thisEntity.level().getBiome(thisEntity.blockPosition()).asBiomeMoLangValue() },
|
||||
"is_passenger" to { DoubleValue(thisEntity.isPassenger) },
|
||||
"is_passenger" to isPassenger@{ params ->
|
||||
val passengerEntity = (params.get<MoValue>(0) as? ObjectValue<*>)?.obj as? LivingEntity ?: return@isPassenger DoubleValue.ZERO
|
||||
DoubleValue(passengerEntity in thisEntity.passengers)
|
||||
},
|
||||
"discard" to { thisEntity.discard() },
|
||||
"is_sneaking" to { _ -> DoubleValue(thisEntity.isShiftKeyDown) },
|
||||
"is_sprinting" to { _ -> DoubleValue(thisEntity.isSprinting) },
|
||||
@@ -121,6 +115,62 @@ object EntityMoLangFunctions : AbstractMoLangFunctionHolder<Entity>() {
|
||||
listOf(thisEntity.deltaMovement.x, thisEntity.deltaMovement.y, thisEntity.deltaMovement.z)
|
||||
.asArrayValue(::DoubleValue)
|
||||
},
|
||||
"set_position" to { params ->
|
||||
val x = params.getDouble(0)
|
||||
val y = params.getDouble(1)
|
||||
val z = params.getDouble(2)
|
||||
thisEntity.setPos(x, y, z)
|
||||
DoubleValue.ONE
|
||||
},
|
||||
"fertilize_nearby_crops" to { params -> //TODO: pretty bespoke. Maybe should be moved or generalized?
|
||||
val radius = params.getIntOrNull(0) ?: 8
|
||||
val maxCrops = params.getIntOrNull(1) ?: 8
|
||||
|
||||
var fertilizedCount = 0
|
||||
val level = thisEntity.level()
|
||||
val centerPos = thisEntity.blockPosition()
|
||||
|
||||
// Find all bonemealable blocks within radius
|
||||
val bonemealableBlocks = mutableListOf<BlockPos>()
|
||||
|
||||
for (x in -radius..radius) {
|
||||
for (y in -3..3) { // Limited vertical range
|
||||
for (z in -radius..radius) {
|
||||
val pos = centerPos.offset(x, y, z)
|
||||
val blockState = level.getBlockState(pos)
|
||||
val block = blockState.block
|
||||
|
||||
// Check if block can be bonemealed
|
||||
if (block is BonemealableBlock && block is CropBlock && block.isValidBonemealTarget(level, pos, blockState)) {
|
||||
bonemealableBlocks.add(pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shuffle and take up to maxCrops blocks to fertilize
|
||||
bonemealableBlocks.shuffle()
|
||||
val blocksToFertilize = bonemealableBlocks.take(maxCrops)
|
||||
|
||||
for (pos in blocksToFertilize) {
|
||||
val blockState = level.getBlockState(pos)
|
||||
val block = blockState.block
|
||||
|
||||
if (block is BonemealableBlock && block.isValidBonemealTarget(level, pos, blockState)) {
|
||||
if (block.isBonemealSuccess(level, level.random, pos, blockState)) {
|
||||
block.performBonemeal(level as ServerLevel, level.random, pos, blockState)
|
||||
|
||||
// Add bonemeal particle
|
||||
val particlePos = block.getParticlePos(pos)
|
||||
level.levelEvent(1505, particlePos, 15) // Same event used for bonemealing in vanilla
|
||||
|
||||
fertilizedCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DoubleValue(fertilizedCount.toDouble())
|
||||
},
|
||||
"tags" to {
|
||||
val tags = thisEntity.tags
|
||||
val array = ArrayStruct(hashMapOf())
|
||||
@@ -152,12 +202,14 @@ object EntityMoLangFunctions : AbstractMoLangFunctionHolder<Entity>() {
|
||||
StringValue(it)
|
||||
} ?: DoubleValue.ZERO
|
||||
},
|
||||
"find_nearby_block" to findNearbyBlock@{ params ->
|
||||
"find_nearby_blocks" to { params ->
|
||||
val input = params.getString(0)
|
||||
val isTag = input.contains("#")
|
||||
val type = input.replace("#", "").asIdentifierDefaultingNamespace(namespace = "minecraft")
|
||||
|
||||
val range = params.getDoubleOrNull(1) ?: 10
|
||||
val blockPos = thisEntity.level().getBlockStatesWithPos(
|
||||
|
||||
val blockPosList = thisEntity.level().getBlockStatesWithPos(
|
||||
AABB.ofSize(
|
||||
thisEntity.position(),
|
||||
range.toDouble(),
|
||||
@@ -165,28 +217,19 @@ object EntityMoLangFunctions : AbstractMoLangFunctionHolder<Entity>() {
|
||||
range.toDouble()
|
||||
)
|
||||
)
|
||||
.filter { blockPosPair ->
|
||||
blockPosPair.first.blockHolder.let {
|
||||
if (isTag) it.`is`(
|
||||
TagKey.create(
|
||||
Registries.BLOCK,
|
||||
type
|
||||
)
|
||||
) else it.`is`(type)
|
||||
}
|
||||
.filter { blockPosPair ->
|
||||
blockPosPair.first.blockHolder.let {
|
||||
if (isTag) it.`is`(
|
||||
TagKey.create(
|
||||
Registries.BLOCK,
|
||||
type
|
||||
)
|
||||
) else it.`is`(type)
|
||||
}
|
||||
.minByOrNull { it.second.distSqr(thisEntity.blockPosition()) }
|
||||
?.second
|
||||
if (blockPos != null) {
|
||||
return@findNearbyBlock ArrayStruct(
|
||||
mapOf(
|
||||
"0" to DoubleValue(blockPos.x),
|
||||
"1" to DoubleValue(blockPos.y),
|
||||
"2" to DoubleValue(blockPos.z)
|
||||
)
|
||||
)
|
||||
}
|
||||
return@findNearbyBlock DoubleValue.ZERO
|
||||
.map { blockPosPair -> blockPosPair.second }
|
||||
|
||||
blockPosList.map { it.toArrayStruct() }.asArrayValue()
|
||||
},
|
||||
"get_nearby_entities" to { params ->
|
||||
val distance = params.getDouble(0)
|
||||
@@ -233,7 +276,7 @@ object EntityMoLangFunctions : AbstractMoLangFunctionHolder<Entity>() {
|
||||
val intangible = params.getBooleanOrNull(0) ?: true
|
||||
thisEntity.noPhysics = intangible
|
||||
DoubleValue.ONE
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
+18
@@ -39,6 +39,7 @@ import net.minecraft.world.entity.Mob
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.TamableAnimal
|
||||
import net.minecraft.world.entity.ai.behavior.BlockPosTracker
|
||||
import net.minecraft.world.entity.ai.behavior.EntityTracker
|
||||
import net.minecraft.world.entity.ai.memory.MemoryModuleType
|
||||
import net.minecraft.world.entity.ai.memory.MemoryStatus
|
||||
import net.minecraft.world.entity.ai.memory.WalkTarget
|
||||
@@ -123,6 +124,23 @@ object LivingEntityMoLangFunctions : AbstractMoLangFunctionHolder<LivingEntity>(
|
||||
duration.toLong()
|
||||
)
|
||||
}
|
||||
map["look_at_entity"] = put@{ params ->
|
||||
val targetEntity = params.get<MoValue>(0)
|
||||
val duration = params.getDoubleOrNull(1)?.toInt() ?: 20
|
||||
|
||||
val lookEntity = if (targetEntity is ObjectValue<*> && targetEntity.obj is Entity) {
|
||||
targetEntity.obj as Entity
|
||||
} else {
|
||||
return@put DoubleValue.ZERO
|
||||
}
|
||||
|
||||
// Set the current entity to track the looked for entity
|
||||
val brain = entity.brain
|
||||
val tracker = EntityTracker(lookEntity, true)
|
||||
brain.setMemoryWithExpiry(MemoryModuleType.LOOK_TARGET, tracker, duration.toLong())
|
||||
|
||||
DoubleValue.ONE
|
||||
}
|
||||
map["get_wander_control_memory"] = put@{
|
||||
val value = entity.brain.getMemorySafely(CobblemonMemories.WANDER_CONTROL).orElse(null)
|
||||
?: CobblemonWanderControl()
|
||||
|
||||
+62
@@ -25,6 +25,7 @@ import com.cobblemon.mod.common.api.molang.ObjectValue
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.battles.BattleBuilder
|
||||
import com.cobblemon.mod.common.battles.BattleFormat
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.entity.npc.NPCEntity
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.net.messages.client.battle.BattleMusicPacket
|
||||
@@ -34,6 +35,7 @@ import com.cobblemon.mod.common.util.activeDialogue
|
||||
import com.cobblemon.mod.common.util.asBlockPos
|
||||
import com.cobblemon.mod.common.util.asResource
|
||||
import com.cobblemon.mod.common.util.asUUID
|
||||
import com.cobblemon.mod.common.util.blockRegistry
|
||||
import com.cobblemon.mod.common.util.getBattleState
|
||||
import com.cobblemon.mod.common.util.getBooleanOrNull
|
||||
import com.cobblemon.mod.common.util.getDoubleOrNull
|
||||
@@ -46,15 +48,20 @@ import com.cobblemon.mod.common.util.party
|
||||
import com.cobblemon.mod.common.util.pc
|
||||
import com.cobblemon.mod.common.util.pokedex
|
||||
import com.cobblemon.mod.common.util.server
|
||||
import com.cobblemon.mod.common.util.toArrayStruct
|
||||
import com.cobblemon.mod.common.util.tmList
|
||||
import net.minecraft.client.player.AbstractClientPlayer
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.level.ClipContext
|
||||
import net.minecraft.world.level.GameType
|
||||
import net.minecraft.world.phys.HitResult
|
||||
import kotlin.collections.iterator
|
||||
|
||||
object PlayerMoLangFunctions : AbstractMoLangFunctionHolder<Player>() {
|
||||
@@ -399,6 +406,61 @@ object PlayerMoLangFunctions : AbstractMoLangFunctionHolder<Player>() {
|
||||
} ?: DoubleValue.ZERO
|
||||
}
|
||||
map["has_chosen_starter"] = { _ -> DoubleValue(Cobblemon.playerDataManager.getGenericData(player).starterSelected) }
|
||||
map["ride"] = put@{ params ->
|
||||
val entity = (params.get<MoValue>(0) as? ObjectValue<*>)?.obj as? Entity ?: return@put DoubleValue.ZERO
|
||||
player.startRiding(entity)
|
||||
}
|
||||
map["has_respawn_position"] = {
|
||||
DoubleValue(player.respawnPosition != null)
|
||||
}
|
||||
map["respawn_position"] = {
|
||||
player.respawnPosition?.toArrayStruct() ?: DoubleValue.ZERO
|
||||
}
|
||||
map["respawn_dimension"] = {
|
||||
StringValue(player.respawnDimension.location().toString())
|
||||
}
|
||||
map["teleport_to_respawn"] = put@{
|
||||
val respawnPosition = player.respawnPosition?.center ?: return@put DoubleValue.ZERO
|
||||
player.teleportTo(respawnPosition.x, respawnPosition.y, respawnPosition.z)
|
||||
DoubleValue.ONE
|
||||
}
|
||||
map["get_looked_block"] = put@{ params ->
|
||||
// Get the block the player is looking at 'distance' units away
|
||||
val distance = params.getDoubleOrNull(0) ?: 8.0
|
||||
|
||||
// perform clip
|
||||
val level = player.level()
|
||||
val eye = player.eyePosition
|
||||
val view = player.getViewVector(1.0f)
|
||||
val lookPos = eye.add(view.scale(distance))
|
||||
val hitResult = level.clip(ClipContext(eye, lookPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, player))
|
||||
|
||||
if (hitResult.type == HitResult.Type.BLOCK) {
|
||||
// Get base block info
|
||||
val blockPos = hitResult.blockPos
|
||||
val blockState = level.getBlockState(blockPos)
|
||||
val blockHolder = level.blockRegistry.wrapAsHolder(blockState.block)
|
||||
val blockValue = blockHolder.asMoLangValue(Registries.BLOCK)
|
||||
|
||||
// Attach the position to the blockValue return
|
||||
blockValue.addFunction("x") { DoubleValue(blockPos.x.toDouble()) }
|
||||
blockValue.addFunction("y") { DoubleValue(blockPos.y.toDouble()) }
|
||||
blockValue.addFunction("z") { DoubleValue(blockPos.z.toDouble()) }
|
||||
|
||||
return@put blockValue
|
||||
} else {
|
||||
return@put DoubleValue.ZERO
|
||||
}
|
||||
}
|
||||
map["is_battling"] = {
|
||||
DoubleValue(player.isInBattle())
|
||||
}
|
||||
}
|
||||
|
||||
if (player is AbstractClientPlayer) {
|
||||
map["is_battling"] = {
|
||||
DoubleValue(CobblemonClient.battle?.spectating == false) // Checks not-null and not-spectating at the same time, trust
|
||||
}
|
||||
}
|
||||
|
||||
return map
|
||||
|
||||
+28
@@ -15,6 +15,7 @@ import com.bedrockk.molang.runtime.value.MoValue
|
||||
import com.bedrockk.molang.runtime.value.StringValue
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.CobblemonMovesetBuilders
|
||||
import com.cobblemon.mod.common.CobblemonPokeSkills
|
||||
import com.cobblemon.mod.common.api.mark.Marks
|
||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.asMoLangValue
|
||||
import com.cobblemon.mod.common.api.moves.BenchedMove
|
||||
@@ -26,6 +27,9 @@ import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||
import com.cobblemon.mod.common.api.storage.party.PartyStore
|
||||
import com.cobblemon.mod.common.pokemon.IVs
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import com.cobblemon.mod.common.pokemon.activestate.ActivePokemonState
|
||||
import com.cobblemon.mod.common.pokemon.activestate.SentOutState
|
||||
import com.cobblemon.mod.common.pokemon.activestate.ShoulderedState
|
||||
import com.cobblemon.mod.common.util.asArrayValue
|
||||
import com.cobblemon.mod.common.util.asIdentifierDefaultingNamespace
|
||||
import com.cobblemon.mod.common.util.getBooleanOrNull
|
||||
@@ -447,6 +451,30 @@ object PokemonMoLangFunctions : AbstractMoLangFunctionHolder<Pokemon>() {
|
||||
evolution?.forceEvolve(pokemon)
|
||||
StringValue(evolution.toString())
|
||||
}
|
||||
map["is_sent_out"] = {
|
||||
DoubleValue(pokemon.state is SentOutState)
|
||||
}
|
||||
map["is_shouldered"] = {
|
||||
DoubleValue(pokemon.state is ShoulderedState)
|
||||
}
|
||||
map["entity"] = {
|
||||
(pokemon.state as? ActivePokemonState)?.entity?.struct ?: DoubleValue.ZERO
|
||||
}
|
||||
map["is_rideable"] = put@{
|
||||
return@put DoubleValue(!pokemon.riding.behaviours.isNullOrEmpty())
|
||||
}
|
||||
map["has_status"] = put@{ params ->
|
||||
val status = params.getString(0).asIdentifierDefaultingNamespace()
|
||||
return@put DoubleValue(pokemon.status?.status?.name == status)
|
||||
}
|
||||
// TODO remove this or figure a way to determine which tier of the pokeskill is being used
|
||||
map["add_skill_cooldown"] = put@{ params ->
|
||||
val skillId = params.getString(0).asIdentifierDefaultingNamespace()
|
||||
val cooldownTicks = params.getIntOrNull(1)
|
||||
val skill = CobblemonPokeSkills.skills[skillId] ?: return@put DoubleValue.ZERO
|
||||
pokemon.addSkillCooldown(skillId, cooldownTicks ?: skill.cooldownTicks ?: 0)
|
||||
return@put DoubleValue.ONE
|
||||
}
|
||||
|
||||
map["entity"] = { pokemon.entity?.asMoLangValue() ?: DoubleValue.ZERO }
|
||||
map["is_alpha"] = { DoubleValue(pokemon.isAlpha) }
|
||||
|
||||
+23
-2
@@ -40,6 +40,7 @@ import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.level.Level.ExplosionInteraction
|
||||
import net.minecraft.world.level.biome.Biome
|
||||
import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity
|
||||
import net.minecraft.world.level.levelgen.Heightmap
|
||||
import net.minecraft.world.level.storage.loot.LootParams
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets
|
||||
@@ -61,6 +62,26 @@ object WorldMoLangFunctions : AbstractMoLangFunctionHolder<Holder<Level>>() {
|
||||
val time = world.dayTime % 24000
|
||||
return@put DoubleValue(timeOfDay.contains(time.toInt()))
|
||||
}
|
||||
map["add_furnace_fuel"] = put@{ params ->
|
||||
val x = params.getInt(0)
|
||||
val y = params.getInt(1)
|
||||
val z = params.getInt(2)
|
||||
val fuelTicks = params.getInt(3)
|
||||
|
||||
val blockEntity = world.getBlockEntity(BlockPos(x, y, z))
|
||||
if (blockEntity is AbstractFurnaceBlockEntity) {
|
||||
// Add fuel time to the furnace
|
||||
blockEntity.litTime += fuelTicks
|
||||
|
||||
// If this exceeds the litDuration then bump it up
|
||||
if (blockEntity.litTime >= blockEntity.litDuration) {
|
||||
blockEntity.litDuration = blockEntity.litTime
|
||||
}
|
||||
blockEntity.setChanged()
|
||||
return@put DoubleValue.ONE
|
||||
}
|
||||
return@put DoubleValue.ZERO
|
||||
}
|
||||
map["game_time"] = { _ -> DoubleValue(world.gameTime.toDouble()) }
|
||||
map["time_of_day"] = put@{
|
||||
val time = world.dayTime % 24000
|
||||
@@ -128,13 +149,13 @@ object WorldMoLangFunctions : AbstractMoLangFunctionHolder<Holder<Level>>() {
|
||||
val x = params.getDouble(0)
|
||||
val y = params.getDouble(1)
|
||||
val z = params.getDouble(2)
|
||||
val range = params.getDouble(3).toFloat()
|
||||
val range = params.getDoubleOrNull(3) ?: 8.0
|
||||
world.explode(
|
||||
null,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
range,
|
||||
range.toFloat(),
|
||||
ExplosionInteraction.valueOf(
|
||||
params.getStringOrNull(4)?.uppercase() ?: ExplosionInteraction.TNT.name
|
||||
)
|
||||
|
||||
+2
-1
@@ -50,7 +50,7 @@ class ActionEffectTimeline(
|
||||
}
|
||||
|
||||
fun chainKeyframes(context: ActionEffectContext, iterator: Iterator<ActionEffectKeyframe>, finalFuture: CompletableFuture<Unit>) {
|
||||
if (!iterator.hasNext()) {
|
||||
if (!iterator.hasNext() || context.cancelled) {
|
||||
finalFuture.complete(Unit)
|
||||
} else {
|
||||
val keyframe = iterator.next()
|
||||
@@ -70,6 +70,7 @@ class ActionEffectContext(
|
||||
val runtime: MoLangRuntime,
|
||||
var canBeInterrupted: Boolean = false,
|
||||
var interrupted: Boolean = false,
|
||||
var cancelled: Boolean = false,
|
||||
var currentKeyframes: MutableList<ActionEffectKeyframe> = mutableListOf(),
|
||||
var level: Level? = null
|
||||
) {
|
||||
|
||||
@@ -48,6 +48,8 @@ object ActionEffects : JsonDataRegistry<ActionEffectTimeline> {
|
||||
ActionEffectKeyframe.register<CannotInterruptActionEffectKeyframe>("cannot_interrupt")
|
||||
ActionEffectKeyframe.register<RemoveHoldsActionEffectKeyframe>("remove_holds")
|
||||
ActionEffectKeyframe.register<AddHoldsActionEffectKeyframe>("add_holds")
|
||||
ActionEffectKeyframe.register<PauseTasksActionEffectKeyframe>("pause_tasks")
|
||||
ActionEffectKeyframe.register<ResumeTasksActionEffectKeyframe>("resume_tasks")
|
||||
ActionEffectKeyframe.register<MoveToTargetActionEffectKeyframe>("move_to_target")
|
||||
ActionEffectKeyframe.register<ReturnToPositionActionEffectKeyframe>("return_to_position")
|
||||
ActionEffectKeyframe.register<PauseActionEffectKeyframe>("pause")
|
||||
@@ -57,6 +59,7 @@ object ActionEffects : JsonDataRegistry<ActionEffectTimeline> {
|
||||
ActionEffectKeyframe.register<RunActionEffectKeyframe>("run_action_effect")
|
||||
ActionEffectKeyframe.register<EntityParticlesActionEffectKeyframe>("entity_particles")
|
||||
ActionEffectKeyframe.register<EntitySoundActionEffectKeyframe>("entity_sound")
|
||||
ActionEffectKeyframe.register<CancelActionEffectKeyframe>("cancel")
|
||||
}
|
||||
|
||||
override val gson = GsonBuilder()
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.api.moves.animations.keyframes
|
||||
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class CancelActionEffectKeyframe : ConditionalActionEffectKeyframe() {
|
||||
override fun playWhenTrue(context: ActionEffectContext): CompletableFuture<Unit> {
|
||||
context.cancelled = true
|
||||
return CompletableFuture.completedFuture(Unit)
|
||||
}
|
||||
}
|
||||
+28
-6
@@ -21,6 +21,7 @@ import com.cobblemon.mod.common.util.asIdentifierDefaultingNamespace
|
||||
import net.minecraft.commands.arguments.EntityArgument.getPlayers
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
/**
|
||||
* Spawns particles on the entity based on the given particle effect and locator.
|
||||
@@ -65,15 +66,36 @@ class EntityParticlesActionEffectKeyframe : ConditionalActionEffectKeyframe(), E
|
||||
allEntities.any { player.distanceTo(it) <= visibilityRange }
|
||||
}
|
||||
|
||||
// Try to resolve a world-position target from runtime variables
|
||||
val runtimeTargetPosition: Vec3? = try {
|
||||
val x = "v.target_x".asExpressionLike().resolveDouble(context.runtime)
|
||||
val y = "v.target_y".asExpressionLike().resolveDouble(context.runtime)
|
||||
val z = "v.target_z".asExpressionLike().resolveDouble(context.runtime)
|
||||
if (x != 0.0 || y != 0.0 || z != 0.0) Vec3(x, y, z) else null
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
|
||||
sourceEntities.filter { it is PosableEntity }.forEach { entity ->
|
||||
if (targetLocators == null) {
|
||||
val packet = SpawnSnowstormEntityParticlePacket(effectIdentifier, entity.id, locators)
|
||||
packet.sendToPlayers(players)
|
||||
}
|
||||
else {
|
||||
// If target entities are specified, send the particle using entity locators/position.
|
||||
// If there are no target entities then attempt to send to v.target world position or send without target.
|
||||
if (targetEntities.isNotEmpty()) {
|
||||
targetEntities.forEach { targetEntity ->
|
||||
val packet = SpawnSnowstormEntityParticlePacket(effectIdentifier, entity.id, locators, targetEntity.id, targetLocators!!.toList())
|
||||
if (targetLocators != null) {
|
||||
val packet = SpawnSnowstormEntityParticlePacket(effectIdentifier, entity.id, locators, targetEntity.id, targetLocators!!.toList())
|
||||
packet.sendToPlayers(players)
|
||||
} else {
|
||||
val packet = SpawnSnowstormEntityParticlePacket(effectIdentifier, entity.id, locators, targetEntity.id)
|
||||
packet.sendToPlayers(players)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (runtimeTargetPosition != null) {
|
||||
val packet = SpawnSnowstormEntityParticlePacket(effectIdentifier, entity.id, locators, targetPosition = runtimeTargetPosition)
|
||||
packet.sendToPlayers(players)
|
||||
} else {
|
||||
val packet = SpawnSnowstormEntityParticlePacket(effectIdentifier, entity.id, locators)
|
||||
packet.sendToPlayers(players)
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -8,8 +8,6 @@
|
||||
|
||||
package com.cobblemon.mod.common.api.moves.animations.keyframes
|
||||
|
||||
import com.bedrockk.molang.runtime.struct.QueryStruct
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.api.molang.ExpressionLike
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.scheduling.delayedFuture
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.api.moves.animations.keyframes
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonActivities
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.moves.animations.EntityProvider
|
||||
import com.cobblemon.mod.common.api.moves.animations.NPCProvider
|
||||
import com.cobblemon.mod.common.api.moves.animations.UsersProvider
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
|
||||
class PauseTasksActionEffectKeyframe : ActionEffectKeyframe {
|
||||
override fun play(context: ActionEffectContext): CompletableFuture<Unit> {
|
||||
val entities = context.providers
|
||||
.filterIsInstance<EntityProvider>()
|
||||
.filter { it is UsersProvider || it is NPCProvider }
|
||||
.flatMap { it.entities }
|
||||
|
||||
for (entity in entities) {
|
||||
if (entity is LivingEntity) {
|
||||
entity.brain.setActiveActivityIfPossible(CobblemonActivities.ACTION_EFFECT)
|
||||
}
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(Unit)
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.api.moves.animations.keyframes
|
||||
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.moves.animations.EntityProvider
|
||||
import com.cobblemon.mod.common.api.moves.animations.NPCProvider
|
||||
import com.cobblemon.mod.common.api.moves.animations.UsersProvider
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
|
||||
class ResumeTasksActionEffectKeyframe : ActionEffectKeyframe {
|
||||
override fun play(context: ActionEffectContext): CompletableFuture<Unit> {
|
||||
val entities = context.providers
|
||||
.filterIsInstance<EntityProvider>()
|
||||
.filter { it is UsersProvider || it is NPCProvider }
|
||||
.flatMap { it.entities }
|
||||
|
||||
for (entity in entities) {
|
||||
if (entity is LivingEntity) {
|
||||
val level = entity.level()
|
||||
entity.brain.updateActivityFromSchedule(level.dayTime, level.gameTime)
|
||||
}
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(Unit)
|
||||
}
|
||||
}
|
||||
+25
-2
@@ -8,6 +8,8 @@
|
||||
|
||||
package com.cobblemon.mod.common.api.moves.animations.keyframes
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.api.molang.ExpressionLike
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffects
|
||||
import java.util.concurrent.CompletableFuture
|
||||
@@ -18,16 +20,37 @@ import net.minecraft.resources.ResourceLocation
|
||||
* effect is marked complete only when the action effect it runs is complete unless [waitForActionEffect] is
|
||||
* false.
|
||||
*
|
||||
* If [expression] is set, it will be resolved at runtime to determine the action effect identifier.
|
||||
* This allows dynamic delegation based on MoLang variables (e.g. v.granting_move).
|
||||
* If [expression] is not set, the static [actionEffect] identifier is used instead.
|
||||
*
|
||||
* @author Hiroku
|
||||
* @since January 21st, 2024
|
||||
*/
|
||||
class RunActionEffectKeyframe : ConditionalActionEffectKeyframe() {
|
||||
val actionEffect: ResourceLocation? = null
|
||||
val expression: ExpressionLike? = null
|
||||
val waitForActionEffect = true
|
||||
override fun playWhenTrue(context: ActionEffectContext): CompletableFuture<Unit> {
|
||||
return if (actionEffect != null) {
|
||||
ActionEffects.actionEffects[actionEffect]?.run(context)?.takeIf { waitForActionEffect } ?: skip()
|
||||
val effectId = if (expression != null) {
|
||||
val resolved = expression.resolveString(context.runtime)
|
||||
if (resolved == "0" || resolved.isBlank()) {
|
||||
Cobblemon.LOGGER.warn("RunActionEffectKeyframe expression resolved to empty/zero string: $resolved")
|
||||
return skip()
|
||||
}
|
||||
try {
|
||||
ResourceLocation.parse(resolved)
|
||||
} catch (e: Exception) {
|
||||
Cobblemon.LOGGER.warn("RunActionEffectKeyframe expression resolved to invalid resource location: $resolved with exception: $e")
|
||||
return skip()
|
||||
}
|
||||
} else {
|
||||
actionEffect
|
||||
}
|
||||
return if (effectId != null) {
|
||||
ActionEffects.actionEffects[effectId]?.run(context)?.takeIf { waitForActionEffect } ?: skip()
|
||||
} else {
|
||||
Cobblemon.LOGGER.warn("RunActionEffectKeyframe has no action effect identifier or expression to run")
|
||||
skip()
|
||||
}
|
||||
}
|
||||
|
||||
+6
-8
@@ -22,7 +22,6 @@ import com.cobblemon.mod.common.api.riding.posing.PoseOption
|
||||
import com.cobblemon.mod.common.api.riding.posing.PoseProvider
|
||||
import com.cobblemon.mod.common.api.riding.sound.RideSoundSettingsList
|
||||
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.entity.PoseType
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.util.blockPositionsAsListRounded
|
||||
@@ -145,12 +144,11 @@ class HorseBehaviour : RidingBehaviour<HorseSettings, HorseState> {
|
||||
) {
|
||||
val sprintTimerTickLength = 7 // Emulate vanillas tick timer length
|
||||
var hasDoubleTapped = false
|
||||
val forward = Minecraft.getInstance().player?.input?.up == true
|
||||
|
||||
// If you are not sprinting and you just pressed down and theres no
|
||||
if (!state.forwardHeldLastTick.get() && forward && !state.sprinting.get() && state.sprintTickTimer.get() == 0) {
|
||||
if (!state.forwardHeldLastTick.get() && Minecraft.getInstance().options.keyUp.isDown() && !state.sprinting.get() && state.sprintTickTimer.get() == 0) {
|
||||
state.sprintTickTimer.set(sprintTimerTickLength)
|
||||
} else if (!state.forwardHeldLastTick.get() && forward && state.sprintTickTimer.get() != 0) { // If has double tapped
|
||||
} else if (!state.forwardHeldLastTick.get() && Minecraft.getInstance().options.keyUp.isDown() && state.sprintTickTimer.get() != 0) { // If has double tapped
|
||||
hasDoubleTapped = true
|
||||
}else if(!state.sprinting.get() && state.sprintTickTimer.get() > 0) {
|
||||
state.sprintTickTimer.set(state.sprintTickTimer.get() - 1)
|
||||
@@ -158,9 +156,9 @@ class HorseBehaviour : RidingBehaviour<HorseSettings, HorseState> {
|
||||
state.sprintTickTimer.set(0)
|
||||
}
|
||||
|
||||
val tryingToSprint = hasDoubleTapped || CobblemonClient.ridingSprintHandler.any { it.value.invoke() }
|
||||
val tryingToSprint = (Minecraft.getInstance().options.keySprint.isDown() && Minecraft.getInstance().options.keyUp.isDown()) || hasDoubleTapped
|
||||
|
||||
if (state.stamina.get() <= 0.0f || !forward) {
|
||||
if (state.stamina.get() <= 0.0f || !Minecraft.getInstance().options.keyUp.isDown()) {
|
||||
// If stamina runs out or the player is not holding forward then stop sprinting
|
||||
state.sprinting.set(false)
|
||||
if (state.stamina.get() <= 0.0f) {
|
||||
@@ -174,8 +172,8 @@ class HorseBehaviour : RidingBehaviour<HorseSettings, HorseState> {
|
||||
state.sprinting.set(true)
|
||||
}
|
||||
|
||||
// Take note of whether forward was held last tick
|
||||
state.forwardHeldLastTick.set(forward)
|
||||
// Take not of whether forward was held last tick
|
||||
state.forwardHeldLastTick.set(Minecraft.getInstance().options.keyUp.isDown())
|
||||
}
|
||||
|
||||
fun tickStamina(
|
||||
|
||||
@@ -12,5 +12,6 @@ enum class ParticleMaterial {
|
||||
ALPHA,
|
||||
OPAQUE,
|
||||
BLEND,
|
||||
ADD
|
||||
ADD,
|
||||
XRAY,
|
||||
}
|
||||
@@ -24,6 +24,7 @@ object ParticleMaterials {
|
||||
override fun begin(tessellator: Tesselator, textureManager: TextureManager): BufferBuilder {
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.enableCull()
|
||||
RenderSystem.enableDepthTest()
|
||||
RenderSystem.depthMask(true)
|
||||
RenderSystem.setShader { GameRenderer.getParticleShader() }
|
||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_PARTICLES)
|
||||
@@ -38,6 +39,7 @@ object ParticleMaterials {
|
||||
override fun begin(tessellator: Tesselator, textureManager: TextureManager): BufferBuilder {
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.disableCull()
|
||||
RenderSystem.enableDepthTest()
|
||||
RenderSystem.depthMask(true)
|
||||
RenderSystem.setShader { GameRenderer.getParticleShader() }
|
||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_PARTICLES)
|
||||
@@ -52,6 +54,7 @@ object ParticleMaterials {
|
||||
override fun begin(tessellator: Tesselator, textureManager: TextureManager): BufferBuilder {
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.disableCull()
|
||||
RenderSystem.enableDepthTest()
|
||||
RenderSystem.depthMask(true)
|
||||
RenderSystem.setShader { GameRenderer.getParticleShader() }
|
||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_PARTICLES)
|
||||
@@ -66,6 +69,7 @@ object ParticleMaterials {
|
||||
override fun begin(tessellator: Tesselator, textureManager: TextureManager): BufferBuilder {
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.enableCull()
|
||||
RenderSystem.enableDepthTest()
|
||||
RenderSystem.depthMask(true)
|
||||
RenderSystem.setShader { GameRenderer.getParticleShader() }
|
||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_PARTICLES)
|
||||
@@ -73,6 +77,21 @@ object ParticleMaterials {
|
||||
return tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE)
|
||||
}
|
||||
|
||||
override fun toString() = "OPAQUE"
|
||||
override fun toString() = "OPAQUE"
|
||||
}
|
||||
|
||||
val XRAY = object : ParticleRenderType {
|
||||
override fun begin(tessellator: Tesselator, textureManager: TextureManager): BufferBuilder {
|
||||
RenderSystem.enableBlend()
|
||||
RenderSystem.disableCull()
|
||||
RenderSystem.disableDepthTest()
|
||||
RenderSystem.depthMask(false)
|
||||
RenderSystem.setShader { GameRenderer.getParticleShader() }
|
||||
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_PARTICLES)
|
||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA)
|
||||
return tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE)
|
||||
}
|
||||
|
||||
override fun toString() = "XRAY"
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -102,7 +102,7 @@ open class PlayerPartyStore(
|
||||
for (pokemon in this) {
|
||||
// Awake from fainted
|
||||
if (pokemon.isFainted()) {
|
||||
//Skip awaken logic check if config value is 0
|
||||
// Skip awaken logic check if config value is 0
|
||||
if (Cobblemon.config.faintAwakenHealthPercent > 0) {
|
||||
pokemon.faintedTimer -= 1
|
||||
if (pokemon.faintedTimer <= -1) {
|
||||
@@ -119,7 +119,7 @@ open class PlayerPartyStore(
|
||||
}
|
||||
// Passive healing while less than full health
|
||||
else if (pokemon.currentHealth < pokemon.maxHealth) {
|
||||
//Skip passive healing logic check if config value is 0
|
||||
// Skip passive healing logic check if config value is 0
|
||||
if (Cobblemon.config.healPercent > 0) {
|
||||
pokemon.healTimer--
|
||||
if (pokemon.healTimer <= -1) {
|
||||
|
||||
@@ -25,7 +25,6 @@ import net.minecraft.world.level.block.SoundType
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType
|
||||
import net.minecraft.world.level.block.entity.CommandBlockEntity
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
import net.minecraft.world.level.block.state.StateDefinition
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty
|
||||
@@ -81,13 +80,11 @@ class HabitatBlock(properties: Properties) : Block(properties), EntityBlock {
|
||||
}
|
||||
|
||||
override fun useWithoutItem(state: BlockState, level: Level, pos: BlockPos, player: Player, hitResult: BlockHitResult): InteractionResult {
|
||||
val blockEntity = level.getBlockEntity(pos)
|
||||
val be = level.getBlockEntity(pos) as? HabitatBlockEntity ?: return InteractionResult.PASS
|
||||
return if (blockEntity is HabitatBlockEntity && player.canUseGameMasterBlocks()) {
|
||||
be.onUse(player, hitResult)
|
||||
} else {
|
||||
InteractionResult.PASS
|
||||
if (!level.isClientSide) {
|
||||
val be = level.getBlockEntity(pos) as? HabitatBlockEntity ?: return InteractionResult.PASS
|
||||
return be.onUse(player, hitResult)
|
||||
}
|
||||
return InteractionResult.SUCCESS
|
||||
}
|
||||
|
||||
override fun getDrops(state: BlockState, params: LootParams.Builder): MutableList<ItemStack> {
|
||||
|
||||
@@ -70,7 +70,6 @@ import com.cobblemon.mod.common.entity.boat.CobblemonBoatType
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.platform.events.PlatformEvents
|
||||
import com.cobblemon.mod.common.pokedex.scanner.PokedexUsageContext
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.util.isLookingAt
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.color.block.BlockColor
|
||||
@@ -80,19 +79,16 @@ import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.model.BoatModel
|
||||
import net.minecraft.client.model.ChestBoatModel
|
||||
import net.minecraft.client.model.PlayerModel
|
||||
import net.minecraft.client.player.LocalPlayer
|
||||
import net.minecraft.client.renderer.RenderType
|
||||
import net.minecraft.client.renderer.blockentity.HangingSignRenderer
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer
|
||||
import net.minecraft.client.renderer.entity.LivingEntityRenderer
|
||||
import net.minecraft.client.resources.PlayerSkin
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.packs.resources.ResourceManager
|
||||
import net.minecraft.world.InteractionHand
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.phys.AABB
|
||||
import org.joml.Vector2d
|
||||
|
||||
object CobblemonClient {
|
||||
|
||||
@@ -113,8 +109,6 @@ object CobblemonClient {
|
||||
val battleOverlay: BattleOverlay by lazy { BattleOverlay() }
|
||||
val pokedexUsageContext: PokedexUsageContext by lazy { PokedexUsageContext() }
|
||||
val rideControlsOverlay: RideControlsOverlay by lazy { RideControlsOverlay() }
|
||||
val ridingTurnInputHandler: MutableMap<ResourceLocation, (LocalPlayer, Double, Double, Double) -> Vector2d> = mutableMapOf()
|
||||
val ridingSprintHandler: MutableMap<ResourceLocation, () -> Boolean> = mutableMapOf()
|
||||
|
||||
fun onLogin() {
|
||||
clientPlayerData = ClientGeneralPlayerData()
|
||||
@@ -185,6 +179,8 @@ object CobblemonClient {
|
||||
return@subscribe
|
||||
}
|
||||
|
||||
storage.party.forEach { it?.tickSkillCooldowns() }
|
||||
|
||||
val nearbyPokemon = player.level().getEntities(
|
||||
player,
|
||||
AABB.ofSize(player.position(), 16.0, 16.0, 16.0)
|
||||
@@ -200,8 +196,6 @@ object CobblemonClient {
|
||||
ClientPlayerIcon.onTick()
|
||||
PartyOverlayDataControl.tick(event.client.isPaused)
|
||||
}
|
||||
|
||||
ridingSprintHandler.put(cobblemonResource("normal")) { Minecraft.getInstance().options.keySprint.isDown }
|
||||
}
|
||||
|
||||
private fun registerTooltipManagers() {
|
||||
|
||||
@@ -129,10 +129,6 @@ class PartyOverlay : Gui(Minecraft.getInstance()) {
|
||||
val panelX = 0
|
||||
val party = CobblemonClient.storage.party
|
||||
val matrices = context.pose()
|
||||
|
||||
matrices.pushPose()
|
||||
matrices.translate(0.0, 0.0, -100.0)
|
||||
|
||||
if (party.slots.none { it != null }) {
|
||||
if (!this.attachedToast &&
|
||||
CobblemonClient.clientPlayerData.promptStarter &&
|
||||
@@ -186,11 +182,10 @@ class PartyOverlay : Gui(Minecraft.getInstance()) {
|
||||
)
|
||||
|
||||
matrices.pushPose()
|
||||
matrices.scale(1F, 1F, 0.2F)
|
||||
matrices.translate(
|
||||
panelX + portraitFrameOffsetX + selectedOffsetX + PORTRAIT_DIAMETER / 2.0 - 1.0,
|
||||
y.toDouble() - 12,
|
||||
-50.0
|
||||
0.0
|
||||
)
|
||||
|
||||
val shouldAnimate = when (Cobblemon.config.partyPortraitAnimations) {
|
||||
@@ -562,7 +557,5 @@ class PartyOverlay : Gui(Minecraft.getInstance()) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrices.popPose()
|
||||
}
|
||||
}
|
||||
@@ -195,7 +195,7 @@ abstract class ScrollingWidget<T : ObjectSelectionList.Entry<T>>(
|
||||
return this.width
|
||||
}
|
||||
|
||||
public override fun getRowTop(index: Int): Int {
|
||||
override fun getRowTop(index: Int): Int {
|
||||
return this.y - scrollAmount.toInt() + (index * this.itemHeight)
|
||||
}
|
||||
|
||||
@@ -205,19 +205,6 @@ abstract class ScrollingWidget<T : ObjectSelectionList.Entry<T>>(
|
||||
|
||||
override fun getScrollbarPosition(): Int = this.left + this.width - this.scrollBarWidth
|
||||
|
||||
public override fun ensureVisible(entry: T) {
|
||||
val i = getRowTop(children().indexOf(entry))
|
||||
val topDifference = i - y
|
||||
if (topDifference < 0) {
|
||||
scroll(topDifference)
|
||||
}
|
||||
|
||||
val bottomDifference = bottom - i - itemHeight - 4
|
||||
if (bottomDifference < 0) {
|
||||
scroll(-bottomDifference)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Slot<T : Slot<T>>(): Entry<T>() {
|
||||
// Override render to show each individual element
|
||||
}
|
||||
|
||||
+18
-29
@@ -68,23 +68,25 @@ open class VariableObjectSelectionList(x: Int, y: Int, width: Int, height: Int):
|
||||
}
|
||||
|
||||
override fun renderWidget(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, partialTick: Float) {
|
||||
var stackHeight = -scrollAmount.toInt()
|
||||
guiGraphics.enableScissor(x, y, x + width, y + height)
|
||||
children.forEachIndexed { index, entry ->
|
||||
val yTop = getRowTop(entry)
|
||||
if (yTop + entry.height > y || yTop < y + height) {
|
||||
entry.render(guiGraphics, index, x, yTop, mouseX, mouseY, partialTick)
|
||||
if (stackHeight in 1..<height || stackHeight + entry.height in 1..<height) {
|
||||
entry.render(guiGraphics, index, x, y + stackHeight, mouseX, mouseY, partialTick)
|
||||
}
|
||||
stackHeight += entry.height
|
||||
}
|
||||
guiGraphics.disableScissor()
|
||||
}
|
||||
|
||||
fun getEntryAtPosition(mouseX: Int, mouseY: Int): Entry? {
|
||||
if (mouseX in x..(x + width) && mouseY in y..(y + height)) {
|
||||
var stackHeight = -scrollAmount
|
||||
children.forEach {
|
||||
val yTop = getRowTop(it)
|
||||
if (mouseY in (yTop)..(yTop + it.height)) {
|
||||
if (mouseY.toDouble() in (y + stackHeight)..(y + stackHeight + it.height)) {
|
||||
return it
|
||||
}
|
||||
stackHeight += it.height
|
||||
}
|
||||
}
|
||||
return null
|
||||
@@ -92,16 +94,10 @@ open class VariableObjectSelectionList(x: Int, y: Int, width: Int, height: Int):
|
||||
|
||||
fun ensureVisible(index: Int) {
|
||||
val entry = children[index]
|
||||
ensureVisible(entry)
|
||||
}
|
||||
|
||||
open fun ensureVisible(entry: Entry) {
|
||||
if (entry !in children) return
|
||||
val yTop = entry.scrolledY - scrollAmount.toInt()
|
||||
if (yTop < 0) {
|
||||
if (entry.scrolledY - scrollAmount < 0) {
|
||||
setScroll(entry.scrolledY.toDouble())
|
||||
} else if (yTop + entry.height > height) {
|
||||
setScroll((entry.scrolledY + entry.height - height).toDouble())
|
||||
} else if (entry.scrolledY + entry.height > height) {
|
||||
setScroll(entry.scrolledY.toDouble() + entry.height)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,12 +121,14 @@ open class VariableObjectSelectionList(x: Int, y: Int, width: Int, height: Int):
|
||||
}
|
||||
|
||||
fun getRowTop(entry: Entry): Int {
|
||||
if (entry !in children) return -1
|
||||
return y + entry.scrolledY - scrollAmount.toInt()
|
||||
}
|
||||
|
||||
fun getLeft(): Int {
|
||||
return x
|
||||
var stackHeight = -scrollAmount.toInt()
|
||||
children.forEach {
|
||||
if (it == entry) {
|
||||
return y + stackHeight
|
||||
}
|
||||
stackHeight += it.height
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
override fun defaultButtonNarrationText(pNarrationElementOutput: NarrationElementOutput) {}
|
||||
@@ -138,7 +136,6 @@ open class VariableObjectSelectionList(x: Int, y: Int, width: Int, height: Int):
|
||||
|
||||
abstract inner class Entry(var height: Int): GuiEventListener {
|
||||
var scrolledY: Int = 0
|
||||
|
||||
private var widgetFocused = false
|
||||
|
||||
override fun setFocused(focused: Boolean) {
|
||||
@@ -148,14 +145,6 @@ open class VariableObjectSelectionList(x: Int, y: Int, width: Int, height: Int):
|
||||
override fun isFocused(): Boolean = widgetFocused
|
||||
|
||||
abstract fun render(guiGraphics: GuiGraphics, index: Int, x: Int, y: Int, mouseX: Int, mouseY: Int, partialTick: Float)
|
||||
|
||||
fun getRowTop(): Int {
|
||||
return getRowTop(this)
|
||||
}
|
||||
|
||||
fun getRowLeft(): Int {
|
||||
return getLeft()
|
||||
}
|
||||
}
|
||||
|
||||
inner class EmptySeparator(height: Int): Entry(height) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
package com.cobblemon.mod.common.client.gui.battle
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.battles.PassActionResponse
|
||||
import com.cobblemon.mod.common.battles.ShowdownActionResponse
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
@@ -18,18 +17,9 @@ import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.gui.battle.subscreen.BattleActionSelection
|
||||
import com.cobblemon.mod.common.client.gui.battle.subscreen.BattleBackButton
|
||||
import com.cobblemon.mod.common.client.gui.battle.subscreen.BattleGeneralActionSelection
|
||||
import com.cobblemon.mod.common.client.gui.battle.subscreen.BattleMoveSelection
|
||||
import com.cobblemon.mod.common.client.gui.battle.subscreen.BattleSwitchPokemonSelection
|
||||
import com.cobblemon.mod.common.client.gui.battle.subscreen.BattleTargetSelection
|
||||
import com.cobblemon.mod.common.client.gui.battle.subscreen.ForfeitConfirmationSelection
|
||||
import com.cobblemon.mod.common.client.gui.battle.widgets.BattleMessagePane
|
||||
import com.cobblemon.mod.common.client.gui.battle.widgets.BattleOptionTile
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary.Companion.PARTY
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.PartyWidget
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.SubManagerComponent
|
||||
import com.cobblemon.mod.common.client.keybind.boundKey
|
||||
import com.cobblemon.mod.common.client.keybind.keybinds.PartySendBinding
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
@@ -39,11 +29,8 @@ import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import org.joml.Vector4i
|
||||
|
||||
class BattleGUI : Screen(battleLang("gui.title")), CobblemonRenderable, ControllerScreen {
|
||||
class BattleGUI : Screen(battleLang("gui.title")), CobblemonRenderable {
|
||||
companion object {
|
||||
const val OPTION_VERTICAL_SPACING = 3
|
||||
const val OPTION_HORIZONTAL_SPACING = 3
|
||||
@@ -64,49 +51,11 @@ class BattleGUI : Screen(battleLang("gui.title")), CobblemonRenderable, Controll
|
||||
|
||||
var queuedActions = mutableListOf<() -> Unit>()
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
super.init()
|
||||
messagePane = BattleMessagePane(CobblemonClient.battle!!.messages)
|
||||
messagePane.opacity = CobblemonClient.battleOverlay.opacityRatio.toFloat().coerceAtLeast(0.3F)
|
||||
addRenderableWidget(messagePane)
|
||||
|
||||
controllerComponentManager.componentList["spectating_quit"] = ControllerComponent().also {
|
||||
it.onPress = {
|
||||
quitSpectating()
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["battle_action"] = SubManagerComponent().also {
|
||||
it.subManager = { getCurrentActionSelection()?.controllerComponentManager }
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["battle_action"]
|
||||
it.onActiveChange = { state ->
|
||||
if (!state) {
|
||||
getCurrentActionSelection()?.controllerComponentManager?.active = false
|
||||
} else {
|
||||
if (it.currentSelectedComponent == "battle_action") getCurrentActionSelection()?.controllerComponentManager?.active = true
|
||||
}
|
||||
}
|
||||
it.onBack = {
|
||||
if (it.currentSelectedComponent == "battle_action") {
|
||||
getCurrentActionSelection()?.controllerComponentManager?.onBack?.invoke()
|
||||
} else {
|
||||
minimizeBattle()
|
||||
}
|
||||
}
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_1,
|
||||
{ (getCurrentActionSelection() as? BattleMoveSelection)?.shiftButtonActive() ?: false },
|
||||
Component.translatable("cobblemon.controller.battle.swap_position"),
|
||||
true
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fun changeActionSelection(newSelection: BattleActionSelection?) {
|
||||
@@ -116,11 +65,6 @@ class BattleGUI : Screen(battleLang("gui.title")), CobblemonRenderable, Controll
|
||||
if (newSelection != null) {
|
||||
addRenderableWidget(newSelection)
|
||||
}
|
||||
if (controllerComponentManager.currentSelectedComponent == "battle_action" && controllerComponentManager.active) {
|
||||
focused = null
|
||||
getCurrentActionSelection()?.controllerComponentManager?.active = true
|
||||
controllerComponentManager.focused?.onFocus?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,38 +85,6 @@ class BattleGUI : Screen(battleLang("gui.title")), CobblemonRenderable, Controll
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSelectionPosAndSize(): Vector4i? {
|
||||
val data = super.getSelectionPosAndSize()
|
||||
if (data != null) {
|
||||
return data
|
||||
}
|
||||
|
||||
val actionSelection = getCurrentActionSelection()
|
||||
var newData: Vector4i? = null
|
||||
when (actionSelection) {
|
||||
is BattleGeneralActionSelection -> {
|
||||
val tile = actionSelection.controllerComponentManager.focused?.associatedGUIElement as? BattleOptionTile
|
||||
if (tile != null) {
|
||||
newData = Vector4i(tile.x - 2, tile.y - 2, BattleOptionTile.OPTION_WIDTH + 4, BattleOptionTile.OPTION_HEIGHT + 4)
|
||||
}
|
||||
}
|
||||
is BattleMoveSelection -> {
|
||||
val move = actionSelection.moveTiles[actionSelection.selectedMoveIndex]
|
||||
newData = Vector4i(move.x.toInt() - 10, move.y.toInt() - 2, BattleMoveSelection.MOVE_WIDTH + 12, BattleMoveSelection.MOVE_HEIGHT + 4)
|
||||
}
|
||||
is BattleSwitchPokemonSelection -> {
|
||||
val tile = actionSelection.tiles[actionSelection.selectedTileIndex]
|
||||
newData = Vector4i(tile.x.toInt() - 2, tile.y.toInt() - 2, BattleSwitchPokemonSelection.SwitchTile.SELECT_WIDTH + 2, BattleSwitchPokemonSelection.SwitchTile.SELECT_HEIGHT - 1)
|
||||
}
|
||||
is BattleTargetSelection -> {
|
||||
val tile = actionSelection.baseTiles[actionSelection.selectedTileIndex]
|
||||
newData = Vector4i(tile.x.toInt() - 2, tile.y.toInt() - 2, BattleTargetSelection.TARGET_WIDTH + 4, BattleTargetSelection.TARGET_HEIGHT + 2)
|
||||
}
|
||||
}
|
||||
|
||||
return newData
|
||||
}
|
||||
|
||||
override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
super.render(context, mouseX, mouseY, delta)
|
||||
|
||||
@@ -210,10 +122,9 @@ class BattleGUI : Screen(battleLang("gui.title")), CobblemonRenderable, Controll
|
||||
|
||||
val currentSelection = getCurrentActionSelection()
|
||||
if (currentSelection == null || currentSelection is BattleGeneralActionSelection ) {
|
||||
val hideLabelButton = if (controllerComponentManager.active) controllerComponentManager.getVisual(ResourceLocation.fromNamespaceAndPath("controlify", "gui_back")) else PartySendBinding.boundKey().displayName
|
||||
drawScaledText(
|
||||
context = context,
|
||||
text = battleLang("ui.hide_label", hideLabelButton),
|
||||
text = battleLang("ui.hide_label", PartySendBinding.boundKey().displayName),
|
||||
x = Minecraft.getInstance().window.guiScaledWidth / 2,
|
||||
y = (Minecraft.getInstance().window.guiScaledHeight / 5),
|
||||
opacity = 0.75F * opacity,
|
||||
@@ -230,17 +141,6 @@ class BattleGUI : Screen(battleLang("gui.title")), CobblemonRenderable, Controll
|
||||
)
|
||||
}
|
||||
|
||||
renderSelection(context.pose())
|
||||
|
||||
val activeComponent: ControllerComponent?
|
||||
if (battle.spectating) {
|
||||
activeComponent = controllerComponentManager.componentList["spectator_quit"]
|
||||
} else {
|
||||
activeComponent = controllerComponentManager.componentList["battle_action"]
|
||||
}
|
||||
if (controllerComponentManager.focused != activeComponent) {
|
||||
controllerComponentManager.focused = activeComponent
|
||||
}
|
||||
|
||||
queuedActions.forEach { it() }
|
||||
queuedActions.clear()
|
||||
@@ -251,6 +151,8 @@ class BattleGUI : Screen(battleLang("gui.title")), CobblemonRenderable, Controll
|
||||
}
|
||||
|
||||
fun deriveRootActionSelection(actor: ClientBattleActor, request: SingleActionRequest): BattleActionSelection? {
|
||||
|
||||
|
||||
return if (request.forceSwitch) {
|
||||
BattleSwitchPokemonSelection(this, request)
|
||||
} else {
|
||||
@@ -290,21 +192,15 @@ class BattleGUI : Screen(battleLang("gui.title")), CobblemonRenderable, Controll
|
||||
return minimizeBattle()
|
||||
}
|
||||
|
||||
if (specBackButton.isHovered(mouseX, mouseY)) {
|
||||
quitSpectating()
|
||||
val battle = CobblemonClient.battle
|
||||
if (battle?.spectating == true && specBackButton.isHovered(mouseX, mouseY)) {
|
||||
RemoveSpectatorPacket(battle.battleId).sendToServer()
|
||||
CobblemonClient.endBattle()
|
||||
}
|
||||
return super.mouseClicked(mouseX, mouseY, button)
|
||||
}
|
||||
|
||||
fun quitSpectating() {
|
||||
val battle = CobblemonClient.battle
|
||||
if (battle?.spectating == true) {
|
||||
RemoveSpectatorPacket(battle.battleId).sendToServer()
|
||||
CobblemonClient.endBattle()
|
||||
}
|
||||
}
|
||||
|
||||
fun minimizeBattle(): Boolean {
|
||||
private fun minimizeBattle(): Boolean {
|
||||
val battle = CobblemonClient.battle ?: return false
|
||||
battle.minimised = !battle.minimised
|
||||
PartySendBinding.actioned()
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.battle.ActiveClientBattlePokemon
|
||||
import com.cobblemon.mod.common.client.battle.ClientBallDisplay
|
||||
import com.cobblemon.mod.common.client.gui.battle.widgets.BattleMessagePane
|
||||
import com.cobblemon.mod.common.client.integration.controlify.CobblemonControlifyEntrypoint
|
||||
import com.cobblemon.mod.common.client.keybind.boundKey
|
||||
import com.cobblemon.mod.common.client.keybind.keybinds.PartySendBinding
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
@@ -115,10 +114,6 @@ class BattleOverlay : Gui(Minecraft.getInstance()), Schedulable {
|
||||
override val schedulingTracker = SchedulingTracker()
|
||||
|
||||
override fun render(context: GuiGraphics, tickCounter: DeltaTracker) {
|
||||
val matrixStack = context.pose()
|
||||
matrixStack.pushPose()
|
||||
matrixStack.translate(0.0, 0.0, -50.0) // Push back so controlify gui renders infront
|
||||
|
||||
val tickDelta = tickCounter.realtimeDeltaTicks.takeIf { !Minecraft.getInstance()!!.isPaused } ?: 0F
|
||||
schedulingTracker.update(tickDelta / 20F)
|
||||
passedSeconds += tickDelta / 20
|
||||
@@ -147,14 +142,9 @@ class BattleOverlay : Gui(Minecraft.getInstance()), Schedulable {
|
||||
|
||||
if (Minecraft.getInstance().screen !is BattleGUI && battle.mustChoose) {
|
||||
val textOpacity = PROMPT_TEXT_OPACITY_CURVE(passedSeconds)
|
||||
|
||||
val bindingComponent = if (Cobblemon.implementation.isModInstalled("controlify") && CobblemonControlifyEntrypoint.controllerActive())
|
||||
CobblemonControlifyEntrypoint.SEND_OUT_POKEMON!!.inputGlyph()
|
||||
else PartySendBinding.boundKey().displayName
|
||||
|
||||
drawScaledText(
|
||||
context = context,
|
||||
text = battleLang("ui.actions_label", bindingComponent),
|
||||
text = battleLang("ui.actions_label", PartySendBinding.boundKey().displayName),
|
||||
x = Minecraft.getInstance().window.guiScaledWidth / 2,
|
||||
y = Minecraft.getInstance().window.guiScaledHeight / 5,
|
||||
opacity = textOpacity,
|
||||
@@ -170,8 +160,6 @@ class BattleOverlay : Gui(Minecraft.getInstance()), Schedulable {
|
||||
messagePane.opacity = 0.3F
|
||||
messagePane.render(context, 0, 0, 0F)
|
||||
}
|
||||
|
||||
matrixStack.popPose()
|
||||
}
|
||||
|
||||
fun drawTile(context: GuiGraphics, tickDelta: Float, activeBattlePokemon: ActiveClientBattlePokemon, left: Boolean, rank: Int, dexState: PokedexEntryProgress, hasCommand: Boolean = false, isHovered: Boolean = false, isCompact: Boolean = false) {
|
||||
@@ -309,11 +297,10 @@ class BattleOverlay : Gui(Minecraft.getInstance()), Schedulable {
|
||||
(y + portraitDiameter + portraitOffsetY).toInt(),
|
||||
)
|
||||
matrixStack.pushPose()
|
||||
matrixStack.scale(1F, 1F, 0.2F)
|
||||
matrixStack.translate(
|
||||
portraitStartX + portraitDiameter / 2.0,
|
||||
y.toDouble() + portraitOffsetY - if (isCompact) 15.0 else 5.0,
|
||||
-50.0
|
||||
0.0
|
||||
)
|
||||
|
||||
if (ballState != null && ballState.currentPose != "shut") {
|
||||
|
||||
-3
@@ -11,7 +11,6 @@ package com.cobblemon.mod.common.client.gui.battle.subscreen
|
||||
import com.cobblemon.mod.common.api.gui.ParentWidget
|
||||
import com.cobblemon.mod.common.client.battle.SingleActionRequest
|
||||
import com.cobblemon.mod.common.client.gui.battle.BattleGUI
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.mojang.blaze3d.platform.InputConstants
|
||||
import net.minecraft.network.chat.MutableComponent
|
||||
|
||||
@@ -27,8 +26,6 @@ abstract class BattleActionSelection(
|
||||
val opacity: Float
|
||||
get() = battleGUI.opacity
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(battleGUI)
|
||||
|
||||
override fun mouseClicked(pMouseX: Double, pMouseY: Double, pButton: Int): Boolean {
|
||||
if(pButton == InputConstants.MOUSE_BUTTON_LEFT){
|
||||
return mousePrimaryClicked(pMouseX, pMouseY)
|
||||
|
||||
+9
-30
@@ -15,7 +15,6 @@ import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.client.battle.SingleActionRequest
|
||||
import com.cobblemon.mod.common.client.gui.battle.BattleGUI
|
||||
import com.cobblemon.mod.common.client.gui.battle.widgets.BattleOptionTile
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.util.battleLang
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
@@ -42,7 +41,6 @@ class BattleGeneralActionSelection(
|
||||
val lastAnwseredRequest = CobblemonClient.battle?.getLastAnsweredRequest()
|
||||
|
||||
val tiles = mutableListOf<BattleOptionTile>()
|
||||
|
||||
init {
|
||||
var rank = 0
|
||||
|
||||
@@ -78,41 +76,22 @@ class BattleGeneralActionSelection(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["tile_0_0"]
|
||||
it.onBack = {
|
||||
battleGUI.minimizeBattle()
|
||||
}
|
||||
it.onActiveChange = { state ->
|
||||
if (state) it.focused?.onSelect?.invoke() else it.focused?.onUnselect?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addOption(rank: Int, text: MutableComponent, texture: ResourceLocation, onClick: () -> Unit) {
|
||||
val startY = Minecraft.getInstance().window.guiScaledHeight - BattleGUI.OPTION_VERTICAL_OFFSET
|
||||
val x = if (rank % 2 == 0) BattleGUI.OPTION_ROOT_X else BattleGUI.OPTION_ROOT_X + BattleGUI.OPTION_HORIZONTAL_SPACING + BattleOptionTile.OPTION_WIDTH
|
||||
val y = if (rank > 1) startY + BattleOptionTile.OPTION_HEIGHT + BattleGUI.OPTION_HORIZONTAL_SPACING else startY
|
||||
val tile = BattleOptionTile(
|
||||
battleGUI = battleGUI,
|
||||
x = x,
|
||||
y = y,
|
||||
resource = texture,
|
||||
text = text,
|
||||
onClick = onClick
|
||||
tiles.add(
|
||||
BattleOptionTile(
|
||||
battleGUI = battleGUI,
|
||||
x = x,
|
||||
y = y,
|
||||
resource = texture,
|
||||
text = text,
|
||||
onClick = onClick
|
||||
)
|
||||
)
|
||||
tiles.add(tile)
|
||||
val row = rank / 2
|
||||
val column = rank % 2
|
||||
controllerComponentManager.componentList["tile_${row}_${column}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = tile
|
||||
if (row == 1) it.up = { controllerComponentManager.componentList["tile_0_${column}"] }
|
||||
else it.down = { controllerComponentManager.componentList["tile_1_${column}"] }
|
||||
if (column == 1) it.left = { controllerComponentManager.componentList["tile_${row}_0"] }
|
||||
else it.right = { controllerComponentManager.componentList["tile_${row}_1"] }
|
||||
it.onPress = { tile.onClick.invoke() }
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
|
||||
+4
-63
@@ -21,12 +21,10 @@ import com.cobblemon.mod.common.client.battle.SingleActionRequest
|
||||
import com.cobblemon.mod.common.client.gui.MoveCategoryIcon
|
||||
import com.cobblemon.mod.common.client.gui.TypeIcon
|
||||
import com.cobblemon.mod.common.client.gui.battle.BattleGUI
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.util.battleLang
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.util.math.toRGB
|
||||
import com.cobblemon.mod.common.util.startWith
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
@@ -68,10 +66,6 @@ class BattleMoveSelection(
|
||||
MoveTile(this, inBattleMove, x, y)
|
||||
}
|
||||
var moveTiles = baseTiles
|
||||
set(value) {
|
||||
field = value
|
||||
recalculateMoveGrid()
|
||||
}
|
||||
|
||||
val backButton = BattleBackButton(x - 11F, Minecraft.getInstance().window.guiScaledHeight - 22F)
|
||||
val gimmickButtons = moveSet.getGimmicks().filter { it !in moveSet.pendingGimmickUsedThisTurn }.mapIndexed { index, gimmick ->
|
||||
@@ -82,53 +76,6 @@ class BattleMoveSelection(
|
||||
|
||||
val shiftButton = BattleShiftButton(x + 22.5F, Minecraft.getInstance().window.guiScaledHeight - 22F )
|
||||
|
||||
private fun recalculateMoveGrid() {
|
||||
controllerComponentManager.componentList.filter { it.key.startsWith("move_") }.forEach { controllerComponentManager.componentList.remove(it.key) }
|
||||
moveTiles.forEachIndexed { index, tile ->
|
||||
val column = index % 2
|
||||
val row = index / 2
|
||||
controllerComponentManager.componentList["move_${row}_${column}"] = ControllerComponent().also {
|
||||
if (row == 1) it.up = { controllerComponentManager.componentList["move_${0}_${column}"] }
|
||||
else it.down = { controllerComponentManager.componentList["move_${1}_${column}"] }
|
||||
if (column == 1) it.left = { controllerComponentManager.componentList["move_${row}_0"] }
|
||||
else it.right = { controllerComponentManager.componentList["move_${row}_1"] }
|
||||
it.onPress = {
|
||||
if(request.activePokemon.getFormat().battleType.pokemonPerSide == 1) {
|
||||
tile.onClick()
|
||||
} else {
|
||||
battleGUI.changeActionSelection(BattleTargetSelection(battleGUI, request, tile.move, tile.response.gimmickID, tile.move.gimmickMove))
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
}
|
||||
}
|
||||
it.onSpecial1 = {
|
||||
if (shiftButtonActive()) {
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
battleGUI.selectAction(request, ShiftActionResponse())
|
||||
}
|
||||
}
|
||||
it.onFocus = { tile.controllerSelected = true }
|
||||
it.onUnfocus = { tile.controllerSelected = false }
|
||||
it.onSelect = { selectedMoveIndex = index }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var selectedMoveIndex = 0
|
||||
|
||||
init {
|
||||
recalculateMoveGrid()
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["move_0_0"]
|
||||
it.onBack = {
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
battleGUI.changeActionSelection(null)
|
||||
}
|
||||
it.onActiveChange = { state ->
|
||||
if (state) it.focused?.onSelect?.invoke() else it.focused?.onUnselect?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class MoveTile(
|
||||
val moveSelection: BattleMoveSelection,
|
||||
val move: InBattleMove,
|
||||
@@ -152,8 +99,6 @@ class BattleMoveSelection(
|
||||
}
|
||||
}
|
||||
|
||||
var controllerSelected = false
|
||||
|
||||
fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
|
||||
val selectConditionOpacity = moveSelection.opacity * if (!selectable) 0.5F else 1F
|
||||
@@ -165,7 +110,7 @@ class BattleMoveSelection(
|
||||
y = y,
|
||||
width = MOVE_WIDTH,
|
||||
height = MOVE_HEIGHT,
|
||||
vOffset = if (selectable && (isHovered(mouseX.toDouble(), mouseY.toDouble()) || controllerSelected)) MOVE_HEIGHT else 0,
|
||||
vOffset = if (selectable && isHovered(mouseX.toDouble(), mouseY.toDouble())) MOVE_HEIGHT else 0,
|
||||
textureHeight = MOVE_HEIGHT * 2,
|
||||
red = rgb.first,
|
||||
green = rgb.second,
|
||||
@@ -230,7 +175,7 @@ class BattleMoveSelection(
|
||||
)
|
||||
}
|
||||
|
||||
fun isHovered(mouseX: Double, mouseY: Double) = (mouseX >= x && mouseX <= x + MOVE_WIDTH && mouseY >= y && mouseY <= y + MOVE_HEIGHT)
|
||||
fun isHovered(mouseX: Double, mouseY: Double) = mouseX >= x && mouseX <= x + MOVE_WIDTH && mouseY >= y && mouseY <= y + MOVE_HEIGHT
|
||||
|
||||
fun onClick() {
|
||||
if (!selectable) return
|
||||
@@ -239,10 +184,6 @@ class BattleMoveSelection(
|
||||
}
|
||||
}
|
||||
|
||||
fun shiftButtonActive(): Boolean {
|
||||
return this.request.activePokemon.getFormat().battleType.slotsPerActor == 3 && (request.activePokemon.getPNX()[2] == 'a' || request.activePokemon.getPNX()[2] == 'c')
|
||||
}
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
moveTiles.forEach {
|
||||
it.render(context, mouseX, mouseY, delta)
|
||||
@@ -251,7 +192,7 @@ class BattleMoveSelection(
|
||||
gimmickButtons.forEach {
|
||||
it.render(context.pose(), mouseX, mouseY, delta)
|
||||
}
|
||||
if(shiftButtonActive()) {
|
||||
if(this.request.activePokemon.getFormat().battleType.slotsPerActor == 3 && (request.activePokemon.getPNX()[2] == 'a' || request.activePokemon.getPNX()[2] == 'c')) {
|
||||
shiftButton.render(context, mouseX, mouseY, delta)
|
||||
}
|
||||
}
|
||||
@@ -273,7 +214,7 @@ class BattleMoveSelection(
|
||||
} else if (gimmick != null) {
|
||||
gimmickButtons.filter { it != gimmick }.forEach { it.toggled = false }
|
||||
moveTiles = if (gimmick.toggle()) gimmick.tiles else baseTiles
|
||||
} else if(shiftButton.isHovered(mouseX,mouseY) && shiftButtonActive()) {
|
||||
} else if(shiftButton.isHovered(mouseX,mouseY)) {
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
battleGUI.selectAction(request, ShiftActionResponse())
|
||||
}
|
||||
|
||||
+5
-41
@@ -21,7 +21,6 @@ import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.battle.SingleActionRequest
|
||||
import com.cobblemon.mod.common.client.gui.battle.BattleGUI
|
||||
import com.cobblemon.mod.common.client.gui.drawProfilePokemon
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.render.getDepletableRedGreen
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.FloatingState
|
||||
@@ -69,8 +68,6 @@ class BattleSwitchPokemonSelection(
|
||||
|
||||
var isReviving = false
|
||||
|
||||
var selectedTileIndex = 0
|
||||
|
||||
init {
|
||||
val pendingActionRequests = CobblemonClient.battle!!.pendingActionRequests
|
||||
val switchingInPokemon = pendingActionRequests.mapNotNull { it.response }.filterIsInstance<SwitchActionResponse>().map { it.newPokemonId }
|
||||
@@ -95,33 +92,6 @@ class BattleSwitchPokemonSelection(
|
||||
|
||||
tiles.add(SwitchTile(this, slotX, slotY, pokemon, showdownPokemon, isFainted, isCurrentlyInBattle))
|
||||
}
|
||||
|
||||
tiles.forEachIndexed { index, tile ->
|
||||
val row = index / 2
|
||||
val column = index % 2
|
||||
val maxRow = (tiles.size + 1) / 2
|
||||
controllerComponentManager.componentList["tile_${row}_${column}"] = ControllerComponent().also {
|
||||
if (row - 1 >= 0) it.up = { controllerComponentManager.componentList["tile_${row-1}_${column}"] }
|
||||
if (row + 1 < maxRow) it.down = { controllerComponentManager.componentList["tile_${row+1}_${column}"] }
|
||||
if (column == 1) it.left = { controllerComponentManager.componentList["tile_${row}_0"] }
|
||||
else if (row != maxRow || tiles.size % 2 == 0) it.right = { controllerComponentManager.componentList["tile_${row}_1"] }
|
||||
it.onPress = { clickTile(tile) }
|
||||
it.onFocus = { tile.controllerSelected = true }
|
||||
it.onUnfocus = { tile.controllerSelected = false }
|
||||
it.onSelect = { selectedTileIndex = index }
|
||||
}
|
||||
}
|
||||
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["tile_0_0"]
|
||||
it.onBack = {
|
||||
battleGUI.changeActionSelection(null)
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
}
|
||||
it.onActiveChange = { state ->
|
||||
if (state) it.focused?.onSelect?.invoke() else it.focused?.onUnselect?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getSlotPosition(index: Int): Pair<Float, Float> {
|
||||
@@ -184,15 +154,11 @@ class BattleSwitchPokemonSelection(
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
return true
|
||||
}
|
||||
val clicked = tiles.find { it.isHovered(mouseX, mouseY) } ?: return false
|
||||
return clickTile(clicked)
|
||||
}
|
||||
|
||||
fun clickTile(tile: SwitchTile): Boolean {
|
||||
if (!(if (isReviving) tile.isFainted else (!tile.isFainted && !tile.isCurrentlyInBattle))) return false
|
||||
val pokemon = tile.pokemon
|
||||
val clicked = tiles.find { it.isHovered(mouseX, mouseY) && if (isReviving) it.isFainted else (!it.isFainted && !it.isCurrentlyInBattle) } ?: return false
|
||||
val pokemon = clicked.pokemon
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
battleGUI.selectAction(request, SwitchActionResponse(pokemon.uuid))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -224,9 +190,7 @@ class BattleSwitchPokemonSelection(
|
||||
|
||||
val state = FloatingState()
|
||||
|
||||
var controllerSelected = false
|
||||
|
||||
fun isHovered(mouseX: Double, mouseY: Double) = (mouseX in x..(x + SELECT_WIDTH) && mouseY in (y..(y + SELECT_HEIGHT)))
|
||||
fun isHovered(mouseX: Double, mouseY: Double) = mouseX in x..(x + SELECT_WIDTH) && mouseY in (y..(y + SELECT_HEIGHT))
|
||||
|
||||
fun render(context: GuiGraphics, mouseX: Double, mouseY: Double, deltaTicks: Float) {
|
||||
state.currentAspects = pokemon.aspects
|
||||
@@ -265,7 +229,7 @@ class BattleSwitchPokemonSelection(
|
||||
y = y,
|
||||
width = SELECT_WIDTH,
|
||||
height = SELECT_HEIGHT,
|
||||
vOffset = if (!isFainted && (isHovered(mouseX, mouseY) || isCurrentlyInBattle || controllerSelected)) SELECT_HEIGHT else 0,
|
||||
vOffset = if (!isFainted && (isHovered(mouseX, mouseY) || isCurrentlyInBattle)) SELECT_HEIGHT else 0,
|
||||
textureHeight = SELECT_HEIGHT * 2,
|
||||
)
|
||||
|
||||
|
||||
+3
-31
@@ -26,7 +26,6 @@ import com.cobblemon.mod.common.client.gui.battle.BattleGUI
|
||||
import com.cobblemon.mod.common.client.gui.battle.BattleOverlay
|
||||
import com.cobblemon.mod.common.client.gui.battle.subscreen.BattleSwitchPokemonSelection.Companion
|
||||
import com.cobblemon.mod.common.client.gui.drawProfilePokemon
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.FloatingState
|
||||
import com.cobblemon.mod.common.pokemon.Gender
|
||||
@@ -112,35 +111,10 @@ class BattleTargetSelection(
|
||||
else -> if (isAlly) ArrowDirection.UP else ArrowDirection.DOWN
|
||||
}
|
||||
}
|
||||
var out = TargetTile(this, target, x, y, arrowDirection)
|
||||
controllerComponentManager.componentList["tile_${if (isAlly) 0 else 1}_${fieldPos}"] = ControllerComponent().also {
|
||||
if (isAlly) it.up = { controllerComponentManager.componentList["tile_1_${fieldPos}"] }
|
||||
else it.down = { controllerComponentManager.componentList["tile_0_${fieldPos}"] }
|
||||
if (fieldPos - 1 >= 0) it.left = { controllerComponentManager.componentList["tile_${if (isAlly) 0 else 1}_${fieldPos-1}"] }
|
||||
if (fieldPos + 1 < teamSize) it.right = { controllerComponentManager.componentList["tile_${if (isAlly) 0 else 1}_${fieldPos+1}"] }
|
||||
it.onPress = { out.onClick() }
|
||||
it.onFocus = { out.controllerSelected = true }
|
||||
it.onUnfocus = { out.controllerSelected = false }
|
||||
it.onSelect = { selectedTileIndex = index }
|
||||
}
|
||||
out
|
||||
TargetTile(this, target, x, y, arrowDirection)
|
||||
}
|
||||
var targetTiles = baseTiles
|
||||
|
||||
var selectedTileIndex = 0
|
||||
|
||||
init {
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["tile_0_0"]
|
||||
it.onBack = {
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
battleGUI.changeActionSelection(BattleMoveSelection(battleGUI, request))
|
||||
}
|
||||
it.onActiveChange = { state ->
|
||||
if (state) it.focused?.onSelect?.invoke() else it.focused?.onUnselect?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open inner class TargetTile(
|
||||
val targetSelection: BattleTargetSelection,
|
||||
@@ -177,8 +151,6 @@ class BattleTargetSelection(
|
||||
ArrowDirection.DOWN -> Pair(this.x + TARGET_WIDTH / 2 - 4F, this.y - 7)
|
||||
}
|
||||
|
||||
var controllerSelected = false
|
||||
|
||||
fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
val passedSeconds = CobblemonClient.battleOverlay.passedSeconds // This syncs the role throbbers
|
||||
val selectConditionOpacity = targetSelection.opacity * if (!selectable) 0.5F else 1F
|
||||
@@ -332,9 +304,9 @@ class BattleTargetSelection(
|
||||
|
||||
fun isHovered(mouseX: Double, mouseY: Double): Boolean {
|
||||
if(isMultiTarget) {
|
||||
return targetTiles.firstOrNull { it.selectable && ((mouseX >= it.x && mouseX <= it.x + TARGET_WIDTH && mouseY >= it.y && mouseY <= it.y + TARGET_HEIGHT) || it.controllerSelected) } != null
|
||||
return targetTiles.firstOrNull { it.selectable && mouseX >= it.x && mouseX <= it.x + TARGET_WIDTH && mouseY >= it.y && mouseY <= it.y + TARGET_HEIGHT } != null
|
||||
}
|
||||
return mouseX >= x && mouseX <= x + TARGET_WIDTH && mouseY >= y && mouseY <= y + TARGET_HEIGHT || controllerSelected
|
||||
return mouseX >= x && mouseX <= x + TARGET_WIDTH && mouseY >= y && mouseY <= y + TARGET_HEIGHT
|
||||
}
|
||||
|
||||
fun onClick() {
|
||||
|
||||
+9
-41
@@ -17,7 +17,6 @@ import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.battle.SingleActionRequest
|
||||
import com.cobblemon.mod.common.client.gui.battle.BattleGUI
|
||||
import com.cobblemon.mod.common.client.gui.interact.battleRequest.BattleResponseButton
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.util.battleLang
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
@@ -52,52 +51,21 @@ class ForfeitConfirmationSelection(
|
||||
|
||||
acceptButton = BattleResponseButton(xPos + 22, yPos + 18, true) {}
|
||||
declineButton = BattleResponseButton(xPos + 57, yPos + 18, false) {}
|
||||
|
||||
controllerComponentManager.componentList["accept_button"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = acceptButton
|
||||
it.onPress = {
|
||||
onAccept()
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
}
|
||||
it.right = { controllerComponentManager.componentList["decline_button"] }
|
||||
}
|
||||
controllerComponentManager.componentList["decline_button"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = declineButton
|
||||
it.onPress = {
|
||||
onDecline()
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
}
|
||||
it.left = { controllerComponentManager.componentList["accept_button"] }
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["decline_button"]
|
||||
it.onBack = {
|
||||
it.componentList["decline_button"]?.onPress?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onAccept() {
|
||||
battleGUI.selectAction(request, ForfeitActionResponse())
|
||||
|
||||
// Need to fill out any other pending requests
|
||||
var pendingRequest = CobblemonClient.battle?.getFirstUnansweredRequest()
|
||||
while (pendingRequest != null) {
|
||||
battleGUI.selectAction(pendingRequest, PassActionResponse)
|
||||
pendingRequest = CobblemonClient.battle?.getFirstUnansweredRequest()
|
||||
}
|
||||
}
|
||||
|
||||
fun onDecline() {
|
||||
battleGUI.changeActionSelection(null)
|
||||
}
|
||||
|
||||
override fun mousePrimaryClicked(mouseX: Double, mouseY: Double): Boolean {
|
||||
if (declineButton.isHovered(mouseX, mouseY) || acceptButton.isHovered(mouseX, mouseY)) {
|
||||
if (declineButton.isHovered(mouseX, mouseY)) {
|
||||
onDecline()
|
||||
battleGUI.changeActionSelection(null)
|
||||
} else {
|
||||
onAccept()
|
||||
battleGUI.selectAction(request, ForfeitActionResponse())
|
||||
|
||||
// Need to fill out any other pending requests
|
||||
var pendingRequest = CobblemonClient.battle?.getFirstUnansweredRequest()
|
||||
while (pendingRequest != null) {
|
||||
battleGUI.selectAction(pendingRequest, PassActionResponse)
|
||||
pendingRequest = CobblemonClient.battle?.getFirstUnansweredRequest()
|
||||
}
|
||||
}
|
||||
playDownSound(Minecraft.getInstance().soundManager)
|
||||
return true
|
||||
|
||||
+2
-2
@@ -50,7 +50,7 @@ class BattleOptionTile(
|
||||
alpha = opacity,
|
||||
width = OPTION_WIDTH,
|
||||
height = OPTION_HEIGHT,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble()) || focused) OPTION_HEIGHT else 0,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble())) OPTION_HEIGHT else 0,
|
||||
textureHeight = OPTION_HEIGHT * 2
|
||||
)
|
||||
|
||||
@@ -80,7 +80,7 @@ class BattleOptionTile(
|
||||
|
||||
override fun isFocused() = focused
|
||||
|
||||
fun isHovered(mouseX: Double, mouseY: Double) = (mouseX > x && mouseY > y && mouseX < x + OPTION_WIDTH && mouseY < y + OPTION_HEIGHT)
|
||||
fun isHovered(mouseX: Double, mouseY: Double) = mouseX > x && mouseY > y && mouseX < x + OPTION_WIDTH && mouseY < y + OPTION_HEIGHT
|
||||
|
||||
override fun updateNarration(builder: NarrationElementOutput) {
|
||||
builder.add(NarratedElementType.TITLE, text)
|
||||
|
||||
+1
-56
@@ -10,10 +10,6 @@ package com.cobblemon.mod.common.client.gui.config
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.gui.config.variable.CobblemonConfigVariable
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.config.CobblemonConfig
|
||||
import com.cobblemon.mod.common.util.asTranslated
|
||||
import com.cobblemon.mod.common.util.ifServer
|
||||
@@ -26,14 +22,11 @@ import net.minecraft.client.gui.components.StringWidget
|
||||
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout
|
||||
import net.minecraft.client.gui.layouts.LinearLayout
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.CommonComponents
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
|
||||
class CobblemonConfigScreen(
|
||||
private val previousScreen: Screen?,
|
||||
) : Screen("gui.cobblemon_config.title".asTranslated()), CobblemonRenderable, ControllerScreen {
|
||||
) : Screen("gui.cobblemon_config.title".asTranslated()), CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
const val HEIGHT = 240
|
||||
@@ -48,7 +41,6 @@ class CobblemonConfigScreen(
|
||||
const val WIDGET_HEIGHT = SLOT_HEIGHT - PADDING
|
||||
const val LABEL_Y_OFFSET = 4
|
||||
const val WIDGET_Y_OFFSET = 0
|
||||
const val LABEL_MAX_WIDTH = SLOT_WIDTH - RESET_SLOT_WIDTH - WIDGET_WIDTH - PADDING * 2
|
||||
}
|
||||
|
||||
val clonedConfig = Cobblemon.config.clone()
|
||||
@@ -62,13 +54,6 @@ class CobblemonConfigScreen(
|
||||
|
||||
private var searchString: String = ""
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
var lastSelectedEntry = 0
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
super.init()
|
||||
|
||||
@@ -112,46 +97,6 @@ class CobblemonConfigScreen(
|
||||
addRenderableWidget(widget)
|
||||
}
|
||||
arrangeLayoutElements()
|
||||
|
||||
controllerComponentManager.componentList["search"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = searchEdit
|
||||
it.down = {
|
||||
val variableEntries = variableList.children().filter { it is CobblemonConfigVariable }
|
||||
if (variableEntries.isNotEmpty()) {
|
||||
controllerComponentManager.componentList["entry_${lastSelectedEntry}_input"]
|
||||
} else {
|
||||
controllerComponentManager.componentList["done"]
|
||||
}
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["done"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = doneButton
|
||||
it.up = {
|
||||
val variableEntries = variableList.children().filter { it is CobblemonConfigVariable }
|
||||
if (variableEntries.isNotEmpty()) {
|
||||
controllerComponentManager.componentList["entry_${lastSelectedEntry}_input"]
|
||||
} else {
|
||||
controllerComponentManager.componentList["search"]
|
||||
}
|
||||
}
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["search"]
|
||||
it.onBack = {
|
||||
Minecraft.getInstance().soundManager.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 1.0F))
|
||||
doneButtonClick()
|
||||
}
|
||||
it.onStart = {
|
||||
it.focused = it.componentList["search"]
|
||||
it.openKeyboard.invoke(it.focused!!.associatedGUIElement as EditBox)
|
||||
Minecraft.getInstance().soundManager.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 1.0F))
|
||||
}
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.START,
|
||||
{ true },
|
||||
Component.translatable("cobblemon.controller.quick_search")
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
private fun arrangeLayoutElements() {
|
||||
|
||||
-58
@@ -17,7 +17,6 @@ import com.cobblemon.mod.common.client.gui.config.CobblemonConfigScreen.Companio
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigScreen.Companion.SLOT_WIDTH
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigVariableList.CobblemonConfigVariableListEntry
|
||||
import com.cobblemon.mod.common.client.gui.config.variable.*
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.config.Category
|
||||
import com.cobblemon.mod.common.config.CobblemonConfig
|
||||
@@ -135,63 +134,6 @@ class CobblemonConfigVariableList(
|
||||
}
|
||||
|
||||
scrollAmount = min(maxScroll.toDouble(), scrollAmount)
|
||||
|
||||
val variableEntries = children().filter { it is CobblemonConfigVariable }
|
||||
variableEntries.forEachIndexed { index, entry ->
|
||||
parent.controllerComponentManager.componentList["entry_${index}_input"] = ControllerComponent().also {
|
||||
when (entry) {
|
||||
is CobblemonConfigButtonVariable -> it.associatedGUIElement = entry.button
|
||||
is CobblemonConfigEditBoxVariable -> it.associatedGUIElement = entry.editBox
|
||||
}
|
||||
it.right = {
|
||||
if ((entry as CobblemonConfigVariable).resetButton.active) {
|
||||
parent.controllerComponentManager.componentList["entry_${index}_reset"]
|
||||
}
|
||||
else null
|
||||
}
|
||||
if (index + 1 <= variableEntries.size - 1) it.down = { parent.controllerComponentManager.componentList["entry_${index+1}_input"] }
|
||||
else it.down = { parent.controllerComponentManager.componentList["done"] }
|
||||
if (index - 1 >= 0) it.up = { parent.controllerComponentManager.componentList["entry_${index-1}_input"] }
|
||||
else it.up = { parent.controllerComponentManager.componentList["search"] }
|
||||
it.onSelect = { parent.lastSelectedEntry = index }
|
||||
it.onFocus = { ensureVisible(entry) }
|
||||
}
|
||||
parent.controllerComponentManager.componentList["entry_${index}_reset"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = (entry as CobblemonConfigVariable).resetButton
|
||||
it.left = { parent.controllerComponentManager.componentList["entry_${index}_input"] }
|
||||
if (index + 1 <= variableEntries.size - 1) it.down = {
|
||||
if ((variableEntries[index+1] as CobblemonConfigVariable).resetButton.active) {
|
||||
parent.controllerComponentManager.componentList["entry_${index+1}_reset"]
|
||||
}
|
||||
else null
|
||||
}
|
||||
else it.down = { parent.controllerComponentManager.componentList["done"] }
|
||||
if (index - 1 >= 0) it.up = {
|
||||
if ((variableEntries[index-1] as CobblemonConfigVariable).resetButton.active) {
|
||||
parent.controllerComponentManager.componentList["entry_${index-1}_reset"]
|
||||
}
|
||||
else null
|
||||
}
|
||||
else it.up = { parent.controllerComponentManager.componentList["search"] }
|
||||
it.onPress = {
|
||||
entry.resetButton.also { button ->
|
||||
button.onPress()
|
||||
button.playDownSound(Minecraft.getInstance().soundManager)
|
||||
parent.controllerComponentManager.also { manager ->
|
||||
manager.focused = manager.componentList["entry_${index}_input"]
|
||||
}
|
||||
}
|
||||
}
|
||||
it.onSelect = { parent.lastSelectedEntry = index }
|
||||
it.onFocus = { ensureVisible(entry) }
|
||||
}
|
||||
}
|
||||
parent.controllerComponentManager.let {
|
||||
if (it.currentSelectedComponent.startsWith("entry_")) {
|
||||
it.focused = it.componentList["search"]
|
||||
}
|
||||
}
|
||||
parent.lastSelectedEntry = 0
|
||||
}
|
||||
|
||||
abstract class CobblemonConfigVariableListEntry(
|
||||
|
||||
+8
-12
@@ -8,18 +8,17 @@
|
||||
|
||||
package com.cobblemon.mod.common.client.gui.config.variable
|
||||
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigScreen.Companion.LABEL_MAX_WIDTH
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigScreen.Companion.LABEL_Y_OFFSET
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigScreen.Companion.RESET_SLOT_WIDTH
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigScreen.Companion.SLOT_WIDTH
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigScreen.Companion.WIDGET_HEIGHT
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigScreen.Companion.WIDGET_Y_OFFSET
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigVariableList
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigVariableList.CobblemonConfigVariableListEntry
|
||||
import com.cobblemon.mod.common.client.render.drawScrollingText
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.config.CobblemonConfig
|
||||
import com.cobblemon.mod.common.config.CobblemonConfigField
|
||||
import com.cobblemon.mod.common.util.lang
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.gui.components.Tooltip
|
||||
@@ -92,15 +91,12 @@ abstract class CobblemonConfigVariable(
|
||||
val x = getX(left)
|
||||
val y = getY(top)
|
||||
|
||||
drawScrollingText(
|
||||
context,
|
||||
Minecraft.getInstance().font,
|
||||
labelLang,
|
||||
x,
|
||||
y + WIDGET_Y_OFFSET,
|
||||
x + LABEL_MAX_WIDTH,
|
||||
y + WIDGET_Y_OFFSET + WIDGET_HEIGHT,
|
||||
-1
|
||||
drawScaledText(
|
||||
context = context,
|
||||
text = labelLang,
|
||||
x = getX(left),
|
||||
y = getY(top) + LABEL_Y_OFFSET,
|
||||
shadow = true
|
||||
)
|
||||
|
||||
resetButton.x = x + SLOT_WIDTH - RESET_SLOT_WIDTH
|
||||
|
||||
+1
-41
@@ -26,9 +26,6 @@ import com.cobblemon.mod.common.client.gui.dialogue.widgets.DialogueOptionWidget
|
||||
import com.cobblemon.mod.common.client.gui.dialogue.widgets.DialoguePortraitWidget
|
||||
import com.cobblemon.mod.common.client.gui.dialogue.widgets.DialogueTextInputWidget
|
||||
import com.cobblemon.mod.common.client.gui.dialogue.widgets.DialogueTimerWidget
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.entity.PosableEntity
|
||||
import com.cobblemon.mod.common.net.messages.client.dialogue.dto.DialogueDTO
|
||||
import com.cobblemon.mod.common.net.messages.client.dialogue.dto.DialogueGibberDTO
|
||||
@@ -48,10 +45,9 @@ import net.minecraft.client.gui.components.EditBox
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
|
||||
class DialogueScreen(var dialogueDTO: DialogueDTO) : Screen("gui.dialogue".asTranslated()), CobblemonRenderable, ControllerScreen {
|
||||
class DialogueScreen(var dialogueDTO: DialogueDTO) : Screen("gui.dialogue".asTranslated()), CobblemonRenderable {
|
||||
val speakers = dialogueDTO.speakers?.mapNotNull { (key, value) ->
|
||||
val name = value.name
|
||||
when (val face = value.face) {
|
||||
@@ -145,12 +141,6 @@ class DialogueScreen(var dialogueDTO: DialogueDTO) : Screen("gui.dialogue".asTra
|
||||
)
|
||||
}
|
||||
|
||||
var controllerComponentManager = ControllerComponentManager(this)
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
override fun renderBackground(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {}
|
||||
|
||||
override fun renderBlurredBackground(delta: Float) {}
|
||||
@@ -252,34 +242,6 @@ class DialogueScreen(var dialogueDTO: DialogueDTO) : Screen("gui.dialogue".asTra
|
||||
}
|
||||
|
||||
this.dialogueStartTick = minecraft!!.player!!.tickCount
|
||||
|
||||
controllerComponentManager = ControllerComponentManager(this)
|
||||
|
||||
controllerComponentManager.componentList["none"] = ControllerComponent().also {
|
||||
it.onPress = { dialogueBox.onClick() }
|
||||
}
|
||||
dialogueOptionWidgets.forEachIndexed { index, option ->
|
||||
controllerComponentManager.componentList["option_${index}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = option
|
||||
if (index + 1 <= dialogueOptionWidgets.size - 1) it.right = { controllerComponentManager.componentList["option_${index+1}"] }
|
||||
if (index - 1 >= 0) it.left = { controllerComponentManager.componentList["option_${index-1}"] }
|
||||
it.onPress = { if (!option.onClick()) dialogueBox.onClick() }
|
||||
}
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = if (dialogueOptionWidgets.isNotEmpty()) {
|
||||
it.componentList["option_0"]
|
||||
} else {
|
||||
it.componentList["none"]
|
||||
}
|
||||
it.onSpecial1 = { dialogueBox.onClick() }
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_1,
|
||||
{ dialogueBox.dialogue.dialogueInput.allowSkip && dialogueBox.dialogue.dialogueInput.inputType in listOf(DialogueInputDTO.InputType.NONE, DialogueInputDTO.InputType.AUTO_CONTINUE)},
|
||||
Component.translatable("cobblemon.controller.dialogue.skip"),
|
||||
true
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
var gibberIndex = 0
|
||||
@@ -303,8 +265,6 @@ class DialogueScreen(var dialogueDTO: DialogueDTO) : Screen("gui.dialogue".asTra
|
||||
super.render(guiGraphics, mouseX, mouseY, delta)
|
||||
expressionsToRun.forEach { runtime.resolve(it) }
|
||||
expressionsToRun = emptyList()
|
||||
|
||||
renderSelection(guiGraphics.pose())
|
||||
}
|
||||
|
||||
override fun isPauseScreen() = false
|
||||
|
||||
+4
-10
@@ -160,17 +160,10 @@ class DialogueBox(
|
||||
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
// TODO change this coordinate check to just be "anywhere the scroll bar isn't"
|
||||
if (mouseX > this.x && mouseX < this.scrollbarPosition &&
|
||||
if (!dialogueScreen.waitingForServerUpdate &&
|
||||
mouseX > this.x && mouseX < this.scrollbarPosition &&
|
||||
mouseY > this.y && mouseY < this.bottom
|
||||
) {
|
||||
if (onClick()) return true
|
||||
}
|
||||
|
||||
return super.mouseClicked(mouseX, mouseY, button)
|
||||
}
|
||||
|
||||
fun onClick(): Boolean {
|
||||
if (!dialogueScreen.waitingForServerUpdate) {
|
||||
if (dialogue.dialogueInput.allowSkip && dialogue.dialogueInput.inputType in listOf(DialogueInputDTO.InputType.NONE, DialogueInputDTO.InputType.AUTO_CONTINUE)) {
|
||||
val gibber = dialogueScreen.gibber
|
||||
if (gibber != null && gibber.graduallyShowText && !dialogueScreen.gibberDone) {
|
||||
@@ -184,7 +177,8 @@ class DialogueBox(
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
return super.mouseClicked(mouseX, mouseY, button)
|
||||
}
|
||||
|
||||
class DialogueLine(val line: FormattedCharSequence, val lineColor: Int) : Entry<DialogueLine>() {
|
||||
|
||||
+2
-6
@@ -42,7 +42,7 @@ class DialogueOptionWidget(
|
||||
y = y,
|
||||
width = width,
|
||||
height = height,
|
||||
vOffset = if (selectable) (if (isHovered || isFocused) height else 0) else (height * 2),
|
||||
vOffset = if (selectable) (if (isHovered) height else 0) else (height * 2),
|
||||
textureHeight = height * 3,
|
||||
)
|
||||
|
||||
@@ -58,14 +58,10 @@ class DialogueOptionWidget(
|
||||
}
|
||||
|
||||
override fun mouseClicked(pMouseX: Double, pMouseY: Double, pButton: Int): Boolean {
|
||||
if (!isHovered) return false
|
||||
return onClick()
|
||||
}
|
||||
|
||||
fun onClick(): Boolean {
|
||||
if (!dialogueScreen.renderInput()) {
|
||||
return false
|
||||
}
|
||||
if (!isHovered) return false
|
||||
|
||||
if (!selectable || dialogueScreen.waitingForServerUpdate) return true
|
||||
|
||||
|
||||
+21
-68
@@ -8,7 +8,6 @@
|
||||
|
||||
package com.cobblemon.mod.common.client.gui.interact.battleRequest
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.ColourLibrary
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.text.bold
|
||||
@@ -17,9 +16,6 @@ import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.battle.ClientBattleChallenge
|
||||
import com.cobblemon.mod.common.client.battle.ClientTeamRequest
|
||||
import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.net.messages.client.PlayerInteractOptionsPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.*
|
||||
@@ -31,18 +27,16 @@ import com.cobblemon.mod.common.util.lang
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.network.chat.MutableComponent
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import java.util.*
|
||||
|
||||
class BattleConfigureGUI(
|
||||
private val packet: PlayerInteractOptionsPacket,
|
||||
private val activeRequest: ClientBattleChallenge? = null,
|
||||
private val activeTeamRequest: ClientTeamRequest? = null
|
||||
) : Screen(lang("ui.challenge.challenge_title")), CobblemonRenderable, ControllerScreen {
|
||||
) : Screen(lang("ui.challenge.challenge_title")), CobblemonRenderable {
|
||||
companion object {
|
||||
const val SIZE = 113
|
||||
private val backgroundResource = cobblemonResource("textures/gui/interact/request/battle_request.png")
|
||||
@@ -206,12 +200,6 @@ class BattleConfigureGUI(
|
||||
private var hasRequest = false
|
||||
private var ticksPassed = 0F
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
override fun renderBlurredBackground(delta: Float) { }
|
||||
override fun renderMenuBackground(context: GuiGraphics) { }
|
||||
|
||||
@@ -230,29 +218,29 @@ class BattleConfigureGUI(
|
||||
}
|
||||
val (x, y) = getDimensions()
|
||||
|
||||
var battleAccept: BattleResponseButton? = null
|
||||
var battleDecline: BattleResponseButton? = null
|
||||
if(pendingRequest != null) {
|
||||
// Draw Accept/Decline buttons
|
||||
battleAccept = BattleResponseButton(
|
||||
x + 22,
|
||||
y + 99,
|
||||
true
|
||||
) {
|
||||
battleRequestMap[options[currentPage]]?.onResponse?.let { it1 -> it1(packet, pendingRequest.requestID, true) }
|
||||
closeGUI()
|
||||
}
|
||||
this.addRenderableWidget(battleAccept)
|
||||
this.addRenderableWidget(
|
||||
BattleResponseButton(
|
||||
x + 22,
|
||||
y + 99,
|
||||
true
|
||||
) {
|
||||
battleRequestMap[options[currentPage]]?.onResponse?.let { it1 -> it1(packet, pendingRequest.requestID, true) }
|
||||
closeGUI()
|
||||
}
|
||||
)
|
||||
|
||||
battleDecline = BattleResponseButton(
|
||||
x + 56,
|
||||
y + 99,
|
||||
false
|
||||
) {
|
||||
battleRequestMap[options[currentPage]]?.onResponse?.let { it1 -> it1(packet, pendingRequest.requestID, false) }
|
||||
closeGUI()
|
||||
}
|
||||
this.addRenderableWidget(battleDecline)
|
||||
this.addRenderableWidget(
|
||||
BattleResponseButton(
|
||||
x + 56,
|
||||
y + 99,
|
||||
false
|
||||
) {
|
||||
battleRequestMap[options[currentPage]]?.onResponse?.let { it1 -> it1(packet, pendingRequest.requestID, false) }
|
||||
closeGUI()
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
else {
|
||||
@@ -318,36 +306,6 @@ class BattleConfigureGUI(
|
||||
this.addRenderableWidget(autoLevelNavButtonRight)
|
||||
}
|
||||
}
|
||||
|
||||
controllerComponentManager.componentList["battle_accept"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = battleAccept
|
||||
it.right = { controllerComponentManager.componentList["battle_decline"] }
|
||||
}
|
||||
controllerComponentManager.componentList["battle_decline"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = battleDecline
|
||||
it.left = { controllerComponentManager.componentList["battle_accept"] }
|
||||
}
|
||||
controllerComponentManager.componentList["request"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = requestButton
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
if (pendingRequest != null) {
|
||||
it.focused = it.componentList["battle_decline"]
|
||||
} else {
|
||||
it.focused = it.componentList["request"]
|
||||
it.onTabNav = { nextTab ->
|
||||
currentPage = (currentPage + (if (nextTab) 1 else -1)) % options.count()
|
||||
updateRequestButtonText()
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
}
|
||||
if (battleRequestMap[options[currentPage]]?.option != PlayerInteractOptionsPacket.Options.TEAM_REQUEST) {
|
||||
it.onSecondaryTabNav = { nextTab ->
|
||||
levelRulesetOptionIndex += if (nextTab) 1 else -1
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateRequestButtonText() {
|
||||
@@ -480,8 +438,6 @@ class BattleConfigureGUI(
|
||||
)
|
||||
|
||||
super.render(context, mouseX, mouseY, delta)
|
||||
|
||||
renderSelection(context.pose())
|
||||
}
|
||||
|
||||
private fun getDimensions(): Pair<Int, Int> {
|
||||
@@ -498,7 +454,4 @@ class BattleConfigureGUI(
|
||||
Minecraft.getInstance().setScreen(null)
|
||||
}
|
||||
|
||||
fun playSound(soundEvent: SoundEvent) {
|
||||
Minecraft.getInstance().soundManager.play(SimpleSoundInstance.forUI(soundEvent, 1.0F))
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -35,7 +35,7 @@ class BattleResponseButton(
|
||||
}
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, pMouseX: Int, pMouseY: Int, pPartialTicks: Float) {
|
||||
val hovered = (isHovered(pMouseX.toDouble(), pMouseY.toDouble()) || isFocused)
|
||||
val hovered = (isHovered(pMouseX.toDouble(), pMouseY.toDouble()))
|
||||
blitk(
|
||||
matrixStack = context.pose(),
|
||||
x = x / SCALE,
|
||||
|
||||
+11
-31
@@ -14,9 +14,6 @@ import com.cobblemon.mod.common.api.callback.MoveSelectDTO
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.gui.ExitButton
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.net.messages.server.callback.move.MoveSelectCancelledPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.callback.move.MoveSelectedPacket
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
@@ -39,7 +36,7 @@ class MoveSelectConfiguration(
|
||||
|
||||
class MoveSelectGUI(
|
||||
val config: MoveSelectConfiguration
|
||||
) : Screen(Component.translatable("cobblemon.ui.interact.moveselect")), CobblemonRenderable, ControllerScreen {
|
||||
) : Screen(Component.translatable("cobblemon.ui.interact.moveselect")), CobblemonRenderable {
|
||||
companion object {
|
||||
const val WIDTH = 122
|
||||
const val HEIGHT = 133
|
||||
@@ -49,8 +46,6 @@ class MoveSelectGUI(
|
||||
|
||||
var closed = false
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
|
||||
constructor(
|
||||
title: MutableComponent,
|
||||
moves: List<MoveSelectDTO>,
|
||||
@@ -68,10 +63,6 @@ class MoveSelectGUI(
|
||||
)
|
||||
)
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
fun closeProperly() {
|
||||
closed = true
|
||||
onClose()
|
||||
@@ -82,21 +73,16 @@ class MoveSelectGUI(
|
||||
val y = (height - HEIGHT) / 2
|
||||
|
||||
config.moves.forEachIndexed { index, move ->
|
||||
val moveSlot = MoveSlotButton(
|
||||
x = x + 7,
|
||||
y = y + 7 + ((MoveSlotButton.HEIGHT + 3) * index),
|
||||
move = move.moveTemplate,
|
||||
pp = move.pp,
|
||||
ppMax = move.ppMax,
|
||||
enabled = move.enabled
|
||||
) { onPress(move) }
|
||||
addRenderableWidget(moveSlot)
|
||||
|
||||
controllerComponentManager.componentList["move_${index}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = moveSlot
|
||||
if (index + 1 <= config.moves.size - 1) it.down = { controllerComponentManager.componentList["move_${index+1}"] }
|
||||
if (index - 1 >= 0) it.up = { controllerComponentManager.componentList["move_${index-1}"] }
|
||||
}
|
||||
addRenderableWidget(
|
||||
MoveSlotButton(
|
||||
x = x + 7,
|
||||
y = y + 7 + ((MoveSlotButton.HEIGHT + 3) * index),
|
||||
move = move.moveTemplate,
|
||||
pp = move.pp,
|
||||
ppMax = move.ppMax,
|
||||
enabled = move.enabled
|
||||
) { onPress(move) }
|
||||
)
|
||||
}
|
||||
|
||||
// Add Exit Button
|
||||
@@ -111,10 +97,6 @@ class MoveSelectGUI(
|
||||
)
|
||||
|
||||
super.init()
|
||||
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["move_0"]
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, partialTicks: Float) {
|
||||
@@ -132,8 +114,6 @@ class MoveSelectGUI(
|
||||
|
||||
// Render all added Widgets
|
||||
super.render(context, mouseX, mouseY, partialTicks)
|
||||
|
||||
renderSelection(context.pose())
|
||||
}
|
||||
|
||||
private fun onPress(move: MoveSelectDTO) {
|
||||
|
||||
+15
-39
@@ -16,9 +16,6 @@ import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.gui.ExitButton
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.net.messages.server.callback.party.PartyPokemonSelectedPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.callback.party.PartySelectCancelledPacket
|
||||
@@ -41,7 +38,7 @@ class PartySelectConfiguration(
|
||||
)
|
||||
class PartySelectGUI(
|
||||
val config: PartySelectConfiguration
|
||||
) : Screen(Component.translatable("cobblemon.ui.interact.moveselect")), CobblemonRenderable, ControllerScreen {
|
||||
) : Screen(Component.translatable("cobblemon.ui.interact.moveselect")), CobblemonRenderable {
|
||||
companion object {
|
||||
const val WIDTH = 163
|
||||
const val HEIGHT = 132
|
||||
@@ -53,8 +50,6 @@ class PartySelectGUI(
|
||||
|
||||
var closed = false
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
|
||||
constructor(
|
||||
title: MutableComponent,
|
||||
pokemon: List<PartySelectPokemonDTO>,
|
||||
@@ -72,10 +67,6 @@ class PartySelectGUI(
|
||||
)
|
||||
)
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
fun closeProperly() {
|
||||
closed = true
|
||||
onClose()
|
||||
@@ -99,29 +90,20 @@ class PartySelectGUI(
|
||||
slotY += (31 * offsetIndex) + offsetY
|
||||
}
|
||||
|
||||
val slot = PartySlotButton(
|
||||
parent = this,
|
||||
x = slotX,
|
||||
y = slotY,
|
||||
pokemon = pokemon.pokemonProperties,
|
||||
aspects = pokemon.aspects,
|
||||
heldItem = pokemon.heldItem,
|
||||
currentHealth = pokemon.currentHealth,
|
||||
maxHealth = pokemon.maxHealth,
|
||||
enabled = pokemon.enabled,
|
||||
hoverText = pokemon.hoverText,
|
||||
) { onPress(pokemon) }
|
||||
addRenderableWidget(slot)
|
||||
|
||||
val row = index / 2
|
||||
val column = index % 2
|
||||
controllerComponentManager.componentList["slot_${row}_${column}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = slot
|
||||
if (column == 0) it.right = { controllerComponentManager.componentList["slot_${row}_${1}"] }
|
||||
else it.left = { controllerComponentManager.componentList["slot_${row}_${0}"] }
|
||||
if (row - 1 >= 0) it.up = { controllerComponentManager.componentList["slot_${row-1}_${column}"] }
|
||||
if (row + 1 <= 2) it.down = { controllerComponentManager.componentList["slot_${row+1}_${column}"] }
|
||||
}
|
||||
addRenderableWidget(
|
||||
PartySlotButton(
|
||||
parent = this,
|
||||
x = slotX,
|
||||
y = slotY,
|
||||
pokemon = pokemon.pokemonProperties,
|
||||
aspects = pokemon.aspects,
|
||||
heldItem = pokemon.heldItem,
|
||||
currentHealth = pokemon.currentHealth,
|
||||
maxHealth = pokemon.maxHealth,
|
||||
enabled = pokemon.enabled,
|
||||
hoverText = pokemon.hoverText,
|
||||
) { onPress(pokemon) }
|
||||
)
|
||||
}
|
||||
|
||||
// Add Exit Button
|
||||
@@ -136,10 +118,6 @@ class PartySelectGUI(
|
||||
)
|
||||
|
||||
super.init()
|
||||
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["slot_0_0"]
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, partialTicks: Float) {
|
||||
@@ -177,8 +155,6 @@ class PartySelectGUI(
|
||||
|
||||
// Render all added Widgets
|
||||
super.render(context, mouseX, mouseY, partialTicks)
|
||||
|
||||
renderSelection(context.pose())
|
||||
}
|
||||
|
||||
private fun onPress(pokemon: PartySelectPokemonDTO) {
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ class PartySlotButton(
|
||||
private val renderablePokemon = pokemon.asRenderablePokemon().also { it.aspects = aspects }
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, pMouseX: Int, pMouseY: Int, pPartialTicks: Float) {
|
||||
isHovered = ((pMouseX >= x && pMouseY >= y && pMouseX < x + width && pMouseY < y + height) || isFocused) && enabled
|
||||
isHovered = pMouseX >= x && pMouseY >= y && pMouseX < x + width && pMouseY < y + height && enabled
|
||||
val alpha = if (enabled) 1.0 else 0.7
|
||||
val matrices = context.pose()
|
||||
|
||||
|
||||
+7
-7
@@ -28,7 +28,7 @@ class InteractWheelButton(
|
||||
private val tooltipText: String?,
|
||||
x: Int,
|
||||
y: Int,
|
||||
val isEnabled: Boolean,
|
||||
private val isEnabled: () -> Boolean,
|
||||
private val colour: () -> Vector3f?,
|
||||
onPress: OnPress,
|
||||
private val canHover: (Double, Double) -> Boolean
|
||||
@@ -74,12 +74,12 @@ class InteractWheelButton(
|
||||
y = y,
|
||||
width = width,
|
||||
height = height,
|
||||
vOffset = if ((isHovered(mouseX.toFloat(), mouseY.toFloat()) || isFocused) && isEnabled) height else 0,
|
||||
vOffset = if (isHovered(mouseX.toFloat(), mouseY.toFloat()) && isEnabled()) height else 0,
|
||||
textureHeight = height * 2,
|
||||
alpha = if (isEnabled) 1f else 0.4F
|
||||
alpha = if (isEnabled()) 1f else 0.4F
|
||||
)
|
||||
|
||||
if(isEnabled && (isHovered(mouseX.toFloat(), mouseY.toFloat()) || isFocused)){
|
||||
if (isEnabled() && isHovered(mouseX.toFloat(), mouseY.toFloat())){
|
||||
tooltipText?.let {
|
||||
context.renderTooltip(Minecraft.getInstance().font, Component.translatable(it), mouseX, mouseY)
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class InteractWheelButton(
|
||||
y = iconY,
|
||||
width = ICON_SIZE,
|
||||
height = ICON_SIZE,
|
||||
alpha = if (isEnabled) 1F else 0.2F,
|
||||
alpha = if (isEnabled()) 1F else 0.2F,
|
||||
red = colour.x,
|
||||
green = colour.y,
|
||||
blue = colour.z,
|
||||
@@ -114,7 +114,7 @@ class InteractWheelButton(
|
||||
y = iconY - ICON_SIZE,
|
||||
width = ICON_SIZE,
|
||||
height = ICON_SIZE,
|
||||
alpha = if (isEnabled) 1F else 0.4F,
|
||||
alpha = if (isEnabled()) 1F else 0.4F,
|
||||
red = colour.x,
|
||||
green = colour.y,
|
||||
blue = colour.z,
|
||||
@@ -162,7 +162,7 @@ class InteractWheelButton(
|
||||
}
|
||||
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
return if (isHovered(mouseX.toFloat(), mouseY.toFloat()) || isFocused) super.mouseClicked(mouseX, mouseY, button) else false
|
||||
return if (isHovered(mouseX.toFloat(), mouseY.toFloat())) super.mouseClicked(mouseX, mouseY, button) else false
|
||||
}
|
||||
|
||||
override fun getTooltip(): Tooltip? {
|
||||
|
||||
+4
-5
@@ -18,7 +18,7 @@ import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.network.chat.Component
|
||||
import kotlin.math.max
|
||||
|
||||
class InteractWheelGUI(private val options: Multimap<Orientation, InteractWheelOption>, title: Component) : Screen(title), CobblemonRenderable {
|
||||
open class InteractWheelGUI(private val options: Multimap<Orientation, InteractWheelOption>, title: Component) : Screen(title), CobblemonRenderable {
|
||||
companion object {
|
||||
const val SIZE = 170
|
||||
private val backgroundResource = cobblemonResource("textures/gui/interact/interact_wheel_base.png")
|
||||
@@ -32,10 +32,9 @@ class InteractWheelGUI(private val options: Multimap<Orientation, InteractWheelO
|
||||
return super.keyPressed(keyCode, scanCode, modifiers)
|
||||
}
|
||||
|
||||
val buttons = mutableListOf<InteractWheelButton>()
|
||||
protected val buttons = mutableListOf<InteractWheelButton>()
|
||||
private var maxPage = 1
|
||||
private var currentPage = 0
|
||||
|
||||
override fun renderBlurredBackground(delta: Float) { }
|
||||
override fun renderMenuBackground(context: GuiGraphics) {}
|
||||
|
||||
@@ -87,7 +86,7 @@ class InteractWheelGUI(private val options: Multimap<Orientation, InteractWheelO
|
||||
currentPage = page
|
||||
buttons.forEach { removeWidget(it) }
|
||||
buttons.clear()
|
||||
val orientations = Orientation.entries.toTypedArray()
|
||||
val orientations = Orientation.values()
|
||||
orientations.forEach { orientation ->
|
||||
val option = options[orientation].toList().getOrNull(page)
|
||||
addButton(orientation, option)
|
||||
@@ -105,7 +104,7 @@ class InteractWheelGUI(private val options: Multimap<Orientation, InteractWheelO
|
||||
tooltipText = option?.tooltipText,
|
||||
x = x,
|
||||
y = y,
|
||||
isEnabled = option != null && option.enabled,
|
||||
isEnabled = { option != null && option.enabled() },
|
||||
colour = option?.colour ?: { null },
|
||||
onPress = { option?.onPress?.invoke() },
|
||||
canHover = { a: Double, b: Double -> !isMouseInCenter(a, b)}
|
||||
|
||||
+71
-4
@@ -9,20 +9,25 @@
|
||||
package com.cobblemon.mod.common.client.gui.interact.wheel
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonNetwork
|
||||
import com.cobblemon.mod.common.CobblemonPokeSkills
|
||||
import com.cobblemon.mod.common.api.events.CobblemonEvents
|
||||
import com.cobblemon.mod.common.api.events.pokemon.interaction.PokemonInteractionGUICreationEvent
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.client.gui.interact.battleRequest.BattleConfigureGUI
|
||||
import com.cobblemon.mod.common.net.messages.client.PlayerInteractOptionsPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.UsePokeSkillPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.battle.SpectateBattlePacket
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.interact.InteractPokemonPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.trade.AcceptTradeRequestPacket
|
||||
import com.cobblemon.mod.common.net.messages.server.trade.OfferTradePacket
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import com.cobblemon.mod.common.util.asTranslated
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import com.google.common.collect.Multimap
|
||||
import java.util.UUID
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.player.AbstractClientPlayer
|
||||
import net.minecraft.network.chat.Component
|
||||
import org.joml.Vector3f
|
||||
|
||||
@@ -30,7 +35,7 @@ fun createPokemonInteractGui(pokemonID: UUID, canMountShoulder: Boolean, canGive
|
||||
val mountShoulder = InteractWheelOption(
|
||||
iconResource = cobblemonResource("textures/gui/interact/interact_wheel_icon_shoulder.png"),
|
||||
tooltipText = "cobblemon.ui.interact.mount.shoulder",
|
||||
enabled = canMountShoulder,
|
||||
enabled = { canMountShoulder },
|
||||
onPress = {
|
||||
if (canMountShoulder) {
|
||||
InteractPokemonPacket(pokemonID, InteractTypePokemon.SHOULDER).sendToServer()
|
||||
@@ -41,7 +46,7 @@ fun createPokemonInteractGui(pokemonID: UUID, canMountShoulder: Boolean, canGive
|
||||
val giveHeldItem = InteractWheelOption(
|
||||
iconResource = cobblemonResource("textures/gui/interact/interact_wheel_icon_held_item.png"),
|
||||
tooltipText = "cobblemon.ui.interact.give.item",
|
||||
enabled = canGiveHeld,
|
||||
enabled = { canGiveHeld },
|
||||
onPress = {
|
||||
if (canGiveHeld) {
|
||||
InteractPokemonPacket(pokemonID, InteractTypePokemon.HELD_ITEM).sendToServer()
|
||||
@@ -52,7 +57,7 @@ fun createPokemonInteractGui(pokemonID: UUID, canMountShoulder: Boolean, canGive
|
||||
val giveCosmeticItem = InteractWheelOption(
|
||||
iconResource = cobblemonResource("textures/gui/interact/interact_wheel_icon_cosmetic_item.png"),
|
||||
tooltipText = "cobblemon.ui.interact.give.cosmetic_item",
|
||||
enabled = canGiveCosmetic,
|
||||
enabled = { canGiveCosmetic },
|
||||
onPress = {
|
||||
if (canGiveCosmetic) {
|
||||
InteractPokemonPacket(pokemonID, InteractTypePokemon.COSMETIC_ITEM).sendToServer()
|
||||
@@ -64,7 +69,7 @@ fun createPokemonInteractGui(pokemonID: UUID, canMountShoulder: Boolean, canGive
|
||||
val ride = InteractWheelOption(
|
||||
iconResource = cobblemonResource("textures/gui/interact/interact_wheel_icon_ride.png"),
|
||||
tooltipText = "cobblemon.ui.interact.ride",
|
||||
enabled = canRide,
|
||||
enabled = { canRide },
|
||||
onPress = {
|
||||
if (canRide) {
|
||||
InteractPokemonPacket(pokemonID, InteractTypePokemon.RIDE).sendToServer()
|
||||
@@ -177,6 +182,68 @@ fun createPlayerInteractGui(optionsPacket: PlayerInteractOptionsPacket): Interac
|
||||
return InteractWheelGUI(options, Component.translatable("cobblemon.ui.interact.player"))
|
||||
}
|
||||
|
||||
fun createPokeSkillGui(player: AbstractClientPlayer, pokemon: Pokemon): InteractWheelGUI {
|
||||
val accessibleSkills = CobblemonPokeSkills.getAccessiblePokeSkillTiers(player, pokemon)
|
||||
val options: Multimap<Orientation, InteractWheelOption> = ArrayListMultimap.create()
|
||||
for (skill in accessibleSkills) {
|
||||
val skillOption = InteractWheelOption(
|
||||
iconResource = skill.icon,
|
||||
enabled = { skill.id !in pokemon.skillCooldownsTicks },
|
||||
tooltipText = "${skill.name.asTranslated().string} ${getRomanNumeral(skill.tier)}",
|
||||
onPress = {
|
||||
CobblemonNetwork.sendToServer(UsePokeSkillPacket(skillId = skill.id, pokemonId = pokemon.uuid))
|
||||
closeGUI()
|
||||
}
|
||||
)
|
||||
|
||||
when (options.size()) {
|
||||
0 -> options.put(Orientation.NORTH, skillOption)
|
||||
1 -> options.put(Orientation.NORTHEAST, skillOption)
|
||||
2 -> options.put(Orientation.SOUTHEAST, skillOption)
|
||||
3 -> options.put(Orientation.SOUTH, skillOption)
|
||||
4 -> options.put(Orientation.SOUTHWEST, skillOption)
|
||||
5 -> options.put(Orientation.NORTHWEST, skillOption)
|
||||
6 -> options.put(Orientation.WEST, skillOption)
|
||||
7 -> options.put(Orientation.EAST, skillOption)
|
||||
else -> break // We only have 8 slots
|
||||
}
|
||||
}
|
||||
|
||||
return PokeSkillWheelGUI(options, Component.translatable("cobblemon.ui.interact.poke_skill"))
|
||||
}
|
||||
|
||||
private fun getRomanNumeral(number: Int): String {
|
||||
if (number <= 0) return number.toString()
|
||||
|
||||
val numerals = listOf(
|
||||
1000 to "M",
|
||||
900 to "CM",
|
||||
500 to "D",
|
||||
400 to "CD",
|
||||
100 to "C",
|
||||
90 to "XC",
|
||||
50 to "L",
|
||||
40 to "XL",
|
||||
10 to "X",
|
||||
9 to "IX",
|
||||
5 to "V",
|
||||
4 to "IV",
|
||||
1 to "I"
|
||||
)
|
||||
|
||||
var remaining = number
|
||||
val result = StringBuilder()
|
||||
|
||||
for ((value, numeral) in numerals) {
|
||||
while (remaining >= value) {
|
||||
result.append(numeral)
|
||||
remaining -= value
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString()
|
||||
}
|
||||
|
||||
private fun getLangKey(status: PlayerInteractOptionsPacket.OptionStatus) : String {
|
||||
return when (status) {
|
||||
PlayerInteractOptionsPacket.OptionStatus.TOO_FAR -> "cobblemon.ui.interact.too_far"
|
||||
|
||||
+2
-2
@@ -12,9 +12,9 @@ import net.minecraft.resources.ResourceLocation
|
||||
import org.joml.Vector3f
|
||||
|
||||
data class InteractWheelOption(
|
||||
val iconResource: ResourceLocation,
|
||||
val iconResource: ResourceLocation? = null,
|
||||
val secondaryIconResource: ResourceLocation? = null,
|
||||
val enabled: Boolean = true,
|
||||
val enabled: () -> Boolean = { true },
|
||||
val tooltipText: String?,
|
||||
val colour: () -> Vector3f? = { null },
|
||||
val onPress: () -> Unit
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.client.gui.interact.wheel
|
||||
|
||||
import com.google.common.collect.Multimap
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.network.chat.Component
|
||||
|
||||
class PokeSkillWheelGUI(
|
||||
private val options: Multimap<Orientation, InteractWheelOption>,
|
||||
title: Component
|
||||
) : InteractWheelGUI(options, title) {
|
||||
|
||||
/**
|
||||
* Due to the button being held swallow the event
|
||||
*/
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
if (button == 0) return false
|
||||
return super.mouseClicked(mouseX, mouseY, button)
|
||||
}
|
||||
|
||||
/**
|
||||
* On release will close the wheel and trigger the button press of the hovered button
|
||||
* TODO: make this wheel choose more like pizza slices.
|
||||
*/
|
||||
override fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
if (button == 0) {
|
||||
// Manually trigger the hovered button's press
|
||||
buttons.forEach { btn ->
|
||||
if (btn.isMouseOver(mouseX, mouseY)) {
|
||||
btn.onClick(mouseX, mouseY)
|
||||
return true
|
||||
}
|
||||
}
|
||||
Minecraft.getInstance().setScreen(null)
|
||||
return true
|
||||
}
|
||||
return super.mouseReleased(mouseX, mouseY, button)
|
||||
}
|
||||
|
||||
}
|
||||
+3
-54
@@ -19,7 +19,6 @@ import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.gui.drawProfilePokemon
|
||||
import com.cobblemon.mod.common.client.gui.pc.StorageSlot
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.PartySlotWidget
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.render.drawScaledTextJustifiedRight
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.FloatingState
|
||||
@@ -77,58 +76,11 @@ class PasturePokemonScrollList(
|
||||
|
||||
removedEntries.forEach(this::removeEntry)
|
||||
newEntries.forEach { addEntry(PastureSlot(it, parent)) }
|
||||
|
||||
rebuildControllerSelection()
|
||||
}
|
||||
}
|
||||
|
||||
fun rebuildControllerSelection() {
|
||||
if (parent.lastSelectedIndex > 0 && parent.lastSelectedIndex >= children().size) parent.lastSelectedIndex = children().size - 1
|
||||
children().forEachIndexed { index, slot ->
|
||||
parent.controllerComponentManager.componentList["slot_${index}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = slot
|
||||
if (index - 1 >= 0) it.up = { parent.controllerComponentManager.componentList["slot_${index - 1}"] }
|
||||
if (index + 1 <= children().size - 1) it.down =
|
||||
{ parent.controllerComponentManager.componentList["slot_${index + 1}"] }
|
||||
else it.down = { parent.controllerComponentManager.componentList["recall_all"] }
|
||||
it.onPress = { slot.moveButton.onPress() }
|
||||
it.onSpecial1 = { slot.conflictButton.onPress() }
|
||||
it.onFocus = {
|
||||
slot.controllerFocused = true
|
||||
ensureVisible(slot)
|
||||
}
|
||||
it.onUnfocus = {
|
||||
slot.controllerFocused = false
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parent.controllerComponentManager.currentSelectedComponent.let { it.startsWith("slot_") || it == "empty" }) {
|
||||
parent.controllerComponentManager.focused =
|
||||
if (children().isEmpty()) parent.controllerComponentManager.componentList["empty"]
|
||||
else parent.controllerComponentManager.componentList["slot_${parent.lastSelectedIndex}"]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun getScrollbarPosition() = x + width - 3
|
||||
|
||||
public override fun ensureVisible(entry: PastureSlot) {
|
||||
val i = getRowTop(children().indexOf(entry))
|
||||
val topDifference = i - y
|
||||
if (topDifference < 0) {
|
||||
scroll(topDifference)
|
||||
}
|
||||
|
||||
val bottomDifference = bottom - i - itemHeight - 4
|
||||
if (bottomDifference < 0) {
|
||||
scroll(-bottomDifference)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun getRowTop(index: Int): Int {
|
||||
return super.getRowTop(index)
|
||||
}
|
||||
|
||||
public override fun addEntry(entry: PastureSlot) = super.addEntry(entry)
|
||||
public override fun removeEntry(entry: PastureSlot) = super.removeEntry(entry)
|
||||
override fun renderSelection(context: GuiGraphics, y: Int, entryWidth: Int, entryHeight: Int, borderColor: Int, fillColor: Int) {}
|
||||
@@ -214,8 +166,6 @@ class PasturePokemonScrollList(
|
||||
val client: Minecraft = Minecraft.getInstance()
|
||||
val state = FloatingState()
|
||||
|
||||
var controllerFocused = false
|
||||
|
||||
fun isOwned() = client.player?.uuid == pokemon.playerId
|
||||
fun canUnpasture() = isOwned() || parent.pasturePCGUIConfiguration.permissions.canUnpastureOthers
|
||||
fun canDefend() = PokemonSpecies.getByIdentifier(pokemon.species)?.behaviour?.combat?.willDefendOwner
|
||||
@@ -232,7 +182,7 @@ class PasturePokemonScrollList(
|
||||
setEnabled(PokemonBehaviourFlag.PASTURE_CONFLICT in pokemon.behaviourFlags)
|
||||
}
|
||||
|
||||
val moveButton: PastureSlotIconButton = PastureSlotIconButton(
|
||||
private val moveButton: PastureSlotIconButton = PastureSlotIconButton(
|
||||
xPos = 0,
|
||||
yPos = 0,
|
||||
onPress = {
|
||||
@@ -241,8 +191,7 @@ class PasturePokemonScrollList(
|
||||
pastureId = parent.pasturePCGUIConfiguration.pastureId,
|
||||
pokemonId = pokemon.pokemonId
|
||||
).sendToServer()
|
||||
},
|
||||
parent = this@PastureSlot
|
||||
}
|
||||
)
|
||||
|
||||
override fun getNarration() = pokemon.displayName
|
||||
@@ -270,7 +219,7 @@ class PasturePokemonScrollList(
|
||||
y = y,
|
||||
height = SLOT_HEIGHT,
|
||||
width = rowWidth,
|
||||
vOffset = if (isHovered || controllerFocused) SLOT_HEIGHT else 0,
|
||||
vOffset = if (isHovered) SLOT_HEIGHT else 0,
|
||||
textureHeight = SLOT_HEIGHT * 2
|
||||
)
|
||||
|
||||
|
||||
+2
-3
@@ -18,8 +18,7 @@ import net.minecraft.network.chat.Component
|
||||
|
||||
class PastureSlotIconButton(
|
||||
var xPos: Int, var yPos: Int,
|
||||
onPress: OnPress,
|
||||
var parent: PasturePokemonScrollList.PastureSlot
|
||||
onPress: OnPress
|
||||
) : Button(xPos, yPos, (SIZE * SCALE).toInt(), (SIZE * SCALE).toInt(), Component.literal("Pasture Move"), onPress, DEFAULT_NARRATION), CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
@@ -36,7 +35,7 @@ class PastureSlotIconButton(
|
||||
y = yPos / SCALE,
|
||||
width = SIZE,
|
||||
height = SIZE,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble()) || parent.controllerFocused) SIZE else 0,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble())) SIZE else 0,
|
||||
textureHeight = SIZE * 2,
|
||||
texture = baseResource,
|
||||
scale = SCALE
|
||||
|
||||
@@ -15,8 +15,6 @@ import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.pc.PCGUI
|
||||
import com.cobblemon.mod.common.client.gui.pc.StorageWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.SoundlessWidget
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.net.messages.server.pasture.UnpastureAllPokemonPacket
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
@@ -36,9 +34,6 @@ class PastureWidget(
|
||||
private val baseResource = cobblemonResource("textures/gui/pasture/pasture_panel.png")
|
||||
}
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(storageWidget.pcGui)
|
||||
var lastSelectedIndex = 0
|
||||
|
||||
private val recallButton = RecallButton(
|
||||
x = x + 6,
|
||||
y = y + 153
|
||||
@@ -53,23 +48,6 @@ class PastureWidget(
|
||||
parent = this
|
||||
)
|
||||
|
||||
init {
|
||||
controllerComponentManager.componentList["recall_all"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = recallButton
|
||||
it.up = {
|
||||
if (pastureScrollList.children().isEmpty()) controllerComponentManager.componentList["empty"]
|
||||
else controllerComponentManager.componentList["slot_${pastureScrollList.children().size-1}"]
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["empty"] = ControllerComponent().also {
|
||||
it.down = { controllerComponentManager.componentList["recall_all"] }
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = if (pastureScrollList.children().isEmpty()) it.componentList["empty"]
|
||||
else it.componentList["slot_0"]
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
blitk(
|
||||
matrixStack = context.pose(),
|
||||
|
||||
@@ -40,7 +40,7 @@ class RecallButton(
|
||||
y = y,
|
||||
width = WIDTH,
|
||||
height = HEIGHT,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble()) || isFocused) HEIGHT else 0,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble())) HEIGHT else 0,
|
||||
textureHeight = HEIGHT * 2
|
||||
)
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.gui.ExitButton
|
||||
import com.cobblemon.mod.common.client.gui.TypeIcon
|
||||
import com.cobblemon.mod.common.client.gui.pasture.PasturePokemonScrollList
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary.Companion.iconCosmeticItemResource
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary.Companion.iconHeldItemResource
|
||||
@@ -29,10 +28,6 @@ import com.cobblemon.mod.common.client.gui.summary.SummaryButton
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.MarkingsWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.ModelWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.common.reformatNatureTextIfMinted
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.SubManagerComponent
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.storage.ClientPC
|
||||
import com.cobblemon.mod.common.client.storage.ClientParty
|
||||
@@ -49,15 +44,12 @@ import com.cobblemon.mod.common.util.toAssetPath
|
||||
import com.mojang.blaze3d.platform.InputConstants
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.EditBox
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import kotlin.isInitialized
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import org.joml.Vector4i
|
||||
|
||||
class PCGUI(
|
||||
val pc: ClientPC,
|
||||
@@ -65,7 +57,7 @@ class PCGUI(
|
||||
val configuration: PCGUIConfiguration,
|
||||
val openOnBox: Int = CobblemonClient.lastPcBoxViewed,
|
||||
val unseenWallpapers: MutableSet<ResourceLocation> = mutableSetOf()
|
||||
) : Screen(Component.translatable("cobblemon.ui.pc.title")), CobblemonRenderable, ControllerScreen {
|
||||
) : Screen(Component.translatable("cobblemon.ui.pc.title")), CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
const val BASE_WIDTH = 349
|
||||
@@ -136,14 +128,6 @@ class PCGUI(
|
||||
var selectPointerOffsetIncrement = false
|
||||
var displayOptions = false
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
var lastSelectedBeforeOptions = ""
|
||||
var controllerShiftToggle = false
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
override fun renderBlurredBackground(delta: Float) {}
|
||||
|
||||
override fun renderMenuBackground(context: GuiGraphics) {}
|
||||
@@ -214,39 +198,30 @@ class PCGUI(
|
||||
this.addRenderableWidget(boxNameWidget)
|
||||
|
||||
// Initialise box options if not pasture
|
||||
var optionsButton: IconButton? = null
|
||||
var wallpaperButton: IconButton? = null
|
||||
if (storageWidget.pastureWidget == null) {
|
||||
optionButtons.clear()
|
||||
optionsButton = IconButton(
|
||||
pX = x + 218,
|
||||
pY = y + 186,
|
||||
buttonWidth = 16,
|
||||
buttonHeight = 16,
|
||||
resource = buttonOptionsResource,
|
||||
label = "options"
|
||||
) {
|
||||
if (!displayOptions) {
|
||||
lastSelectedBeforeOptions = controllerComponentManager.currentSelectedComponent
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["setting_button_0"]
|
||||
controllerShiftToggle = false
|
||||
} else {
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList[lastSelectedBeforeOptions]
|
||||
}
|
||||
|
||||
displayOptions = !displayOptions
|
||||
if (!displayOptions && wallpaperWidget.visible) {
|
||||
configuration.showParty = true
|
||||
wallpaperWidget.visible = false
|
||||
}
|
||||
(it as IconButton).highlighted = displayOptions
|
||||
storageWidget.setupStorageSlots()
|
||||
for (button in optionButtons) {
|
||||
button.visible = displayOptions
|
||||
button.highlighted = false
|
||||
}
|
||||
}.also { it.highlighted = displayOptions }
|
||||
addRenderableWidget(optionsButton)
|
||||
addRenderableWidget(
|
||||
IconButton(
|
||||
pX = x + 218,
|
||||
pY = y + 186,
|
||||
buttonWidth = 16,
|
||||
buttonHeight = 16,
|
||||
resource = buttonOptionsResource,
|
||||
label = "options"
|
||||
) {
|
||||
displayOptions = !displayOptions
|
||||
if (!displayOptions && wallpaperWidget.visible) {
|
||||
configuration.showParty = true
|
||||
wallpaperWidget.visible = false
|
||||
}
|
||||
(it as IconButton).highlighted = displayOptions
|
||||
storageWidget.setupStorageSlots()
|
||||
for (button in optionButtons) {
|
||||
button.visible = displayOptions
|
||||
button.highlighted = false
|
||||
}
|
||||
}.also { it.highlighted = displayOptions }
|
||||
)
|
||||
|
||||
// Add Wallpaper Widget
|
||||
this.wallpaperWidget = WallpapersScrollingWidget(
|
||||
@@ -262,7 +237,7 @@ class PCGUI(
|
||||
this.addRenderableWidget(wallpaperWidget)
|
||||
|
||||
// Add Wallpaper Settings Button
|
||||
wallpaperButton = IconButton(
|
||||
this.addRenderableWidget(IconButton(
|
||||
pX = x + 242,
|
||||
pY = y + 31,
|
||||
buttonWidth = 20,
|
||||
@@ -275,16 +250,14 @@ class PCGUI(
|
||||
wallpaperWidget.visible = !isVisible
|
||||
(it as IconButton).highlighted = !isVisible
|
||||
if (!unseenWallpapers.isEmpty()) MarkPCBoxWallpapersSeenPacket(unseenWallpapers).sendToServer()
|
||||
controllerComponentManager.focused = if (wallpaperWidget.visible) controllerComponentManager.componentList["wallpaper_widget"] else controllerComponentManager.componentList["wallpaper_button"]
|
||||
}.also {
|
||||
it.visible = displayOptions
|
||||
optionButtons.add(it)
|
||||
}
|
||||
this.addRenderableWidget(wallpaperButton)
|
||||
})
|
||||
|
||||
PokemonSortMode.entries.forEachIndexed { index, sortType ->
|
||||
val typeName = sortType.name.lowercase()
|
||||
val button = IconButton(
|
||||
this.addRenderableWidget(IconButton(
|
||||
pX = x + 92 + (12 * index),
|
||||
pY = y + 31,
|
||||
buttonWidth = 20,
|
||||
@@ -295,58 +268,33 @@ class PCGUI(
|
||||
label = "sort_${typeName}"
|
||||
) {
|
||||
storageWidget.resetSelected()
|
||||
SortPCBoxPacket(pc.uuid, storageWidget.box, sortType, hasShiftDown() || (controllerComponentManager.active && controllerShiftToggle)).sendToServer()
|
||||
SortPCBoxPacket(pc.uuid, storageWidget.box, sortType, hasShiftDown()).sendToServer()
|
||||
}.also {
|
||||
it.visible = displayOptions
|
||||
optionButtons.add(it)
|
||||
}
|
||||
this.addRenderableWidget(button)
|
||||
|
||||
controllerComponentManager.componentList["setting_button_${index}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = button
|
||||
if (index - 1 >= 0) it.left = { controllerComponentManager.componentList["setting_button_${index-1}"] }
|
||||
if (index + 1 <= PokemonSortMode.entries.size - 1) it.right = { controllerComponentManager.componentList["setting_button_${index+1}"] }
|
||||
else it.right = { controllerComponentManager.componentList["wallpaper_button"] }
|
||||
it.onSpecial1 = {
|
||||
controllerShiftToggle = !controllerShiftToggle
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
controllerComponentManager.componentList["wallpaper_button"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = wallpaperButton
|
||||
it.left = { controllerComponentManager.componentList["setting_button_${PokemonSortMode.entries.size - 1}"] }
|
||||
}
|
||||
controllerComponentManager.componentList["wallpaper_widget"] = SubManagerComponent().also {
|
||||
it.subManager = { wallpaperWidget.controllerComponentManager }
|
||||
it.onSpecial1 = {
|
||||
controllerShiftToggle = !controllerShiftToggle
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.markingsWidget = MarkingsWidget(x + 29, y + 96.5, null, false)
|
||||
this.addRenderableWidget(markingsWidget)
|
||||
|
||||
|
||||
val switchCosmetic = SummaryButton(
|
||||
buttonX = x + 67F,
|
||||
buttonY = y + 107F,
|
||||
buttonWidth = 12,
|
||||
buttonHeight = 12,
|
||||
scale = 0.5F,
|
||||
resource = iconCosmeticItemResource,
|
||||
activeResource = iconHeldItemResource,
|
||||
clickAction = {
|
||||
showCosmeticItem = !showCosmeticItem
|
||||
(it as SummaryButton).buttonActive = showCosmeticItem
|
||||
}
|
||||
)
|
||||
// Held/Cosmetic Item Button
|
||||
addRenderableWidget(switchCosmetic)
|
||||
|
||||
addRenderableWidget(
|
||||
SummaryButton(
|
||||
buttonX = x + 67F,
|
||||
buttonY = y + 107F,
|
||||
buttonWidth = 12,
|
||||
buttonHeight = 12,
|
||||
scale = 0.5F,
|
||||
resource = iconCosmeticItemResource,
|
||||
activeResource = iconHeldItemResource,
|
||||
clickAction = {
|
||||
showCosmeticItem = !showCosmeticItem
|
||||
(it as SummaryButton).buttonActive = showCosmeticItem
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
addRenderableWidget(
|
||||
IconButton(
|
||||
@@ -364,149 +312,6 @@ class PCGUI(
|
||||
this.setPreviewPokemon(null)
|
||||
|
||||
super.init()
|
||||
|
||||
controllerComponentManager.componentList["box_name"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = boxNameWidget
|
||||
it.down = { controllerComponentManager.componentList["storage"] }
|
||||
}
|
||||
controllerComponentManager.componentList["storage"] = SubManagerComponent().also {
|
||||
it.subManager = { storageWidget.controllerComponentManager }
|
||||
it.up = {
|
||||
var returnVal: ControllerComponent? = null
|
||||
val manager = storageWidget.controllerComponentManager
|
||||
if (manager.up() && manager.currentSelectedComponent.startsWith("slot") && storageWidget.grabbedSlot == null) {
|
||||
returnVal = controllerComponentManager.componentList["box_name"]
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
it.down = {
|
||||
var returnVal: ControllerComponent? = null
|
||||
val manager = storageWidget.controllerComponentManager
|
||||
if (manager.down() && manager.currentSelectedComponent.startsWith("slot") && storageWidget.grabbedSlot == null) {
|
||||
returnVal = controllerComponentManager.componentList["filter"]
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
it.onSpecial1 = {
|
||||
if (storageWidget.controllerComponentManager.currentSelectedComponent == "pasture") {
|
||||
storageWidget.controllerComponentManager.special1()
|
||||
} else {
|
||||
switchCosmetic.onPress()
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
}
|
||||
|
||||
}
|
||||
it.onSpecial2 = { if (storageWidget.pastureWidget == null) displayOptions = !displayOptions }
|
||||
}
|
||||
controllerComponentManager.componentList["filter"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = filterWidget
|
||||
it.up = { controllerComponentManager.componentList["storage"] }
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["storage"]
|
||||
it.onTabNav = { nextTab ->
|
||||
storageWidget.box += if (nextTab) 1 else -1
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
}
|
||||
it.onSecondaryTabNav = { nextTab ->
|
||||
var nextValue = currentStatIndex + if (nextTab) 1 else -1
|
||||
if (nextValue > 2) nextValue = 0
|
||||
if (nextValue < 0) nextValue = 2
|
||||
currentStatIndex = nextValue
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
}
|
||||
it.onStart = {
|
||||
if (it.currentSelectedComponent != "storage" || storageWidget.grabbedSlot == null) {
|
||||
it.focused = controllerComponentManager.componentList["filter"]
|
||||
storageWidget.controllerComponentManager.focused =
|
||||
storageWidget.controllerComponentManager.componentList["slot_4_0"]
|
||||
it.openKeyboard.invoke(it.focused!!.associatedGUIElement as EditBox)
|
||||
playSound(SoundEvents.UI_BUTTON_CLICK.value())
|
||||
}
|
||||
}
|
||||
it.onSpecial2 = {
|
||||
if (storageWidget.pastureWidget == null && storageWidget.grabbedSlot == null) {
|
||||
optionsButton!!.onPress()
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
}
|
||||
}
|
||||
it.onBack = {
|
||||
if (storageWidget.pastureWidget == null && wallpaperWidget.visible) {
|
||||
wallpaperButton?.onPress()
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
} else if (displayOptions) {
|
||||
optionsButton!!.onPress()
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
} else if (storageWidget.grabbedSlot != null) {
|
||||
storageWidget.resetSelected()
|
||||
} else {
|
||||
closeNormally(true)
|
||||
}
|
||||
}
|
||||
it.onActiveChange = { state ->
|
||||
if (!state) {
|
||||
storageWidget.controllerComponentManager.active = false
|
||||
} else {
|
||||
if (it.currentSelectedComponent == "storage") storageWidget.controllerComponentManager.active = true
|
||||
}
|
||||
}
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.START,
|
||||
{ true },
|
||||
Component.translatable("cobblemon.controller.quick_search")
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.TAB,
|
||||
{ true },
|
||||
Component.translatable("cobblemon.controller.pc.switch_box")
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SECONDARY_TAB,
|
||||
{ true },
|
||||
Component.translatable("cobblemon.controller.pc.switch_stats")
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_1,
|
||||
{ it.currentSelectedComponent == "storage" && storageWidget.controllerComponentManager.currentSelectedComponent != "pasture" },
|
||||
Component.translatable("cobblemon.controller.toggle_held_item_type"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_1,
|
||||
{ it.currentSelectedComponent == "storage" && storageWidget.controllerComponentManager.currentSelectedComponent == "pasture" &&
|
||||
storageWidget.pastureWidget!!.controllerComponentManager.currentSelectedComponent.startsWith("slot_") },
|
||||
Component.translatable("cobblemon.controller.pc.toggle_defence"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_2,
|
||||
{ it.currentSelectedComponent == "storage" && storageWidget.controllerComponentManager.currentSelectedComponent != "pasture" },
|
||||
Component.translatable("cobblemon.controller.pc.box_settings"),
|
||||
true
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSelectionPosAndSize(): Vector4i? {
|
||||
val data = super.getSelectionPosAndSize()
|
||||
if (data == null) {
|
||||
when (controllerComponentManager.currentSelectedComponent) {
|
||||
"wallpaper_widget" -> return Vector4i(wallpaperWidget.rowLeft - 2, wallpaperWidget.getRowTop(wallpaperWidget.children().indexOf(focused)) + 2,
|
||||
WallpapersScrollingWidget.SLOT_WIDTH + 4, WallpapersScrollingWidget.SLOT_HEIGHT + 4)
|
||||
"storage" -> {
|
||||
if (storageWidget.pastureWidget != null && storageWidget.controllerComponentManager.currentSelectedComponent == "pasture") {
|
||||
val scrollWidget = storageWidget.pastureWidget!!.pastureScrollList
|
||||
if (storageWidget.pastureWidget!!.controllerComponentManager.currentSelectedComponent.startsWith("slot_")) {
|
||||
return Vector4i(scrollWidget.rowLeft - 6, scrollWidget.getRowTop(scrollWidget.children().indexOf(focused)),
|
||||
PasturePokemonScrollList.SLOT_WIDTH + 4, PasturePokemonScrollList.SLOT_HEIGHT + 4)
|
||||
} else if (storageWidget.pastureWidget!!.controllerComponentManager.currentSelectedComponent == "empty") {
|
||||
return Vector4i(scrollWidget.x - 2, scrollWidget.y - 11, scrollWidget.width + 4, scrollWidget.height + 13)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
@@ -880,7 +685,7 @@ class PCGUI(
|
||||
)
|
||||
|
||||
if (!optionButtons.isEmpty() && displayOptions) {
|
||||
for (button in optionButtons) button.showAlt = hasShiftDown() || (controllerComponentManager.active && controllerShiftToggle)
|
||||
for (button in optionButtons) button.showAlt = hasShiftDown()
|
||||
}
|
||||
|
||||
super.render(context, mouseX, mouseY, delta)
|
||||
@@ -895,8 +700,6 @@ class PCGUI(
|
||||
if (itemHovered) context.renderTooltip(Minecraft.getInstance().font, displayedItem, mouseX, mouseY)
|
||||
}
|
||||
}
|
||||
|
||||
renderSelection(matrices)
|
||||
}
|
||||
|
||||
fun closeNormally(unlink: Boolean = true) {
|
||||
|
||||
@@ -27,8 +27,8 @@ class ReleaseButton(
|
||||
) : Button(x, y, WIDTH, HEIGHT, Component.literal("Release"), onPress, DEFAULT_NARRATION), CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
const val WIDTH = 58
|
||||
const val HEIGHT = 16
|
||||
private const val WIDTH = 58
|
||||
private const val HEIGHT = 16
|
||||
|
||||
private val buttonResource = cobblemonResource("textures/gui/pc/pc_release_button.png")
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class ReleaseButton(
|
||||
y = y,
|
||||
width = WIDTH,
|
||||
height = HEIGHT,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble()) || isFocused) HEIGHT else 0,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble())) HEIGHT else 0,
|
||||
textureHeight = HEIGHT * 2
|
||||
)
|
||||
|
||||
|
||||
+3
-3
@@ -28,8 +28,8 @@ class ReleaseConfirmButton(
|
||||
) : Button(x, y, WIDTH, HEIGHT, Component.literal("ReleaseConfirm"), onPress, DEFAULT_NARRATION), CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
const val WIDTH = 30
|
||||
const val HEIGHT = 13
|
||||
private const val WIDTH = 30
|
||||
private const val HEIGHT = 13
|
||||
|
||||
private val buttonResource = cobblemonResource("textures/gui/pc/pc_release_button_confirm.png")
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class ReleaseConfirmButton(
|
||||
y = y,
|
||||
width = WIDTH,
|
||||
height = HEIGHT,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble()) || isFocused) HEIGHT else 0,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble())) HEIGHT else 0,
|
||||
textureHeight = HEIGHT * 2
|
||||
)
|
||||
|
||||
|
||||
@@ -20,9 +20,6 @@ import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.pasture.PasturePCGUIConfiguration
|
||||
import com.cobblemon.mod.common.client.gui.pasture.PastureWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.SoundlessWidget
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.SubManagerComponent
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.render.gui.PCBoxWallpaperRepository
|
||||
import com.cobblemon.mod.common.client.settings.ServerSettings
|
||||
@@ -44,7 +41,6 @@ import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import org.joml.Vector2i
|
||||
|
||||
class StorageWidget(
|
||||
pX: Int, pY: Int,
|
||||
@@ -95,9 +91,6 @@ class StorageWidget(
|
||||
this.setupStorageSlots()
|
||||
}
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(pcGui)
|
||||
var grabbedSlotControllerPos = Vector2i()
|
||||
|
||||
init {
|
||||
this.setupStorageSlots()
|
||||
|
||||
@@ -109,7 +102,6 @@ class StorageWidget(
|
||||
if (!displayConfirmRelease && canDeleteSelected()) {
|
||||
displayConfirmRelease = true
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["release_no"]
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -134,7 +126,6 @@ class StorageWidget(
|
||||
playSound(CobblemonSounds.PC_RELEASE)
|
||||
resetSelected()
|
||||
displayConfirmRelease = false
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["slot_0_0"]
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -148,7 +139,6 @@ class StorageWidget(
|
||||
if (displayConfirmRelease) {
|
||||
displayConfirmRelease = false
|
||||
playSound(CobblemonSounds.PC_CLICK)
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["release"]
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -156,47 +146,6 @@ class StorageWidget(
|
||||
if (pcGui.configuration is PasturePCGUIConfiguration) {
|
||||
this.pastureWidget = PastureWidget(this, pcGui.configuration, x + 182, y - 19)
|
||||
}
|
||||
|
||||
controllerComponentManager.componentList["release"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = releaseButton
|
||||
it.up = { controllerComponentManager.componentList["party_slot_2_0"] }
|
||||
it.left = { controllerComponentManager.componentList["slot_4_5"] }
|
||||
it.onSelect = {
|
||||
grabbedSlotControllerPos = Vector2i(releaseButton.x + ReleaseButton.WIDTH / 2 + 4, releaseButton.y + ReleaseButton.HEIGHT / 2 + 4)
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["release_no"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = releaseNoButton
|
||||
it.up = { controllerComponentManager.componentList["party_slot_2_1"] }
|
||||
it.left = { controllerComponentManager.componentList["release_yes"] }
|
||||
it.onSelect = {
|
||||
grabbedSlotControllerPos = Vector2i(releaseNoButton.x + ReleaseConfirmButton.WIDTH / 2 + 4, releaseNoButton.y + ReleaseConfirmButton.HEIGHT / 2 + 4)
|
||||
}
|
||||
it.onUnselect = {
|
||||
if (!controllerComponentManager.currentSelectedComponent.startsWith("release")) displayConfirmRelease = false
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["release_yes"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = releaseYesButton
|
||||
it.up = { controllerComponentManager.componentList["party_slot_2_0"] }
|
||||
it.left = { controllerComponentManager.componentList["slot_4_5"] }
|
||||
it.right = { controllerComponentManager.componentList["release_no"] }
|
||||
it.onSelect = {
|
||||
grabbedSlotControllerPos = Vector2i(releaseYesButton.x + ReleaseConfirmButton.WIDTH / 2 + 4, releaseYesButton.y + ReleaseConfirmButton.HEIGHT / 2 + 4)
|
||||
}
|
||||
it.onUnselect = {
|
||||
if (!controllerComponentManager.currentSelectedComponent.startsWith("release")) displayConfirmRelease = false
|
||||
}
|
||||
}
|
||||
if (pastureWidget != null) {
|
||||
controllerComponentManager.componentList["pasture"] = SubManagerComponent().also {
|
||||
it.subManager = { pastureWidget!!.controllerComponentManager }
|
||||
it.left = { controllerComponentManager.componentList["slot_0_5"] }
|
||||
}
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["slot_0_0"]
|
||||
}
|
||||
}
|
||||
|
||||
fun canDeleteSelected(): Boolean {
|
||||
@@ -215,7 +164,7 @@ class StorageWidget(
|
||||
|
||||
for (row in 1..5) {
|
||||
for (col in 1..6) {
|
||||
val slot = BoxStorageSlot(
|
||||
BoxStorageSlot(
|
||||
x = boxStartX + ((col - 1) * (StorageSlot.SIZE + BOX_SLOT_PADDING)),
|
||||
y = boxStartY + ((row - 1) * (StorageSlot.SIZE + BOX_SLOT_PADDING)),
|
||||
parent = this,
|
||||
@@ -227,27 +176,6 @@ class StorageWidget(
|
||||
this.boxSlots.add(widget)
|
||||
}
|
||||
index++
|
||||
|
||||
val adjCol = col - 1
|
||||
val adjRow = row - 1
|
||||
controllerComponentManager.componentList["slot_${adjRow}_${adjCol}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = slot
|
||||
if (adjCol - 1 >= 0) it.left = { controllerComponentManager.componentList["slot_${adjRow}_${adjCol-1}"] }
|
||||
if (adjCol + 1 <= 5) it.right = { controllerComponentManager.componentList["slot_${adjRow}_${adjCol+1}"] }
|
||||
else if (pastureWidget == null) {
|
||||
it.right = when (adjRow) {
|
||||
4 -> {{ if (canDeleteSelected()) controllerComponentManager.componentList["release"] else null }}
|
||||
3 -> {{ controllerComponentManager.componentList["party_slot_2_0"] }}
|
||||
else -> {{ controllerComponentManager.componentList["party_slot_${adjRow}_0"] }}
|
||||
}
|
||||
} else {
|
||||
it.right = { controllerComponentManager.componentList["pasture"] }
|
||||
}
|
||||
if (adjRow - 1 >= 0) it.up = { controllerComponentManager.componentList["slot_${adjRow-1}_${adjCol}"] }
|
||||
if (adjRow + 1 <= 4) it.down = { controllerComponentManager.componentList["slot_${adjRow+1}_${adjCol}"] }
|
||||
it.onSelect = { grabbedSlotControllerPos = Vector2i(slot.x + slot.width / 2 + 4, slot.y + slot.height / 2 + 4) }
|
||||
it.onPress = { if (slot.clickable()) slot.onPress() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +194,7 @@ class StorageWidget(
|
||||
partyY += ((StorageSlot.SIZE + PARTY_SLOT_PADDING) * offsetIndex) + offsetY
|
||||
}
|
||||
|
||||
val slot = PartyStorageSlot(
|
||||
PartyStorageSlot(
|
||||
x = partyX,
|
||||
y = partyY,
|
||||
parent = this,
|
||||
@@ -277,22 +205,6 @@ class StorageWidget(
|
||||
this.addWidget(widget)
|
||||
this.partySlots.add(widget)
|
||||
}
|
||||
|
||||
val row = partyIndex / 2
|
||||
val col = partyIndex % 2
|
||||
controllerComponentManager.componentList["party_slot_${row}_${col}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = slot
|
||||
if (col == 1) it.left = { controllerComponentManager.componentList["party_slot_${row}_0"] }
|
||||
else {
|
||||
it.right = { controllerComponentManager.componentList["party_slot_${row}_1"] }
|
||||
it.left = { controllerComponentManager.componentList["slot_${row}_5"] }
|
||||
}
|
||||
if (row - 1 >= 0) it.up = { controllerComponentManager.componentList["party_slot_${row-1}_${col}"] }
|
||||
if (row + 1 <= 2) it.down = { controllerComponentManager.componentList["party_slot_${row+1}_${col}"] }
|
||||
else it.down = { if (canDeleteSelected()) controllerComponentManager.componentList["release"] else null }
|
||||
it.onSelect = { grabbedSlotControllerPos = Vector2i(slot.x + slot.width / 2 + 4, slot.y + slot.height / 2 + 4) }
|
||||
it.onPress = { if (slot.clickable()) slot.onPress() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +307,7 @@ class StorageWidget(
|
||||
this.boxSlots.forEach { slot ->
|
||||
slot.render(context, mouseX, mouseY, delta)
|
||||
val pokemon = slot.getPokemon()
|
||||
if (grabbedSlot == null && (slot.isHovered(mouseX, mouseY) || slot.isFocused)
|
||||
if (grabbedSlot == null && slot.isHovered(mouseX, mouseY)
|
||||
&& pokemon != null && pokemon != pcGui.previewPokemon
|
||||
) {
|
||||
pcGui.setPreviewPokemon(pokemon, pcGui.isPreviewInParty ?: false)
|
||||
@@ -411,7 +323,7 @@ class StorageWidget(
|
||||
this.partySlots.forEach { slot ->
|
||||
slot.render(context, mouseX, mouseY, delta)
|
||||
val pokemon = slot.getPokemon()
|
||||
if (grabbedSlot == null && (slot.isHovered(mouseX, mouseY) || slot.isFocused)
|
||||
if (grabbedSlot == null && slot.isHovered(mouseX, mouseY)
|
||||
&& pokemon != null && pokemon != pcGui.previewPokemon
|
||||
) {
|
||||
pcGui.setPreviewPokemon(pokemon, pcGui.isPreviewInParty ?: true)
|
||||
@@ -423,11 +335,7 @@ class StorageWidget(
|
||||
pastureWidget?.render(context, mouseX, mouseY, delta)
|
||||
matrices.pushPose()
|
||||
matrices.translate(0.0, 0.0, 1000.0)
|
||||
if (controllerComponentManager.active) {
|
||||
grabbedSlot?.render(context, grabbedSlotControllerPos.x, grabbedSlotControllerPos.y, delta)
|
||||
} else {
|
||||
grabbedSlot?.render(context, mouseX, mouseY, delta)
|
||||
}
|
||||
grabbedSlot?.render(context, mouseX, mouseY, delta)
|
||||
matrices.popPose()
|
||||
}
|
||||
|
||||
@@ -464,9 +372,6 @@ class StorageWidget(
|
||||
}
|
||||
|
||||
// Reset release confirmation
|
||||
if (controllerComponentManager.currentSelectedComponent.startsWith("release")) {
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["slot_0_0"]
|
||||
}
|
||||
displayConfirmRelease = false
|
||||
|
||||
// Clicking on itself, so unselect position
|
||||
|
||||
+8
-36
@@ -15,8 +15,6 @@ import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.ScrollingWidget
|
||||
import com.cobblemon.mod.common.client.gui.pc.WallpapersScrollingWidget.WallpaperEntry
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.render.gui.PCBoxWallpaperRepository
|
||||
import com.cobblemon.mod.common.net.messages.server.storage.pc.RequestChangePCBoxWallpaperPacket
|
||||
@@ -51,14 +49,10 @@ class WallpapersScrollingWidget(
|
||||
val backgroundResource = cobblemonResource("textures/gui/pc/wallpaper_scroll_background.png")
|
||||
}
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(pcGui)
|
||||
|
||||
init {
|
||||
this.visible = false
|
||||
this.y = pY
|
||||
createEntries()
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun getScrollbarPosition(): Int = x + width - 3
|
||||
@@ -96,24 +90,6 @@ class WallpapersScrollingWidget(
|
||||
}
|
||||
}
|
||||
|
||||
override fun addEntry(entry: WallpaperEntry): Int {
|
||||
val i = super.addEntry(entry)
|
||||
controllerComponentManager.componentList["wallpaper_${i}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = entry
|
||||
it.onPress = { entry.selectWallpaper() }
|
||||
it.onFocus = { ensureVisible(entry) }
|
||||
}
|
||||
if (children().size > 1) {
|
||||
controllerComponentManager.componentList["wallpaper_${i}"]?.let {
|
||||
it.pairUp(controllerComponentManager.componentList["wallpaper_${i-1}"])
|
||||
it.pairDown(controllerComponentManager.componentList["wallpaper_${0}"])
|
||||
}
|
||||
} else {
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["wallpaper_${i}"]
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
override fun getRowLeft(): Int {
|
||||
return this.left + SLOT_PADDING
|
||||
}
|
||||
@@ -140,7 +116,7 @@ class WallpapersScrollingWidget(
|
||||
partialTick: Float
|
||||
) {
|
||||
val matrices = guiGraphics.pose()
|
||||
val resource = if ((Screen.hasShiftDown() || (pcGui.controllerComponentManager.active && pcGui.controllerShiftToggle)) && altWallpaper !== null) altWallpaper else wallpaper
|
||||
val resource = if (Screen.hasShiftDown() && altWallpaper !== null) altWallpaper else wallpaper
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = resource,
|
||||
@@ -157,28 +133,24 @@ class WallpapersScrollingWidget(
|
||||
y = top + SLOT_PADDING,
|
||||
width = width,
|
||||
height = SLOT_HEIGHT,
|
||||
vOffset = if (hovering || isFocused) SLOT_HEIGHT else 0,
|
||||
vOffset = if (hovering) SLOT_HEIGHT else 0,
|
||||
textureHeight = SLOT_HEIGHT * 2
|
||||
)
|
||||
}
|
||||
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
if (this@WallpapersScrollingWidget.visible && isMouseOver(mouseX, mouseY)) {
|
||||
selectWallpaper()
|
||||
val appliedWallpaper = if (Screen.hasShiftDown()) altWallpaper ?: wallpaper else wallpaper
|
||||
RequestChangePCBoxWallpaperPacket(pcGui.pc.uuid, storageWidget.box, wallpaper, if (Screen.hasShiftDown()) altWallpaper else null).sendToServer()
|
||||
pcGui.pc.boxes[storageWidget.box].wallpaper = appliedWallpaper
|
||||
pcGui.unseenWallpapers.remove(wallpaper)
|
||||
isNew = false
|
||||
minecraft.soundManager.play(SimpleSoundInstance.forUI(CobblemonSounds.PC_CLICK, 1.0F))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun selectWallpaper() {
|
||||
val appliedWallpaper = if (Screen.hasShiftDown() || (pcGui.controllerComponentManager.active && pcGui.controllerShiftToggle)) altWallpaper ?: wallpaper else wallpaper
|
||||
RequestChangePCBoxWallpaperPacket(pcGui.pc.uuid, storageWidget.box, wallpaper, if (Screen.hasShiftDown() || (pcGui.controllerComponentManager.active && pcGui.controllerShiftToggle)) altWallpaper else null).sendToServer()
|
||||
pcGui.pc.boxes[storageWidget.box].wallpaper = appliedWallpaper
|
||||
pcGui.unseenWallpapers.remove(wallpaper)
|
||||
isNew = false
|
||||
minecraft.soundManager.play(SimpleSoundInstance.forUI(CobblemonSounds.PC_CLICK, 1.0F))
|
||||
}
|
||||
|
||||
override fun getNarration(): Component? {
|
||||
return wallpaper.toString().text()
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.setup
|
||||
import com.cobblemon.mod.common.api.pokedex.CaughtCount
|
||||
import com.cobblemon.mod.common.api.pokedex.Dexes
|
||||
import com.cobblemon.mod.common.api.pokedex.PokedexEntryProgress
|
||||
import com.cobblemon.mod.common.api.pokedex.SeenCount
|
||||
import com.cobblemon.mod.common.api.pokedex.def.PokedexDef
|
||||
import com.cobblemon.mod.common.api.pokedex.entry.PokedexEntry
|
||||
@@ -47,10 +46,6 @@ import com.cobblemon.mod.common.client.gui.pokedex.PokedexGUIConstants.TAB_ICON_
|
||||
import com.cobblemon.mod.common.client.gui.pokedex.PokedexGUIConstants.TAB_MOVES
|
||||
import com.cobblemon.mod.common.client.gui.pokedex.PokedexGUIConstants.TAB_SIZE
|
||||
import com.cobblemon.mod.common.client.gui.pokedex.PokedexGUIConstants.TAB_STATS
|
||||
import com.cobblemon.mod.common.client.gui.pokedex.widgets.*
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.client.gui.pokedex.widgets.AbilitiesWidget
|
||||
import com.cobblemon.mod.common.client.gui.pokedex.widgets.DescriptionWidget
|
||||
import com.cobblemon.mod.common.client.gui.pokedex.widgets.DropsScrollingWidget
|
||||
@@ -79,8 +74,6 @@ import net.minecraft.core.BlockPos
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import org.joml.Vector4i
|
||||
|
||||
/**
|
||||
* Pokedex GUI
|
||||
@@ -92,7 +85,7 @@ class PokedexGUI private constructor(
|
||||
val type: PokedexType,
|
||||
val initSpecies: ResourceLocation?,
|
||||
val blockPos: BlockPos?
|
||||
): Screen(Component.translatable("cobblemon.ui.pokedex.title")), CobblemonRenderable, ControllerScreen {
|
||||
): Screen(Component.translatable("cobblemon.ui.pokedex.title")), CobblemonRenderable {
|
||||
companion object {
|
||||
private val screenBackground = cobblemonResource("textures/gui/pokedex/pokedex_screen.png")
|
||||
|
||||
@@ -170,14 +163,6 @@ class PokedexGUI private constructor(
|
||||
lateinit var tabInfoElement: GuiEventListener
|
||||
var tabInfoIndex = TAB_DESCRIPTION
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
var lastTileComponent: ControllerComponent? = null
|
||||
var lastSelectedColumn = 0
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
override fun renderBlurredBackground(delta: Float) {}
|
||||
override fun renderMenuBackground(context: GuiGraphics) {}
|
||||
|
||||
@@ -283,222 +268,6 @@ class PokedexGUI private constructor(
|
||||
)
|
||||
addRenderableWidget(categoryFilterButtonDown)
|
||||
updateFilters(true)
|
||||
|
||||
fun hasKnowledge(): Boolean {
|
||||
val currentEntry = pokemonInfoWidget.currentEntry
|
||||
return currentEntry != null && CobblemonClient.clientPokedexData.getKnowledgeForSpecies(currentEntry.speciesId) != PokedexEntryProgress.UNREGISTERED
|
||||
}
|
||||
|
||||
controllerComponentManager.componentList["search"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = searchWidget
|
||||
it.down = {
|
||||
val returnVal = if (scrollScreen.children().isNotEmpty()) {
|
||||
controllerComponentManager.componentList["tile_0_0"]
|
||||
} else {
|
||||
controllerComponentManager.componentList["empty_entries"]
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
it.onSpecial1 = {
|
||||
searchByTypeButton.onPress()
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["empty_entries"] = ControllerComponent().also {
|
||||
it.up = { controllerComponentManager.componentList["search"] }
|
||||
it.right = { controllerComponentManager.componentList["pokemon_render"] }
|
||||
}
|
||||
controllerComponentManager.componentList["pokemon_render"] = ControllerComponent().also {
|
||||
it.left = {
|
||||
val returnVal = if (scrollScreen.children().isNotEmpty()) {
|
||||
lastTileComponent
|
||||
} else {
|
||||
controllerComponentManager.componentList["empty_entries"]
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
it.down = { controllerComponentManager.componentList["info_widget"] }
|
||||
it.onPress = {
|
||||
if (hasKnowledge()) {
|
||||
pokemonInfoWidget.playCry()
|
||||
}
|
||||
}
|
||||
it.onSpecial1 = {
|
||||
if (hasKnowledge() && pokemonInfoWidget.genderButton.visible) {
|
||||
pokemonInfoWidget.genderButton.onPress()
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
}
|
||||
it.onSpecial2 = {
|
||||
if (hasKnowledge() && pokemonInfoWidget.shinyButton.visible) {
|
||||
pokemonInfoWidget.shinyButton.onPress()
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["info_widget"] = ControllerComponent().also {
|
||||
it.left = {
|
||||
val returnVal = if (scrollScreen.children().isNotEmpty()) {
|
||||
lastTileComponent
|
||||
} else {
|
||||
controllerComponentManager.componentList["empty_entries"]
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
it.up = { controllerComponentManager.componentList["pokemon_render"] }
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["tile_0_0"] ?: it.componentList["empty_entries"]
|
||||
it.onTabNav = { nextTab ->
|
||||
if (it.currentSelectedComponent == "empty_entries" || it.currentSelectedComponent.startsWith("tile_")) {
|
||||
updatePokedexRegion(nextTab)
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
} else if (it.currentSelectedComponent == "pokemon_render") {
|
||||
val currentEntry = pokemonInfoWidget.currentEntry
|
||||
if (currentEntry != null) {
|
||||
val hasKnowledge = CobblemonClient.clientPokedexData.getKnowledgeForSpecies(currentEntry.speciesId) != PokedexEntryProgress.UNREGISTERED
|
||||
val showableForms = CobblemonClient.clientPokedexData.getEncounteredForms(currentEntry)
|
||||
if (hasKnowledge && showableForms.size > 1 && showableForms.size > pokemonInfoWidget.selectedFormIndex) {
|
||||
pokemonInfoWidget.switchForm(nextTab)
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
}
|
||||
} else if (it.currentSelectedComponent == "info_widget") {
|
||||
val trimmedTabs = tabButtons.filterIndexed { index, _ -> tabInfoIndex == index || canSelectTab(index) }.map { tabButtons.indexOf(it) }.toMutableList()
|
||||
var currentTab = trimmedTabs.indexOf(tabInfoIndex) + if (nextTab) 1 else -1
|
||||
if (currentTab > trimmedTabs.size - 1) currentTab = 0
|
||||
else if (currentTab < 0) currentTab = trimmedTabs.size - 1
|
||||
displaytabInfoElement(trimmedTabs[currentTab])
|
||||
if (trimmedTabs.size > 1) playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
}
|
||||
it.onSecondaryTabNav = { nextTab ->
|
||||
if (it.currentSelectedComponent == "pokemon_render") {
|
||||
pokemonInfoWidget.switchPose(nextTab)
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
} else if (it.currentSelectedComponent == "info_widget") {
|
||||
(tabInfoElement as? AbilitiesWidget)?.let {
|
||||
it.switchAbility(nextTab)
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
(tabInfoElement as? StatsWidget)?.let { widget ->
|
||||
if (nextTab) {
|
||||
if (children().contains(widget.rightButton)) {
|
||||
widget.rightButton.onPress()
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
} else {
|
||||
if (children().contains(widget.leftButton)) {
|
||||
widget.leftButton.onPress()
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
it.onRHorizontal = { right ->
|
||||
if (it.currentSelectedComponent == "info_widget") {
|
||||
(tabInfoElement as? StatsWidget)?.let { widget ->
|
||||
if (widget.selectedStatTypeIndex == StatsWidget.STAT_TYPE_RIDE) {
|
||||
if (right) {
|
||||
if (children().contains(widget.rightSubButton)) {
|
||||
widget.rightSubButton.onPress()
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
} else {
|
||||
if (children().contains(widget.leftSubButton)) {
|
||||
widget.leftSubButton.onPress()
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK_SHORT)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
it.onStart = {
|
||||
it.focused = it.componentList["search"]
|
||||
it.openKeyboard.invoke(it.focused!!.associatedGUIElement as EditBox)
|
||||
playSound(SoundEvents.UI_BUTTON_CLICK.value())
|
||||
}
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.START,
|
||||
{ true },
|
||||
Component.translatable("cobblemon.controller.quick_search")
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.TAB,
|
||||
{ it.currentSelectedComponent == "empty_entries" || it.currentSelectedComponent.startsWith("tile_") },
|
||||
Component.translatable("cobblemon.controller.dex.cycle_region")
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.TAB,
|
||||
{ it.currentSelectedComponent == "pokemon_render" && hasKnowledge() && pokemonInfoWidget.visibleForms.size > 1},
|
||||
Component.translatable("cobblemon.controller.dex.cycle_form"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SECONDARY_TAB,
|
||||
{ it.currentSelectedComponent == "pokemon_render" && hasKnowledge() },
|
||||
Component.translatable("cobblemon.controller.dex.cycle_animation")
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SECONDARY_TAB,
|
||||
{ it.currentSelectedComponent == "info_widget" && tabInfoElement is AbilitiesWidget },
|
||||
Component.translatable("cobblemon.controller.dex.cycle_ability")
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SECONDARY_TAB,
|
||||
{ it.currentSelectedComponent == "info_widget" && (tabInfoElement as? StatsWidget)?.let { children().contains(it.rightButton) } ?: false },
|
||||
Component.translatable("cobblemon.controller.dex.cycle_stats")
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.JOYSTICK_HORIZONTAL,
|
||||
{ it.currentSelectedComponent == "info_widget" && (tabInfoElement as? StatsWidget)?.let { it.selectedStatTypeIndex == StatsWidget.STAT_TYPE_RIDE && children().contains(it.rightSubButton) } ?: false },
|
||||
Component.translatable("cobblemon.controller.dex.cycle_ride_style")
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_1,
|
||||
{ it.currentSelectedComponent == "search" },
|
||||
Component.translatable("cobblemon.controller.dex.cycle_search_by"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_1,
|
||||
{ it.currentSelectedComponent == "pokemon_render" && hasKnowledge() && pokemonInfoWidget.genderButton.visible },
|
||||
Component.translatable("cobblemon.controller.dex.toggle_gender"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_2,
|
||||
{ it.currentSelectedComponent == "pokemon_render" && hasKnowledge() && pokemonInfoWidget.shinyButton.visible },
|
||||
Component.translatable("cobblemon.controller.dex.toggle_shiny"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.PRESS,
|
||||
{ it.currentSelectedComponent == "pokemon_render" && hasKnowledge() },
|
||||
Component.translatable("cobblemon.controller.dex.play_cry"),
|
||||
true
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSelectionPosAndSize(): Vector4i? {
|
||||
return when (controllerComponentManager.currentSelectedComponent) {
|
||||
"search" -> Vector4i(searchWidget.x - 2, searchWidget.y - 2, searchWidget.width + 15, searchWidget.height + 4)
|
||||
"pokemon_render" -> Vector4i(pokemonInfoWidget.x - 2, pokemonInfoWidget.y + 12, pokemonInfoWidget.width + 6, pokemonInfoWidget.height + 16)
|
||||
"info_widget" -> Vector4i(pokemonInfoWidget.x - 2, pokemonInfoWidget.y + 94, pokemonInfoWidget.width + 6, pokemonInfoWidget.height + 3)
|
||||
"empty_entries" -> Vector4i(scrollScreen.x - 2, scrollScreen.y - 2, scrollScreen.width + 4, scrollScreen.height + 4)
|
||||
else -> {
|
||||
if (controllerComponentManager.currentSelectedComponent.startsWith("tile_")) {
|
||||
val scrollWidget = controllerComponentManager.focused?.associatedGUIElement as? EntriesScrollingWidget.PokemonScrollSlotRow
|
||||
val startX = scrollScreen.x + lastSelectedColumn * (PokedexGUIConstants.SCROLL_SLOT_SIZE + PokedexGUIConstants.SCROLL_SLOT_SPACING)
|
||||
if (scrollWidget != null) {
|
||||
Vector4i(startX - 2, scrollScreen.getRowTop(scrollScreen.children().indexOf(scrollWidget)) + 1, PokedexGUIConstants.SCROLL_SLOT_SIZE + 4, PokedexGUIConstants.SCROLL_SLOT_SIZE + 4)
|
||||
} else null
|
||||
} else null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getSufficientlyKnownForms(selectedEntry: PokedexEntry, tabIndex: Int) = if (tabIndex in looseUnlockTabs) {
|
||||
@@ -643,8 +412,6 @@ class PokedexGUI private constructor(
|
||||
|
||||
super.render(context, mouseX, mouseY, delta)
|
||||
|
||||
renderSelection(context.pose())
|
||||
|
||||
// Search type tooltip
|
||||
if (searchByTypeButton.isButtonHovered(mouseX, mouseY)) {
|
||||
val searchTypeText = lang("ui.pokedex.search.search_by", lang("ui.pokedex.search.type.${selectedSearchByType.name.lowercase()}")).bold()
|
||||
@@ -700,7 +467,6 @@ class PokedexGUI private constructor(
|
||||
if (isDragging && canDragRender) {
|
||||
val dragOffsetY = (oldDragPosX - mouseX).toFloat()
|
||||
pokemonInfoWidget.rotationY = (((pokemonInfoWidget.rotationY + dragOffsetY) % 360 + 360) % 360)
|
||||
pokemonInfoWidget.lastRotationY = pokemonInfoWidget.rotationY
|
||||
}
|
||||
oldDragPosX = mouseX
|
||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)
|
||||
@@ -716,18 +482,6 @@ class PokedexGUI private constructor(
|
||||
|
||||
override fun tick() {
|
||||
if (::pokemonInfoWidget.isInitialized && !pokemonInfoWidget.suppressViewport) pokemonInfoWidget.tick()
|
||||
|
||||
//Controller
|
||||
if (controllerComponentManager.rHorizontalState != 0) {
|
||||
if (controllerComponentManager.currentSelectedComponent == "pokemon_render") {
|
||||
pokemonInfoWidget.rotationY = ((pokemonInfoWidget.rotationY + 5F * controllerComponentManager.rHorizontalState) % 360 + 360) % 360
|
||||
}
|
||||
}
|
||||
if (controllerComponentManager.rVerticalState != 0) {
|
||||
if (controllerComponentManager.currentSelectedComponent == "info_widget") {
|
||||
(tabInfoElement as? InfoTextScrollWidget)?.scroll(-3 * controllerComponentManager.rVerticalState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updatePokedexRegion(nextIndex: Boolean) {
|
||||
@@ -787,45 +541,6 @@ class PokedexGUI private constructor(
|
||||
} else {
|
||||
setSelectedEntry(entries.first())
|
||||
}
|
||||
|
||||
val totalRows = scrollScreen.children().size
|
||||
val lastRowCount = scrollScreen.children()[totalRows-1].dexDataList.size
|
||||
scrollScreen.children().forEachIndexed { row, scrollRow ->
|
||||
scrollRow.dexDataList.forEachIndexed { column, slot ->
|
||||
controllerComponentManager.componentList["tile_${row}_${column}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = scrollRow
|
||||
if (row - 1 >= 0) it.up = { controllerComponentManager.componentList["tile_${row-1}_${column}"] }
|
||||
else it.up = { controllerComponentManager.componentList["search"] }
|
||||
if (row + 1 <= scrollScreen.children().size - 1 &&
|
||||
(row + 1 != totalRows || column <= lastRowCount - 1)) it.down = { controllerComponentManager.componentList["tile_${row+1}_${column}"] }
|
||||
if (column - 1 >= 0) it.left = { controllerComponentManager.componentList["tile_${row}_${column-1}"] }
|
||||
if (column + 1 <= scrollRow.dexDataList.size - 1) it.right = { controllerComponentManager.componentList["tile_${row}_${column+1}"] }
|
||||
else it.right = { controllerComponentManager.componentList["pokemon_render"] }
|
||||
it.onPress = {
|
||||
scrollRow.setPokedexEntry.invoke(slot)
|
||||
playSound(CobblemonSounds.POKEDEX_CLICK)
|
||||
}
|
||||
it.onSelect = {
|
||||
lastTileComponent = it
|
||||
lastSelectedColumn = column
|
||||
scrollScreen.ensureVisible(scrollRow)
|
||||
}
|
||||
it.onFocus = {
|
||||
scrollRow.slotControllerSelected = column
|
||||
}
|
||||
it.onUnfocus = {
|
||||
scrollRow.slotControllerSelected = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (controllerComponentManager.currentSelectedComponent.let { it == "empty_entries" || it.startsWith("tile_") }) {
|
||||
if (entries.isNotEmpty()) {
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["tile_0_0"]
|
||||
} else {
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["empty_entries"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ class AbilitiesWidget(x: Int, y: Int): InfoTextScrollWidget(pX = x, pY = y) {
|
||||
|
||||
init { setAbility() }
|
||||
|
||||
fun switchAbility(nextIndex: Boolean) {
|
||||
private fun switchAbility(nextIndex: Boolean) {
|
||||
val size = abilitiesList.size
|
||||
selectedAbilitiesIndex = if (nextIndex) {
|
||||
(selectedAbilitiesIndex + 1) % size
|
||||
|
||||
+1
-3
@@ -149,8 +149,6 @@ class EntriesScrollingWidget(val pX: Int, val pY: Int, val setPokedexEntry: (Pok
|
||||
var x: Int = 0
|
||||
var y: Int = 0
|
||||
|
||||
var slotControllerSelected = -1
|
||||
|
||||
override fun render(
|
||||
context: GuiGraphics,
|
||||
index: Int,
|
||||
@@ -192,7 +190,7 @@ class EntriesScrollingWidget(val pX: Int, val pY: Int, val setPokedexEntry: (Pok
|
||||
height = SCROLL_SLOT_SIZE
|
||||
)
|
||||
|
||||
if (getHoveredSlotIndex(mouseX, mouseY) == index || slotControllerSelected == index) {
|
||||
if (getHoveredSlotIndex(mouseX, mouseY) == index) {
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = slotHighlight,
|
||||
|
||||
+9
-15
@@ -56,7 +56,6 @@ import net.minecraft.network.chat.Component
|
||||
import net.minecraft.network.chat.MutableComponent
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import net.minecraft.util.Mth
|
||||
import org.joml.Quaternionf
|
||||
import org.joml.Vector3f
|
||||
import java.io.FileNotFoundException
|
||||
@@ -124,7 +123,6 @@ class PokemonInfoWidget(val pX: Int, val pY: Int, val updateForm: (PokedexForm)
|
||||
|
||||
var state = FloatingState()
|
||||
var rotationY = 30F
|
||||
var lastRotationY = rotationY // Used to smooth out rotation for controllers
|
||||
|
||||
var ticksElapsed = 0
|
||||
var pokeBallBackgroundFrame = 0
|
||||
@@ -190,7 +188,7 @@ class PokemonInfoWidget(val pX: Int, val pY: Int, val updateForm: (PokedexForm)
|
||||
|
||||
val variationButtons = mutableListOf<VariationButtonWrapper>()
|
||||
|
||||
val genderButton: ScaledButton = ScaledButton(
|
||||
private val genderButton: ScaledButton = ScaledButton(
|
||||
pX + 114F,
|
||||
pY + 27F,
|
||||
20,
|
||||
@@ -202,7 +200,7 @@ class PokemonInfoWidget(val pX: Int, val pY: Int, val updateForm: (PokedexForm)
|
||||
}
|
||||
).apply { addWidget(this) }
|
||||
|
||||
val shinyButton: ScaledButton = ScaledButton(
|
||||
private val shinyButton: ScaledButton = ScaledButton(
|
||||
(pX + 126F),
|
||||
(pY + 27F),
|
||||
20,
|
||||
@@ -263,8 +261,6 @@ class PokemonInfoWidget(val pX: Int, val pY: Int, val updateForm: (PokedexForm)
|
||||
).apply { addWidget(this) }
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
val realDetla = Minecraft.getInstance().timer.getGameTimeDeltaPartialTick(true)
|
||||
|
||||
val currentEntry = this.currentEntry ?: return
|
||||
|
||||
val hasKnowledge =
|
||||
@@ -379,10 +375,10 @@ class PokemonInfoWidget(val pX: Int, val pY: Int, val updateForm: (PokedexForm)
|
||||
matrices.translate(
|
||||
pX.toDouble() + (POKEMON_PORTRAIT_WIDTH.toDouble() + 2) / 2,
|
||||
pY.toDouble() + portraitStartY - 12,
|
||||
10.0 // Dont use too big numbers otherwise side mod overlays can break (controllify keyboard)
|
||||
1000.0 // Prevent model from clipping into background
|
||||
)
|
||||
matrices.scale(scaleAmount, scaleAmount, 0.2F)
|
||||
val rotationVector = Vector3f(13F, Mth.rotLerp(realDetla, lastRotationY, rotationY), 0F)
|
||||
matrices.scale(scaleAmount, scaleAmount, scaleAmount)
|
||||
val rotationVector = Vector3f(13F, rotationY, 0F)
|
||||
|
||||
drawProfilePokemon(
|
||||
renderablePokemon = renderablePokemon!!,
|
||||
@@ -411,7 +407,7 @@ class PokemonInfoWidget(val pX: Int, val pY: Int, val updateForm: (PokedexForm)
|
||||
|
||||
// Ensure elements are not hidden behind Pokémon render
|
||||
matrices.pushPose()
|
||||
matrices.translate(0.0, 0.0, 20.0)
|
||||
matrices.translate(0.0, 0.0, 2000.0)
|
||||
|
||||
if (isSelectedPokemonOwned()) {
|
||||
val primaryType = type[0]
|
||||
@@ -642,12 +638,12 @@ class PokemonInfoWidget(val pX: Int, val pY: Int, val updateForm: (PokedexForm)
|
||||
type = arrayOf(form.primaryType, form.secondaryType)
|
||||
}
|
||||
|
||||
fun playCry() {
|
||||
private fun playCry() {
|
||||
state.activeAnimations.clear()
|
||||
state.addFirstAnimation(setOf("cry"))
|
||||
}
|
||||
|
||||
fun switchForm(nextIndex: Boolean) {
|
||||
private fun switchForm(nextIndex: Boolean) {
|
||||
if (visibleForms.isEmpty() || currentEntry == null) {
|
||||
return
|
||||
}
|
||||
@@ -668,7 +664,7 @@ class PokemonInfoWidget(val pX: Int, val pY: Int, val updateForm: (PokedexForm)
|
||||
updateAspects()
|
||||
}
|
||||
|
||||
fun switchPose(nextIndex: Boolean) {
|
||||
private fun switchPose(nextIndex: Boolean) {
|
||||
if (nextIndex) {
|
||||
if (selectedPoseIndex < poseList.lastIndex) selectedPoseIndex++
|
||||
else selectedPoseIndex = 0
|
||||
@@ -760,8 +756,6 @@ class PokemonInfoWidget(val pX: Int, val pY: Int, val updateForm: (PokedexForm)
|
||||
val delay = 3
|
||||
if (ticksElapsed % delay == 0) pokeBallBackgroundFrame++
|
||||
if (pokeBallBackgroundFrame == 16) pokeBallBackgroundFrame = 0
|
||||
|
||||
lastRotationY = rotationY
|
||||
}
|
||||
|
||||
fun isWithinPortraitSpace(mouseX: Double, mouseY: Double): Boolean =
|
||||
|
||||
+5
-41
@@ -9,9 +9,6 @@
|
||||
package com.cobblemon.mod.common.client.gui.snapshots
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonBuildDetails
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.OptionInstance
|
||||
|
||||
@@ -23,12 +20,10 @@ import net.minecraft.client.gui.components.Tooltip
|
||||
import net.minecraft.client.gui.layouts.FrameLayout
|
||||
import net.minecraft.client.gui.layouts.GridLayout
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.CommonComponents
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
|
||||
class SnapshotWarningScreen(val consumer: (Acknowledgement, Boolean) -> Unit) : Screen(TITLE), ControllerScreen {
|
||||
class SnapshotWarningScreen(val consumer: (Acknowledgement, Boolean) -> Unit) : Screen(TITLE) {
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -41,12 +36,6 @@ class SnapshotWarningScreen(val consumer: (Acknowledgement, Boolean) -> Unit) :
|
||||
private val layout = GridLayout().columnSpacing(10).rowSpacing(20)
|
||||
private val dontShowAgain = OptionInstance.createBoolean("cobblemon\$snapshots\$dont_show_again", false)
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
super.init()
|
||||
|
||||
@@ -56,42 +45,17 @@ class SnapshotWarningScreen(val consumer: (Acknowledgement, Boolean) -> Unit) :
|
||||
helper.addChild(StringWidget(this.title, this.font), 2, settings)
|
||||
helper.addChild(MultiLineTextWidget(DESCRIPTION, this.font).setCentered(true).setMaxWidth(310), 2, settings)
|
||||
|
||||
val checkbox = Checkbox.builder(Component.translatable("cobblemon.snapshots.warning.dont_show_again"), Minecraft.getInstance().font)
|
||||
helper.addChild(Checkbox.builder(Component.translatable("cobblemon.snapshots.warning.dont_show_again"), Minecraft.getInstance().font)
|
||||
.selected(dontShowAgain)
|
||||
.tooltip(Tooltip.create(DONT_SHOW_AGAIN_TIP))
|
||||
.build()
|
||||
helper.addChild(checkbox, 2, settings)
|
||||
.build(), 2, settings)
|
||||
|
||||
val yesButton = Button.builder(CommonComponents.GUI_YES) { this.consumer.invoke(Acknowledgement.YES, dontShowAgain.get()) }.build()
|
||||
helper.addChild(yesButton)
|
||||
val noButton = Button.builder(CommonComponents.GUI_NO) { this.consumer.invoke(Acknowledgement.NO, false) }.build()
|
||||
helper.addChild(noButton)
|
||||
helper.addChild(Button.builder(CommonComponents.GUI_YES) { this.consumer.invoke(Acknowledgement.YES, dontShowAgain.get()) }.build())
|
||||
helper.addChild(Button.builder(CommonComponents.GUI_NO) { this.consumer.invoke(Acknowledgement.NO, false) }.build())
|
||||
|
||||
this.layout.visitWidgets { this.addRenderableWidget(it) }
|
||||
this.layout.arrangeElements()
|
||||
this.repositionElements()
|
||||
|
||||
controllerComponentManager.componentList["checkbox"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = checkbox
|
||||
it.down = { controllerComponentManager.componentList["yes_button"] }
|
||||
it.onPress = {
|
||||
Minecraft.getInstance().soundManager.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F))
|
||||
checkbox.onPress()
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["yes_button"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = yesButton
|
||||
it.up = { controllerComponentManager.componentList["checkbox"] }
|
||||
it.right = { controllerComponentManager.componentList["no_button"] }
|
||||
}
|
||||
controllerComponentManager.componentList["no_button"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = noButton
|
||||
it.up = { controllerComponentManager.componentList["checkbox"] }
|
||||
it.left = { controllerComponentManager.componentList["yes_button"] }
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["yes_button"]
|
||||
}
|
||||
}
|
||||
|
||||
override fun repositionElements() {
|
||||
|
||||
+4
-101
@@ -25,10 +25,9 @@ import com.cobblemon.mod.common.client.gui.TypeIcon
|
||||
import com.cobblemon.mod.common.client.gui.VariableObjectSelectionScrollbar
|
||||
import com.cobblemon.mod.common.client.gui.startselection.widgets.CategoryList
|
||||
import com.cobblemon.mod.common.client.gui.startselection.widgets.SelectionButton
|
||||
import com.cobblemon.mod.common.client.gui.startselection.widgets.preview.StarterRoundabout
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary.Companion.PARTY
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.ModelWidget
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.client.keybind.keybinds.SummaryBinding
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.config.starter.RenderableStarterCategory
|
||||
@@ -42,9 +41,8 @@ import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.toasts.Toast
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import org.joml.Vector4i
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
/**
|
||||
@@ -53,7 +51,7 @@ import java.io.FileNotFoundException
|
||||
* @author Qu
|
||||
* @since 2022-06-18
|
||||
*/
|
||||
class StarterSelectionScreen(private val categories: List<RenderableStarterCategory>): Screen("cobblemon.ui.starter.title".asTranslated()), CobblemonRenderable, ControllerScreen {
|
||||
class StarterSelectionScreen(private val categories: List<RenderableStarterCategory>): Screen("cobblemon.ui.starter.title".asTranslated()), CobblemonRenderable {
|
||||
companion object {
|
||||
// Size of UI at scale 1
|
||||
private const val BASE_WIDTH = 239
|
||||
@@ -75,14 +73,6 @@ class StarterSelectionScreen(private val categories: List<RenderableStarterCateg
|
||||
private lateinit var modelWidget: ModelWidget
|
||||
private lateinit var currentPokemon: RenderablePokemon
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
var lastSelectedCategory = 0
|
||||
var lastSelectedButton = 0
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
var ticksElapsed = 0
|
||||
var currentBallBackgroundFrame = 0
|
||||
|
||||
@@ -161,91 +151,6 @@ class StarterSelectionScreen(private val categories: List<RenderableStarterCateg
|
||||
width = 3,
|
||||
height = 145
|
||||
))
|
||||
|
||||
|
||||
controllerComponentManager.componentList["select"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = selectionButton
|
||||
it.right = { controllerComponentManager.componentList["pokemon_${lastSelectedCategory}_${lastSelectedButton}"] }
|
||||
}
|
||||
categoryList.generatedCategoriesWidgets.forEachIndexed { categoryIndex, category ->
|
||||
for (buttonIndex in 0..<category.category.pokemon.size) {
|
||||
val column = buttonIndex % 3
|
||||
controllerComponentManager.componentList["pokemon_${categoryIndex}_${buttonIndex}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = category
|
||||
it.right = {
|
||||
if (column < 2) controllerComponentManager.componentList["pokemon_${categoryIndex}_${buttonIndex+1}"]
|
||||
else null
|
||||
}
|
||||
it.left = {
|
||||
if (column > 0) controllerComponentManager.componentList["pokemon_${categoryIndex}_${buttonIndex-1}"]
|
||||
else controllerComponentManager.componentList["select"]
|
||||
}
|
||||
it.up = {
|
||||
if (buttonIndex-3 < 0) {
|
||||
var returnVal: ControllerComponent? = null
|
||||
var index = categoryIndex
|
||||
while (index-1 >= 0) {
|
||||
val lastCategory = categoryList.generatedCategoriesWidgets[index-1]
|
||||
val row = (lastCategory.category.pokemon.size - 1) / 3 + if ((lastCategory.category.pokemon.size - 1) % 3 < column) -1 else 0
|
||||
if (row >= 0) {
|
||||
returnVal = controllerComponentManager.componentList["pokemon_${index-1}_${row*3+column}"]
|
||||
break
|
||||
}
|
||||
index -= 1
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
else controllerComponentManager.componentList["pokemon_${categoryIndex}_${buttonIndex-3}"]
|
||||
}
|
||||
it.down = {
|
||||
if (buttonIndex+3 >= category.category.pokemon.size) {
|
||||
var returnVal: ControllerComponent? = null
|
||||
var index = categoryIndex
|
||||
while (index+1 < categoryList.generatedCategoriesWidgets.size) {
|
||||
val nextCategory = categoryList.generatedCategoriesWidgets[index+1]
|
||||
if (nextCategory.category.pokemon.size > column) {
|
||||
returnVal = controllerComponentManager.componentList["pokemon_${index+1}_${column}"]
|
||||
break
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
else controllerComponentManager.componentList["pokemon_${categoryIndex}_${buttonIndex+3}"]
|
||||
}
|
||||
it.onPress = {
|
||||
selectPokemon(category.category, buttonIndex)
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
}
|
||||
it.onSelect = {
|
||||
lastSelectedCategory = categoryIndex
|
||||
lastSelectedButton = buttonIndex
|
||||
}
|
||||
it.onFocus = {
|
||||
category.controllerButtonSelected = buttonIndex
|
||||
categoryList.ensureVisible(category)
|
||||
}
|
||||
it.onUnfocus = {
|
||||
category.controllerButtonSelected = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = controllerComponentManager.componentList["select"]
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSelectionPosAndSize(): Vector4i? {
|
||||
if (controllerComponentManager.currentSelectedComponent.startsWith("pokemon_")) {
|
||||
val category = controllerComponentManager.focused?.associatedGUIElement as? CategoryList.Category ?: return null
|
||||
val row = category.controllerButtonSelected / 3
|
||||
val column = category.controllerButtonSelected % 3
|
||||
val x = category.getRowLeft() + (CategoryList.CONTAINER_BUTTON_SIZE + 2) * column + CategoryList.MARGIN + 3
|
||||
val y = category.getRowTop() + (CategoryList.CONTAINER_BUTTON_SIZE + CategoryList.BUTTON_SEPERATION) * row + CategoryList.HEADER_HEIGHT + CategoryList.BUTTON_SEPERATION - 1
|
||||
return Vector4i(x, y, CategoryList.CONTAINER_BUTTON_SIZE + 4, CategoryList.CONTAINER_BUTTON_SIZE + 4)
|
||||
}
|
||||
return super.getSelectionPosAndSize()
|
||||
}
|
||||
|
||||
override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
@@ -402,8 +307,6 @@ class StarterSelectionScreen(private val categories: List<RenderableStarterCateg
|
||||
matrices.popPose()
|
||||
|
||||
super.render(context, mouseX, mouseY, delta)
|
||||
|
||||
renderSelection(matrices)
|
||||
}
|
||||
|
||||
fun getPlatformResource(type: ElementalType): ResourceLocation? {
|
||||
|
||||
+2
-16
@@ -59,12 +59,9 @@ class CategoryList(
|
||||
const val CONTAINER_WIDTH = 89
|
||||
}
|
||||
|
||||
val generatedCategoriesWidgets = mutableListOf<Category>()
|
||||
|
||||
init {
|
||||
addEntry(EmptySeparator(MARGIN))
|
||||
createEntries().forEach {
|
||||
generatedCategoriesWidgets.add(it)
|
||||
addEntry(it)
|
||||
addEntry(EmptySeparator(MARGIN))
|
||||
}
|
||||
@@ -76,18 +73,7 @@ class CategoryList(
|
||||
Category(category, height)
|
||||
}
|
||||
|
||||
override fun ensureVisible(entry: Entry) {
|
||||
if (entry !in children) return
|
||||
val yTop = entry.scrolledY - scrollAmount.toInt()
|
||||
if (yTop - MARGIN < 0) {
|
||||
setScroll((entry.scrolledY - MARGIN).toDouble())
|
||||
} else if (yTop + entry.height + MARGIN > height) {
|
||||
setScroll((entry.scrolledY + entry.height - height + MARGIN).toDouble())
|
||||
}
|
||||
}
|
||||
|
||||
inner class Category(val category: RenderableStarterCategory, height: Int) : Entry(height) {
|
||||
var controllerButtonSelected = -1
|
||||
inner class Category(private val category: RenderableStarterCategory, height: Int) : Entry(height) {
|
||||
|
||||
override fun render(
|
||||
guiGraphics: GuiGraphics,
|
||||
@@ -184,7 +170,7 @@ class CategoryList(
|
||||
width = CONTAINER_BUTTON_SIZE,
|
||||
height = CONTAINER_BUTTON_SIZE,
|
||||
textureHeight = CONTAINER_BUTTON_SIZE * 2,
|
||||
vOffset = if (hovered || controllerButtonSelected == index) CONTAINER_BUTTON_SIZE else 0
|
||||
vOffset = if (hovered) CONTAINER_BUTTON_SIZE else 0
|
||||
)
|
||||
|
||||
matrices.pushPose()
|
||||
|
||||
+5
-1
@@ -8,6 +8,8 @@
|
||||
|
||||
package com.cobblemon.mod.common.client.gui.startselection.widgets
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.ColourLibrary
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
@@ -15,8 +17,10 @@ import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.util.lang
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.client.sounds.SoundManager
|
||||
import net.minecraft.network.chat.Component
|
||||
|
||||
@@ -46,7 +50,7 @@ class SelectionButton(
|
||||
width = BUTTON_WIDTH,
|
||||
height = BUTTON_HEIGHT,
|
||||
textureHeight = BUTTON_HEIGHT * 2,
|
||||
vOffset = if (isHovered || isFocused) BUTTON_HEIGHT else 0
|
||||
vOffset = if (isHovered) BUTTON_HEIGHT else 0
|
||||
)
|
||||
|
||||
drawScaledText(
|
||||
|
||||
@@ -20,27 +20,14 @@ import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.gui.ExitButton
|
||||
import com.cobblemon.mod.common.client.gui.TypeIcon
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.EvolutionSelectScreen
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.MarkingsWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.ModelWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.NicknameEntryWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.PartySlotWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.PartyWidget
|
||||
import com.cobblemon.mod.common.client.gui.*
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.*
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.screens.SummaryTab
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.screens.info.InfoWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.screens.marks.MarksScrollingWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.screens.marks.MarksWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.screens.moves.MoveSwapScreen
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.screens.moves.MovesWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.screens.stats.StatWidget
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.SubManagerComponent
|
||||
import com.cobblemon.mod.common.client.keybind.keybinds.SummaryBinding
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetItemHiddenPacket
|
||||
@@ -63,8 +50,6 @@ import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import org.joml.Vector2i
|
||||
import org.joml.Vector4i
|
||||
|
||||
/**
|
||||
* The screen responsible for displaying various information regarding a Pokémon team.
|
||||
@@ -75,7 +60,7 @@ import org.joml.Vector4i
|
||||
* @param selection The index the [party] will have as the base [selectedPokemon].
|
||||
*/
|
||||
class Summary private constructor(party: Collection<Pokemon?>, private val editable: Boolean, private val selection: Int): Screen(
|
||||
Component.translatable("cobblemon.ui.summary.title")), Schedulable, CobblemonRenderable, ControllerScreen {
|
||||
Component.translatable("cobblemon.ui.summary.title")), Schedulable, CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
const val BASE_WIDTH = 331
|
||||
@@ -84,10 +69,10 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
private const val SCALE = 0.5F
|
||||
|
||||
// Main Screen Index
|
||||
const val INFO = 0
|
||||
const val MOVES = 1
|
||||
const val STATS = 2
|
||||
const val MARKS = 3
|
||||
private const val INFO = 0
|
||||
private const val MOVES = 1
|
||||
private const val STATS = 2
|
||||
private const val MARKS = 3
|
||||
|
||||
// Side Screen Index
|
||||
const val PARTY = 0
|
||||
@@ -131,32 +116,19 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
|
||||
override val schedulingTracker = SchedulingTracker()
|
||||
|
||||
val party = ArrayList(party)
|
||||
private val party = ArrayList(party)
|
||||
internal var selectedPokemon: Pokemon = this.party[selection] ?: this.party.first { it != null }!!
|
||||
lateinit var mainScreen: AbstractWidget
|
||||
private lateinit var mainScreen: AbstractWidget
|
||||
lateinit var sideScreen: GuiEventListener
|
||||
private lateinit var modelWidget: ModelWidget
|
||||
lateinit var nicknameEntryWidget: NicknameEntryWidget
|
||||
private lateinit var nicknameEntryWidget: NicknameEntryWidget
|
||||
private lateinit var markingsWidget: MarkingsWidget
|
||||
val summaryTabs = mutableListOf<SummaryTab>()
|
||||
private val summaryTabs = mutableListOf<SummaryTab>()
|
||||
private var showCosmeticItem = false
|
||||
lateinit var heldItemVisibilityButton: SummaryButton
|
||||
lateinit var heldItemSwitchTypeButton: SummaryButton
|
||||
lateinit var evolveButton: SummaryButton
|
||||
var mainScreenIndex = INFO
|
||||
private lateinit var heldItemVisibilityButton: SummaryButton
|
||||
private var mainScreenIndex = INFO
|
||||
var sideScreenIndex = PARTY
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
var mainScreenComponentManager: ControllerComponentManager? = null
|
||||
var sideScreenComponentManager: ControllerComponentManager? = null
|
||||
var selectedMoveIndex = 0
|
||||
var moveSwitchingMode = false
|
||||
var lastSelectedPartySlot = 0
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
override fun renderBlurredBackground(delta: Float) { }
|
||||
|
||||
/**
|
||||
@@ -186,7 +158,7 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
addRenderableWidget(markingsWidget)
|
||||
|
||||
// Evolve Button
|
||||
evolveButton = addRenderableWidget(
|
||||
addRenderableWidget(
|
||||
SummaryButton(
|
||||
buttonX = x + 12F,
|
||||
buttonY = y + 145F,
|
||||
@@ -232,22 +204,22 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
heldItemVisibilityButton.buttonActive = !selectedPokemon.heldItemVisible
|
||||
addRenderableWidget(heldItemVisibilityButton)
|
||||
|
||||
|
||||
// Held/Cosmetic Item Button
|
||||
heldItemSwitchTypeButton = SummaryButton(
|
||||
buttonX = x + 67F,
|
||||
buttonY = y + 113F,
|
||||
buttonWidth = 12,
|
||||
buttonHeight = 12,
|
||||
scale = 0.5F,
|
||||
resource = iconCosmeticItemResource,
|
||||
activeResource = iconHeldItemResource,
|
||||
clickAction = {
|
||||
showCosmeticItem = !showCosmeticItem
|
||||
(it as SummaryButton).buttonActive = showCosmeticItem
|
||||
}
|
||||
addRenderableWidget(
|
||||
SummaryButton(
|
||||
buttonX = x + 67F,
|
||||
buttonY = y + 113F,
|
||||
buttonWidth = 12,
|
||||
buttonHeight = 12,
|
||||
scale = 0.5F,
|
||||
resource = iconCosmeticItemResource,
|
||||
activeResource = iconHeldItemResource,
|
||||
clickAction = {
|
||||
showCosmeticItem = !showCosmeticItem
|
||||
(it as SummaryButton).buttonActive = showCosmeticItem
|
||||
}
|
||||
)
|
||||
)
|
||||
addRenderableWidget(heldItemSwitchTypeButton)
|
||||
|
||||
// Init Tabs
|
||||
summaryTabs.clear()
|
||||
@@ -281,7 +253,14 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
// Add Exit Button
|
||||
addRenderableWidget(
|
||||
ExitButton(pX = x + 302, pY = y + 145) {
|
||||
onBack()
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
if (sideScreenIndex != PARTY) {
|
||||
displaySideScreen(PARTY)
|
||||
} else {
|
||||
saveActiveMark()
|
||||
saveMarkings()
|
||||
Minecraft.getInstance().setScreen(null)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -315,214 +294,9 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
addRenderableWidget(this.modelWidget)
|
||||
|
||||
updatePokemonInfo()
|
||||
|
||||
//Controller Support
|
||||
controllerComponentManager.componentList["nickname"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = nicknameEntryWidget
|
||||
it.right = { controllerComponentManager.componentList["center_screen"] }
|
||||
}
|
||||
controllerComponentManager.componentList["held_item"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = heldItemVisibilityButton
|
||||
it.right = { controllerComponentManager.componentList["center_screen"] }
|
||||
it.pairUp(controllerComponentManager.componentList["nickname"]!!)
|
||||
it.down = { if (evolveButton.renderRequirement.invoke(evolveButton)) controllerComponentManager.componentList["evolve"] else null }
|
||||
it.onSpecial1 = {
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
heldItemSwitchTypeButton.onPress()
|
||||
}
|
||||
it.onPress = {
|
||||
if (heldItemVisibilityButton.clickRequirement.invoke(heldItemVisibilityButton)) heldItemVisibilityButton.onPress()
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["evolve"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = evolveButton
|
||||
it.right = { controllerComponentManager.componentList["center_screen"] }
|
||||
it.up = { controllerComponentManager.componentList["held_item"] }
|
||||
}
|
||||
controllerComponentManager.componentList["center_screen"] = SubManagerComponent().also {
|
||||
it.subManager = { mainScreenComponentManager }
|
||||
it.left = {
|
||||
var returnVal: ControllerComponent? = null
|
||||
if (mainScreenComponentManager?.left() ?: true && !moveSwitchingMode) {
|
||||
returnVal = controllerComponentManager.componentList["nickname"]
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
it.right = {
|
||||
var returnVal: ControllerComponent? = null
|
||||
if (mainScreenComponentManager?.right() ?: true && !moveSwitchingMode) {
|
||||
returnVal = controllerComponentManager.componentList["right_screen"]
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
it.up = {
|
||||
if (mainScreenIndex == STATS) {
|
||||
val statWidget = mainScreen as StatWidget
|
||||
var index = statWidget.statTabIndex + 1
|
||||
if (index > statWidget.statOptions.size - 1) {
|
||||
index = 0
|
||||
}
|
||||
statWidget.statTabIndex = index
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
} else {
|
||||
mainScreenComponentManager?.up()
|
||||
}
|
||||
null
|
||||
}
|
||||
it.down = {
|
||||
if (mainScreenIndex == STATS) {
|
||||
val statWidget = mainScreen as StatWidget
|
||||
var index = statWidget.statTabIndex - 1
|
||||
if (index < 0) {
|
||||
index = statWidget.statOptions.size - 1
|
||||
}
|
||||
statWidget.statTabIndex = index
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
} else {
|
||||
mainScreenComponentManager?.down()
|
||||
}
|
||||
null
|
||||
}
|
||||
it.onPress = {
|
||||
if (mainScreenIndex == STATS) {
|
||||
val statWidget = mainScreen as StatWidget
|
||||
if (statWidget.statOptions.get(statWidget.statTabIndex) == StatWidget.RIDE && (statWidget.pokemon.riding.behaviours?.size ?: 0) > 1) {
|
||||
statWidget.rideBehaviourIndex = (statWidget.rideBehaviourIndex + 1) % (statWidget.pokemon.riding.behaviours?.size ?: 1)
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
}
|
||||
} else {
|
||||
mainScreenComponentManager?.press()
|
||||
}
|
||||
}
|
||||
}
|
||||
controllerComponentManager.componentList["right_screen"] = SubManagerComponent().also {
|
||||
it.subManager = { sideScreenComponentManager }
|
||||
it.left = {
|
||||
var returnVal: ControllerComponent? = null
|
||||
if (sideScreenComponentManager?.left() ?: true && sideScreenIndex == PARTY && (sideScreen as? PartyWidget)?.swapSource == null) {
|
||||
returnVal = controllerComponentManager.componentList["center_screen"]
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
}
|
||||
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["center_screen"]
|
||||
it.onTabNav = { nextTab ->
|
||||
var index = mainScreenIndex + if (nextTab) 1 else -1
|
||||
if (index < 0) index = summaryTabs.size - 1
|
||||
if (index > summaryTabs.size - 1) index = 0
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
displayMainScreen(index)
|
||||
}
|
||||
it.onSecondaryTabNav = { nextTab ->
|
||||
val pokemonIndex = party.indexOf(selectedPokemon)
|
||||
val indexList = party.filter { it != null }.map { party.indexOf(it) }.toMutableList()
|
||||
var index = indexList.indexOf(pokemonIndex) + if (nextTab) 1 else -1
|
||||
if (index < 0) index = indexList.size - 1
|
||||
if (index > indexList.size - 1) index = 0
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
displaySideScreen(PARTY)
|
||||
switchSelection(indexList[index])
|
||||
}
|
||||
it.onBack = {
|
||||
if (moveSwitchingMode) {
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
moveSwitchingMode = false
|
||||
val movesWidget = mainScreen as? MovesWidget
|
||||
if (movesWidget != null) {
|
||||
movesWidget.controllerComponentManager.focused?.onUnselect()
|
||||
}
|
||||
} else {
|
||||
val partyWidget = sideScreen as? PartyWidget
|
||||
if (partyWidget != null && partyWidget.swapSource != null) {
|
||||
partyWidget.draggedSlot = null
|
||||
partyWidget.controllerComponentManager.let {
|
||||
it.focused = it.componentList["slot_${partyWidget.swapSource}"]
|
||||
}
|
||||
partyWidget.swapSource = null
|
||||
playSound(CobblemonSounds.PC_DROP)
|
||||
} else {
|
||||
onBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
it.onActiveChange = { state ->
|
||||
if (!state) {
|
||||
moveSwitchingMode = false
|
||||
}
|
||||
if (mainScreenComponentManager != null) {
|
||||
if (!state) {
|
||||
mainScreenComponentManager?.active = false
|
||||
} else {
|
||||
if (it.currentSelectedComponent == "center_screen") mainScreenComponentManager?.active = true
|
||||
}
|
||||
}
|
||||
if (sideScreenComponentManager != null) {
|
||||
if (!state) {
|
||||
sideScreenComponentManager?.active = false
|
||||
} else {
|
||||
if (it.currentSelectedComponent == "right_screen") sideScreenComponentManager?.active = true
|
||||
}
|
||||
}
|
||||
}
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SECONDARY_TAB,
|
||||
{ true },
|
||||
Component.translatable("cobblemon.controller.summary.quick_switch"),
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_1,
|
||||
{ it.currentSelectedComponent == "center_screen" && mainScreenIndex == MOVES },
|
||||
Component.translatable("cobblemon.controller.summary.change_move"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_1,
|
||||
{ it.currentSelectedComponent == "held_item" },
|
||||
Component.translatable("cobblemon.controller.toggle_held_item_type"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_2,
|
||||
{ it.currentSelectedComponent == "center_screen" && mainScreenIndex == MOVES },
|
||||
Component.translatable("cobblemon.controller.summary.adjust_move"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_2,
|
||||
{ it.currentSelectedComponent == "center_screen" && mainScreenIndex == MARKS },
|
||||
Component.translatable("cobblemon.controller.summary.clear_mark"),
|
||||
true
|
||||
))
|
||||
it.buttonGuides.add(ControllerComponentManager.ButtonGuide(
|
||||
ControllerComponentManager.ButtonGuideType.SPECIAL_2,
|
||||
{ it.currentSelectedComponent == "right_screen" && sideScreenIndex == PARTY },
|
||||
Component.translatable("cobblemon.controller.summary.swap_position"),
|
||||
true
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fun onBack() {
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
if (sideScreenIndex != PARTY) {
|
||||
if (sideScreenIndex == EVOLVE) {
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["evolve"]
|
||||
} else {
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["center_screen"]
|
||||
}
|
||||
displaySideScreen(PARTY)
|
||||
} else {
|
||||
saveActiveMark()
|
||||
saveMarkings()
|
||||
Minecraft.getInstance().setScreen(null)
|
||||
}
|
||||
}
|
||||
|
||||
fun swapPartySlot(sourceIndex: Int, targetIndex: Int) {
|
||||
moveSwitchingMode = false
|
||||
|
||||
if (sourceIndex >= this.party.size || targetIndex >= this.party.size) {
|
||||
return
|
||||
}
|
||||
@@ -583,11 +357,11 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
}
|
||||
}
|
||||
|
||||
fun saveMarkings() {
|
||||
private fun saveMarkings() {
|
||||
if (::markingsWidget.isInitialized) markingsWidget.saveMarkingsToPokemon()
|
||||
}
|
||||
|
||||
fun saveActiveMark() {
|
||||
private fun saveActiveMark() {
|
||||
if (mainScreenIndex == MARKS && mainScreen is MarksWidget) (mainScreen as MarksWidget).saveActiveMarkToPokemon()
|
||||
}
|
||||
|
||||
@@ -599,16 +373,12 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
/**
|
||||
* Switch center screen
|
||||
*/
|
||||
fun displayMainScreen(screen: Int) {
|
||||
private fun displayMainScreen(screen: Int) {
|
||||
// Save mark to Pokémon if any changes when switching out of marks screen
|
||||
saveActiveMark()
|
||||
|
||||
// Get stat tab index if currently displaying stat screen
|
||||
val subIndex = if (mainScreenIndex == STATS && mainScreen is StatWidget) (mainScreen as StatWidget).rawStatTabIndex else 0
|
||||
|
||||
if (screen != MOVES) {
|
||||
moveSwitchingMode = false
|
||||
}
|
||||
val subIndex = if (mainScreenIndex == STATS && mainScreen is StatWidget) (mainScreen as StatWidget).statTabIndex else 0
|
||||
|
||||
mainScreenIndex = screen
|
||||
if (::mainScreen.isInitialized) removeWidget(mainScreen)
|
||||
@@ -628,7 +398,6 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
pY = y + 12,
|
||||
pokemon = this.selectedPokemon
|
||||
)
|
||||
mainScreenComponentManager = null
|
||||
}
|
||||
|
||||
MOVES -> {
|
||||
@@ -636,13 +405,7 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
pX = x + 77,
|
||||
pY = y + 12,
|
||||
summary = this
|
||||
).also { movesWidget ->
|
||||
mainScreenComponentManager = movesWidget.controllerComponentManager
|
||||
movesWidget.controllerComponentManager.let {
|
||||
it.focused = it.componentList["move_${selectedMoveIndex}"]
|
||||
}
|
||||
}
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
STATS -> {
|
||||
@@ -650,38 +413,25 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
pX = x + 77,
|
||||
pY = y + 12,
|
||||
pokemon = this.selectedPokemon,
|
||||
tabIndex = subIndex,
|
||||
summary = this
|
||||
tabIndex = subIndex
|
||||
)
|
||||
mainScreenComponentManager = null
|
||||
}
|
||||
|
||||
MARKS -> {
|
||||
mainScreen = MarksWidget(
|
||||
pX = x + 77,
|
||||
pY = y + 12,
|
||||
pokemon = this.selectedPokemon,
|
||||
summary = this
|
||||
).also {
|
||||
mainScreenComponentManager = it.controllerComponentManager
|
||||
}
|
||||
pokemon = this.selectedPokemon
|
||||
)
|
||||
}
|
||||
}
|
||||
addRenderableWidget(mainScreen)
|
||||
|
||||
if (controllerComponentManager.currentSelectedComponent == "center_screen" && controllerComponentManager.active) {
|
||||
focused = null
|
||||
mainScreenComponentManager?.active = true
|
||||
controllerComponentManager.focused?.onFocus?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch right screen
|
||||
*/
|
||||
fun displaySideScreen(screen: Int, move: Move? = null) {
|
||||
moveSwitchingMode = false
|
||||
|
||||
sideScreenIndex = screen
|
||||
if (::sideScreen.isInitialized) removeWidget(sideScreen)
|
||||
|
||||
@@ -696,9 +446,7 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
isParty = selectedPokemon in CobblemonClient.storage.party,
|
||||
summary = this,
|
||||
partyList = this.party
|
||||
).also {
|
||||
sideScreenComponentManager = it.controllerComponentManager
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
MOVE_SWAP -> {
|
||||
@@ -720,9 +468,7 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
moveSlotList += MoveSwapScreen.MoveSlot(switchPane, null, 0, pokemon)
|
||||
}
|
||||
moveSlotList.forEach { switchPane.addEntry(it) }
|
||||
sideScreenComponentManager = switchPane.controllerComponentManager
|
||||
}
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["right_screen"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,67 +478,14 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
sideScreen = EvolutionSelectScreen(
|
||||
x + 216,
|
||||
y + 23,
|
||||
pokemon = selectedPokemon,
|
||||
summary = this
|
||||
).also {
|
||||
sideScreenComponentManager = it.controllerComponentManager
|
||||
}
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["right_screen"]
|
||||
pokemon = selectedPokemon
|
||||
)
|
||||
}
|
||||
}
|
||||
val element = sideScreen
|
||||
if (element is Renderable && element is NarratableEntry) {
|
||||
addRenderableWidget(element)
|
||||
}
|
||||
|
||||
if (controllerComponentManager.currentSelectedComponent == "right_screen" && controllerComponentManager.active) {
|
||||
focused = null
|
||||
sideScreenComponentManager?.active = true
|
||||
controllerComponentManager.focused?.onFocus?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSelectionPosAndSize(): Vector4i? {
|
||||
val data = super.getSelectionPosAndSize()
|
||||
if (data != null) {
|
||||
when (focused) {
|
||||
nicknameEntryWidget -> return Vector4i(nicknameEntryWidget.x - 12, nicknameEntryWidget.y - 4, 78, 17)
|
||||
heldItemVisibilityButton -> return Vector4i(data.x + 1, data.y + 1, data.z / 2, data.w / 2)
|
||||
is PartySlotWidget -> return data.add(-2, -2, 0, 2)
|
||||
else -> return data
|
||||
}
|
||||
} else {
|
||||
when (controllerComponentManager.currentSelectedComponent) {
|
||||
"center_screen" -> {
|
||||
when (mainScreenIndex) {
|
||||
MARKS -> {
|
||||
val marksScreen = mainScreen as MarksWidget
|
||||
val horizontalSpacing = if (marksScreen.marksScrollList.children().size > 5) MarksScrollingWidget.SLOT_SPACING else (MarksScrollingWidget.SLOT_SPACING + 1)
|
||||
val row = marksScreen.lastSelectedMark / 6
|
||||
val column = marksScreen.lastSelectedMark % 6
|
||||
val startX = marksScreen.marksScrollList.rowLeft + (horizontalSpacing + MarksScrollingWidget.SLOT_SIZE) * column
|
||||
val startY = marksScreen.marksScrollList.getRowTop(row) + MarksScrollingWidget.SLOT_SPACING
|
||||
return Vector4i(startX - 2, startY - 2, MarksScrollingWidget.SLOT_SIZE + 4, MarksScrollingWidget.SLOT_SIZE + 4)
|
||||
}
|
||||
else -> return Vector4i(mainScreen.x + 2, mainScreen.y + 2, 130, 144)
|
||||
}
|
||||
}
|
||||
"right_screen" -> {
|
||||
when (sideScreenIndex) {
|
||||
EVOLVE -> {
|
||||
val evolveScreen = sideScreen as EvolutionSelectScreen
|
||||
return Vector4i(evolveScreen.rowLeft - 5, evolveScreen.getRowTop(evolveScreen.children().indexOf(focused)) - 2, evolveScreen.rowWidth + 4, EvolutionSelectScreen.SLOT_HEIGHT + 4)
|
||||
}
|
||||
MOVE_SWAP -> {
|
||||
val moveSwapScreen = sideScreen as MoveSwapScreen
|
||||
return Vector4i(moveSwapScreen.rowLeft - 11, moveSwapScreen.getRowTop(moveSwapScreen.children().indexOf(focused)) - 2, moveSwapScreen.rowWidth + 13, MoveSwapScreen.SLOT_HEIGHT + 4)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
override fun renderMenuBackground(context: GuiGraphics) {}
|
||||
@@ -932,11 +625,8 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
val itemX = x + 3
|
||||
val itemY = y + 104
|
||||
if (!displayedItem.isEmpty) {
|
||||
matrices.pushPose()
|
||||
matrices.translate(0.0,0.0,-200.0)
|
||||
context.renderItem(displayedItem, itemX, itemY)
|
||||
context.renderItemDecorations(Minecraft.getInstance().font, displayedItem, itemX, itemY)
|
||||
matrices.popPose()
|
||||
}
|
||||
|
||||
drawScaledText(
|
||||
@@ -965,25 +655,19 @@ class Summary private constructor(party: Collection<Pokemon?>, private val edita
|
||||
scale = SCALE
|
||||
)
|
||||
|
||||
// Set Look View Pos
|
||||
val selectionData = getSelectionPosAndSize()
|
||||
if (controllerComponentManager.active && selectionData != null) {
|
||||
modelWidget.overrideLookPos = Vector2i(selectionData.x + selectionData.z / 2, selectionData.y + selectionData.w / 2)
|
||||
} else {
|
||||
modelWidget.overrideLookPos = null
|
||||
}
|
||||
matrices.pushPose()
|
||||
// Prevent widgets from being overlapped by other components
|
||||
matrices.translate(0.0, 0.0, 1000.0)
|
||||
|
||||
// Render all added Widgets
|
||||
super.render(context, mouseX, mouseY, delta)
|
||||
|
||||
// Selection Rendering
|
||||
renderSelection(matrices)
|
||||
|
||||
// Render Item Tooltip
|
||||
if (!displayedItem.isEmpty) {
|
||||
val itemHovered = mouseX.toFloat() in (itemX.toFloat()..(itemX.toFloat() + 16)) && mouseY.toFloat() in (itemY.toFloat()..(itemY.toFloat() + 16))
|
||||
if (itemHovered) context.renderTooltip(Minecraft.getInstance().font, displayedItem, mouseX, mouseY)
|
||||
}
|
||||
matrices.popPose()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,8 +32,8 @@ class SummaryButton(
|
||||
private val text: MutableComponent = Component.empty(),
|
||||
private val resource: ResourceLocation,
|
||||
private val activeResource: ResourceLocation? = null,
|
||||
val renderRequirement: ((button: SummaryButton) -> Boolean) = { true },
|
||||
val clickRequirement: ((button: SummaryButton) -> Boolean) = { true },
|
||||
private val renderRequirement: ((button: SummaryButton) -> Boolean) = { true },
|
||||
private val clickRequirement: ((button: SummaryButton) -> Boolean) = { true },
|
||||
private val hoverTexture: Boolean = true,
|
||||
private val silent: Boolean = false,
|
||||
private val boldText: Boolean = true,
|
||||
@@ -67,7 +67,7 @@ class SummaryButton(
|
||||
y = buttonY / scale,
|
||||
width = buttonWidth,
|
||||
height = buttonHeight,
|
||||
vOffset = if (hoverTexture && (isButtonHovered(pMouseX, pMouseY) || isFocused)) buttonHeight else 0,
|
||||
vOffset = if (hoverTexture && isButtonHovered(pMouseX, pMouseY)) buttonHeight else 0,
|
||||
textureHeight = if (hoverTexture) (buttonHeight.toFloat() * 2) else buttonHeight,
|
||||
scale = scale
|
||||
)
|
||||
|
||||
+2
-34
@@ -15,11 +15,8 @@ import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.TypeIcon
|
||||
import com.cobblemon.mod.common.client.gui.drawProfilePokemon
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary
|
||||
import com.cobblemon.mod.common.client.gui.summary.SummaryButton
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.common.SummaryScrollList
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.FloatingState
|
||||
import com.cobblemon.mod.common.pokemon.FormData
|
||||
@@ -37,8 +34,7 @@ import org.joml.Vector3f
|
||||
class EvolutionSelectScreen(
|
||||
x: Int,
|
||||
y: Int,
|
||||
val pokemon: Pokemon,
|
||||
val summary: Summary
|
||||
val pokemon: Pokemon
|
||||
): SummaryScrollList<EvolutionSelectScreen.EvolveSlot>(
|
||||
x,
|
||||
y,
|
||||
@@ -56,36 +52,8 @@ class EvolutionSelectScreen(
|
||||
|
||||
private var entriesCreated = false
|
||||
|
||||
var controllerComponentManager = ControllerComponentManager(summary).also {
|
||||
it.onActiveChange = { state ->
|
||||
if (state) it.focused?.onSelect?.invoke() else it.focused?.onUnselect?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
public override fun addEntry(entry: EvolveSlot): Int {
|
||||
val i = super.addEntry(entry)
|
||||
controllerComponentManager.componentList["moves_${i}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = entry
|
||||
it.onPress = {
|
||||
entry.selectButton.onPress()
|
||||
}
|
||||
it.onSelect = {
|
||||
ensureVisible(entry)
|
||||
entry.selectButton.isFocused = true
|
||||
}
|
||||
it.onUnselect = {
|
||||
entry.selectButton.isFocused = false
|
||||
}
|
||||
}
|
||||
if (children().size > 1) {
|
||||
controllerComponentManager.componentList["moves_${i}"]?.let {
|
||||
it.pairUp(controllerComponentManager.componentList["moves_${i-1}"])
|
||||
it.pairDown(controllerComponentManager.componentList["moves_${0}"])
|
||||
}
|
||||
} else {
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["moves_${i}"]
|
||||
}
|
||||
return i
|
||||
return super.addEntry(entry)
|
||||
}
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, partialTicks: Float) {
|
||||
|
||||
+3
-14
@@ -21,7 +21,6 @@ import com.cobblemon.mod.common.util.math.fromEulerXYZDegrees
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.network.chat.Component
|
||||
import org.joml.Quaternionf
|
||||
import org.joml.Vector2i
|
||||
import org.joml.Vector3f
|
||||
|
||||
class ModelWidget(
|
||||
@@ -60,8 +59,6 @@ class ModelWidget(
|
||||
var currentYawAndPitch: Pair<Float, Float> = Pair(0f, 0f)
|
||||
val rotationVector = Vector3f(13F, rotationY, 0F)
|
||||
|
||||
var overrideLookPos: Vector2i? = null
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, pMouseX: Int, pMouseY: Int, partialTicks: Float) {
|
||||
if (!render) {
|
||||
return
|
||||
@@ -91,7 +88,7 @@ class ModelWidget(
|
||||
|
||||
val timeLooking = lookStartTime?.let { (System.currentTimeMillis() - it) / 1000 } ?: MAX_SECONDS_LOOKING
|
||||
val lookedTooMuch = timeLooking >= MAX_SECONDS_LOOKING
|
||||
val resetToCenter = (!isHovered && lookedTooMuch && overrideLookPos == null) || !shouldFollowCursor || !Cobblemon.config.summaryPokemonFollowCursor
|
||||
val resetToCenter = (!isHovered && lookedTooMuch) || !shouldFollowCursor || !Cobblemon.config.summaryPokemonFollowCursor
|
||||
|
||||
if (resetToCenter) {
|
||||
lookStartTime = null
|
||||
@@ -100,19 +97,12 @@ class ModelWidget(
|
||||
val rotation = Quaternionf().fromEulerXYZDegrees(rotationVector)
|
||||
|
||||
if (shouldFollowCursor) {
|
||||
var xPos = mouseX
|
||||
var yPos = mouseY
|
||||
if (overrideLookPos != null) {
|
||||
xPos = overrideLookPos!!.x
|
||||
yPos = overrideLookPos!!.y
|
||||
}
|
||||
|
||||
currentYawAndPitch = calculateHeadYawAndPitch(
|
||||
x + width / 2f,
|
||||
y + height / 2f,
|
||||
rotation,
|
||||
xPos,
|
||||
yPos,
|
||||
mouseX,
|
||||
mouseY,
|
||||
currentYawAndPitch.first,
|
||||
currentYawAndPitch.second,
|
||||
resetToCenter
|
||||
@@ -130,7 +120,6 @@ class ModelWidget(
|
||||
blockLight = blockLight,
|
||||
profileTransformType = ProfileTransformType.SUMMARY,
|
||||
)
|
||||
context.flush()
|
||||
|
||||
heldItemRenderer.renderOnModel(
|
||||
pokemon.heldItem,
|
||||
|
||||
+6
-11
@@ -88,7 +88,7 @@ class PartySlotWidget(
|
||||
y = y,
|
||||
width = width,
|
||||
height = height,
|
||||
vOffset = getSlotVOffset(slotPokemon, isHovered || isFocused, isSelected),
|
||||
vOffset = getSlotVOffset(slotPokemon, isHovered, isSelected),
|
||||
textureHeight = height * 2,
|
||||
)
|
||||
|
||||
@@ -223,21 +223,16 @@ class PartySlotWidget(
|
||||
if (partyWidget.swapEnabled) {
|
||||
toggleDrag(true)
|
||||
} else {
|
||||
if (onPress()) return true
|
||||
if ((index > -1) && (summary.selectedPokemon.uuid != pokemon?.uuid)) {
|
||||
summary.switchSelection(index)
|
||||
if (pokemon != null) partyWidget.playSound(CobblemonSounds.GUI_CLICK)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.mouseClicked(pMouseX, pMouseY, pButton)
|
||||
}
|
||||
|
||||
fun onPress(): Boolean {
|
||||
if ((index > -1) && (summary.selectedPokemon.uuid != pokemon?.uuid)) {
|
||||
summary.switchSelection(index)
|
||||
if (pokemon != null) partyWidget.playSound(CobblemonSounds.GUI_CLICK)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun mouseReleased(pMouseX: Double, pMouseY: Double, pButton: Int): Boolean {
|
||||
if (partyWidget.swapEnabled) toggleDrag(false)
|
||||
return partyWidget.mouseReleased(pMouseX, pMouseY, pButton)
|
||||
|
||||
+1
-85
@@ -14,8 +14,6 @@ import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary
|
||||
import com.cobblemon.mod.common.client.gui.summary.SummaryButton
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
@@ -69,8 +67,6 @@ class PartyWidget(
|
||||
}
|
||||
)
|
||||
|
||||
var controllerComponentManager = ControllerComponentManager(summary)
|
||||
|
||||
init {
|
||||
if (partySize > 6 || partySize < 1)
|
||||
throw InvalidParameterException("Invalid party size")
|
||||
@@ -89,7 +85,7 @@ class PartyWidget(
|
||||
y += (32 * offsetIndex) + offsetY
|
||||
}
|
||||
|
||||
val slot = PartySlotWidget(
|
||||
PartySlotWidget(
|
||||
pX = x,
|
||||
pY = y,
|
||||
partyWidget = this,
|
||||
@@ -101,86 +97,6 @@ class PartyWidget(
|
||||
this.addWidget(widget)
|
||||
partySlots.add(widget)
|
||||
}
|
||||
|
||||
controllerComponentManager.componentList["slot_${index}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = slot
|
||||
it.onPress = {
|
||||
if (swapEnabled) {
|
||||
if (swapSource == null) {
|
||||
if (partyList[index] != null) {
|
||||
swapSource = index
|
||||
draggedSlot = PartySlotWidget(
|
||||
pX = slot.x + 4,
|
||||
pY = slot.y + 4,
|
||||
partyWidget = this,
|
||||
summary = summary,
|
||||
pokemon = partyList[index],
|
||||
index = -1,
|
||||
isClientPartyMember = isParty
|
||||
)
|
||||
draggedSlot?.isFocused = true
|
||||
playSound(CobblemonSounds.PC_GRAB)
|
||||
}
|
||||
} else {
|
||||
if (swapSource != index) {
|
||||
summary.swapPartySlot(swapSource!!, index)
|
||||
}
|
||||
swapSource = null
|
||||
draggedSlot = null
|
||||
playSound(CobblemonSounds.PC_DROP)
|
||||
}
|
||||
} else slot.onPress()
|
||||
}
|
||||
it.onSpecial1 = {
|
||||
swapEnabled = !swapEnabled
|
||||
swapButton.buttonActive = swapEnabled
|
||||
if (!swapEnabled) {
|
||||
swapSource = null
|
||||
draggedSlot = null
|
||||
}
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
}
|
||||
|
||||
fun updateDraggedSlotPos() {
|
||||
draggedSlot?.let { theSlot ->
|
||||
theSlot.x = slot.x + 4
|
||||
theSlot.y = slot.y + 4
|
||||
}
|
||||
}
|
||||
|
||||
if (index-2 >= 0) {
|
||||
it.up = {
|
||||
controllerComponentManager.componentList["slot_${index-2}"]
|
||||
}
|
||||
}
|
||||
if (index+2 <= 5) {
|
||||
it.down = {
|
||||
controllerComponentManager.componentList["slot_${index+2}"]
|
||||
}
|
||||
}
|
||||
if (index.mod(2) == 0) {
|
||||
it.right = {
|
||||
controllerComponentManager.componentList["slot_${index+1}"]
|
||||
}
|
||||
} else {
|
||||
it.left = {
|
||||
controllerComponentManager.componentList["slot_${index-1}"]
|
||||
}
|
||||
}
|
||||
it.onSelect = {
|
||||
updateDraggedSlotPos()
|
||||
summary.lastSelectedPartySlot = index
|
||||
}
|
||||
}
|
||||
}
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["slot_${summary.lastSelectedPartySlot}"]
|
||||
it.onActiveChange = { state ->
|
||||
if (!state) {
|
||||
swapSource = null
|
||||
draggedSlot = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-19
@@ -125,23 +125,6 @@ abstract class SummaryScrollList<T : ObjectSelectionList.Entry<T>>(
|
||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)
|
||||
}
|
||||
|
||||
public override fun ensureVisible(entry: T) {
|
||||
val i = getRowTop(children().indexOf(entry))
|
||||
val topDifference = i - y - 4
|
||||
if (topDifference < 0) {
|
||||
scroll(topDifference)
|
||||
}
|
||||
|
||||
val bottomDifference = bottom - i - itemHeight
|
||||
if (bottomDifference < 0) {
|
||||
scroll(-bottomDifference)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun getRowTop(index: Int): Int {
|
||||
return super.getRowTop(index)
|
||||
}
|
||||
|
||||
private fun updateScrollingState(mouseX: Double, mouseY: Double) {
|
||||
scrolling = mouseX >= this.scrollbarPosition.toDouble()
|
||||
&& mouseX < (this.scrollbarPosition + 3).toDouble()
|
||||
@@ -152,6 +135,4 @@ abstract class SummaryScrollList<T : ObjectSelectionList.Entry<T>>(
|
||||
private fun correctSize() {
|
||||
setRectangle(WIDTH, HEIGHT, listX, listY)
|
||||
}
|
||||
|
||||
open fun onPress(entry: T) {}
|
||||
}
|
||||
+3
-4
@@ -106,11 +106,10 @@ class MarksScrollingWidget(val pX: Int, val pY: Int, val setSelectedMark: () ->
|
||||
companion object {
|
||||
private val slotResource = cobblemonResource("textures/gui/summary/summary_mark_slot.png")
|
||||
}
|
||||
|
||||
var x: Int = 0
|
||||
var y: Int = 0
|
||||
|
||||
var slotSelected: (Int) -> Boolean = { false }
|
||||
|
||||
fun renderRow(context: GuiGraphics, y: Int, x: Int, mouseX: Int, mouseY: Int): Boolean {
|
||||
var anyHovered = false
|
||||
val horizontalSpacing = if (isScrollVisible()) SLOT_SPACING else (SLOT_SPACING + 1)
|
||||
@@ -134,7 +133,7 @@ class MarksScrollingWidget(val pX: Int, val pY: Int, val setSelectedMark: () ->
|
||||
y = startPosY,
|
||||
width = SLOT_SIZE,
|
||||
height = SLOT_SIZE,
|
||||
vOffset = if (slotHovered || (mark != null && slotSelected.invoke(index))) SLOT_SIZE else 0,
|
||||
vOffset = if (slotHovered) SLOT_SIZE else 0,
|
||||
textureHeight = SLOT_SIZE * 2
|
||||
)
|
||||
|
||||
@@ -161,7 +160,7 @@ class MarksScrollingWidget(val pX: Int, val pY: Int, val setSelectedMark: () ->
|
||||
return true
|
||||
}
|
||||
|
||||
fun isScrollVisible(): Boolean = parent.children().size > 5
|
||||
private fun isScrollVisible(): Boolean = parent.children().size > 5
|
||||
|
||||
private fun getHoveredSlotIndex(mouseX: Int, mouseY: Int): Int {
|
||||
val horizontalSpacing = if (isScrollVisible()) SLOT_SPACING else (SLOT_SPACING + 1)
|
||||
|
||||
+1
-56
@@ -15,10 +15,7 @@ import com.cobblemon.mod.common.api.gui.MultiLineLabelK
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.mark.Mark
|
||||
import com.cobblemon.mod.common.client.gui.common.MarkIcon
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.SoundlessWidget
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.SetActiveMarkPacket
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
@@ -30,8 +27,7 @@ import net.minecraft.network.chat.Component
|
||||
|
||||
class MarksWidget(
|
||||
pX: Int, pY: Int,
|
||||
val pokemon: Pokemon,
|
||||
val summary: Summary
|
||||
val pokemon: Pokemon
|
||||
): SoundlessWidget(pX, pY, WIDTH, HEIGHT, Component.literal("MarksWidget")) {
|
||||
companion object {
|
||||
private const val WIDTH = 134
|
||||
@@ -57,9 +53,6 @@ class MarksWidget(
|
||||
setHoveredMark = { hoveredMark = it }
|
||||
)
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(summary)
|
||||
var lastSelectedMark = 0
|
||||
|
||||
init {
|
||||
children.clear()
|
||||
activeMark = pokemon.activeMark
|
||||
@@ -71,54 +64,6 @@ class MarksWidget(
|
||||
while ((marksList.size < 30) || (marksList.size > 30 && marksList.size % 6 != 0)) marksList.add(null)
|
||||
marksScrollList.createEntries(marksList)
|
||||
addWidget(marksScrollList)
|
||||
|
||||
marksScrollList.children().forEachIndexed { firstIndex, row ->
|
||||
row.markList.forEachIndexed { secondIndex, mark ->
|
||||
controllerComponentManager.componentList["mark_${firstIndex}_${secondIndex}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = row
|
||||
it.onPress = {
|
||||
if (mark != null) {
|
||||
selectedMark = mark
|
||||
Minecraft.getInstance().soundManager.play(SimpleSoundInstance.forUI(CobblemonSounds.GUI_CLICK, 1.0F))
|
||||
}
|
||||
}
|
||||
it.onSpecial1 = {
|
||||
if (selectedMark !== null) {
|
||||
selectedMark = null
|
||||
Minecraft.getInstance().soundManager.play(SimpleSoundInstance.forUI(CobblemonSounds.GUI_CLICK, 1.0F))
|
||||
}
|
||||
}
|
||||
it.onSelect = {
|
||||
lastSelectedMark = firstIndex * 6 + secondIndex
|
||||
marksScrollList.ensureVisible(row)
|
||||
}
|
||||
if (firstIndex - 1 >= 0) {
|
||||
it.up = {
|
||||
controllerComponentManager.componentList["mark_${firstIndex-1}_${secondIndex}"]
|
||||
}
|
||||
}
|
||||
if (firstIndex + 1 <= marksScrollList.children().size - 1) {
|
||||
it.down = {
|
||||
controllerComponentManager.componentList["mark_${firstIndex+1}_${secondIndex}"]
|
||||
}
|
||||
}
|
||||
if (secondIndex - 1 >= 0) {
|
||||
it.left = {
|
||||
controllerComponentManager.componentList["mark_${firstIndex}_${secondIndex-1}"]
|
||||
}
|
||||
}
|
||||
if (secondIndex + 1 <= row.markList.size - 1) {
|
||||
it.right = {
|
||||
controllerComponentManager.componentList["mark_${firstIndex}_${secondIndex+1}"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
row.slotSelected = { index ->
|
||||
controllerComponentManager.active && lastSelectedMark / 6 == firstIndex && lastSelectedMark % 6 == index
|
||||
}
|
||||
}
|
||||
controllerComponentManager.let { it.focused = it.componentList["mark_${lastSelectedMark / 6}_${lastSelectedMark % 6}"] }
|
||||
}
|
||||
|
||||
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||
|
||||
+2
-2
@@ -45,14 +45,14 @@ class MoveSlotWidget(
|
||||
const val MOVE_HEIGHT = 22
|
||||
}
|
||||
|
||||
val moveUpButton = ReorderMoveButton(x, y, true) {
|
||||
private val moveUpButton = ReorderMoveButton(x, y, true) {
|
||||
movesWidget.selectMove(null)
|
||||
movesWidget.reorderMove(this, true)
|
||||
}.apply {
|
||||
addWidget(this)
|
||||
}
|
||||
|
||||
val moveDownButton = ReorderMoveButton(x, y, false) {
|
||||
private val moveDownButton = ReorderMoveButton(x, y, false) {
|
||||
movesWidget.selectMove(null)
|
||||
movesWidget.reorderMove(this, false)
|
||||
}.apply {
|
||||
|
||||
+16
-58
@@ -20,8 +20,6 @@ import com.cobblemon.mod.common.client.gui.MoveCategoryIcon
|
||||
import com.cobblemon.mod.common.client.gui.TypeIcon
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.common.SummaryScrollList
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.net.messages.server.BenchMovePacket
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
@@ -51,45 +49,13 @@ class MoveSwapScreen(
|
||||
private val forgetMoveIconResource = cobblemonResource("textures/gui/summary/summary_move_condensed_empty_icon.png")
|
||||
}
|
||||
|
||||
var controllerComponentManager = ControllerComponentManager(movesWidget.summary).also {
|
||||
it.onActiveChange = { state ->
|
||||
if (state) it.focused?.onSelect?.invoke() else it.focused?.onUnselect?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
public override fun addEntry(entry: MoveSlot): Int {
|
||||
val i = super.addEntry(entry)
|
||||
controllerComponentManager.componentList["moves_${i}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = entry
|
||||
it.onPress = {
|
||||
entry.onPress()
|
||||
movesWidget.summary.controllerComponentManager.let { controller -> controller.focused = controller.componentList["center_screen"] }
|
||||
}
|
||||
it.onSelect = {
|
||||
ensureVisible(entry)
|
||||
entry.slotSelected = true
|
||||
}
|
||||
it.onUnselect = {
|
||||
entry.slotSelected = false
|
||||
}
|
||||
}
|
||||
if (children().size > 1) {
|
||||
controllerComponentManager.componentList["moves_${i}"]?.let {
|
||||
it.pairUp(controllerComponentManager.componentList["moves_${i-1}"])
|
||||
it.pairDown(controllerComponentManager.componentList["moves_${0}"])
|
||||
}
|
||||
} else {
|
||||
controllerComponentManager.focused = controllerComponentManager.componentList["moves_${i}"]
|
||||
}
|
||||
return i
|
||||
return super.addEntry(entry)
|
||||
}
|
||||
|
||||
class MoveSlot(val pane: MoveSwapScreen, val move: MoveTemplate?, val ppRaisedStages: Int, pokemon: Pokemon) : Entry<MoveSlot>() {
|
||||
override fun getNarration() = move?.displayName ?: lang("ui.moves.forget")
|
||||
|
||||
val elementalType = move?.getEffectiveElementalType(pokemon) ?: ElementalTypes.NORMAL
|
||||
var slotSelected = false
|
||||
|
||||
override fun render(
|
||||
context: GuiGraphics,
|
||||
index: Int,
|
||||
@@ -114,7 +80,7 @@ class MoveSwapScreen(
|
||||
y = tweakedRowTop,
|
||||
height = SLOT_HEIGHT,
|
||||
width = rowWidth,
|
||||
vOffset = if (isHovered || slotSelected) SLOT_HEIGHT else 0,
|
||||
vOffset = if (isHovered) SLOT_HEIGHT else 0,
|
||||
textureHeight = SLOT_HEIGHT * 2,
|
||||
red = rgb.first,
|
||||
green = rgb.second,
|
||||
@@ -230,7 +196,7 @@ class MoveSwapScreen(
|
||||
y = tweakedRowTop,
|
||||
height = SLOT_HEIGHT,
|
||||
width = 100,
|
||||
vOffset = if (isHovered || slotSelected) SLOT_HEIGHT else 0,
|
||||
vOffset = if (isHovered) SLOT_HEIGHT else 0,
|
||||
textureHeight = SLOT_HEIGHT * 2,
|
||||
)
|
||||
blitk(
|
||||
@@ -240,7 +206,7 @@ class MoveSwapScreen(
|
||||
y = tweakedRowTop + SLOT_HEIGHT / 2 - 4,
|
||||
height = 7,
|
||||
width = 7,
|
||||
vOffset = if (isHovered || slotSelected) 7 else 0,
|
||||
vOffset = if (isHovered) 7 else 0,
|
||||
textureHeight = 14,
|
||||
)
|
||||
}
|
||||
@@ -249,29 +215,21 @@ class MoveSwapScreen(
|
||||
|
||||
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
|
||||
if (isMouseOver(d, e)) {
|
||||
onPress()
|
||||
val pokemon = pane.movesWidget.summary.selectedPokemon
|
||||
val isParty = pokemon in CobblemonClient.storage.party
|
||||
CobblemonNetwork.sendToServer(
|
||||
BenchMovePacket(
|
||||
isParty = isParty,
|
||||
uuid = pokemon.uuid,
|
||||
oldMove = pane.replacedMove?.template,
|
||||
newMove = move
|
||||
)
|
||||
)
|
||||
pane.movesWidget.summary.playSound(CobblemonSounds.GUI_CLICK)
|
||||
pane.movesWidget.summary.displaySideScreen(Summary.PARTY)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun onPress() {
|
||||
switchMove()
|
||||
pane.movesWidget.summary.playSound(CobblemonSounds.GUI_CLICK)
|
||||
pane.movesWidget.summary.displaySideScreen(Summary.PARTY)
|
||||
}
|
||||
|
||||
fun switchMove() {
|
||||
val pokemon = pane.movesWidget.summary.selectedPokemon
|
||||
val isParty = pokemon in CobblemonClient.storage.party
|
||||
CobblemonNetwork.sendToServer(
|
||||
BenchMovePacket(
|
||||
isParty = isParty,
|
||||
uuid = pokemon.uuid,
|
||||
oldMove = pane.replacedMove?.template,
|
||||
newMove = move
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-78
@@ -9,15 +9,12 @@
|
||||
package com.cobblemon.mod.common.client.gui.summary.widgets.screens.moves
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonNetwork
|
||||
import com.cobblemon.mod.common.CobblemonSounds
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.api.moves.Move
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.SoundlessWidget
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.net.messages.server.RequestMoveSwapPacket
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
@@ -55,8 +52,8 @@ class MovesWidget(
|
||||
|
||||
var selectedMove: Move? = null
|
||||
|
||||
var index = -1
|
||||
val moves = (
|
||||
private var index = -1
|
||||
private val moves = (
|
||||
if (summary.selectedPokemon.relearnableMoves.count() > 0)
|
||||
summary.selectedPokemon.moveSet.getMovesWithNulls()
|
||||
else summary.selectedPokemon.moveSet
|
||||
@@ -79,79 +76,6 @@ class MovesWidget(
|
||||
5
|
||||
)
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(summary).also { controller ->
|
||||
var i = 0
|
||||
moves.forEach { move ->
|
||||
controller.componentList["move_${i}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = move
|
||||
var upLoc = i - 1
|
||||
if (upLoc < 0) upLoc = moves.size - 1
|
||||
it.up = {
|
||||
var returnVal: ControllerComponent?
|
||||
if (!summary.moveSwitchingMode) {
|
||||
returnVal = controller.componentList["move_${upLoc}"]
|
||||
} else {
|
||||
returnVal = null
|
||||
summary.selectedMoveIndex = upLoc
|
||||
reorderMove(move, true)
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
var downLoc = i + 1
|
||||
if (downLoc > moves.size - 1) downLoc = 0
|
||||
it.down = {
|
||||
var returnVal: ControllerComponent?
|
||||
if (!summary.moveSwitchingMode) {
|
||||
returnVal = controller.componentList["move_${downLoc}"]
|
||||
} else {
|
||||
returnVal = null
|
||||
summary.selectedMoveIndex = downLoc
|
||||
reorderMove(move, false)
|
||||
}
|
||||
returnVal
|
||||
}
|
||||
it.onSpecial1 = {
|
||||
if (!summary.moveSwitchingMode) {
|
||||
summary.playSound(CobblemonSounds.GUI_CLICK)
|
||||
summary.displaySideScreen(Summary.MOVE_SWAP, move.move)
|
||||
}
|
||||
}
|
||||
it.onSpecial2 = {
|
||||
summary.playSound(CobblemonSounds.GUI_CLICK)
|
||||
summary.moveSwitchingMode = !summary.moveSwitchingMode
|
||||
if (summary.moveSwitchingMode) {
|
||||
move.moveUpButton.isFocused = true
|
||||
move.moveDownButton.isFocused = true
|
||||
} else {
|
||||
move.moveUpButton.isFocused = false
|
||||
move.moveDownButton.isFocused = false
|
||||
}
|
||||
}
|
||||
val staticI = i
|
||||
it.onSelect = {
|
||||
summary.selectedMoveIndex = staticI
|
||||
if (selectedMove != move.move) selectMove(move.move)
|
||||
if (summary.moveSwitchingMode) {
|
||||
move.moveUpButton.isFocused = true
|
||||
move.moveDownButton.isFocused = true
|
||||
}
|
||||
}
|
||||
it.onUnselect = {
|
||||
move.moveUpButton.isFocused = false
|
||||
move.moveDownButton.isFocused = false
|
||||
}
|
||||
}
|
||||
i++
|
||||
}
|
||||
controller.onNoneSelected = {
|
||||
summary.selectedMoveIndex = summary.selectedMoveIndex.coerceIn(0, moves.size - 1)
|
||||
controller.focused = controller.componentList["move_${summary.selectedMoveIndex}"]
|
||||
true
|
||||
}
|
||||
controller.onActiveChange = { state ->
|
||||
if (state) controller.focused?.onSelect?.invoke() else controller.focused?.onUnselect?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, pMouseX: Int, pMouseY: Int, pPartialTicks: Float) {
|
||||
val matrices = context.pose()
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ class ReorderMoveButton(
|
||||
texture = if (isUp) moveReorderUpResource else moveReorderDownResource,
|
||||
width = WIDTH,
|
||||
height = HEIGHT,
|
||||
vOffset = if (isHovered(pMouseX.toDouble(), pMouseY.toDouble(), offsetY.toFloat()) || isFocused) HEIGHT else 0,
|
||||
vOffset = if (isHovered(pMouseX.toDouble(), pMouseY.toDouble(), offsetY.toFloat())) HEIGHT else 0,
|
||||
textureHeight = HEIGHT * 2,
|
||||
scale = SCALE
|
||||
)
|
||||
|
||||
+11
-13
@@ -19,7 +19,6 @@ import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||
import com.cobblemon.mod.common.api.text.bold
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.client.CobblemonResources
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary
|
||||
import com.cobblemon.mod.common.client.gui.summary.SummaryButton
|
||||
import com.cobblemon.mod.common.client.gui.summary.featurerenderers.BarSummarySpeciesFeatureRenderer
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.SoundlessWidget
|
||||
@@ -50,17 +49,16 @@ import org.joml.Vector3f
|
||||
class StatWidget(
|
||||
pX: Int, pY: Int,
|
||||
val pokemon: Pokemon,
|
||||
val tabIndex: Int = 0,
|
||||
val summary: Summary
|
||||
val tabIndex: Int = 0
|
||||
): SoundlessWidget(pX, pY, WIDTH, HEIGHT, Component.literal("StatWidget")) {
|
||||
|
||||
companion object {
|
||||
// Stat tab options
|
||||
const val STATS = "stats"
|
||||
const val IV = "ivs"
|
||||
const val EV = "evs"
|
||||
const val RIDE = "ride"
|
||||
const val OTHER = "other"
|
||||
private const val STATS = "stats"
|
||||
private const val IV = "ivs"
|
||||
private const val EV = "evs"
|
||||
private const val RIDE = "ride"
|
||||
private const val OTHER = "other"
|
||||
|
||||
private const val OTHER_STAT_BARS_PER_PAGE = 4
|
||||
private const val STAT_TAB_WIDTH_6 = 22
|
||||
@@ -115,13 +113,13 @@ class StatWidget(
|
||||
)
|
||||
}
|
||||
|
||||
val statOptions = if (pokemon.form.riding.behaviours != null) listOf(STATS, IV, EV, RIDE, OTHER) else listOf(STATS, IV, EV, OTHER)
|
||||
private val statOptions = if (pokemon.form.riding.behaviours != null) listOf(STATS, IV, EV, RIDE, OTHER) else listOf(STATS, IV, EV, OTHER)
|
||||
|
||||
var rawStatTabIndex: Int = tabIndex
|
||||
private var _statTabIndex: Int = tabIndex
|
||||
var statTabIndex: Int
|
||||
get() = rawStatTabIndex.coerceIn(0, statOptions.size - 1)
|
||||
get() = _statTabIndex.coerceIn(0, statOptions.size - 1)
|
||||
set(value) {
|
||||
rawStatTabIndex = value.coerceIn(0, statOptions.size - 1)
|
||||
_statTabIndex = value.coerceIn(0, statOptions.size - 1)
|
||||
}
|
||||
|
||||
private var _rideBehaviourIndex: Int = 0
|
||||
@@ -304,7 +302,7 @@ class StatWidget(
|
||||
pokemon.form.riding.behaviours?.let {
|
||||
val behaviours = it.entries.toList()
|
||||
val selectedBehaviour = behaviours[rideBehaviourIndex]
|
||||
val canSwitchStyle = behaviours.size > 1 && (centerHovered(pMouseX, pMouseY) || (summary.controllerComponentManager.let { it.active && it.currentSelectedComponent == "center_screen" }))
|
||||
val canSwitchStyle = behaviours.size > 1 && centerHovered(pMouseX, pMouseY)
|
||||
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
|
||||
@@ -49,7 +49,7 @@ open class PartySlot(
|
||||
|
||||
override fun renderWidget(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
val matrices = context.pose()
|
||||
if (!isOpposing && (isHovered(mouseX, mouseY) || isFocused)) {
|
||||
if (!isOpposing && isHovered(mouseX, mouseY)) {
|
||||
blitk(
|
||||
matrixStack = matrices,
|
||||
texture = hoverBackgroundResource,
|
||||
|
||||
@@ -49,7 +49,7 @@ class TradeButton(
|
||||
y = y,
|
||||
width = WIDTH,
|
||||
height = HEIGHT,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble()) || isFocused) HEIGHT else 0,
|
||||
vOffset = if (isHovered(mouseX.toDouble(), mouseY.toDouble())) HEIGHT else 0,
|
||||
textureHeight = HEIGHT * 2
|
||||
)
|
||||
|
||||
|
||||
@@ -22,9 +22,6 @@ import com.cobblemon.mod.common.client.gui.TypeIcon
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.MarkingsWidget
|
||||
import com.cobblemon.mod.common.client.gui.summary.widgets.common.reformatNatureTextIfMinted
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponent
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.render.drawScaledTextJustifiedRight
|
||||
import com.cobblemon.mod.common.client.trade.ClientTrade
|
||||
@@ -58,7 +55,7 @@ class TradeGUI(
|
||||
val traderName: MutableComponent,
|
||||
val traderParty: MutableList<TradeablePokemon?>,
|
||||
val party: MutableList<TradeablePokemon?>
|
||||
): Screen(lang("trade.gui.title")), CobblemonRenderable, ControllerScreen {
|
||||
): Screen(lang("trade.gui.title")), CobblemonRenderable {
|
||||
|
||||
companion object {
|
||||
const val BASE_WIDTH = 293
|
||||
@@ -121,13 +118,6 @@ class TradeGUI(
|
||||
|
||||
var tradeSoundInstance: SoundInstance? = null
|
||||
|
||||
val controllerComponentManager = ControllerComponentManager(this)
|
||||
var lastSelectedRow = 0
|
||||
|
||||
override fun getComponentManager(): ControllerComponentManager {
|
||||
return controllerComponentManager
|
||||
}
|
||||
|
||||
init {
|
||||
trade.cancelEmitter.subscribe {
|
||||
cancelTradeSound()
|
||||
@@ -188,25 +178,21 @@ class TradeGUI(
|
||||
)
|
||||
|
||||
// Trade Button
|
||||
val tradeButton = TradeButton(
|
||||
x = x + 120,
|
||||
y = y + 119,
|
||||
parent = this,
|
||||
onPress = {
|
||||
if (offeredPokemon != null && opposingOfferedPokemon != null && protectiveTicks <= 0 && !tradeProcessing) {
|
||||
ticksElapsed = 0
|
||||
readyProgress = 0
|
||||
CobblemonNetwork.sendToServer(ChangeTradeAcceptancePacket(opposingOfferedPokemon!!.uuid, !trade.acceptedOppositeOffer))
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
this.addRenderableWidget(
|
||||
TradeButton(
|
||||
x = x + 120,
|
||||
y = y + 119,
|
||||
parent = this,
|
||||
onPress = {
|
||||
if (offeredPokemon != null && opposingOfferedPokemon != null && protectiveTicks <= 0 && !tradeProcessing) {
|
||||
ticksElapsed = 0
|
||||
readyProgress = 0
|
||||
CobblemonNetwork.sendToServer(ChangeTradeAcceptancePacket(opposingOfferedPokemon!!.uuid, !trade.acceptedOppositeOffer))
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
this.addRenderableWidget(tradeButton)
|
||||
|
||||
controllerComponentManager.componentList["trade"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = tradeButton
|
||||
it.left = { controllerComponentManager.componentList["slot_${lastSelectedRow}_${1}"] }
|
||||
}
|
||||
|
||||
// Party
|
||||
for (partyIndex in 0..5) {
|
||||
@@ -224,7 +210,7 @@ class TradeGUI(
|
||||
}
|
||||
|
||||
val pokemon = party[partyIndex]
|
||||
val slot = PartySlot(
|
||||
PartySlot(
|
||||
x = slotX,
|
||||
y = slotY,
|
||||
pokemon = pokemon,
|
||||
@@ -237,22 +223,6 @@ class TradeGUI(
|
||||
}
|
||||
}
|
||||
).also { widget -> addRenderableWidget(widget) }
|
||||
|
||||
val row = partyIndex / 2
|
||||
val column = partyIndex % 2
|
||||
controllerComponentManager.componentList["slot_${row}_${column}"] = ControllerComponent().also {
|
||||
it.associatedGUIElement = slot
|
||||
if (column == 0) it.right = { controllerComponentManager.componentList["slot_${row}_${1}"] }
|
||||
else {
|
||||
it.left = { controllerComponentManager.componentList["slot_${row}_${0}"] }
|
||||
it.right = { controllerComponentManager.componentList["trade"] }
|
||||
}
|
||||
if (row - 1 >= 0) it.up = { controllerComponentManager.componentList["slot_${row-1}_${column}"] }
|
||||
if (row + 1 <= 2) it.down = { controllerComponentManager.componentList["slot_${row+1}_${column}"] }
|
||||
it.onSelect = {
|
||||
lastSelectedRow = row
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Opposing Party
|
||||
@@ -287,10 +257,6 @@ class TradeGUI(
|
||||
opposingOfferedPokemonMarkings = MarkingsWidget(x + 177.5, y + 21, opposingOfferedPokemon, false)
|
||||
addRenderableWidget(offeredPokemonMarkings)
|
||||
addRenderableWidget(opposingOfferedPokemonMarkings)
|
||||
|
||||
controllerComponentManager.let {
|
||||
it.focused = it.componentList["slot_0_0"]
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(context: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
@@ -479,8 +445,6 @@ class TradeGUI(
|
||||
val itemHovered = mouseX.toFloat() in (itemX.toFloat()..(itemX.toFloat() + 16)) && mouseY.toFloat() in (itemY.toFloat()..(itemY.toFloat() + 16))
|
||||
if (itemHovered) context.renderTooltip(Minecraft.getInstance().font, opposingOfferedPokemon!!.heldItemNoCopy(), mouseX, mouseY)
|
||||
}
|
||||
|
||||
renderSelection(matrices)
|
||||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
|
||||
-363
@@ -1,363 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.client.integration.controlify
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonItems
|
||||
import com.cobblemon.mod.common.OrientationControllable
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.client.CobblemonClient.ridingTurnInputHandler
|
||||
import com.cobblemon.mod.common.client.gui.battle.BattleGUI
|
||||
import com.cobblemon.mod.common.client.gui.config.CobblemonConfigScreen
|
||||
import com.cobblemon.mod.common.client.gui.cookingpot.CookingPotScreen
|
||||
import com.cobblemon.mod.common.client.gui.dialogue.DialogueScreen
|
||||
import com.cobblemon.mod.common.client.gui.interact.battleRequest.BattleConfigureGUI
|
||||
import com.cobblemon.mod.common.client.gui.interact.moveselect.MoveSelectGUI
|
||||
import com.cobblemon.mod.common.client.gui.interact.partyselect.PartySelectGUI
|
||||
import com.cobblemon.mod.common.client.gui.interact.wheel.InteractWheelGUI
|
||||
import com.cobblemon.mod.common.client.gui.pc.PCGUI
|
||||
import com.cobblemon.mod.common.client.gui.pokedex.PokedexGUI
|
||||
import com.cobblemon.mod.common.client.gui.snapshots.SnapshotWarningScreen
|
||||
import com.cobblemon.mod.common.client.gui.startselection.StarterSelectionScreen
|
||||
import com.cobblemon.mod.common.client.gui.summary.Summary
|
||||
import com.cobblemon.mod.common.client.gui.trade.TradeGUI
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.CobblemonGUIProcessor
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.InteractWheelProcessor
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import com.cobblemon.mod.common.client.keybind.CobblemonKeyBinds
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import dev.isxander.controlify.Controlify
|
||||
import dev.isxander.controlify.api.ControlifyApi
|
||||
import dev.isxander.controlify.api.bind.ControlifyBindApi
|
||||
import dev.isxander.controlify.api.bind.InputBindingBuilder
|
||||
import dev.isxander.controlify.api.bind.InputBindingSupplier
|
||||
import dev.isxander.controlify.api.entrypoint.ControlifyEntrypoint
|
||||
import dev.isxander.controlify.api.entrypoint.InitContext
|
||||
import dev.isxander.controlify.api.entrypoint.PreInitContext
|
||||
import dev.isxander.controlify.bindings.BindContext
|
||||
import dev.isxander.controlify.bindings.ControlifyBindings
|
||||
import dev.isxander.controlify.bindings.RadialIcons
|
||||
import dev.isxander.controlify.screenop.ScreenProcessor
|
||||
import dev.isxander.controlify.screenop.ScreenProcessorFactory
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.player.LocalPlayer
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.item.Items
|
||||
import org.joml.Vector2d
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.primaryConstructor
|
||||
|
||||
class CobblemonControlifyEntrypoint : ControlifyEntrypoint {
|
||||
override fun onControlifyInit(initContext: InitContext) {
|
||||
ridingTurnInputHandler.put(
|
||||
cobblemonResource("compat.controlify"),
|
||||
({ localPlayer: LocalPlayer, xDelta: Double, yDelta: Double, deltaTime: Double ->
|
||||
val vec = Vector2d(xDelta, yDelta)
|
||||
val controller = initContext.controlify().currentController.getOrNull()
|
||||
val vehicle = localPlayer.vehicle
|
||||
if (vehicle is OrientationControllable && vehicle.orientationController.isActive() && initContext.controlify().currentInputMode().isController && controller != null){
|
||||
val multiplier = deltaTime * 1500
|
||||
val config = controller.input().getOrNull()?.config()?.config()
|
||||
val vSensitivity = config?.vLookSensitivity ?: 0.9f
|
||||
val hSensitivity = config?.hLookSensitivity ?: 1f
|
||||
|
||||
// Should never be null once bindings are set
|
||||
var vAxis = (RIDING_DOWN!!.on(controller).analogueNow() - RIDING_UP!!.on(controller).analogueNow()).toDouble()
|
||||
var hAxis = (RIDING_RIGHT!!.on(controller).analogueNow() - RIDING_LEFT!!.on(controller).analogueNow()).toDouble()
|
||||
|
||||
vAxis *= multiplier * vSensitivity
|
||||
hAxis *= multiplier * hSensitivity
|
||||
vec.x = hAxis
|
||||
vec.y = vAxis
|
||||
}
|
||||
vec
|
||||
})
|
||||
)
|
||||
|
||||
CobblemonClient.ridingSprintHandler.put(
|
||||
cobblemonResource("compat.controlify")
|
||||
) {
|
||||
initContext.controlify().currentController.getOrNull()?.let { ControlifyBindings.SPRINT.on(it).digitalNow() } == true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onControlifyPreInit(initContext: PreInitContext) {
|
||||
val bindings = ControlifyBindApi.get()
|
||||
bindings.registerBindContext(RIDING_POKEMON)
|
||||
bindings.registerBindContext(ORIENTATION_CONTROLLER_ACTIVE)
|
||||
|
||||
bindings.registerBindContext(HAS_POKEMON)
|
||||
bindings.registerBindContext(INTERACT_WHEEL_SCREEN)
|
||||
bindings.registerBindContext(COBBLEMON_CONTROLLER_SCREEN)
|
||||
|
||||
RIDING_UP =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("riding_up"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.riding_up"))
|
||||
.allowedContexts(ORIENTATION_CONTROLLER_ACTIVE, BindContext.IN_GAME)
|
||||
}
|
||||
|
||||
RIDING_DOWN =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("riding_down"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.riding_down"))
|
||||
.allowedContexts(ORIENTATION_CONTROLLER_ACTIVE, BindContext.IN_GAME)
|
||||
}
|
||||
|
||||
RIDING_LEFT =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("riding_left"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.riding_left"))
|
||||
.allowedContexts(ORIENTATION_CONTROLLER_ACTIVE, BindContext.IN_GAME)
|
||||
}
|
||||
|
||||
RIDING_RIGHT =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("riding_right"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.riding_right"))
|
||||
.allowedContexts(ORIENTATION_CONTROLLER_ACTIVE, BindContext.IN_GAME)
|
||||
}
|
||||
|
||||
HIDE_PARTY =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("hide_party"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("key.cobblemon.hideparty"))
|
||||
.allowedContexts(BindContext.IN_GAME)
|
||||
.radialCandidate(RadialIcons.getItem(Items.BARRIER))
|
||||
.addKeyCorrelation(CobblemonKeyBinds.HIDE_PARTY)
|
||||
.keyEmulation(CobblemonKeyBinds.HIDE_PARTY)
|
||||
}
|
||||
|
||||
SUMMARY =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("summary"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("key.cobblemon.summary"))
|
||||
.allowedContexts(BindContext.IN_GAME)
|
||||
.radialCandidate(RadialIcons.getItem(CobblemonItems.GREAT_BALL))
|
||||
.addKeyCorrelation(CobblemonKeyBinds.SUMMARY)
|
||||
.keyEmulation(CobblemonKeyBinds.SUMMARY)
|
||||
}
|
||||
|
||||
PARTY_OVERLAY_DOWN =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("party_overlay_down"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("key.cobblemon.downshiftparty"))
|
||||
.allowedContexts(HAS_POKEMON, BindContext.IN_GAME)
|
||||
.radialCandidate(RadialIcons.EMPTY)
|
||||
.addKeyCorrelation(CobblemonKeyBinds.PARTY_OVERLAY_DOWN)
|
||||
.keyEmulation(CobblemonKeyBinds.PARTY_OVERLAY_DOWN)
|
||||
}
|
||||
|
||||
PARTY_OVERLAY_UP =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("party_overlay_up"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("key.cobblemon.upshiftparty"))
|
||||
.allowedContexts(HAS_POKEMON, BindContext.IN_GAME)
|
||||
.radialCandidate(RadialIcons.EMPTY)
|
||||
.addKeyCorrelation(CobblemonKeyBinds.PARTY_OVERLAY_UP)
|
||||
.keyEmulation(CobblemonKeyBinds.PARTY_OVERLAY_DOWN)
|
||||
}
|
||||
|
||||
SEND_OUT_POKEMON =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("send_out_pokemon"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("key.cobblemon.throwpartypokemon"))
|
||||
.allowedContexts(HAS_POKEMON, BindContext.IN_GAME)
|
||||
.radialCandidate(RadialIcons.getItem(CobblemonItems.POKE_BALL))
|
||||
.addKeyCorrelation(CobblemonKeyBinds.SEND_OUT_POKEMON)
|
||||
.keyEmulation(CobblemonKeyBinds.SEND_OUT_POKEMON)
|
||||
}
|
||||
|
||||
|
||||
RIDING_FREELOOK =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("riding_freelook"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("key.cobblemon.ridingfreelook"))
|
||||
.allowedContexts(RIDING_POKEMON, BindContext.IN_GAME)
|
||||
.radialCandidate(RadialIcons.EMPTY)
|
||||
.addKeyCorrelation(CobblemonKeyBinds.RIDING_FREELOOK)
|
||||
.keyEmulation(CobblemonKeyBinds.RIDING_FREELOOK)
|
||||
}
|
||||
|
||||
INTERACT_WHEEL_UP_AXIS =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("interact_wheel_up"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.interact_wheel_up"))
|
||||
.allowedContexts(INTERACT_WHEEL_SCREEN, BindContext.IN_GAME)
|
||||
}
|
||||
|
||||
INTERACT_WHEEL_DOWN_AXIS =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("interact_wheel_down"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.interact_wheel_down"))
|
||||
.allowedContexts(INTERACT_WHEEL_SCREEN, BindContext.IN_GAME)
|
||||
}
|
||||
|
||||
INTERACT_WHEEL_RIGHT_AXIS =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("interact_wheel_right"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.interact_wheel_right"))
|
||||
.allowedContexts(INTERACT_WHEEL_SCREEN, BindContext.IN_GAME)
|
||||
}
|
||||
|
||||
INTERACT_WHEEL_LEFT_AXIS =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("interact_wheel_left"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.interact_wheel_left"))
|
||||
.allowedContexts(INTERACT_WHEEL_SCREEN, BindContext.IN_GAME)
|
||||
}
|
||||
|
||||
GUI_SECONDARY_NEXT_TAB =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("gui_secondary_next_tab"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.gui_secondary_next_tab"))
|
||||
.allowedContexts(COBBLEMON_CONTROLLER_SCREEN)
|
||||
}
|
||||
|
||||
GUI_SECONDARY_PREV_TAB =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("gui_secondary_prev_tab"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.gui_secondary_prev_tab"))
|
||||
.allowedContexts(COBBLEMON_CONTROLLER_SCREEN)
|
||||
}
|
||||
|
||||
GUI_START =
|
||||
bindings.registerBinding { builder: InputBindingBuilder ->
|
||||
builder
|
||||
.id(cobblemonResource("gui_start"))
|
||||
.category(Component.translatable("controlify.category.cobblemon.cobblemon"))
|
||||
.name(Component.translatable("controlify.bind.cobblemon.gui_start"))
|
||||
.allowedContexts(COBBLEMON_CONTROLLER_SCREEN)
|
||||
}
|
||||
|
||||
|
||||
addProcessor(InteractWheelGUI::class, InteractWheelProcessor::class)
|
||||
// This is the lazy way to do all of these (just using the vmouse), if someone with more time and dedication did this that would be better
|
||||
addProcessor(DialogueScreen::class, CobblemonGUIProcessor::class)
|
||||
// Below are implemented processors for our GUIs
|
||||
addProcessor(Summary::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(BattleGUI::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(PokedexGUI::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(StarterSelectionScreen::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(TradeGUI::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(PartySelectGUI::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(MoveSelectGUI::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(PCGUI::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(BattleConfigureGUI::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(SnapshotWarningScreen::class, CobblemonGUIProcessor::class)
|
||||
addProcessor(CobblemonConfigScreen::class, CobblemonGUIProcessor::class)
|
||||
// This once don't need any
|
||||
addProcessor(CookingPotScreen::class, CobblemonGUIProcessor::class)
|
||||
}
|
||||
|
||||
override fun onControllersDiscovered(controlifyApi: ControlifyApi) {
|
||||
}
|
||||
|
||||
// This is jank, but I did it after I got my wisdom teeth extracted so tbh I think I did good enough, but I won't be offended if someone changes it to something sane.
|
||||
fun addProcessor(t: KClass<out Screen>, processorClazz: KClass<out ScreenProcessor<Screen>>) {
|
||||
ScreenProcessorFactory.registerProvider(t.java) {
|
||||
processorClazz.primaryConstructor?.call(it)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
var RIDING_UP: InputBindingSupplier? = null
|
||||
var RIDING_DOWN: InputBindingSupplier? = null
|
||||
var RIDING_RIGHT: InputBindingSupplier? = null
|
||||
var RIDING_LEFT: InputBindingSupplier? = null
|
||||
var HIDE_PARTY: InputBindingSupplier? = null
|
||||
var SUMMARY: InputBindingSupplier? = null
|
||||
var PARTY_OVERLAY_DOWN: InputBindingSupplier? = null
|
||||
var PARTY_OVERLAY_UP: InputBindingSupplier? = null
|
||||
var SEND_OUT_POKEMON: InputBindingSupplier? = null
|
||||
var RIDING_FREELOOK: InputBindingSupplier? = null
|
||||
var INTERACT_WHEEL_UP_AXIS: InputBindingSupplier? = null
|
||||
var INTERACT_WHEEL_DOWN_AXIS: InputBindingSupplier? = null
|
||||
var INTERACT_WHEEL_LEFT_AXIS: InputBindingSupplier? = null
|
||||
var INTERACT_WHEEL_RIGHT_AXIS: InputBindingSupplier? = null
|
||||
//gui special keybinds
|
||||
var GUI_SECONDARY_NEXT_TAB: InputBindingSupplier? = null
|
||||
var GUI_SECONDARY_PREV_TAB: InputBindingSupplier? = null
|
||||
var GUI_START: InputBindingSupplier? = null
|
||||
|
||||
val RIDING_POKEMON: BindContext = BindContext(
|
||||
cobblemonResource("riding"),
|
||||
{ mc: Minecraft ->
|
||||
mc.player?.vehicle is PokemonEntity
|
||||
}
|
||||
)
|
||||
|
||||
val ORIENTATION_CONTROLLER_ACTIVE: BindContext = BindContext(
|
||||
cobblemonResource("orientation_controller_active"),
|
||||
{ mc: Minecraft ->
|
||||
val localPlayer = mc.player
|
||||
if (localPlayer == null) return@BindContext false
|
||||
val vehicle = localPlayer.vehicle
|
||||
vehicle is OrientationControllable && vehicle.getOrientationController().isActive()
|
||||
}
|
||||
)
|
||||
|
||||
val HAS_POKEMON: BindContext = BindContext(
|
||||
cobblemonResource("has_pokemon"),
|
||||
{mc: Minecraft ->
|
||||
!CobblemonClient.storage.party.isEmpty()
|
||||
}
|
||||
)
|
||||
|
||||
val INTERACT_WHEEL_SCREEN: BindContext = BindContext(
|
||||
cobblemonResource("wheel_screen"),
|
||||
{ it.screen is InteractWheelGUI}
|
||||
)
|
||||
|
||||
val COBBLEMON_CONTROLLER_SCREEN: BindContext = BindContext(
|
||||
cobblemonResource("cobblemon_controller_screen"),
|
||||
{ mc: Minecraft ->
|
||||
mc.screen is ControllerScreen
|
||||
}
|
||||
)
|
||||
|
||||
fun controllerActive(): Boolean {
|
||||
return Controlify.instance().currentInputMode().isController
|
||||
}
|
||||
}
|
||||
}
|
||||
-247
@@ -1,247 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.client.integration.controlify.gui
|
||||
|
||||
import com.cobblemon.mod.common.client.integration.controlify.CobblemonControlifyEntrypoint
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerComponentManager.ButtonGuideType
|
||||
import com.cobblemon.mod.common.client.integration.controlify.gui.component.ControllerScreen
|
||||
import dev.isxander.controlify.Controlify
|
||||
import dev.isxander.controlify.InputMode
|
||||
import dev.isxander.controlify.bindings.ControlifyBindings
|
||||
import dev.isxander.controlify.bindings.InputBindingSupplierImpl
|
||||
import dev.isxander.controlify.controller.ControllerEntity
|
||||
import dev.isxander.controlify.controller.input.GamepadInputs
|
||||
import dev.isxander.controlify.font.BindingFontHelper
|
||||
import dev.isxander.controlify.gui.guide.GuideRenderer
|
||||
import dev.isxander.controlify.gui.guide.PrecomputedLines
|
||||
import dev.isxander.controlify.screenop.ScreenProcessor
|
||||
import dev.isxander.controlify.virtualmouse.VirtualMouseBehaviour
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.gui.components.EditBox
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.network.chat.Component
|
||||
|
||||
open class CobblemonGUIProcessor(open val screen: Screen) : ScreenProcessor<Screen>(screen) {
|
||||
companion object {
|
||||
val typeToGlyth = mutableMapOf<ButtonGuideType, () -> Component>(
|
||||
ButtonGuideType.PRESS to { ControlifyBindings.GUI_PRESS.inputGlyph() },
|
||||
ButtonGuideType.BACK to { ControlifyBindings.GUI_BACK.inputGlyph() },
|
||||
ButtonGuideType.SPECIAL_1 to { ControlifyBindings.GUI_ABSTRACT_ACTION_1.inputGlyph() },
|
||||
ButtonGuideType.SPECIAL_2 to { ControlifyBindings.GUI_ABSTRACT_ACTION_2.inputGlyph() },
|
||||
ButtonGuideType.TAB to { Component.empty().append(ControlifyBindings.GUI_PREV_TAB.inputGlyph()).append(ControlifyBindings.GUI_NEXT_TAB.inputGlyph()) },
|
||||
ButtonGuideType.SECONDARY_TAB to { Component.empty().append(CobblemonControlifyEntrypoint.GUI_SECONDARY_PREV_TAB!!.inputGlyph()).append(CobblemonControlifyEntrypoint.GUI_SECONDARY_NEXT_TAB!!.inputGlyph()) },
|
||||
ButtonGuideType.START to { CobblemonControlifyEntrypoint.GUI_START!!.inputGlyph() },
|
||||
ButtonGuideType.JOYSTICK_HORIZONTAL to { Component.empty().append(ControlifyBindings.GUI_SECONDARY_NAVI_LEFT.inputGlyph()).append(ControlifyBindings.GUI_SECONDARY_NAVI_RIGHT.inputGlyph()) },
|
||||
ButtonGuideType.JOYSTICK_VERTICAL to { Component.empty().append(ControlifyBindings.GUI_SECONDARY_NAVI_UP.inputGlyph()).append(ControlifyBindings.GUI_SECONDARY_NAVI_DOWN.inputGlyph()) }
|
||||
)
|
||||
}
|
||||
|
||||
var editBoxWidget: EditBox? = null
|
||||
|
||||
// Until someone with more dedication than me adds non-vmouse support, we will make heavy use of the vmouse so make that the defualt for us
|
||||
override fun virtualMouseBehaviour(): VirtualMouseBehaviour {
|
||||
if (screen is ControllerScreen) {
|
||||
return VirtualMouseBehaviour.DISABLED
|
||||
}
|
||||
return VirtualMouseBehaviour.CURSOR_ONLY
|
||||
}
|
||||
|
||||
override fun onWidgetRebuild() {
|
||||
(screen as? ControllerScreen)?.getComponentManager()?.let {
|
||||
it.active = Controlify.instance().let { it.currentInputMode().isController && !it.virtualMouseHandler().isVirtualMouseEnabled }
|
||||
it.openKeyboard = { editBox ->
|
||||
editBoxWidget = editBox
|
||||
}
|
||||
it.getVisual = { location ->
|
||||
InputBindingSupplierImpl(location).inputGlyph()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onInputModeChanged(mode: InputMode) {
|
||||
(screen as? ControllerScreen)?.getComponentManager()?.let {
|
||||
val active = mode.isController && !Controlify.instance().virtualMouseHandler().isVirtualMouseEnabled
|
||||
it.active = active
|
||||
}
|
||||
}
|
||||
|
||||
override fun onVirtualMouseToggled(enabled: Boolean) {
|
||||
(screen as? ControllerScreen)?.getComponentManager()?.let{
|
||||
it.active = Controlify.instance().currentInputMode().isController && !enabled
|
||||
}
|
||||
}
|
||||
|
||||
override fun onControllerUpdate(controller: ControllerEntity) {
|
||||
val componentManager = (screen as? ControllerScreen)?.getComponentManager()
|
||||
|
||||
if (componentManager == null) {
|
||||
super.onControllerUpdate(controller)
|
||||
return
|
||||
}
|
||||
|
||||
//It was easier to fully handle this myself
|
||||
Controlify.instance().virtualMouseHandler().handleControllerInput(controller)
|
||||
|
||||
val repeatAvailable = holdRepeatHelper.canNavigate()
|
||||
|
||||
if (!Controlify.instance().virtualMouseHandler().isVirtualMouseEnabled) {
|
||||
//Handling Base
|
||||
if (ControlifyBindings.GUI_PRESS.on(controller).justPressed()) {
|
||||
componentManager.press()
|
||||
}
|
||||
if (ControlifyBindings.GUI_BACK.on(controller).justPressed()) {
|
||||
componentManager.onBack.invoke()
|
||||
}
|
||||
//Handling Special
|
||||
if (ControlifyBindings.GUI_ABSTRACT_ACTION_1.on(controller).justPressed()) {
|
||||
componentManager.special1()
|
||||
}
|
||||
if (ControlifyBindings.GUI_ABSTRACT_ACTION_2.on(controller).justPressed()) {
|
||||
componentManager.special2()
|
||||
}
|
||||
if (CobblemonControlifyEntrypoint.GUI_START!!.on(controller).justPressed()) {
|
||||
componentManager.onStart.invoke()
|
||||
}
|
||||
//Handling RJoystick
|
||||
val guiNaviRight = ControlifyBindings.GUI_SECONDARY_NAVI_RIGHT.on(controller)
|
||||
val guiNaviLeft = ControlifyBindings.GUI_SECONDARY_NAVI_LEFT.on(controller)
|
||||
val guiNaviUp = ControlifyBindings.GUI_SECONDARY_NAVI_UP.on(controller)
|
||||
val guiNaviDown = ControlifyBindings.GUI_SECONDARY_NAVI_DOWN.on(controller)
|
||||
|
||||
if (guiNaviRight.digitalNow() && (!guiNaviRight.digitalPrev() || repeatAvailable)) {
|
||||
holdRepeatHelper.reset()
|
||||
componentManager.onRHorizontal.invoke(true)
|
||||
} else if (guiNaviLeft.digitalNow() && (!guiNaviLeft.digitalPrev() || repeatAvailable)) {
|
||||
holdRepeatHelper.reset()
|
||||
componentManager.onRHorizontal.invoke(false)
|
||||
}
|
||||
if (guiNaviUp.digitalNow() && (!guiNaviUp.digitalPrev() || repeatAvailable)) {
|
||||
holdRepeatHelper.reset()
|
||||
componentManager.onRVertical.invoke(true)
|
||||
} else if (guiNaviDown.digitalNow() && (!guiNaviDown.digitalPrev() || repeatAvailable)) {
|
||||
holdRepeatHelper.reset()
|
||||
componentManager.onRVertical.invoke(false)
|
||||
}
|
||||
componentManager.rHorizontalState = if (guiNaviRight.digitalNow()) 1 else if (guiNaviLeft.digitalNow()) -1 else 0
|
||||
componentManager.rVerticalState = if (guiNaviUp.digitalNow()) 1 else if (guiNaviDown.digitalNow()) -1 else 0
|
||||
|
||||
//Handle Navigation
|
||||
handleNavigation(controller, componentManager)
|
||||
} else {
|
||||
componentManager.rHorizontalState = 0
|
||||
componentManager.rVerticalState = 0
|
||||
|
||||
handleScreenVMouse(controller, Controlify.instance().virtualMouseHandler())
|
||||
}
|
||||
|
||||
//Main Tab
|
||||
if (ControlifyBindings.GUI_NEXT_TAB.on(controller).digitalNow() && (repeatAvailable || !ControlifyBindings.GUI_NEXT_TAB.on(controller).digitalPrev())) {
|
||||
holdRepeatHelper.reset()
|
||||
componentManager.onTabNav.invoke(true)
|
||||
} else if (ControlifyBindings.GUI_PREV_TAB.on(controller).digitalNow() && (repeatAvailable || !ControlifyBindings.GUI_PREV_TAB.on(controller).digitalPrev())) {
|
||||
holdRepeatHelper.reset()
|
||||
componentManager.onTabNav.invoke(false)
|
||||
}
|
||||
|
||||
//Secondary Tab
|
||||
if (CobblemonControlifyEntrypoint.GUI_SECONDARY_NEXT_TAB!!.on(controller).digitalNow() && (repeatAvailable || !CobblemonControlifyEntrypoint.GUI_SECONDARY_NEXT_TAB!!.on(controller).digitalPrev())) {
|
||||
holdRepeatHelper.reset()
|
||||
componentManager.onSecondaryTabNav.invoke(true)
|
||||
} else if (CobblemonControlifyEntrypoint.GUI_SECONDARY_PREV_TAB!!.on(controller).digitalNow() && (repeatAvailable || !CobblemonControlifyEntrypoint.GUI_SECONDARY_PREV_TAB!!.on(controller).digitalPrev())) {
|
||||
holdRepeatHelper.reset()
|
||||
componentManager.onSecondaryTabNav.invoke(false)
|
||||
}
|
||||
|
||||
if (editBoxWidget != null) {
|
||||
tryOpenKeyboard(controller, editBoxWidget)
|
||||
editBoxWidget = null
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleNavigation(controller: ControllerEntity, componentManager: ControllerComponentManager) {
|
||||
val repeatAvailable = holdRepeatHelper.canNavigate()
|
||||
|
||||
val input = controller.input().orElseThrow()
|
||||
val state = input.stateNow()
|
||||
val prevState = input.stateThen()
|
||||
|
||||
val guiNaviRight = ControlifyBindings.GUI_NAVI_RIGHT.on(controller)
|
||||
val guiNaviLeft = ControlifyBindings.GUI_NAVI_LEFT.on(controller)
|
||||
val guiNaviUp = ControlifyBindings.GUI_NAVI_UP.on(controller)
|
||||
val guiNaviDown = ControlifyBindings.GUI_NAVI_DOWN.on(controller)
|
||||
|
||||
if (guiNaviRight.digitalNow() && (repeatAvailable || !guiNaviRight.digitalPrev())) {
|
||||
componentManager.right()
|
||||
holdRepeatHelper.reset()
|
||||
} else if (guiNaviLeft.digitalNow() && (repeatAvailable || !guiNaviLeft.digitalPrev())) {
|
||||
componentManager.left()
|
||||
holdRepeatHelper.reset()
|
||||
} else if (guiNaviUp.digitalNow() && (repeatAvailable || !guiNaviUp.digitalPrev())) {
|
||||
componentManager.up()
|
||||
holdRepeatHelper.reset()
|
||||
} else if (guiNaviDown.digitalNow() && (repeatAvailable || !guiNaviDown.digitalPrev())) {
|
||||
componentManager.down()
|
||||
holdRepeatHelper.reset()
|
||||
} else if (state.isButtonDown(GamepadInputs.DPAD_RIGHT_BUTTON) && (repeatAvailable || !prevState.isButtonDown(GamepadInputs.DPAD_RIGHT_BUTTON))) {
|
||||
componentManager.right()
|
||||
holdRepeatHelper.reset()
|
||||
} else if (state.isButtonDown(GamepadInputs.DPAD_LEFT_BUTTON) && (repeatAvailable || !prevState.isButtonDown(GamepadInputs.DPAD_LEFT_BUTTON))) {
|
||||
componentManager.left()
|
||||
holdRepeatHelper.reset()
|
||||
} else if (state.isButtonDown(GamepadInputs.DPAD_UP_BUTTON) && (repeatAvailable || !prevState.isButtonDown(GamepadInputs.DPAD_UP_BUTTON))) {
|
||||
componentManager.up()
|
||||
holdRepeatHelper.reset()
|
||||
} else if (state.isButtonDown(GamepadInputs.DPAD_DOWN_BUTTON) && (repeatAvailable || !prevState.isButtonDown(GamepadInputs.DPAD_DOWN_BUTTON))) {
|
||||
componentManager.down()
|
||||
holdRepeatHelper.reset()
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(controller: ControllerEntity, graphics: GuiGraphics, tickDelta: Float) {
|
||||
if (!controller.genericConfig().config().showScreenGuides) return
|
||||
val manager = (screen as? ControllerScreen)?.getComponentManager() ?: return
|
||||
if (!manager.active) return
|
||||
|
||||
val minecraft = Minecraft.getInstance()
|
||||
|
||||
val guideList = manager.buttonGuides.filter { it.condition.invoke() }
|
||||
|
||||
val font = minecraft.font
|
||||
|
||||
val leftLinesBuilder = PrecomputedLines.Builder()
|
||||
val rightLinesBuilder = PrecomputedLines.Builder()
|
||||
|
||||
guideList.forEach { guide ->
|
||||
val builder = if (guide.rightAligned) rightLinesBuilder else leftLinesBuilder
|
||||
|
||||
val glyphAfter = font.isBidirectional.xor(guide.rightAligned)
|
||||
val text = Component.empty()
|
||||
.append(if (glyphAfter) guide.text else typeToGlyth[guide.type]!!.invoke())
|
||||
.append(" ")
|
||||
.append(if (!glyphAfter) guide.text else typeToGlyth[guide.type]!!.invoke())
|
||||
|
||||
val ruleNameWidth: Int = font.width(guide.text)
|
||||
val width = font.width(text)
|
||||
val glyphWidth = width - ruleNameWidth
|
||||
val backgroundLeft = if (glyphAfter) 0 else glyphWidth
|
||||
val backgroundRight = backgroundLeft + ruleNameWidth
|
||||
|
||||
val height = BindingFontHelper.getComponentHeight(font, typeToGlyth[guide.type]!!.invoke())
|
||||
|
||||
builder.addLine(text, width, height, backgroundLeft, backgroundRight)
|
||||
}
|
||||
|
||||
val method = GuideRenderer::class.java.declaredMethods.first { it.name == "renderLines" } //We love Java Reflections
|
||||
method.isAccessible = true
|
||||
method.invoke(null,graphics, leftLinesBuilder.build(), font, minecraft.window.guiScaledWidth, minecraft.window.guiScaledHeight, false, false, true)
|
||||
method.invoke(null,graphics, rightLinesBuilder.build(), font, minecraft.window.guiScaledWidth, minecraft.window.guiScaledHeight, false, true, true)
|
||||
}
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.client.integration.controlify.gui
|
||||
|
||||
import com.cobblemon.mod.common.client.gui.interact.wheel.InteractWheelGUI
|
||||
import com.cobblemon.mod.common.client.integration.controlify.CobblemonControlifyEntrypoint
|
||||
import dev.isxander.controlify.bindings.ControlifyBindings
|
||||
import dev.isxander.controlify.controller.ControllerEntity
|
||||
import dev.isxander.controlify.controller.haptic.HapticEffects
|
||||
import dev.isxander.controlify.screenop.ScreenControllerEventListener
|
||||
import dev.isxander.controlify.screenop.ScreenProcessor
|
||||
import dev.isxander.controlify.virtualmouse.VirtualMouseBehaviour
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.util.Mth
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
// Lots of this is taken from the RadialMenu in Controlify to make this screen feel consistent with it
|
||||
class InteractWheelProcessor(val screen: InteractWheelGUI) : ScreenProcessor<Screen>(screen), ScreenControllerEventListener {
|
||||
private var selectedButton = -1
|
||||
|
||||
override fun onWidgetRebuild() {}
|
||||
|
||||
override fun virtualMouseBehaviour(): VirtualMouseBehaviour {
|
||||
return VirtualMouseBehaviour.DISABLED
|
||||
}
|
||||
|
||||
override fun onControllerUpdate(controller: ControllerEntity) {
|
||||
if (ControlifyBindings.GUI_BACK.on(controller).justPressed()) {
|
||||
screen.onClose()
|
||||
return
|
||||
}
|
||||
|
||||
// If not created from entrypoint then something is very wrong
|
||||
val x = CobblemonControlifyEntrypoint.INTERACT_WHEEL_RIGHT_AXIS!!.on(controller).analogueNow() -
|
||||
CobblemonControlifyEntrypoint.INTERACT_WHEEL_LEFT_AXIS!!.on(controller).analogueNow()
|
||||
val y = CobblemonControlifyEntrypoint.INTERACT_WHEEL_DOWN_AXIS!!.on(controller).analogueNow() -
|
||||
CobblemonControlifyEntrypoint.INTERACT_WHEEL_UP_AXIS!!.on(controller).analogueNow()
|
||||
val threshold = controller.input().orElseThrow().config().config().buttonActivationThreshold
|
||||
|
||||
if (abs(x) >= threshold || abs(y) >= threshold) {
|
||||
val angle = Mth.wrapDegrees(Mth.RAD_TO_DEG * Mth.atan2(y.toDouble(), x.toDouble()) - 90f) + 180f
|
||||
val buttonCount = screen.buttons.size
|
||||
val each = 360f / buttonCount
|
||||
|
||||
val newSelected = Mth.floor((angle + each / 2f) / each) % buttonCount
|
||||
if (newSelected != selectedButton) {
|
||||
selectedButton = newSelected
|
||||
controller.hdHaptics().ifPresent { haptics -> haptics.playHaptic(HapticEffects.NAVIGATE) }
|
||||
}
|
||||
|
||||
for (button in 0..<buttonCount) {
|
||||
val selected = button == selectedButton
|
||||
screen.buttons[button].isFocused = selected
|
||||
}
|
||||
} else if (selectedButton != -1) {
|
||||
if (screen.buttons[selectedButton].isEnabled) {
|
||||
screen.buttons[selectedButton].onPress()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.client.integration.controlify.gui.component
|
||||
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.gui.components.EditBox
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
open class ControllerComponent {
|
||||
var left: () -> ControllerComponent? = { null }
|
||||
var right: () -> ControllerComponent? = { null }
|
||||
var up: () -> ControllerComponent? = { null }
|
||||
var down: () -> ControllerComponent? = { null }
|
||||
|
||||
var onPress: (() -> Unit)? = null
|
||||
var onSpecial1: () -> Unit = {}
|
||||
var onSpecial2: () -> Unit = {}
|
||||
|
||||
var onSelect: () -> Unit = {}
|
||||
var onUnselect: () -> Unit = {}
|
||||
|
||||
var onFocus: () -> Unit = {}
|
||||
var onUnfocus: () -> Unit = {}
|
||||
|
||||
var associatedGUIElement: GuiEventListener? = null
|
||||
|
||||
fun pairLeft(leftComponent: ControllerComponent?) {
|
||||
left = { leftComponent }
|
||||
leftComponent?.right = { this }
|
||||
}
|
||||
|
||||
fun pairRight(rightComponent: ControllerComponent?) {
|
||||
right = { rightComponent }
|
||||
rightComponent?.left = { this }
|
||||
}
|
||||
|
||||
fun pairUp(upComponent: ControllerComponent?) {
|
||||
up = { upComponent }
|
||||
upComponent?.down = { this }
|
||||
}
|
||||
|
||||
fun pairDown(downComponent: ControllerComponent?) {
|
||||
down = { downComponent }
|
||||
downComponent?.up = { this }
|
||||
}
|
||||
}
|
||||
-163
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.client.integration.controlify.gui.component
|
||||
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.gui.components.EditBox
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
|
||||
class ControllerComponentManager(val screen: Screen) {
|
||||
var active: Boolean = false
|
||||
get() = field
|
||||
set(value) {
|
||||
if (field != value) {
|
||||
field = value
|
||||
onActiveChange.invoke(value)
|
||||
}
|
||||
if (mainScreenManager()) {
|
||||
if (!value) {
|
||||
screen.focused = null
|
||||
focused?.onUnfocus?.invoke()
|
||||
} else {
|
||||
screen.focused = focused?.associatedGUIElement
|
||||
focused?.onFocus?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var focused: ControllerComponent? = null
|
||||
get() = field
|
||||
set(value) {
|
||||
currentSelectedComponent = (componentList.entries.firstOrNull { it.value == value }?.key ?: "")
|
||||
field?.onUnselect?.invoke()
|
||||
if (active) { field?.onUnfocus?.invoke() }
|
||||
field = value
|
||||
if (active) {
|
||||
field?.associatedGUIElement.let { screen.focused = it }
|
||||
field?.onFocus?.invoke()
|
||||
}
|
||||
field?.onSelect?.invoke()
|
||||
}
|
||||
|
||||
val componentList: MutableMap<String, ControllerComponent> = mutableMapOf()
|
||||
var currentSelectedComponent = ""
|
||||
|
||||
var onTabNav: (Boolean) -> Unit = {}
|
||||
var onSecondaryTabNav: (Boolean) -> Unit = {}
|
||||
var onBack: () -> Unit = {
|
||||
screen.onClose()
|
||||
}
|
||||
var onStart: () -> Unit = {}
|
||||
|
||||
var onActiveChange: (Boolean) -> Unit = {}
|
||||
|
||||
var onNoneSelected: () -> Boolean = { false }
|
||||
|
||||
var onRHorizontal: (Boolean) -> Unit = {}
|
||||
var onRVertical: (Boolean) -> Unit = {}
|
||||
|
||||
var rHorizontalState: Int = 0
|
||||
var rVerticalState: Int = 0
|
||||
|
||||
var openKeyboard: (EditBox) -> Unit = {}
|
||||
val buttonGuides = mutableListOf<ButtonGuide>()
|
||||
var getVisual: (ResourceLocation) -> Component = { "".text() }
|
||||
|
||||
var onPress: (() -> Unit)? = null
|
||||
var onSpecial1: () -> Unit = { focused?.onSpecial1?.invoke() }
|
||||
var onSpecial2: () -> Unit = { focused?.onSpecial2?.invoke() }
|
||||
|
||||
fun left(): Boolean {
|
||||
if (focused == null && onNoneSelected.invoke()) return false
|
||||
focused?.left?.invoke()?.let {
|
||||
focused = it
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
fun right(): Boolean {
|
||||
if (focused == null && onNoneSelected.invoke()) return false
|
||||
focused?.right?.invoke()?.let {
|
||||
focused = it
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
fun up(): Boolean {
|
||||
if (focused == null && onNoneSelected.invoke()) return false
|
||||
focused?.up?.invoke()?.let {
|
||||
focused = it
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
fun down(): Boolean {
|
||||
if (focused == null && onNoneSelected.invoke()) return false
|
||||
focused?.down?.invoke()?.let {
|
||||
focused = it
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun press() {
|
||||
focused?.let {
|
||||
if (onPress != null) {
|
||||
onPress!!.invoke()
|
||||
} else {
|
||||
if (it.onPress != null) {
|
||||
it.onPress!!.invoke()
|
||||
} else {
|
||||
(it.associatedGUIElement as? Button)?.onPress()
|
||||
(it.associatedGUIElement as? Button)?.playDownSound(Minecraft.getInstance().soundManager)
|
||||
if (it.associatedGUIElement is EditBox) {
|
||||
openKeyboard.invoke(it.associatedGUIElement as EditBox)
|
||||
Minecraft.getInstance().soundManager.play(
|
||||
SimpleSoundInstance.forUI(
|
||||
SoundEvents.UI_BUTTON_CLICK,
|
||||
1.0F
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fun special1() = onSpecial1.invoke()
|
||||
fun special2() = onSpecial2.invoke()
|
||||
|
||||
private fun mainScreenManager(): Boolean {
|
||||
return screen is ControllerScreen && screen.getComponentManager() == this
|
||||
}
|
||||
|
||||
data class ButtonGuide(
|
||||
val type: ButtonGuideType,
|
||||
val condition: () -> Boolean,
|
||||
val text: Component,
|
||||
val rightAligned: Boolean = false
|
||||
)
|
||||
|
||||
enum class ButtonGuideType {
|
||||
PRESS,
|
||||
BACK,
|
||||
SPECIAL_1,
|
||||
SPECIAL_2,
|
||||
TAB,
|
||||
SECONDARY_TAB,
|
||||
START,
|
||||
JOYSTICK_HORIZONTAL,
|
||||
JOYSTICK_VERTICAL
|
||||
}
|
||||
}
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.client.integration.controlify.gui.component
|
||||
|
||||
import com.cobblemon.mod.common.api.gui.blitk
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import net.minecraft.client.gui.components.AbstractWidget
|
||||
import org.joml.Vector4i
|
||||
|
||||
interface ControllerScreen {
|
||||
companion object {
|
||||
private val selectionTexture = cobblemonResource("textures/gui/common/selection_box.png")
|
||||
|
||||
const val BASE_SIZE = 3
|
||||
const val SHADOW_OFFSET = 1
|
||||
const val TOTAL_SIZE = BASE_SIZE + SHADOW_OFFSET
|
||||
}
|
||||
|
||||
fun getComponentManager(): ControllerComponentManager
|
||||
|
||||
fun getSelectionPosAndSize(): Vector4i? {
|
||||
val manager = getComponentManager()
|
||||
val focusedWidget = manager.screen.focused as? AbstractWidget ?: return null
|
||||
|
||||
return Vector4i(focusedWidget.x - 2, focusedWidget.y - 2, focusedWidget.width + 4, focusedWidget.height + 4)
|
||||
}
|
||||
|
||||
fun renderSelection(matrices: PoseStack) {
|
||||
if (!getComponentManager().active) return
|
||||
val positioningData = getSelectionPosAndSize() ?: return
|
||||
|
||||
val posX = positioningData.x
|
||||
val posY = positioningData.y
|
||||
|
||||
val width = positioningData.z
|
||||
val height = positioningData.w
|
||||
|
||||
blitk( //NW
|
||||
matrixStack = matrices,
|
||||
texture = selectionTexture,
|
||||
x = posX,
|
||||
y = posY,
|
||||
width = TOTAL_SIZE,
|
||||
height = TOTAL_SIZE,
|
||||
uOffset = 0,
|
||||
vOffset = 0,
|
||||
textureWidth = TOTAL_SIZE * 2,
|
||||
textureHeight = TOTAL_SIZE * 2
|
||||
)
|
||||
|
||||
blitk( //NE
|
||||
matrixStack = matrices,
|
||||
texture = selectionTexture,
|
||||
x = posX + width - BASE_SIZE,
|
||||
y = posY,
|
||||
width = TOTAL_SIZE,
|
||||
height = TOTAL_SIZE,
|
||||
uOffset = 4,
|
||||
vOffset = 0,
|
||||
textureWidth = TOTAL_SIZE * 2,
|
||||
textureHeight = TOTAL_SIZE * 2
|
||||
)
|
||||
|
||||
blitk( //SW
|
||||
matrixStack = matrices,
|
||||
texture = selectionTexture,
|
||||
x = posX,
|
||||
y = posY + height - BASE_SIZE,
|
||||
width = TOTAL_SIZE,
|
||||
height = TOTAL_SIZE,
|
||||
uOffset = 0,
|
||||
vOffset = 4,
|
||||
textureWidth = TOTAL_SIZE * 2,
|
||||
textureHeight = TOTAL_SIZE * 2
|
||||
)
|
||||
|
||||
blitk( //SE
|
||||
matrixStack = matrices,
|
||||
texture = selectionTexture,
|
||||
x = posX + width - BASE_SIZE,
|
||||
y = posY + height - BASE_SIZE,
|
||||
width = TOTAL_SIZE,
|
||||
height = TOTAL_SIZE,
|
||||
uOffset = 4,
|
||||
vOffset = 4,
|
||||
textureWidth = TOTAL_SIZE * 2,
|
||||
textureHeight = TOTAL_SIZE * 2
|
||||
)
|
||||
}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.client.integration.controlify.gui.component
|
||||
|
||||
class SubManagerComponent: ControllerComponent() {
|
||||
var subManager: () -> ControllerComponentManager? = { null }
|
||||
|
||||
init {
|
||||
left = { subManager.invoke()?.left(); null }
|
||||
right = { subManager.invoke()?.right(); null }
|
||||
up = { subManager.invoke()?.up(); null }
|
||||
down = { subManager.invoke()?.down(); null }
|
||||
|
||||
onPress = { subManager.invoke()?.press() }
|
||||
onSpecial1 = { subManager.invoke()?.special1() }
|
||||
onSpecial2 = { subManager.invoke()?.special2() }
|
||||
|
||||
onFocus = {
|
||||
subManager.invoke()?.active = true
|
||||
subManager.invoke()?.let { it.screen.focused = it.focused?.associatedGUIElement }
|
||||
subManager.invoke()?.focused?.onFocus?.invoke()
|
||||
}
|
||||
onUnfocus = {
|
||||
subManager.invoke()?.active = false
|
||||
subManager.invoke()?.focused?.onUnfocus?.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-21
@@ -15,6 +15,7 @@ import com.cobblemon.mod.common.battles.BattleFormat
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.client.battle.ClientBattle
|
||||
import com.cobblemon.mod.common.client.gui.battle.BattleGUI
|
||||
import com.cobblemon.mod.common.client.gui.interact.wheel.createPokeSkillGui
|
||||
import com.cobblemon.mod.common.client.keybind.CobblemonBlockingKeyBinding
|
||||
import com.cobblemon.mod.common.client.keybind.KeybindCategories
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
@@ -26,12 +27,12 @@ import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import com.cobblemon.mod.common.util.isUsingPokedex
|
||||
import com.cobblemon.mod.common.util.traceFirstEntityCollision
|
||||
import com.mojang.blaze3d.platform.InputConstants
|
||||
import kotlin.math.pow
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.player.LocalPlayer
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.level.ClipContext
|
||||
import kotlin.math.pow
|
||||
|
||||
object PartySendBinding : CobblemonBlockingKeyBinding(
|
||||
"key.cobblemon.throwpartypokemon",
|
||||
@@ -39,32 +40,17 @@ object PartySendBinding : CobblemonBlockingKeyBinding(
|
||||
InputConstants.KEY_R,
|
||||
KeybindCategories.COBBLEMON_CATEGORY
|
||||
) {
|
||||
const val POKE_SKILL_TIME = 0.7F
|
||||
var canApplyChange = true
|
||||
var heldDownSeconds = 0F
|
||||
|
||||
fun actioned() {
|
||||
canApplyChange = false
|
||||
wasDown = true
|
||||
heldDownSeconds = 0F
|
||||
}
|
||||
|
||||
fun canAction() = canApplyChange && Minecraft.getInstance().player?.isUsingPokedex() == false
|
||||
|
||||
override fun onTick() {
|
||||
if (wasDown) {
|
||||
if (heldDownSeconds < 100) {
|
||||
heldDownSeconds += Minecraft.getInstance().timer.getGameTimeDeltaPartialTick(false)
|
||||
}
|
||||
} else {
|
||||
heldDownSeconds = 0F
|
||||
}
|
||||
|
||||
super.onTick()
|
||||
}
|
||||
|
||||
override fun onRelease() {
|
||||
val canAction = canAction()
|
||||
wasDown = false
|
||||
canApplyChange = true
|
||||
if (!canAction) {
|
||||
return
|
||||
@@ -105,7 +91,8 @@ object PartySendBinding : CobblemonBlockingKeyBinding(
|
||||
entityClass = LivingEntity::class.java,
|
||||
ignoreEntity = player,
|
||||
maxDistance = Cobblemon.config.battleSpectateMaxDistance,
|
||||
collideBlock = ClipContext.Fluid.NONE)
|
||||
collideBlock = ClipContext.Fluid.NONE
|
||||
)
|
||||
if (canSendOutPokemon(player, targetEntity)) {
|
||||
sendToServer(SendOutPokemonPacket(CobblemonClient.storage.selectedSlot))
|
||||
} else {
|
||||
@@ -127,10 +114,13 @@ object PartySendBinding : CobblemonBlockingKeyBinding(
|
||||
//The server sends a packet back that opens the player interaction menu with the proper options
|
||||
sendToServer(RequestPlayerInteractionsPacket(entity.uuid, entity.id, pokemon.uuid))
|
||||
}
|
||||
|
||||
is PokemonEntity -> {
|
||||
if (!entity.canBattle(player) || entity.position().distanceToSqr(player.position()) > Cobblemon.config.battleWildMaxDistance.pow(2)) return
|
||||
sendToServer(BattleChallengePacket(entity.id, pokemon.uuid, BattleFormat.GEN_9_SINGLES))
|
||||
}
|
||||
if (!entity.canBattle(player) || entity.position()
|
||||
.distanceToSqr(player.position()) > Cobblemon.config.battleWildMaxDistance.pow(2)
|
||||
) return
|
||||
sendToServer(BattleChallengePacket(entity.id, pokemon.uuid, BattleFormat.GEN_9_SINGLES))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-1
@@ -19,6 +19,7 @@ import com.cobblemon.mod.common.entity.PosableEntity
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.SpawnSnowstormEntityParticlePacket
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object SpawnSnowstormEntityParticleHandler : ClientNetworkPacketHandler<SpawnSnowstormEntityParticlePacket> {
|
||||
override fun handle(packet: SpawnSnowstormEntityParticlePacket, client: Minecraft) {
|
||||
@@ -31,6 +32,7 @@ object SpawnSnowstormEntityParticleHandler : ClientNetworkPacketHandler<SpawnSno
|
||||
val targetState = (targetedEntity as? PosableEntity)?.delegate as? PosableState
|
||||
val sourceLocators = packet.sourceLocators.firstNotNullOfOrNull { sourceState.getMatchingLocators(it).takeIf { it.isNotEmpty() } } ?: return
|
||||
val targetedLocator = packet.targetLocators?.firstOrNull { targetState?.getMatchingLocators(it)?.isNotEmpty() == true }
|
||||
val targetPosition = packet.targetPosition
|
||||
val rootMatrix = sourceState.locatorStates["root"]!!
|
||||
|
||||
sourceLocators.forEach { locator ->
|
||||
@@ -40,6 +42,16 @@ object SpawnSnowstormEntityParticleHandler : ClientNetworkPacketHandler<SpawnSno
|
||||
val particleRuntime = MoLangRuntime().setup().setupClient()
|
||||
particleRuntime.environment.query.addFunction("entity") { sourceState.runtime.environment.query }
|
||||
|
||||
// Target resolution priority: entity+locator > world position > none
|
||||
val targetPos: (() -> Vec3)? = if (targetedEntity != null) {
|
||||
{ targetedLocator?.let { targetState?.locatorStates?.get(it) }?.getOrigin() ?: targetedEntity.position() }
|
||||
} else if (targetPosition != null) {
|
||||
val pos = packet.targetPosition
|
||||
{ pos }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val storm = ParticleStorm(
|
||||
effect = effect,
|
||||
emitterSpaceMatrix = particleMatrix,
|
||||
@@ -49,7 +61,7 @@ object SpawnSnowstormEntityParticleHandler : ClientNetworkPacketHandler<SpawnSno
|
||||
sourceVelocity = { sourceEntity.deltaMovement },
|
||||
sourceAlive = { !sourceEntity.isRemoved },
|
||||
sourceVisible = { !sourceEntity.isInvisible },
|
||||
targetPos = if (targetedEntity != null) { { targetedLocator?.let { targetState?.locatorStates?.get(it) }?.getOrigin() ?: targetedEntity.position() } } else null,
|
||||
targetPos = targetPos,
|
||||
entity = sourceEntity
|
||||
)
|
||||
|
||||
|
||||
@@ -18,23 +18,17 @@ import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer
|
||||
import com.mojang.math.Axis
|
||||
import net.minecraft.Util
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.Font
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.renderer.MultiBufferSource
|
||||
import net.minecraft.client.renderer.RenderType
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.network.chat.MutableComponent
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.util.FormattedCharSequence
|
||||
import net.minecraft.util.Mth
|
||||
import net.minecraft.world.item.ItemDisplayContext
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.sin
|
||||
|
||||
fun renderScaledGuiItemIcon(itemStack: ItemStack, x: Double, y: Double, scale: Double = 1.0, zTranslation: Float = 100.0F, matrixStack: PoseStack? = null) {
|
||||
val itemRenderer = Minecraft.getInstance().itemRenderer
|
||||
@@ -103,55 +97,6 @@ fun getDepletableRedGreen(
|
||||
return r.toFloat() to g.toFloat()
|
||||
}
|
||||
|
||||
fun drawScrollingText(
|
||||
context: GuiGraphics,
|
||||
font: Font,
|
||||
text: Component,
|
||||
minX: Int,
|
||||
minY: Int,
|
||||
maxX: Int,
|
||||
maxY: Int,
|
||||
colour: Int,
|
||||
minScrollVelocity: Double? = 10.0
|
||||
) {
|
||||
val textWidth = font.width(text)
|
||||
val fittedMaxX = if (textWidth <= maxX - minX) minX + textWidth else maxX
|
||||
renderScrollingString(context, font, text, minX, minY, fittedMaxX, maxY, colour, minScrollVelocity)
|
||||
}
|
||||
|
||||
/** Copied from [net.minecraft.client.gui.components.AbstractWidget.renderScrollingString] **/
|
||||
fun renderScrollingString(
|
||||
context: GuiGraphics,
|
||||
font: Font,
|
||||
text: Component,
|
||||
minX: Int,
|
||||
minY: Int,
|
||||
maxX: Int,
|
||||
maxY: Int,
|
||||
colour: Int,
|
||||
minScrollVelocity: Double? = 10.0
|
||||
) {
|
||||
val textWidth = font.width(text)
|
||||
val centerY = (minY + maxY - 9) / 2 + 1
|
||||
val boxWidth = maxX - minX
|
||||
if (textWidth <= boxWidth) {
|
||||
val centerX = Mth.clamp((minX + maxX) / 2, minX + textWidth / 2, maxX - textWidth / 2)
|
||||
context.drawCenteredString(font, text, centerX, centerY, colour)
|
||||
return
|
||||
}
|
||||
|
||||
val overflow = textWidth - boxWidth
|
||||
var period = (overflow * 0.5).coerceAtLeast(3.0)
|
||||
if (minScrollVelocity != null) {
|
||||
period = period.coerceAtMost(2 * overflow / minScrollVelocity)
|
||||
}
|
||||
val time = Util.getMillis() / 1000.0
|
||||
val easedProgress = sin((Math.PI / 2) * cos(2 * Math.PI * time / period)) / 2.0 + 0.5
|
||||
val offset = Mth.lerp(easedProgress, 0.0, overflow.toDouble())
|
||||
context.enableScissor(minX, minY, maxX, maxY)
|
||||
context.drawString(font, text, minX - offset.toInt(), centerY, colour)
|
||||
context.disableScissor()
|
||||
}
|
||||
|
||||
fun drawScaledText(
|
||||
context: GuiGraphics,
|
||||
|
||||
Loaded 100 of 191 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user