@@ -28,50 +28,173 @@ import com.google.common.collect.Multimap
2828import generations.gg.generations.core.generationscore.common.GenerationsCore
2929import generations.gg.generations.core.generationscore.common.network.GenerationsNetwork
3030import generations.gg.generations.core.generationscore.common.network.packets.GensInteractPokemonPacket
31+ import java.util.UUID
3132import net.minecraft.client.Minecraft
3233import net.minecraft.network.chat.Component
33- import java.util.*
3434import org.joml.Vector3f
3535
3636fun createPokemonInteractGui (
3737 pokemonID : UUID ,
38- canMountShoulder : Boolean ,
38+ canMountShoulder :
39+ Boolean ,
3940 canGiveHeld : Boolean ,
4041 canGiveCosmetic : Boolean ,
4142 canRide : Boolean ,
42- changeFormData : Pair <Boolean , String >): InteractWheelGUI {
43-
43+ changeFormData : Pair <Boolean , String >
44+ ): InteractWheelGUI {
4445 val mountShoulder = InteractWheelOption (
45- iconResource = cobblemonResource(" textures/gui/interact/icon_shoulder .png" ),
46+ iconResource = cobblemonResource(" textures/gui/interact/interact_wheel_icon_shoulder .png" ),
4647 tooltipText = " cobblemon.ui.interact.mount.shoulder" ,
48+ enabled = canMountShoulder,
4749 onPress = {
4850 if (canMountShoulder) {
4951 InteractPokemonPacket (pokemonID, InteractTypePokemon .SHOULDER ).sendToServer()
5052 closeGUI()
5153 }
5254 }
5355 )
54- val giveItem = InteractWheelOption (
55- iconResource = cobblemonResource(" textures/gui/interact/icon_held_item .png" ),
56+ val giveHeldItem = InteractWheelOption (
57+ iconResource = cobblemonResource(" textures/gui/interact/interact_wheel_icon_held_item .png" ),
5658 tooltipText = " cobblemon.ui.interact.give.item" ,
59+ enabled = canGiveHeld,
5760 onPress = {
58- InteractPokemonPacket (pokemonID, InteractTypePokemon .HELD_ITEM ).sendToServer()
59- closeGUI()
61+ if (canGiveHeld) {
62+ InteractPokemonPacket (pokemonID, InteractTypePokemon .HELD_ITEM ).sendToServer()
63+ closeGUI()
64+ }
65+ }
66+ )
67+ val giveCosmeticItem = InteractWheelOption (
68+ iconResource = cobblemonResource(" textures/gui/interact/interact_wheel_icon_cosmetic_item.png" ),
69+ tooltipText = " cobblemon.ui.interact.give.cosmetic_item" ,
70+ enabled = canGiveCosmetic,
71+ onPress = {
72+ if (canGiveCosmetic) {
73+ InteractPokemonPacket (pokemonID, InteractTypePokemon .COSMETIC_ITEM ).sendToServer()
74+ closeGUI()
75+ }
76+ }
77+ )
78+
79+ val ride = InteractWheelOption (
80+ iconResource = cobblemonResource(" textures/gui/interact/interact_wheel_icon_ride.png" ),
81+ tooltipText = " cobblemon.ui.interact.ride" ,
82+ enabled = canRide,
83+ onPress = {
84+ if (canRide) {
85+ InteractPokemonPacket (pokemonID, InteractTypePokemon .RIDE ).sendToServer()
86+ closeGUI()
87+ }
6088 }
6189 )
6290
6391 val options: Multimap <Orientation , InteractWheelOption > = ArrayListMultimap .create()
64- options.put(Orientation .NORTHWEST , giveItem )
65- if (canMountShoulder) {
66- options.put(Orientation .NORTHEAST , mountShoulder )
67- }
92+ options.put(Orientation .NORTH , giveHeldItem )
93+ options.put( Orientation . NORTHEAST , giveCosmeticItem)
94+ options.put(Orientation .WEST , ride )
95+ options.put( Orientation . NORTHWEST , mountShoulder)
6896
69- createOption(pokemonID, changeFormData)?.also { options.put(Orientation .SOUTHWEST , it) }
97+ createOption(pokemonID, changeFormData)?.also { options.put(Orientation .EAST , it) }
7098
71- CobblemonEvents .POKEMON_INTERACTION_GUI_CREATION .post(PokemonInteractionGUICreationEvent (pokemonID, canMountShoulder, true , false /* TOODO: is the items given cosmetic in thsi context? */ , false /* TODO: I'm not even sure about this part. */ , options))
99+ CobblemonEvents .POKEMON_INTERACTION_GUI_CREATION .post(PokemonInteractionGUICreationEvent (
100+ pokemonID = pokemonID,
101+ mountShoulder = canMountShoulder,
102+ giveHeld = canGiveHeld,
103+ giveCosmetic = canGiveCosmetic,
104+ canRide = canRide,
105+ options = options
106+ ))
72107 return InteractWheelGUI (options, Component .translatable(" cobblemon.ui.interact.pokemon" ))
73108}
74109
110+ fun createPlayerInteractGui (optionsPacket : PlayerInteractOptionsPacket ): InteractWheelGUI {
111+ val trade = InteractWheelOption (
112+ iconResource = cobblemonResource(" textures/gui/interact/interact_wheel_icon_trade.png" ),
113+ secondaryIconResource = if (CobblemonClient .requests.tradeOffers[optionsPacket.targetId] != null )
114+ cobblemonResource(" textures/gui/interact/interact_wheel_icon_exclamation.png" )
115+ else null ,
116+ colour = { null },
117+ tooltipText = " cobblemon.ui.interact.trade" ,
118+ onPress = {
119+ val tradeOffer = CobblemonClient .requests.tradeOffers[optionsPacket.targetId]
120+ if (tradeOffer == null ) {
121+ CobblemonNetwork .sendToServer(OfferTradePacket (optionsPacket.targetId))
122+ } else {
123+ CobblemonClient .requests.tradeOffers.remove(optionsPacket.targetId)
124+ CobblemonNetwork .sendToServer(AcceptTradeRequestPacket (tradeOffer.requestID))
125+ }
126+ closeGUI()
127+ }
128+ )
129+ val activeBattleRequest = CobblemonClient .requests.battleChallenges[optionsPacket.targetId]
130+ val activeTeamRequest = CobblemonClient .requests.multiBattleTeamRequests[optionsPacket.targetId]
131+ val battle = InteractWheelOption (
132+ iconResource = cobblemonResource(" textures/gui/interact/interact_wheel_icon_battle.png" ),
133+ secondaryIconResource = if (activeBattleRequest != null || activeTeamRequest != null )
134+ cobblemonResource(" textures/gui/interact/interact_wheel_icon_exclamation.png" )
135+ else null ,
136+ colour = { null },
137+ tooltipText = " cobblemon.ui.interact.battle" ,
138+ onPress = {
139+ Minecraft .getInstance().setScreen(BattleConfigureGUI (optionsPacket, activeBattleRequest, activeTeamRequest))
140+ }
141+ )
142+
143+ val spectate = InteractWheelOption (
144+ iconResource = cobblemonResource(" textures/gui/interact/interact_wheel_icon_spectate_battle.png" ),
145+ colour = { if (CobblemonClient .requests.battleChallenges[optionsPacket.targetId] != null ) Vector3f (0F , 0.6F , 0F ) else null },
146+ onPress = {
147+ SpectateBattlePacket (optionsPacket.targetId).sendToServer()
148+ closeGUI()
149+ },
150+ tooltipText = " cobblemon.ui.interact.spectate"
151+ )
152+ val options: Multimap <Orientation , InteractWheelOption > = ArrayListMultimap .create()
153+ // TODO: hasChallenge and hasTeamRequest get calculated a bunch of times. Might consider having the server just passing it over.
154+ val hasChallenge = CobblemonClient .requests.battleChallenges[optionsPacket.targetId] != null
155+ val hasTeamRequest = CobblemonClient .requests.multiBattleTeamRequests[optionsPacket.targetId] != null
156+ // The way things are positioned should probably be more thought out if more options are added
157+ var addBattleOption = false
158+ optionsPacket.options.forEach {
159+ if (! addBattleOption && (hasChallenge || hasTeamRequest || BattleConfigureGUI .battleRequestMap.containsKey(it.key))) {
160+ if (it.value == = PlayerInteractOptionsPacket .OptionStatus .AVAILABLE ) {
161+ options.put(Orientation .NORTH , battle)
162+ addBattleOption = true
163+ } else {
164+ options.put(Orientation .NORTH , InteractWheelOption (
165+ iconResource = cobblemonResource(" textures/gui/interact/interact_wheel_icon_battle.png" ),
166+ secondaryIconResource = null ,
167+ colour = { Vector3f (0.5f , 0.5f , 0.5f ) },
168+ tooltipText = getLangKey(it.value),
169+ onPress = {}
170+ ))
171+ }
172+ }
173+ if (it.key == PlayerInteractOptionsPacket .Options .SPECTATE_BATTLE ) {
174+ if (! hasChallenge) {
175+ options.put(Orientation .NORTH , spectate)
176+ }
177+ }
178+ if (it.key == PlayerInteractOptionsPacket .Options .TRADE ) {
179+ if (it.value == PlayerInteractOptionsPacket .OptionStatus .AVAILABLE ) {
180+ options.put(Orientation .NORTHEAST , trade)
181+ } else {
182+ val langKey = getLangKey(it.value)
183+ options.put(
184+ Orientation .NORTHEAST , InteractWheelOption (
185+ iconResource = cobblemonResource(" textures/gui/interact/interact_wheel_icon_trade.png" ),
186+ secondaryIconResource = null ,
187+ colour = { Vector3f (0.5f , 0.5f , 0.5f ) },
188+ tooltipText = langKey,
189+ onPress = {}
190+ ))
191+ }
192+ }
193+ }
194+
195+ return InteractWheelGUI (options, Component .translatable(" cobblemon.ui.interact.player" ))
196+ }
197+
75198fun createOption (pokemonID : UUID , changeFormData : Pair <Boolean , String >): InteractWheelOption ? {
76199 var path = " "
77200 var aspect = changeFormData.second
@@ -118,6 +241,14 @@ fun createOption(pokemonID: UUID, changeFormData: Pair<Boolean, String>): Intera
118241 return null
119242}
120243
244+ private fun getLangKey (status : PlayerInteractOptionsPacket .OptionStatus ) : String {
245+ return when (status) {
246+ PlayerInteractOptionsPacket .OptionStatus .TOO_FAR -> " cobblemon.ui.interact.too_far"
247+ PlayerInteractOptionsPacket .OptionStatus .INSUFFICIENT_POKEMON -> " cobblemon.battle.error.no_pokemon_opponent"
248+ else -> " cobblemon.ui.interact.unavailable"
249+ }
250+ }
251+
121252private fun closeGUI () {
122253 Minecraft .getInstance().setScreen(null )
123254}
0 commit comments