Skip to content

Commit

Permalink
Merge pull request #429 from j10a1n15/feature/raredropfiltering
Browse files Browse the repository at this point in the history
Feature: Rare Drop Filtering
  • Loading branch information
Su386yt authored Jul 24, 2024
2 parents a41c224 + bff5c6b commit 78b078b
Show file tree
Hide file tree
Showing 13 changed files with 423 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,4 @@ public void onChat(ClientChatReceivedEvent event) {
FALLEN STAR
§r§5§l✯ §r§eA §r§5Fallen Star §r§ehas crashed at §r§bRoyal Mines§r§e! Nearby ore and Powder drops are amplified!§r
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import me.partlysanestudios.partlysaneskies.features.gui.hud.CooldownHud
import me.partlysanestudios.partlysaneskies.features.gui.hud.LocationBannerDisplay
import me.partlysanestudios.partlysaneskies.features.gui.hud.rngdropbanner.DropBannerDisplay
import me.partlysanestudios.partlysaneskies.features.gui.hud.rngdropbanner.DropWebhook
import me.partlysanestudios.partlysaneskies.features.gui.hud.rngdropbanner.RareDropGUIManager
import me.partlysanestudios.partlysaneskies.features.gui.mainmenu.PSSMainMenu
import me.partlysanestudios.partlysaneskies.features.information.WikiArticleOpener
import me.partlysanestudios.partlysaneskies.features.mining.MiningEvents
Expand Down Expand Up @@ -223,6 +224,11 @@ class PartlySaneSkies {
} catch (e: IOException) {
e.printStackTrace()
}
try {
RareDropGUIManager.loadData()
} catch (e: IOException) {
e.printStackTrace()
}
}.start()


Expand Down Expand Up @@ -306,6 +312,7 @@ class PartlySaneSkies {
PlayerRating.registerReprintCommand()
ModChecker.registerModCheckCommand()
ItemRefill.registerCommand()
RareDropGUIManager.registerCommand()
WebhookMenu.registerWebhookCommand()

registerCoreConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Config : ConfigOption() {
companion object {
val ConfigOption.asConfig get() = this as Config
}

// Recursively find paths for options
fun find(path: String): ConfigOption? {
val indexOfSplit = path.indexOf("/")
Expand All @@ -34,6 +35,7 @@ class Config : ConfigOption() {
}

private val options = LinkedHashMap<String, ConfigOption>()

// Recursively create new options to get to the path
fun registerOption(path: String, configOption: ConfigOption): Config {
val indexOfSplit = path.indexOf("/")
Expand All @@ -55,9 +57,7 @@ class Config : ConfigOption() {
return this
}

fun getAllOptions(): LinkedHashMap<String, ConfigOption> {
return options.clone() as LinkedHashMap<String, ConfigOption>
}
fun getAllOptions(): LinkedHashMap<String, ConfigOption> = options.clone() as LinkedHashMap<String, ConfigOption>

override fun loadFromJson(element: JsonElement) {
val obj = element.asJsonObject
Expand All @@ -66,7 +66,7 @@ class Config : ConfigOption() {
// If the parameter exists
if (obj.has(option.key)) {
try {
option.value.loadFromJson(obj.get(option.key))
option.value.loadFromJson(obj[option.key])

} catch (e: Exception) {
log(Level.ERROR, "Error loading option ${option.key}")
Expand All @@ -88,9 +88,11 @@ class Config : ConfigOption() {
var savePath: String? = null
fun save() {
if (parent == null) {
ConfigManager.saveConfig(savePath ?: throw IllegalArgumentException("Unable to Save. No save path provided. Config is not registered."), this)
ConfigManager.saveConfig(
savePath ?: throw IllegalArgumentException("Unable to Save. No save path provided. Config is not registered."), this,
)
} else {
(parent as? Config)?.save() ?: throw IllegalArgumentException("Unable to save. Parent of config is not a config.")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.google.gson.JsonParser
import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config
import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time
import me.partlysanestudios.partlysaneskies.data.api.GetRequest
import me.partlysanestudios.partlysaneskies.data.api.Request
import me.partlysanestudios.partlysaneskies.data.api.RequestsManager
import me.partlysanestudios.partlysaneskies.utils.MathUtils
import me.partlysanestudios.partlysaneskies.utils.StringUtils.titleCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.LinkedList

object CrystalHollowsGemstoneMapper {

Expand Down Expand Up @@ -102,17 +102,15 @@ object CrystalHollowsGemstoneMapper {
val coordObj = coordElement.asJsonObject
val point = Point3d(coordObj.get("x").asDouble, coordObj.get("y").asDouble, coordObj.get("z").asDouble)
try {
val type = "COLOR_${
world.getBlockState(point.toBlockPosInt())
.getValue(PropertyEnum.create("color", EnumDyeColor::class.java))
}"
val color = world.getBlockState(point.toBlockPosInt())
.getValue(PropertyEnum.create("color", EnumDyeColor::class.java))
val type = "COLOR_$color"

if (!map.contains(type)) {
map[type] = ArrayList<JsonObject>()
}

map[type]?.add(coordObj)
} catch (e: Exception) {
e.printStackTrace()
continue
}
}
Expand Down Expand Up @@ -306,4 +304,4 @@ object CrystalHollowsGemstoneMapper {
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ object RequiredSecretsFound {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ object SkymartValue : SidePanel() {
for ((key, value) in sortedMap) {

val item = getItem(key) ?: SkyblockItem.emptyItem
str += "§6$i. §d${item.name}§7 costs §d${copperCost[key]?.formatNumber() ?: 0}§7 copper and sells for §d${item.getSellPrice().round(1).formatNumber()}§7 coins \n§8 (${value.round(1).formatNumber()} coins per copper)\n"
str += "§6$i. §d${item.name}§7 costs §d${copperCost[key]?.formatNumber() ?: 0}§7 copper and sells for §d${
item.getSellPrice().round(1).formatNumber()
}§7 coins \n§8 (${value.round(1).formatNumber()} coins per copper)\n"

i++
if (i > 5) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft
import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time
import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity
import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity.Companion.getRarityFromColorCode
import me.partlysanestudios.partlysaneskies.features.gui.hud.rngdropbanner.RareDropGUIManager.isAllowedDrop
import me.partlysanestudios.partlysaneskies.render.gui.constraints.ScaledPixelConstraint.Companion.scaledPixels
import me.partlysanestudios.partlysaneskies.utils.MathUtils.onCooldown
import me.partlysanestudios.partlysaneskies.utils.StringUtils.colorCodeToColor
Expand Down Expand Up @@ -69,11 +70,14 @@ object DropBannerDisplay {
val (dropCategoryColor, dropCategory, dropColor, name, magicFind) = match.destructured

val rarity = dropColor.getRarityFromColorCode()
// TODO: add check for blocked drop
if (checkRarity(rarity)) {
return
}

if (!isAllowedDrop(name.trim())) {
return
}

if (config.rareDropBannerSound) {
minecraft.thePlayer.playSound("partlysaneskies:rngdropjingle", 100f, 1f)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
//
// Written by J10an15.
// See LICENSE for copyright and license notices.
//


package me.partlysanestudios.partlysaneskies.features.gui.hud.rngdropbanner

import gg.essential.elementa.ElementaVersion
import gg.essential.elementa.WindowScreen
import gg.essential.elementa.components.ScrollComponent
import gg.essential.elementa.components.UIBlock
import gg.essential.elementa.components.UIText
import gg.essential.elementa.components.UIWrappedText
import gg.essential.elementa.components.input.UITextInput
import gg.essential.elementa.constraints.CenterConstraint
import gg.essential.elementa.constraints.CramSiblingConstraint
import gg.essential.elementa.constraints.SiblingConstraint
import gg.essential.elementa.dsl.childOf
import gg.essential.elementa.dsl.constrain
import gg.essential.elementa.dsl.constraint
import gg.essential.elementa.dsl.percent
import gg.essential.elementa.dsl.pixels
import me.partlysanestudios.partlysaneskies.features.gui.hud.rngdropbanner.RareDropGUIManager.currentFilter
import me.partlysanestudios.partlysaneskies.features.gui.hud.rngdropbanner.RareDropGUIManager.currentFilterType
import me.partlysanestudios.partlysaneskies.features.themes.ThemeManager
import me.partlysanestudios.partlysaneskies.features.themes.ThemeManager.primaryColor
import me.partlysanestudios.partlysaneskies.render.gui.components.PSSButton
import me.partlysanestudios.partlysaneskies.render.gui.constraints.ScaledPixelConstraint.Companion.scaledPixels
import java.awt.Color

class RareDropGUI : WindowScreen(ElementaVersion.V5) {
private val backgroundBox = UIBlock().constrain {
width = 75.percent
height = 75.percent
x = CenterConstraint()
y = CenterConstraint()
color = Color(0, 0, 0, 0).constraint
} childOf window


/**
* Create Filter Container
*/
private val createFilterContainer = ThemeManager.currentBackgroundUIImage.constrain {
width = 60.percent
height = 75.percent
x = 40.percent
y = 0.percent
} childOf backgroundBox

private val createFiltersHeading = UIWrappedText("Create Filters:").constrain {
width = 90.percent
x = 5.percent
y = 2.percent
textScale = 1.5.scaledPixels
color = Color.gray.constraint
} childOf createFilterContainer

private val createFiltersInput = UITextInput("Create a ${currentFilterType.displayName} Filter...").constrain {
width = 90.percent
height = 5.percent
x = 5.percent
y = 7.percent
}.onMouseClick {
grabWindowFocus()
} as UITextInput childOf createFilterContainer

private val createFiltersScrollComponent = ScrollComponent(
scrollIconColor = primaryColor.toJavaColor(),
innerPadding = 10f,
scrollAcceleration = 2f,
).constrain {
width = 100.percent
height = 90.percent
x = 0.percent
y = 10.percent
} childOf createFilterContainer

private val createFilterButton = PSSButton()
.setText("Add ${currentFilterType.displayName} Filter")
.setX(5.percent)
.setY(15.percent)
.setHeight(50.pixels)
.setWidth(60.pixels)
.setChildOf(createFilterContainer)
.onMouseClickConsumer {
val text = createFiltersInput.getText()
if (text.isBlank()) return@onMouseClickConsumer
RareDropGUIManager.addFilter(text)
createFiltersInput.setText("")
updateFilterList()
}

private var opposite = RareDropGUIManager.FilterType.entries.first { it != currentFilterType }
private val switchTypeButton = PSSButton()
.setText("Switch to ${opposite.displayName}")
.setX(5.percent)
.setY(SiblingConstraint(5f))
.setHeight(50.pixels)
.setWidth(60.pixels)
.setChildOf(createFilterContainer)
.onMouseClickConsumer {
currentFilterType = opposite
opposite = RareDropGUIManager.FilterType.entries.first { it != currentFilterType }
RareDropGUIManager.saveData()
update()
}

/**
* Active Filter Container
*/
private val activeFiltersContainer = ThemeManager.currentBackgroundUIImage.constrain {
width = 35.percent
height = 100.percent
x = 0.percent
y = 0.percent
} childOf backgroundBox

private val activeFiltersHeading = UIWrappedText("${currentFilterType.displayName} Filters:").constrain {
width = 90.percent
x = 5.percent
y = 2.percent
textScale = 1.5.scaledPixels
color = Color.green.constraint
} childOf activeFiltersContainer

private val activeFiltersSearchBar: UITextInput = UITextInput("Search...").constrain {
width = 90.percent
height = 5.percent
x = 5.percent
y = 7.percent
}.onMouseClick {
grabWindowFocus()
}.onKeyType { _, _ ->
updateFilterList()
} as UITextInput childOf activeFiltersContainer

private val activeFiltersScrollComponent = ScrollComponent(
scrollIconColor = primaryColor.toJavaColor(),
innerPadding = 10f,
).constrain {
width = 100.percent
height = 90.percent
x = 0.percent
y = 10.percent
} childOf activeFiltersContainer


/**
* Presets Container
*/
private val presetsContainer = ThemeManager.currentBackgroundUIImage.constrain {
width = 60.percent
height = 20.percent
x = 40.percent
y = 80.percent
} childOf backgroundBox

private val presetButtons = RareDropGUIManager.presets.forEachIndexed { columnIndex, (presetName, items) ->
PSSButton()
.setText(presetName)
.setX((15 * columnIndex + 5).percent)
.setY(CenterConstraint())
.setHeight(50.pixels)
.setWidth(60.pixels)
.setChildOf(presetsContainer)
.onMouseClickConsumer {
RareDropGUIManager.addFilter(*items.toTypedArray())
updateFilterList()
}
}

init {
update()
}

private fun update() {
updateFilterList()
updateTitles()
}

private fun updateTitles() {
activeFiltersHeading.setText("${currentFilterType.displayName} Filters:")
createFilterButton.setText("Add ${currentFilterType.displayName} Filter")
switchTypeButton.setText("Switch to ${opposite.displayName}")
}

private fun updateFilterList() {
activeFiltersScrollComponent.clearChildren()

currentFilter
.filter { it.contains(activeFiltersSearchBar.getText(), ignoreCase = true) }
.forEach { filter ->
val xText = UIText("§cx").constrain {
x = 0.percent
y = SiblingConstraint(4f)
}.onMouseClick {
currentFilter -= filter
RareDropGUIManager.saveData()
updateFilterList()
} childOf activeFiltersScrollComponent

val filterText = UIText(filter).constrain {
x = 5.percent
y = CramSiblingConstraint()
} childOf activeFiltersScrollComponent

xText.onMouseEnter {
filterText.setText("§m$filter")
}.onMouseLeave {
filterText.setText(filter)
}
}
}
}
Loading

0 comments on commit 78b078b

Please sign in to comment.