Skip to content

Commit

Permalink
cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
LasmGratel committed Jun 6, 2024
1 parent 245e4f4 commit 4046632
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 72 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Crowdin integration
- Chinese (Simplified) localization
- Search bar tooltip

### Removed

- Cleanup unused code


## [1.4.1] - 2024-05-21

### Fixed
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,21 @@ class GuiAdvancedMemoryCard(val theMenu: AdvancedMemoryCardMenu) :

val scrollBar = WidgetScrollBar(tableX, tableY)

val searchBar: EditBox by lazy { EditBox(font, 0, 0, 100, 10, Component.empty()) }
val searchBar: EditBox by lazy {
object : EditBox(font, 0, 0, 100, 10, Component.empty()), ITooltip {
override fun getTooltipMessage(): MutableList<Component> {
return sortRules.asSequence().map { Component.literal(it) }.toMutableList()
}

override fun getTooltipArea(): Rect2i {
return Rect2i(x, y, width, height)
}

override fun isTooltipAreaVisible(): Boolean {
return isVisible
}
}
}
val modeButton = IconButton((mode.ordinal + 3) * 32, 232, ::onChangeMode)

val col = WidgetP2PColumn(this, infos, 0, 0, ::selectedInfo, ::mode, scrollBar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ enum class Filter(val pattern: Regex, val filter: (InfoWrapper, List<String>?) -
"\\A@types*=(.+)\\z".toRegex(),
filter@{ it, strs ->
val tags =
dev.lasm.betterp2p.BetterP2P.proxy.getP2PFromIndex(it.type)!!.dispName.toLowerCase()
dev.lasm.betterp2p.BetterP2P.proxy.getP2PFromIndex(it.type)!!.dispName.lowercase()
for (f in strs!!) {
if (tags.contains(f.toLowerCase())) {
if (tags.contains(f.lowercase())) {
return@filter true
}
}
Expand All @@ -82,7 +82,7 @@ enum class Filter(val pattern: Regex, val filter: (InfoWrapper, List<String>?) -
NAME(
"\"?.+\"?".toRegex(),
filter@{ it, strs ->
val name = it.name.toLowerCase()
val name = it.name.lowercase()
for (f in strs!!) {
// Ppl better not troll and use double quotes in their P2P tunnel names
val query = f.removeSurrounding("\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class InfoWrapper(info: P2PInfo) {
var name: String = info.name
var error: Boolean = false

// val icon: ResourceLocation? = ResourceLocation("appliedenergistics2",
// "textures/blocks/quartz_block.png")
// val overlay: ResourceLocation? = ResourceLocation("appliedenergistics2",
// "textures/items/part/p2p_tunnel_front.png")
/** The backing p2p icon/feature */
var icon: ResourceLocation

Expand Down
29 changes: 17 additions & 12 deletions common/src/main/kotlin/dev/lasm/betterp2p/client/gui/Infolist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,23 @@ class InfoList(initList: Collection<InfoWrapper>, private val search: KProperty0

fun resort() {
sorted.sortBy {
if (it.loc == selectedEntry) {
-2 // Put the selected p2p in the front
// Non-Zero frequencies
} else if (
it.frequency != 0.toShort() && it.frequency == selectedInfo?.frequency && !it.output
) {
-3 // Put input in the beginning
} else if (it.frequency != 0.toShort() && it.frequency == selectedInfo?.frequency) {
-1 // Put same frequency in the front
} else {
// Frequencies from lowest to highest
it.frequency + Short.MAX_VALUE
when {
it.loc == selectedEntry -> {
-2 // Put the selected p2p in the front
// Non-Zero frequencies
}
it.frequency != 0.toShort() &&
it.frequency == selectedInfo?.frequency &&
!it.output -> {
-3 // Put input in the beginning
}
it.frequency != 0.toShort() && it.frequency == selectedInfo?.frequency -> {
-1 // Put same frequency in the front
}
else -> {
// Frequencies from lowest to highest
it.frequency + Short.MAX_VALUE
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.resources.language.I18n

private const val s = "gui.advanced_memory_card.types.filtered"

class P2PTypeButton(
val type: KProperty0<ClientTunnelInfo?>,
onPress: OnPress,
Expand Down Expand Up @@ -67,11 +69,10 @@ class P2PTypeButton(
}

override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
var bl: Boolean
if (!this.active || !this.visible) {
return false
}
if ((clicked(d, e).also { bl = it })) {
if ((clicked(d, e))) {
if (i == 0) {
this.playDownSound(Minecraft.getInstance().soundManager)
this.onClick(d, e)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class WidgetP2PDevice(
}
.size(56, 20)
.build()
// val renameBar: EditBox = EditBox(font, 120, 12, 0, 0, Component.empty())
val unbindButton: Button =
Button.builder(Component.translatable("gui.advanced_memory_card.unbind")) {
col.onUnbindButtonClicked(infoSupplier()!!)
Expand All @@ -78,32 +77,32 @@ class WidgetP2PDevice(
return
}

if (selectedInfo == null) {
// No selected, so we don't show buttons
bindButton.visible = false
unbindButton.visible = false
} else if (mode == BetterMemoryCardModes.UNBIND) {
// Only unbinds allowed in unbind mode
bindButton.visible = false
unbindButton.visible = info.frequency != 0.toShort()
} else if (
mode == BetterMemoryCardModes.COPY &&
((!info.output && info.frequency != 0.toShort()) || selectedInfo!!.output)
) {
// Copy mode
// If this info is (input && set freq) || selected info is an output
// Disable all buttons
bindButton.visible = false
unbindButton.visible = false
} else {
// Other modes:
// Bind allowed only if currently not selected && selected is unbound; OR not bound to
// selected
bindButton.visible =
info.loc != selectedInfo!!.loc &&
(selectedInfo!!.frequency == 0.toShort() ||
info.frequency != selectedInfo!!.frequency)
unbindButton.visible = false
when {
selectedInfo == null ||
mode == BetterMemoryCardModes.COPY &&
((!info.output && info.frequency != 0.toShort()) || selectedInfo!!.output) -> {
// Copy mode
// If this info is (input && set freq) || selected info is an output
// Disable all buttons
bindButton.visible = false
unbindButton.visible = false
}
mode == BetterMemoryCardModes.UNBIND -> {
// Only unbinds allowed in unbind mode
bindButton.visible = false
unbindButton.visible = info.frequency != 0.toShort()
}
else -> {
// Other modes:
// Bind allowed only if currently not selected && selected is unbound; OR not bound
// to
// selected
bindButton.visible =
info.loc != selectedInfo!!.loc &&
(selectedInfo!!.frequency == 0.toShort() ||
info.frequency != selectedInfo!!.frequency)
unbindButton.visible = false
}
}
}

Expand Down Expand Up @@ -159,21 +158,20 @@ class WidgetP2PDevice(
}
}

if (isHovered) {
if (
if (
isHovered &&
mouseX > x.toDouble() + 50 &&
mouseX < x.toDouble() + 50 + 160 &&
mouseY > y.toDouble() + 1 &&
mouseY < y.toDouble() + 1 + 13
) {
graphics.fill(
x + 50,
y + 1,
x + 50 + 160,
y + 1 + 12,
0x6E000000 // ARGB xd
)
}
mouseX < x.toDouble() + 50 + 160 &&
mouseY > y.toDouble() + 1 &&
mouseY < y.toDouble() + 1 + 13
) {
graphics.fill(
x + 50,
y + 1,
x + 50 + 160,
y + 1 + 12,
0x6E000000 // ARGB xd
)
}

graphics.setColor(1.0f, 1.0f, 1.0f, 1.0f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object ItemAdvancedMemoryCard :
) {
val info = getInfo(stack)
list.add(
Component.translatable("gui.advanced_memory_card.mode.${info.mode.name.toLowerCase()}")
Component.translatable("gui.advanced_memory_card.mode.${info.mode.name.lowercase()}")
)
}

Expand Down

0 comments on commit 4046632

Please sign in to comment.