Skip to content

Commit

Permalink
1.0.20 (Tests)
Browse files Browse the repository at this point in the history
How to evolve is finally here!
A lot of things added to make it, including new translations and new textures!
Added some missing translations to translation file (still have a lot, will be available on next update)
  • Loading branch information
Rafacasari committed Jun 20, 2024
1 parent 4933bc4 commit e91b13f
Show file tree
Hide file tree
Showing 16 changed files with 968 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ import net.minecraft.text.Style
import net.minecraft.util.Identifier
import com.rafacasari.mod.cobbledex.Cobbledex
import com.rafacasari.mod.cobbledex.client.gui.menus.BattleMenu
import com.rafacasari.mod.cobbledex.client.gui.menus.EvolutionMenu
import com.rafacasari.mod.cobbledex.client.gui.menus.InfoMenu
import com.rafacasari.mod.cobbledex.client.widget.ArrowButton
import com.rafacasari.mod.cobbledex.client.widget.CobbledexTab
import com.rafacasari.mod.cobbledex.client.widget.LongTextDisplay
import com.rafacasari.mod.cobbledex.client.widget.PokemonEvolutionDisplay
import com.rafacasari.mod.cobbledex.network.server.packets.RequestCobbledexPacket
import com.rafacasari.mod.cobbledex.network.template.SerializableItemDrop
import com.rafacasari.mod.cobbledex.network.template.SerializablePokemonEvolution
import com.rafacasari.mod.cobbledex.network.template.SerializablePokemonSpawnDetail
import com.rafacasari.mod.cobbledex.utils.*
import net.minecraft.text.Text

class CobbledexGUI(var selectedPokemon: FormData?, var selectedAspects: Set<String>? = null) : Screen(cobbledexTranslation("cobbledex.texts.cobbledex")) {

Expand Down Expand Up @@ -76,9 +79,11 @@ class CobbledexGUI(var selectedPokemon: FormData?, var selectedAspects: Set<Stri

// Cache
private var lastLoadedSpecies: Species? = null
private var lastLoadedAspects: Set<String>? = null
private var lastLoadedSpawnDetails: List<SerializablePokemonSpawnDetail>? = null
private var lastLoadedPokemonDrops: List<SerializableItemDrop>? = null
var lastLoadedEvolutions: List<Pair<Species, Set<String>>>? = null

var lastLoadedEvolutions: List<SerializablePokemonEvolution>? = null
var lastLoadedPreEvolutions: List<Pair<Species, Set<String>>>? = null
var lastLoadedForms: List<Pair<Species, Set<String>>>? = null
}
Expand Down Expand Up @@ -199,7 +204,12 @@ class CobbledexGUI(var selectedPokemon: FormData?, var selectedAspects: Set<Stri
}

CobbledexMenu.Evolutions -> {
longTextDisplay?.addText("Coming soon...".text())

if (lastLoadedEvolutions.isNullOrEmpty())
lastLoadedSpecies?.let { species ->
longTextDisplay?.addText(Text.translatable("cobbledex.texts.no_evolution_found", species.translatedName))
}
else lastLoadedEvolutions?.forEach { evolution -> EvolutionMenu.drawText(longTextDisplay, evolution) }
}
}
}
Expand Down Expand Up @@ -369,9 +379,20 @@ class CobbledexGUI(var selectedPokemon: FormData?, var selectedAspects: Set<Stri

evolutionDisplay?.clearEvolutions()

val aspects = pokemonAspects?.let {
CobblemonUtils.removeUnnecessaryAspects(it)
} ?: setOf()

// Request Pokémon Info to server and load into cache in Packet Handler (See ReceiveCobbledexPacketHandler)
if (pokemon != null && (lastLoadedSpecies == null || lastLoadedSpecies != pokemon.species)) {
RequestCobbledexPacket(pokemon.species.resourceIdentifier, pokemonAspects ?: setOf()).sendToServer()
if (pokemon != null
&& ((lastLoadedSpecies == null || lastLoadedSpecies != pokemon.species)
|| (lastLoadedAspects == null || lastLoadedAspects != pokemonAspects))) {

logInfo("Requested Cobbledex Packet")
lastLoadedAspects = aspects

// TODO: Packet seems to be called always, check why
RequestCobbledexPacket(pokemon.species.resourceIdentifier, aspects).sendToServer()
}

if (pokemon != null) {
Expand Down Expand Up @@ -418,7 +439,10 @@ class CobbledexGUI(var selectedPokemon: FormData?, var selectedAspects: Set<Stri

when(selectedRelatedTab) {
CobbledexRelatedMenu.Evolutions -> {
evolutionDisplay?.selectEvolutions(lastLoadedEvolutions)
// TODO: Rework the evolution display
evolutionDisplay?.selectEvolutions(lastLoadedEvolutions?.mapNotNull {
it.species?.let { species -> species to it.resultAspects }
})
}
CobbledexRelatedMenu.PreEvolutions -> {
evolutionDisplay?.selectEvolutions(lastLoadedPreEvolutions)
Expand All @@ -443,8 +467,6 @@ class CobbledexGUI(var selectedPokemon: FormData?, var selectedAspects: Set<Stri
// }




fun updateInfoPage(species: Species?, spawnDetails: List<SerializablePokemonSpawnDetail>?, itemDrops: List<SerializableItemDrop>?, fromCache: Boolean = false) {
if (!fromCache) {
// If our call isn't from cache, then we can update the current cache
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.rafacasari.mod.cobbledex.client.gui.menus

import com.rafacasari.mod.cobbledex.client.widget.LongTextDisplay
import com.rafacasari.mod.cobbledex.network.template.SerializablePokemonEvolution

object EvolutionMenu {


fun drawText(longTextDisplay: LongTextDisplay?, evolution: SerializablePokemonEvolution) {
if (longTextDisplay == null) return

evolution.drawInfo(longTextDisplay)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import net.minecraft.item.ItemStack
import net.minecraft.registry.Registries
import net.minecraft.text.HoverEvent
import net.minecraft.text.Style
import net.minecraft.text.Text
import net.minecraft.world.biome.Biome

object InfoMenu {
Expand All @@ -27,8 +28,7 @@ object InfoMenu {
longTextDisplay.addText(pokedex.asTranslated())
}

if (!pokemonDrops.isNullOrEmpty())
{
if (!pokemonDrops.isNullOrEmpty()) {
longTextDisplay.addText(cobbledexTranslation("cobbledex.texts.drops").bold())
pokemonDrops.forEach { itemDrop ->
val itemStack = ItemStack(Registries.ITEM.get(itemDrop.item))
Expand All @@ -37,12 +37,13 @@ object InfoMenu {
val quantityRange = itemDrop.quantityRange
val quantity: String = if (quantityRange.first == quantityRange.last) quantityRange.first.toString() else "${quantityRange.first}-${quantityRange.last}"

val text = "item.${itemDrop.item.toTranslationKey()}".asTranslated()
text.add(" | ${itemDrop.percentage.format()}% | ${quantity}x".text())

longTextDisplay.addItemEntry(itemStack, text, false)
//longTextDisplay.addText(text, false)

val translation = Text.translatable(
"cobbledex.texts.drops.item",
itemStack.name,
itemDrop.percentage.format(),
quantity
)
longTextDisplay.addItemEntry(itemStack, translation, false)
}

}
Expand Down Expand Up @@ -172,11 +173,7 @@ object InfoMenu {
}

val hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltipText)

longTextDisplay.addText(
condition.asTranslated().setStyle(Style.EMPTY.withHoverEvent(hoverEvent)),
false
)
longTextDisplay.addText(condition.asTranslated().setStyle(Style.EMPTY.withHoverEvent(hoverEvent)), false)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.rafacasari.mod.cobbledex.client.widget

import com.cobblemon.mod.common.api.text.text
import com.cobblemon.mod.common.pokemon.Species
import com.rafacasari.mod.cobbledex.client.widget.entries.EmptyEntry
import com.rafacasari.mod.cobbledex.client.widget.entries.ItemEntry
import com.rafacasari.mod.cobbledex.client.widget.entries.PokemonEntry
import com.rafacasari.mod.cobbledex.client.widget.entries.TextEntry
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.DrawContext
Expand Down Expand Up @@ -55,7 +58,7 @@ class LongTextDisplay (
fun addText(entry: MutableText, breakLine: Boolean = true, shadow: Boolean = false) {

if (breakLine && super.getEntryCount() > 0) {
super.addEntry(TextEntry(null))
addEmptyEntry()
}

val textRenderer = MinecraftClient.getInstance().textRenderer
Expand All @@ -67,7 +70,7 @@ class LongTextDisplay (
fun addItemEntry(item: ItemStack, entry: Text, breakLine: Boolean = true) {

if (breakLine && super.getEntryCount() > 0)
super.addEntry(TextEntry(null))
addEmptyEntry()

val textRenderer = MinecraftClient.getInstance().textRenderer
val reorderedTexts = Language.getInstance()
Expand All @@ -85,6 +88,16 @@ class LongTextDisplay (
return super.addEntry(ItemEntry(item, text))
}

fun addPokemon(pokemon: Species, aspects: Set<String>, translatedName: MutableText, breakLine: Boolean = false) {

if (breakLine && super.getEntryCount() > 0)
addEmptyEntry()

super.addEntry(PokemonEntry(pokemon, aspects, translatedName.asOrderedText()))
super.addEntry(EmptyEntry())

}

fun clear() {
super.clearEntries()
}
Expand Down Expand Up @@ -158,6 +171,9 @@ class LongTextDisplay (
scrollAmount = 0.0
}

fun addEmptyEntry() {
super.addEntry(EmptyEntry())
}

abstract class TextDisplayEntry : Entry<TextDisplayEntry>() {
override fun getNarration(): Text = "".text()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.rafacasari.mod.cobbledex.client.widget.entries


import com.rafacasari.mod.cobbledex.client.widget.LongTextDisplay
import net.minecraft.client.gui.DrawContext
class EmptyEntry : LongTextDisplay.TextDisplayEntry() {

override fun drawTooltip(context: DrawContext, mouseX: Int, mouseY: Int) {

}

override fun render(
context: DrawContext?,
index: Int,
y: Int,
x: Int,
entryWidth: Int,
entryHeight: Int,
mouseX: Int,
mouseY: Int,
hovered: Boolean,
tickDelta: Float
)
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.rafacasari.mod.cobbledex.client.widget.entries

import com.cobblemon.mod.common.api.gui.blitk
import com.cobblemon.mod.common.api.gui.drawPortraitPokemon
import com.cobblemon.mod.common.client.render.drawScaledText
import com.cobblemon.mod.common.pokemon.Species
import com.rafacasari.mod.cobbledex.client.widget.LongTextDisplay
import com.rafacasari.mod.cobbledex.utils.cobbledexResource
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.DrawContext
import net.minecraft.text.OrderedText
import net.minecraft.util.Colors

class PokemonEntry(val species: Species, val aspects: Set<String>, val text: OrderedText) : LongTextDisplay.TextDisplayEntry() {
companion object
{
private val BACKGROUND = cobbledexResource("textures/gui/evolution-menu/background.png")
private val OVERLAY = cobbledexResource("textures/gui/evolution-menu/overlay.png")
private const val IMAGE_SIZE = 16
private const val Y_OFFSET = 1
private const val X_OFFSET = -2
}


override fun render(
context: DrawContext?,
index: Int,
y: Int,
x: Int,
entryWidth: Int,
entryHeight: Int,
mouseX: Int,
mouseY: Int,
hovered: Boolean,
tickDelta: Float
) {
if (context == null) return
val matrices = context.matrices


blitk(
matrixStack = matrices,
texture = BACKGROUND,
x = x + X_OFFSET,
y = y + Y_OFFSET,
height = IMAGE_SIZE,
width = IMAGE_SIZE
)

context.enableScissor(
x + X_OFFSET,
y + Y_OFFSET,
x + X_OFFSET + IMAGE_SIZE,
y + Y_OFFSET + IMAGE_SIZE
)

matrices.push()
matrices.translate(
x + 10.0 + X_OFFSET,
y.toDouble() - 3 + Y_OFFSET,
0.0
)
matrices.scale(0.5f, 0.5f,1f)

drawPortraitPokemon(species, aspects, matrices, partialTicks = tickDelta)

matrices.pop()
context.disableScissor()


blitk(
matrixStack = matrices,
texture = OVERLAY,
x = x + X_OFFSET,
y = y + Y_OFFSET,
height = IMAGE_SIZE,
width = IMAGE_SIZE
)

drawScaledText(context, text, x + 18, y + 5, scaleX = 1.1f, scaleY = 1.1f)
}

override fun drawTooltip(context: DrawContext, mouseX: Int, mouseY: Int) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import net.minecraft.client.MinecraftClient
object ReceiveCobbledexPacketHandler : IClientNetworkPacketHandler<ReceiveCobbledexPacket> {
override fun handle(packet: ReceiveCobbledexPacket, client: MinecraftClient) {
try {
val evolutions = packet.evolutionList.mapNotNull {
val species = PokemonSpecies.getByIdentifier(it.first)
if (species != null) Pair(species, it.second) else null
}
// val evolutions = packet.evolutionList.mapNotNull {
// val species = PokemonSpecies.getByIdentifier(it.first)
// if (species != null) Pair(species, it.second) else null
// }

val preEvolutions = packet.preevolutionList.mapNotNull {
val species = PokemonSpecies.getByIdentifier(it.first)
Expand All @@ -25,7 +25,7 @@ object ReceiveCobbledexPacketHandler : IClientNetworkPacketHandler<ReceiveCobble
if (species != null) Pair(species, it.second) else null
}

CobbledexGUI.lastLoadedEvolutions = evolutions
CobbledexGUI.lastLoadedEvolutions = packet.evolutionList
CobbledexGUI.lastLoadedPreEvolutions = preEvolutions
CobbledexGUI.lastLoadedForms = forms

Expand Down
Loading

0 comments on commit e91b13f

Please sign in to comment.