forked from Wybxc/IngameIME-Minecraft
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
95 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Architectury Transformer DEBUG] Closed File Systems for E:\java\IngameIME-Forge\common\build\libs\IngameIME-Forge-mc1.20.x-1.0.4.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 30 additions & 22 deletions
52
common/src/main/kotlin/city/windmill/ingameime/client/gui/widget/CandidateListWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,84 @@ | ||
package city.windmill.ingameime.client.gui.widget | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack | ||
import net.minecraft.client.gui.Font | ||
import net.minecraft.client.gui.GuiGraphics | ||
|
||
|
||
class CandidateListWidget(font: Font) : Widget(font) { | ||
var candidates: Array<String>? = null | ||
|
||
private val drawItem = CandidateEntry(font) | ||
|
||
override val active get() = !candidates.isNullOrEmpty() | ||
override val width | ||
get() = super.width + candidates!!.sumOf { s -> drawItem.apply { this.text = s }.width } | ||
override val height | ||
get() = super.height + font.lineHeight | ||
override val padding: Pair<Int, Int> | ||
get() = 1 to 3 | ||
|
||
@Suppress("NAME_SHADOWING") | ||
override fun draw(poseStack: PoseStack, offsetX: Int, offsetY: Int, mouseX: Int, mouseY: Int, delta: Float) { | ||
override fun draw(guiGraphics: GuiGraphics, offsetX: Int, offsetY: Int, mouseX: Int, mouseY: Int, delta: Float) { | ||
candidates?.let { | ||
super.draw(poseStack, offsetX, offsetY, mouseX, mouseY, delta) | ||
super.draw(guiGraphics, offsetX, offsetY, mouseX, mouseY, delta) | ||
|
||
var offsetX = offsetX + padding.first | ||
val offsetY = offsetY + padding.second | ||
var index = 1 | ||
for (str in it) { | ||
drawItem.index = index | ||
drawItem.text = str | ||
drawItem.draw(poseStack, offsetX, offsetY, mouseX, mouseY, delta) | ||
drawItem.draw(guiGraphics, offsetX, offsetY, mouseX, mouseY, delta) | ||
offsetX += drawItem.width | ||
index++ | ||
} | ||
} | ||
} | ||
|
||
class CandidateEntry(font: Font) : Widget(font) { | ||
var text: String? = null | ||
var index = 0 | ||
|
||
private val indexWidth = font.width("00") + 5 | ||
|
||
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") | ||
override val width | ||
get() = super.width + font.width(text) + indexWidth | ||
override val height | ||
get() = super.height + font.lineHeight | ||
override val padding: Pair<Int, Int> | ||
get() = 2 to 3 | ||
|
||
@Suppress("NAME_SHADOWING", "NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") | ||
override fun draw(poseStack: PoseStack, offsetX: Int, offsetY: Int, mouseX: Int, mouseY: Int, delta: Float) { | ||
override fun draw( | ||
guiGraphics: GuiGraphics, | ||
offsetX: Int, | ||
offsetY: Int, | ||
mouseX: Int, | ||
mouseY: Int, | ||
delta: Float | ||
) { | ||
var offsetX = offsetX + padding.first | ||
drawCenteredString(poseStack, font, index.toString(), offsetX + indexWidth / 2, offsetY, textColor) | ||
drawCenteredString(guiGraphics, font, index.toString(), offsetX + indexWidth / 2, offsetY, textColor) | ||
offsetX += indexWidth | ||
font.draw(poseStack, text, offsetX.toFloat(), offsetY.toFloat(), textColor) | ||
guiGraphics.drawString(font, text, offsetX, offsetY, textColor) | ||
} | ||
|
||
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") | ||
private fun drawCenteredString( | ||
poseStack: PoseStack, | ||
guiGraphics: GuiGraphics, | ||
font: Font, | ||
text: String?, | ||
centerX: Int, | ||
y: Int, | ||
color: Int | ||
) { | ||
font.draw( | ||
poseStack, text, | ||
(centerX - font.width(text) / 2).toFloat(), y.toFloat(), color | ||
guiGraphics.drawString( | ||
font, | ||
text, | ||
(centerX - font.width(text) / 2), y, color | ||
) | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.