Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: indicator offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Commander07 committed Nov 24, 2023
1 parent 9dadddf commit cda5358
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 42 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loaderVersion = 0.14.22
fabricVersion = 0.89.2+1.20.2
loomVersion = 1.4-SNAPSHOT
# Mod Properties
modVersion = 0.2.14-1.20.2
modVersion = 0.2.15-1.20.2
mavenGroup = io.github.nbcss
archivesBaseName = wynnlib
# Kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ private void renderSideTimers(DrawContext context) {
return;
List<SideIndicator> timers = IndicatorManager.INSTANCE.getSideTimers();
Collections.sort(timers);
int posX = 3;
int posY = (client.getWindow().getScaledHeight() - 11 * timers.size()) / 2;
int posX = 3 + Settings.INSTANCE.getOffset(Settings.SettingOffset.SIDE_INDICATOR_X);
int posY = (client.getWindow().getScaledHeight() - 11 * timers.size()) / 2 + Settings.INSTANCE.getOffset(Settings.SettingOffset.SIDE_INDICATOR_Y);
for (SideIndicator timer : timers) {
timer.render(context, getTextRenderer(), posX, posY);
posY += 11;
Expand All @@ -59,8 +59,8 @@ private void renderIconTimers(DrawContext context, float delta) {
return;
List<IconIndicator> timers = IndicatorManager.INSTANCE.getIconTimers();
//unit = 28 per timer
int posX = client.getWindow().getScaledWidth() / 2 - timers.size() * 14;
int posY = client.getWindow().getScaledHeight() - 108;
int posX = client.getWindow().getScaledWidth() / 2 - timers.size() * 14 + Settings.INSTANCE.getOffset(Settings.SettingOffset.ICON_INDICATOR_X);
int posY = client.getWindow().getScaledHeight() - 108 + Settings.INSTANCE.getOffset(Settings.SettingOffset.ICON_INDICATOR_Y);
RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
RenderSystem.texParameter(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
for (IconIndicator timer : timers) {
Expand Down
33 changes: 33 additions & 0 deletions src/main/kotlin/io/github/nbcss/wynnlib/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object Settings {
private val lockedSlots: MutableSet<Int> = mutableSetOf()
private val indicators: MutableMap<String, Boolean> = mutableMapOf()
private val options: MutableMap<SettingOption, Boolean> = mutableMapOf()
private val offsets: MutableMap<SettingOffset, Int> = mutableMapOf()
private var isTester: Boolean = false
private var dirty: Boolean = false
private var saving: Boolean = false
Expand All @@ -63,6 +64,10 @@ object Settings {
for (option in SettingOption.values()) {
options[option] = getOr(it, option.id, option.defaultValue)
}
offsets.clear()
for (offset in SettingOffset.values()) {
offsets[offset] = getOr(it, offset.id, offset.defaultValue)
}
MatcherType.reload(getOr(it, "matchers", JsonObject()) { x -> x.asJsonObject })
indicators.clear()
for (entry in (getOr(it, "indicators", JsonObject()) { x -> x.asJsonObject }).entrySet()) {
Expand All @@ -87,6 +92,9 @@ object Settings {
for (option in SettingOption.values()) {
data.addProperty(option.id, getOption(option))
}
for (offset in SettingOffset.values()) {
data.addProperty(offset.id, getOffset(offset))
}
data.add("matchers", MatcherType.getData())
val indicatorsJson = JsonObject()
indicators.forEach { (k, v) -> indicatorsJson.add(k, JsonPrimitive(v)) }
Expand Down Expand Up @@ -172,6 +180,15 @@ object Settings {
return options.getOrDefault(option, option.defaultValue)
}

fun setOffset(offset: SettingOffset, value: Int) {
offsets[offset] = value
markDirty()
}

fun getOffset(offset: SettingOffset): Int {
return offsets.getOrDefault(offset, offset.defaultValue)
}

fun setIndicatorEnabled(key: String, enabled: Boolean) {
indicators[key] = enabled
markDirty()
Expand Down Expand Up @@ -210,4 +227,20 @@ object Settings {
return "wynnlib.setting_option.name.$key"
}
}

enum class SettingOffset(val id: String,
val defaultValue: Int): Keyed, Translatable {
ICON_INDICATOR_X("icon_indicator_x", 0),
ICON_INDICATOR_Y("icon_indicator_y", 0),
SIDE_INDICATOR_X("side_indicator_x", 0),
SIDE_INDICATOR_Y("side_indicator_y", 0),
;

override fun getKey(): String = id

override fun getTranslationKey(label: String?): String {
val key = id.lowercase()
return "wynnlib.setting_offset.name.$key"
}
}
}
57 changes: 34 additions & 23 deletions src/main/kotlin/io/github/nbcss/wynnlib/gui/ConfigurationScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.github.nbcss.wynnlib.gui.widgets.*
import io.github.nbcss.wynnlib.gui.widgets.buttons.*
import io.github.nbcss.wynnlib.gui.widgets.scrollable.CheckboxWidget
import io.github.nbcss.wynnlib.gui.widgets.scrollable.LabelWidget
import io.github.nbcss.wynnlib.gui.widgets.scrollable.TextFieldWidget
import io.github.nbcss.wynnlib.i18n.Translations
import io.github.nbcss.wynnlib.items.identity.TooltipProvider
import io.github.nbcss.wynnlib.matcher.MatcherType
Expand All @@ -13,13 +14,12 @@ import io.github.nbcss.wynnlib.timer.status.StatusType
import io.github.nbcss.wynnlib.utils.ItemFactory
import io.github.nbcss.wynnlib.utils.formattingLines
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.Element
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.item.ItemStack
import net.minecraft.text.Text
import net.minecraft.util.Formatting
import java.util.function.Supplier
import javax.swing.text.Element

class ConfigurationScreen(parent: Screen?) : GenericScrollScreen(parent, TITLE) {
companion object {
Expand All @@ -35,6 +35,7 @@ class ConfigurationScreen(parent: Screen?) : GenericScrollScreen(parent, TITLE)
}
private val categories: MutableList<SettingCategory> = CategoryEnum.values().toMutableList()
private val sideTabs: MutableList<SideTabWidget> = mutableListOf()
private val sideTabChildren: MutableList<Element> = mutableListOf()
private var category: SettingCategory = CategoryEnum.GENERAL
private var scroll: ScrollPaneWidget? = null

Expand All @@ -49,6 +50,7 @@ class ConfigurationScreen(parent: Screen?) : GenericScrollScreen(parent, TITLE)
SideTabWidget.Side.LEFT, category.getIcon(), object : SideTabWidget.Handler {
override fun onClick(index: Int) {
this@ConfigurationScreen.category = categories[index]
sideTabChildren.forEach { remove(it) }
scroll = this@ConfigurationScreen.category.createScroll(this@ConfigurationScreen)
slider?.setSlider(0.0)
}
Expand Down Expand Up @@ -119,6 +121,18 @@ class ConfigurationScreen(parent: Screen?) : GenericScrollScreen(parent, TITLE)
return Translations.SETTINGS_INDICATORS.translate()
}

override fun getIcon(): ItemStack = icon
},
OFFSETS{
private val icon: ItemStack = ItemFactory.fromEncoding("minecraft:compass")
override fun createScroll(screen: ConfigurationScreen): ScrollPaneWidget {
return screen.OffsetScroll()
}

override fun getDisplayText(): Text {
return Translations.SETTINGS_OFFSETS.translate()
}

override fun getIcon(): ItemStack = icon
}
}
Expand Down Expand Up @@ -159,14 +173,6 @@ class ConfigurationScreen(parent: Screen?) : GenericScrollScreen(parent, TITLE)
setContentHeight(posY + 2)
}
override fun getSlider(): VerticalSliderWidget? = slider

override fun setFocused(focused: Boolean) {
TODO("Not yet implemented")
}

override fun isFocused(): Boolean {
TODO("Not yet implemented")
}
}

inner class GeneralScroll: ElementsContainerScroll(null, this@ConfigurationScreen,
Expand Down Expand Up @@ -195,14 +201,6 @@ class ConfigurationScreen(parent: Screen?) : GenericScrollScreen(parent, TITLE)
setContentHeight(posY + 2)
}
override fun getSlider(): VerticalSliderWidget? = slider

override fun setFocused(focused: Boolean) {
TODO("Not yet implemented")
}

override fun isFocused(): Boolean {
TODO("Not yet implemented")
}
}

inner class IndicatorScroll: ElementsContainerScroll(null, this@ConfigurationScreen,
Expand All @@ -227,13 +225,26 @@ class ConfigurationScreen(parent: Screen?) : GenericScrollScreen(parent, TITLE)
setContentHeight(posY + 2)
}
override fun getSlider(): VerticalSliderWidget? = slider
}

override fun setFocused(focused: Boolean) {
TODO("Not yet implemented")
inner class OffsetScroll: ElementsContainerScroll(null, this@ConfigurationScreen,
scrollX, scrollY, SCROLL_WIDTH, SCROLL_HEIGHT) {
init {
val posX = 2
var posY = 2
for (offset in Settings.SettingOffset.values()) {
val textField = TextFieldWidget(textRenderer, scrollX + posX, scrollY + posY, 40, 12)
textField.text = Settings.getOffset(offset).toString()
textField.setChangedListener { it.toIntOrNull()?.let { x -> Settings.setOffset(offset, x) } }
sideTabChildren.add(addDrawableChild(textField))
addElement(LabelWidget(posX + 42, posY, Supplier {
return@Supplier offset.formatted(Formatting.GRAY)
}))
posY += 20
}
setContentHeight(posY + 2)
}

override fun isFocused(): Boolean {
TODO("Not yet implemented")
}
override fun getSlider(): VerticalSliderWidget? = slider
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ package io.github.nbcss.wynnlib.gui.dicts.filter
import io.github.nbcss.wynnlib.items.BaseItem
import io.github.nbcss.wynnlib.gui.dicts.sorter.SorterGroup

class SortersContainer<T: BaseItem>(memory: CriteriaState<T>,
sorters: List<SorterGroup>): CriteriaGroup<T>(memory) {
abstract class SortersContainer<T: BaseItem>(memory: CriteriaState<T>,
sorters: List<SorterGroup>): CriteriaGroup<T>(memory) {

init {

}

override fun reload(memory: CriteriaState<T>) {
TODO("Not yet implemented")
}
override fun getHeight(): Int {
TODO("Not yet implemented")
}

class Builder {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AdvanceSearchPaneWidget<T: BaseItem>(private val screen: DictionaryScreen<
//}

override fun appendClickableNarrations(builder: NarrationMessageBuilder?) {
TODO("Not yet implemented")
// todo
}

override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.github.nbcss.wynnlib.gui.TooltipScreen
import io.github.nbcss.wynnlib.gui.widgets.scrollable.ScrollElement
import io.github.nbcss.wynnlib.render.TextureData
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.Drawable
import net.minecraft.client.gui.Element
import net.minecraft.client.util.math.MatrixStack

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ class ConfirmButtonWidget(private val handler: Consumer<ConfirmButtonWidget>,
}

override fun appendClickableNarrations(builder: NarrationMessageBuilder?) {
TODO("Not yet implemented")
// todo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ExitButtonWidget(x: Int, y: Int, private val handler: ExitHandler):
}

override fun appendClickableNarrations(builder: NarrationMessageBuilder?) {
TODO("Not yet implemented")
// todo
}

interface ExitHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ class ItemSlotWidget<T: BaseItem>(x: Int, y: Int,
}

override fun appendClickableNarrations(builder: NarrationMessageBuilder?) {
TODO("Not yet implemented")
// todo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CheckboxWidget(private val posX: Int,
}

override fun appendClickableNarrations(builder: NarrationMessageBuilder?) {
TODO("Not yet implemented")
// todo
}

override fun renderButton(context: DrawContext?, mouseX: Int, mouseY: Int, delta: Float) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.nbcss.wynnlib.gui.widgets.scrollable

import net.minecraft.client.font.TextRenderer
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.widget.TextFieldWidget
import net.minecraft.text.Text

class TextFieldWidget(textRenderer: TextRenderer?, private val posX: Int,
private val posY: Int, width: Int, height: Int) :
TextFieldWidget(textRenderer, posX, posY, width, height, Text.empty()), ScrollElement {
private var interactable: Boolean = true

override fun updateState(x: Int, y: Int, active: Boolean) {
this.x = posX + x
this.y = posY + y
this.interactable = active
}

override fun renderButton(context: DrawContext?, mouseX: Int, mouseY: Int, delta: Float) {
context?.matrices?.translate(0.0,0.0,100.0)
super.renderButton(context, mouseX, mouseY, delta)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object Translations {
val SETTINGS_GENERAL: Translatable = from("wynnlib.setting_category.general")
val SETTINGS_MATCHERS: Translatable = from("wynnlib.setting_category.matchers")
val SETTINGS_INDICATORS: Translatable = from("wynnlib.setting_category.indicators")
val SETTINGS_OFFSETS: Translatable = from("wynnlib.setting_category.offsets")
val MATCHER_ITEM_PROTECTION: Translatable = from("wynnlib.matcher_settings.item_protection")
val TOOLTIP_CLASS_REQ: Translatable = from("wynnlib.tooltip.class_req")
val TOOLTIP_QUEST_REQ: Translatable = from("wynnlib.tooltip.quest_req")
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/wynnlib/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"wynnlib.setting_category.general": "General",
"wynnlib.setting_category.matchers": "Matchers",
"wynnlib.setting_category.indicators": "Indicators",
"wynnlib.setting_category.offsets": "Offsets",
"wynnlib.setting_option.name.durability": "Render Durability Bar",
"wynnlib.setting_option.desc.durability": "Rendering durability bar on crafted items.",
"wynnlib.setting_option.name.emerald_pouch_bar": "Render Emerald Pouch Bar",
Expand All @@ -72,6 +73,10 @@
"wynnlib.setting_option.desc.icon_indicator": "Turn on stats indicator (icon) above the hotbar",
"wynnlib.setting_option.name.starred_item_protect": "Protect Starred Items",
"wynnlib.setting_option.desc.starred_item_protect": "Loot chest will not able to close when have starred items inside",
"wynnlib.setting_offset.name.icon_indicator_x": "Icon indicator X",
"wynnlib.setting_offset.name.icon_indicator_y": "Icon indicator y",
"wynnlib.setting_offset.name.side_indicator_x": "Side indicator X",
"wynnlib.setting_offset.name.side_indicator_y": "Side indicator y",
"wynnlib.matcher_settings.item_protection": "Item Protection",
"wynnlib.tier.mythic": "Mythic",
"wynnlib.tier.fabled": "Fabled",
Expand Down

0 comments on commit cda5358

Please sign in to comment.