Add a texture for the resize button.

Add CN localization for tooltip
This commit is contained in:
Firenoo committed 2023-03-21 19:32:25 -07:00
1 parent 887e8b2593
commit 0c61ee40aa
5 files changed
+54 -14

No files matched your search

@@ -17,7 +17,7 @@ import org.lwjgl.input.Mouse
import java.util.*
const val GUI_WIDTH = 288
const val GUI_TEX_HEIGHT = 200
const val GUI_TEX_HEIGHT = 264
class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
private lateinit var _guiLeft: Lazy<Int>
@@ -81,7 +81,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
col = WidgetP2PColumn(this, infos,0, 0,
::selectedInfo, ::mode, scrollBar)
searchBar = MEGuiTextField(100, 10)
resizeButton = object: WidgetButton(0, 0, 32, 32, { "gui.advanced_memory_card.gui_scale.resize" }) {
resizeButton = object: WidgetButton(this, 0, 0, 32, 32, { scale.unlocalizedName }) {
override fun mousePressed(mouseX: Int, mouseY: Int) {
if (super.mousePressed(mc, mouseX, mouseY)) {
scale = when(scale) {
@@ -127,6 +127,8 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
modeButton.yPosition = guiTop + ySize - 52
resizeButton.setPosition(guiLeft - 32, guiTop + 2)
resizeButton.setTexCoords(scale.ordinal * 32.0, 200.0)
infos.refresh()
checkInfo()
refreshOverlay()
@@ -172,7 +174,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
searchBar.drawTextBox()
col.render(this, mouseX, mouseY, partialTicks)
modeButton.drawButton(mc, mouseX, mouseY)
resizeButton.draw(mouseX, mouseY, partialTicks)
resizeButton.draw(mc, mouseX, mouseY, partialTicks)
fontRendererObj.drawString(I18n.format("item.advanced_memory_card.name"), guiLeft + tableX, guiTop + 6, 0)
if (modeButton.func_146115_a()) {
descriptionLines.clear()
@@ -288,8 +290,8 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
}
// Draw Bottom
tessellator.startDrawingQuads()
tessellator.addVertexWithUV(guiLeft.toDouble(), (guiTop + ySize).toDouble(), 0.0, 0.0, 1.0)
tessellator.addVertexWithUV(((guiLeft + GUI_WIDTH).toDouble()), (guiTop + ySize).toDouble(), 0.0, 1.0, 1.0)
tessellator.addVertexWithUV(guiLeft.toDouble(), (guiTop + ySize).toDouble(), 0.0, 0.0, 200.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(((guiLeft + GUI_WIDTH).toDouble()), (guiTop + ySize).toDouble(), 0.0, 1.0, 200.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV((guiLeft + GUI_WIDTH).toDouble(), guiTop + ySize - 98.0, 0.0, 1.0, 102.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop + ySize - 98.0, 0.0, 0.0, 102.0 / GUI_TEX_HEIGHT)
tessellator.draw()
@@ -1,8 +1,8 @@
package com.projecturanus.betterp2p.client.gui.widget
enum class GuiScale(inline val size: (Int) -> Int, val minHeight: Int) {
SMALL({ 4 }, 0),
NORMAL({ 6 }, 326),
LARGE({ 8 }, 409),
DYNAMIC({ availableHeight -> availableHeight / P2P_ENTRY_HEIGHT }, 0)
enum class GuiScale(inline val size: (Int) -> Int, val minHeight: Int, val unlocalizedName: String) {
SMALL({ 4 }, 0, "gui.advanced_memory_card.gui_scale.small"),
NORMAL({ 6 }, 326, "gui.advanced_memory_card.gui_scale.normal"),
LARGE({ 8 }, 409, "gui.advanced_memory_card.gui_scale.large"),
DYNAMIC({ availableHeight -> availableHeight / P2P_ENTRY_HEIGHT }, 0, "gui.advanced_memory_card.gui_scale.dynamic")
}
@@ -1,6 +1,14 @@
package com.projecturanus.betterp2p.client.gui.widget
import com.projecturanus.betterp2p.MODID
import com.projecturanus.betterp2p.client.gui.GUI_TEX_HEIGHT
import com.projecturanus.betterp2p.client.gui.GUI_WIDTH
import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.renderer.OpenGlHelper
import net.minecraft.client.renderer.Tessellator
import org.lwjgl.opengl.GL11
/**
* Widget button for stuff.
@@ -10,20 +18,46 @@ import net.minecraft.client.gui.GuiButton
* @param height
* @param hoverText - unlocalized text to display when mouse hovering
*/
abstract class WidgetButton(x: Int, y: Int, private var width: Int, private var height: Int,
abstract class WidgetButton(val gui: GuiAdvancedMemoryCard, x: Int, y: Int, width: Int, height: Int,
val hoverText: () -> String): GuiButton(0, x, y, width, height, "") {
private var texX = 0.0
private var texY = 0.0
abstract fun mousePressed(mouseX: Int, mouseY: Int)
fun draw(mouseX: Int, mouseY: Int, partial: Float) {
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xFF shl 24)
fun draw(mc: Minecraft?, mouseX: Int, mouseY: Int, partialTicks: Float) {
val tessellator = Tessellator.instance
gui.bindTexture(MODID, "textures/gui/advanced_memory_card.png")
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f)
field_146123_n = mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height
val k = getHoverState(field_146123_n)
GL11.glEnable(GL11.GL_BLEND)
OpenGlHelper.glBlendFunc(770, 771, 1, 0)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
tessellator.startDrawingQuads()
tessellator.addVertexWithUV(xPosition.toDouble(), (yPosition + height).toDouble(), 0.0, (32.0 * k) / GUI_WIDTH, (232.0 + height) / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(((xPosition + width).toDouble()), (yPosition + height).toDouble(), 0.0, (32.0 * (k + 1)) / GUI_WIDTH, (232.0 + height) / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV((xPosition + width).toDouble(), yPosition.toDouble(), 0.0, (32.0 * (k + 1)) / GUI_WIDTH, 232.0 / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(xPosition.toDouble(), yPosition.toDouble(), 0.0, (32.0 * k) / GUI_WIDTH, 232.0 / GUI_TEX_HEIGHT)
tessellator.draw()
tessellator.startDrawingQuads()
tessellator.addVertexWithUV(xPosition.toDouble(), (yPosition + height).toDouble(), 0.0, texX / GUI_WIDTH, (texY + height) / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(((xPosition + width).toDouble()), (yPosition + height).toDouble(), 0.0, (texX + width) / GUI_WIDTH, (texY + height) / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV((xPosition + width).toDouble(), yPosition.toDouble(), 0.0, (texX + width) / GUI_WIDTH, texY / GUI_TEX_HEIGHT)
tessellator.addVertexWithUV(xPosition.toDouble(), yPosition.toDouble(), 0.0, texX / GUI_WIDTH, texY / GUI_TEX_HEIGHT)
tessellator.draw()
}
fun setPosition(x: Int, y: Int) {
this.xPosition = x
this.yPosition = y
}
fun setTexCoords(x: Double, y: Double) {
this.texX = x
this.texY = y
}
fun setSize(width: Int, height: Int) {
this.width = width
this.height = height
@@ -13,3 +13,7 @@ gui.advanced_memory_card.desc.mode.input=输入
gui.advanced_memory_card.desc.mode.output=输出
gui.advanced_memory_card.desc.not_set=未配置
gui.advanced_memory_card.desc.effect=效果:
gui.advanced_memory_card.gui_scale.small=小
gui.advanced_memory_card.gui_scale.normal=中
gui.advanced_memory_card.gui_scale.large=大
gui.advanced_memory_card.gui_scale.dynamic=自动
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB