Move mode change button to the side.

- Mode change now on the side w/ resize button
- Some code cleanup
- New description (en only for now), texture.
This commit is contained in:
Firenoo committed 2023-05-10 00:26:45 -07:00
1 parent 1c1b9bda29
commit dbf3cab144
9 files changed
+162 -86

No files matched your search

@@ -6,9 +6,10 @@ import com.projecturanus.betterp2p.capability.MemoryInfo
import com.projecturanus.betterp2p.client.ClientCache
import com.projecturanus.betterp2p.client.TextureBound
import com.projecturanus.betterp2p.client.gui.widget.*
import com.projecturanus.betterp2p.item.BetterMemoryCardModes
import com.projecturanus.betterp2p.item.MAX_TOOLTIP_LENGTH
import com.projecturanus.betterp2p.network.*
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.resources.I18n
@@ -16,7 +17,6 @@ import net.minecraft.util.ResourceLocation
import org.lwjgl.input.Keyboard
import org.lwjgl.input.Mouse
import org.lwjgl.opengl.GL11
import java.util.*
const val GUI_WIDTH = 288
const val GUI_TEX_HEIGHT = 264
@@ -39,9 +39,6 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
private val tableX = 9
private val tableY = 19
private var scale = msg.memoryInfo.gui
private val resizeButton: WidgetButton
private var _ySize: Lazy<Int> = lazy { 242 }
private var ySize: Int
get() = _ySize.value
@@ -49,6 +46,12 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
_ySize = lazy { value }
}
private var scale = msg.memoryInfo.gui
private val resizeButton: WidgetButton
private var mode = msg.memoryInfo.mode
private val modeButton: WidgetButton
private val scrollBar: WidgetScrollBar
private val searchBar: MEGuiTextField
@@ -59,10 +62,6 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
private var col: WidgetP2PColumn
private val descriptionLines: MutableList<String> = mutableListOf()
private var mode = msg.memoryInfo.mode
private var modeString = getModeString()
private val modeButton by lazy { GuiButton(0, 0, 0, 256, 20, modeString) }
private val sortRules: List<String> by lazy {
listOf(
"§b§n" + I18n.format("gui.advanced_memory_card.sortinfo1"),
@@ -84,7 +83,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
col = WidgetP2PColumn(this, infos,0, 0,
::selectedInfo, ::mode, scrollBar)
searchBar = MEGuiTextField(100, 10)
resizeButton = object: WidgetButton(this, 0, 0, 32, 32, { scale.unlocalizedName }) {
resizeButton = object: WidgetButton(this, 0, 0, 32, 32) {
override fun mousePressed(mouseX: Int, mouseY: Int) {
if (super.mousePressed(mc, mouseX, mouseY)) {
scale = when(scale) {
@@ -98,6 +97,39 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
}
}
}
modeButton = object: WidgetButton(this, 0, 0, 32, 32) {
val modeDescriptions: List<List<String>> = listOf(
fmtTooltips(
title = BetterMemoryCardModes.OUTPUT.unlocalizedName,
keys = BetterMemoryCardModes.OUTPUT.unlocalizedDesc,
maxChars = MAX_TOOLTIP_LENGTH,
),
fmtTooltips(
title = BetterMemoryCardModes.INPUT.unlocalizedName,
keys = BetterMemoryCardModes.INPUT.unlocalizedDesc,
maxChars = MAX_TOOLTIP_LENGTH,
),
fmtTooltips(
title = BetterMemoryCardModes.COPY.unlocalizedName,
keys = BetterMemoryCardModes.COPY.unlocalizedDesc,
maxChars = MAX_TOOLTIP_LENGTH,
)
)
init {
hoverText = modeDescriptions[mode.ordinal]
}
override fun mousePressed(mouseX: Int, mouseY: Int) {
if (super.mousePressed(mc, mouseX, mouseY)) {
mode = mode.next()
hoverText = modeDescriptions[mode.ordinal]
setTexCoords((mode.ordinal + 3) * 32.0, 232.0)
syncMemoryInfo()
super.func_146113_a(mc.soundHandler)
}
}
}
}
// Note this is called on resize too.
@@ -108,6 +140,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
if (scale.minHeight > h) {
scale = GuiScale.DYNAMIC
}
resizeButton.hoverText = listOf(I18n.format(scale.unlocalizedName))
val numEntries = scale.size(height - 75)
ySize = (numEntries * P2PEntryConstants.HEIGHT) + 75 + (numEntries - 1)
guiTop = (h - ySize) / 2
@@ -126,8 +159,8 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
col.resize(scale, h - 75)
col.setPosition(guiLeft + tableX, guiTop + tableY)
modeButton.xPosition = guiLeft + 8
modeButton.yPosition = guiTop + ySize - 52
modeButton.setPosition(guiLeft - 32, guiTop + 34)
modeButton.setTexCoords((mode.ordinal + 3) * 32.0, 232.0)
resizeButton.setPosition(guiLeft - 32, guiTop + 2)
resizeButton.setTexCoords(scale.ordinal * 32.0, 200.0)
@@ -140,8 +173,10 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
private fun checkInfo() {
infos.filtered.forEach { it.error = false }
// A P2P entry is considered "errored" if it is an output, and has no inputs.
infos.filtered.groupBy { it.frequency }.filter { it.value.none { x -> !x.output } }.forEach { it.value.forEach { info ->
info.error = true
infos.filtered.groupBy { it.frequency }
.filter { it.value.none { x -> !x.output } }
.forEach { it.value.forEach {
info -> info.error = true
} }
}
@@ -155,14 +190,6 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
ModNetwork.channel.sendToServer(C2SUpdateInfo(MemoryInfo(infos.selectedEntry, selectedInfo?.frequency ?: 0, mode, scale)))
}
private fun drawInformation() {
var y = 214
for (line in descriptionLines) {
fontRendererObj.drawString(line, guiLeft + 8, modeButton.yPosition + 20 + 3, 0)
y += fontRendererObj.FONT_HEIGHT
}
}
override fun onGuiClosed() {
ClientCache.searchText = searchBar.text
col.onGuiClosed()
@@ -175,16 +202,9 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
drawBackground()
// Draw the stuff that resets GL state first
fontRendererObj.drawString(I18n.format("item.advanced_memory_card.name"), guiLeft + tableX, guiTop + 6, 0)
if (modeButton.func_146115_a()) {
descriptionLines.clear()
descriptionLines += I18n.format("gui.advanced_memory_card.desc.mode", I18n.format("gui.advanced_memory_card.mode.${mode.next().name.lowercase(Locale.getDefault())}"))
} else {
descriptionLines.clear()
}
drawInformation()
searchBar.drawTextBox()
resizeButton.draw(mc, mouseX, mouseY, partialTicks)
modeButton.drawButton(mc, mouseX, mouseY)
modeButton.draw(mc, mouseX, mouseY, partialTicks)
// Now do our drawing
GL11.glPushAttrib(GL11.GL_BLEND or GL11.GL_TEXTURE_2D or GL11.GL_COLOR)
@@ -199,25 +219,15 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
if (searchBar.isMouseIn(mouseX, mouseY)) {
drawHoveringText(sortRules, guiLeft, guiTop + ySize - 40, fontRendererObj)
} else if (resizeButton.isHovering(mouseX, mouseY)) {
drawHoveringText(listOf(I18n.format(resizeButton.hoverText())), mouseX, mouseY, fontRendererObj)
drawHoveringText(resizeButton.hoverText, mouseX, mouseY, fontRendererObj)
} else if (modeButton.isHovering(mouseX, mouseY)) {
drawHoveringText(modeButton.hoverText, mouseX, mouseY, fontRendererObj)
} else {
col.mouseHovered(mouseX, mouseY)
}
super.drawScreen(mouseX, mouseY, partialTicks)
}
private fun switchMode() {
// Switch mode
mode = mode.next()
modeString = getModeString()
modeButton.displayString = modeString
syncMemoryInfo()
}
private fun getModeString(): String {
return I18n.format("gui.advanced_memory_card.mode.${mode.name.lowercase(Locale.getDefault())}")
}
/**
* Selects the info with the hashCode, if it exists. Otherwise,
* deselect the entry.
@@ -247,11 +257,8 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) {
col.mouseClicked(mouseX, mouseY, mouseButton)
if (modeButton.mousePressed(mc, mouseX, mouseY)) {
switchMode()
modeButton.func_146113_a(mc.soundHandler)
}
scrollBar.click(mouseX, mouseY)
modeButton.mousePressed(mouseX, mouseY)
resizeButton.mousePressed(mouseX, mouseY)
searchBar.mouseClicked(mouseX, mouseY, mouseButton)
if (mouseButton == 1 && searchBar.isMouseIn(mouseX, mouseY)) {
@@ -273,11 +280,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
override fun handleMouseInput() {
super.handleMouseInput()
val i = Mouse.getEventDWheel()
if (i != 0 && isShiftKeyDown()) {
// val x = Mouse.getEventX() * width / mc.displayWidth
// val y = height - Mouse.getEventY() * height / mc.displayHeight - 1
// this.mouseWheelEvent(x, y, i / Math.abs(i))
} else if (i != 0) {
if (i != 0) {
scrollBar.wheel(i)
col.finishRename()
}
@@ -335,3 +338,33 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
super.drawHoveringText(textLines, x, y, font)
}
}
/**
* Format multiple lines of tooltips by the given max chars.
*/
fun fmtTooltips(title: String, vararg keys: String, maxChars: Int): List<String> {
val result: MutableList<String> = mutableListOf()
result.add(I18n.format(title))
for (key in keys) {
val words = I18n.format(key).split(' ')
var i = 0
if (key.length < maxChars) {
result.add(key)
}
while (i < words.size) {
val s = StringBuilder()
perWord@
while (s.length < maxChars) {
s.append(words[i])
i += 1
if (i >= words.size) break@perWord
s.append(" ")
}
if (!s.startsWith('§')) {
s.insert(0, "§7")
}
result.add(s.toString())
}
}
return result
}
@@ -2,19 +2,13 @@ package com.projecturanus.betterp2p.client.gui
import appeng.api.parts.IPart
import appeng.api.parts.IPartItem
import appeng.api.parts.PartItemStack
import appeng.me.GridNode
import appeng.parts.p2p.PartP2PTunnel
import appeng.parts.p2p.PartP2PTunnelME
import appeng.tile.networking.TileCableBus
import com.projecturanus.betterp2p.network.P2PInfo
import com.projecturanus.betterp2p.network.hashP2P
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.resources.I18n
import net.minecraft.init.Blocks
import net.minecraft.item.ItemStack
import net.minecraft.util.IIcon
import net.minecraftforge.common.DimensionManager
import net.minecraftforge.common.util.ForgeDirection
class InfoWrapper(info: P2PInfo) {
@@ -53,7 +47,7 @@ class InfoWrapper(info: P2PInfo) {
}
}
val hoverInfo: List<String>
val hoverInfo: MutableList<String>
val channels: String? by lazy {
if (info.channels >= 0) {
@@ -65,6 +59,14 @@ class InfoWrapper(info: P2PInfo) {
var name: String = info.name
var error: Boolean = false
set(value) {
if (value) {
hoverInfo[4] = "§c" + I18n.format("gui.advanced_memory_card.p2p_status.unbound")
} else {
hoverInfo[4] = "§a" + I18n.format("gui.advanced_memory_card.p2p_status.bound")
}
field = value
}
// Widgets
val bindButton = GuiButton(0, 0, 0, 34, 20, I18n.format("gui.advanced_memory_card.bind"))
@@ -83,9 +85,9 @@ class InfoWrapper(info: P2PInfo) {
append(typeName)
append(" - ")
if (output)
append(I18n.format("gui.advanced_memory_card.desc.mode.output"))
append(I18n.format("gui.advanced_memory_card.p2p_status.output"))
else
append(I18n.format("gui.advanced_memory_card.desc.mode.input"))
append(I18n.format("gui.advanced_memory_card.p2p_status.input"))
}
val online = info.hasChannel
hoverInfo = mutableListOf(
@@ -112,9 +114,8 @@ class InfoWrapper(info: P2PInfo) {
"§e" + I18n.format("gui.advanced_memory_card.dim", info.world)
)
}
}
override fun hashCode(): Int {
return code.hashCode()
}
@@ -1,6 +1,5 @@
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
@@ -19,11 +18,12 @@ import org.lwjgl.opengl.GL11
* @param height
* @param hoverText - unlocalized text to display when mouse hovering
*/
abstract class WidgetButton(val gui: GuiAdvancedMemoryCard, x: Int, y: Int, width: Int, height: Int,
val hoverText: () -> String): GuiButton(0, x, y, width, height, "") {
abstract class WidgetButton(val gui: GuiAdvancedMemoryCard, x: Int, y: Int, width: Int, height: Int):
GuiButton(0, x, y, width, height, "") {
private var texX = 0.0
private var texY = 0.0
var hoverText: List<String> = listOf()
abstract fun mousePressed(mouseX: Int, mouseY: Int)
@@ -41,8 +41,8 @@ abstract class WidgetButton(val gui: GuiAdvancedMemoryCard, x: Int, y: Int, widt
u0 = (32.0 * k) / GUI_WIDTH, v0 = (232.0) / GUI_TEX_HEIGHT,
u1 = (32.0 * (k + 1)) / GUI_WIDTH, v1 = (232.0 + height) / GUI_TEX_HEIGHT)
// Draw button icon
drawTexturedQuad(tessellator, xPosition.toDouble(), yPosition.toDouble(),
(xPosition + width).toDouble(), (yPosition + height).toDouble(),
drawTexturedQuad(tessellator, xPosition + 1.0, yPosition + 1.0,
xPosition + width - 1.0, yPosition + height - 1.0,
u0 = texX / GUI_WIDTH, v0 = texY / GUI_TEX_HEIGHT,
u1 = (texX + width) / GUI_WIDTH, v1 = (texY + height) / GUI_TEX_HEIGHT)
@@ -20,6 +20,10 @@ object P2PEntryConstants {
const val LEFT_ALIGN = 24
}
val typeIcons: List<IIcon> = listOf(
)
class WidgetP2PDevice(private val selectedInfoProperty: KProperty0<InfoWrapper?>, val modeSupplier: () -> BetterMemoryCardModes, val infoSupplier: () -> InfoWrapper?, var x: Int, var y: Int): Widget() {
var renderNameTextField = true
@@ -45,7 +49,7 @@ class WidgetP2PDevice(private val selectedInfoProperty: KProperty0<InfoWrapper?>
}
GL11.glColor3f(255f, 255f, 255f)
// Draw our icons...
drawIcon(gui, info.icon!!, info.overlay!!, x + 3, y + 3)
drawIcon(gui, info.icon, info.overlay, x + 3, y + 3)
gui.bindTexture(gui.BACKGROUND)
if (info.output) {
drawTexturedQuad(Tessellator.instance, x.toDouble(), y + 4.0, x + 16.0, y + 20.0,
@@ -1,20 +1,36 @@
package com.projecturanus.betterp2p.item
enum class BetterMemoryCardModes {
import com.projecturanus.betterp2p.client.gui.fmtTooltips
const val MAX_TOOLTIP_LENGTH = 40
enum class BetterMemoryCardModes(val unlocalizedName: String, vararg val unlocalizedDesc: String) {
/**
* Select an input P2P and bind its output
*/
OUTPUT,
OUTPUT("gui.advanced_memory_card.mode.output",
"gui.advanced_memory_card.mode.output.desc.1",
"gui.advanced_memory_card.mode.output.desc.2",
"gui.advanced_memory_card.mode.output.desc.3"
),
/**
* Select an output P2P and bind its input
*/
INPUT,
INPUT("gui.advanced_memory_card.mode.input",
"gui.advanced_memory_card.mode.input.desc.1",
"gui.advanced_memory_card.mode.input.desc.2",
"gui.advanced_memory_card.mode.input.desc.3"
),
/**
* Copy same output frequency
*/
COPY;
COPY("gui.advanced_memory_card.mode.copy",
"gui.advanced_memory_card.mode.copy.desc.1",
"gui.advanced_memory_card.mode.copy.desc.2",
"gui.advanced_memory_card.mode.copy.desc.3",
);
fun next(): BetterMemoryCardModes {
return values()[ordinal.plus(1) % values().size]
@@ -2,13 +2,16 @@ package com.projecturanus.betterp2p.util
import appeng.api.config.SecurityPermissions
import appeng.api.networking.IGrid
import appeng.api.networking.IGridHost
import appeng.api.networking.security.ISecurityGrid
import appeng.api.parts.IPart
import appeng.api.parts.IPartHost
import appeng.api.parts.SelectedPart
import appeng.api.util.IReadOnlyCollection
import appeng.parts.AEBasePart
import appeng.parts.ICableBusContainer
import appeng.parts.p2p.PartP2PTunnel
import appeng.parts.p2p.PartP2PTunnelME
import appeng.tile.networking.TileCableBus
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.tileentity.TileEntity
@@ -51,6 +54,15 @@ fun listTargetGridP2P(grid: IGrid?, player: EntityPlayer, clazz: Class<out PartP
return grid?.getMachines(clazz)?.map { it.machine as PartP2PTunnel<*> }?.toList() ?: emptyList()
}
fun listAllGridP2P(grid: IGrid?, player: EntityPlayer): List<PartP2PTunnel<*>> {
if (grid is ISecurityGrid && !grid.hasPermission(player, SecurityPermissions.BUILD))
return emptyList()
val classes = grid?.machinesClasses?.filter { c -> c.superclass == PartP2PTunnel::class.java } ?: emptyList()
val ret: MutableList<PartP2PTunnel<*>> = mutableListOf()
classes.forEach{ c -> ret.addAll(grid?.getMachines(c)?.map { it.machine as PartP2PTunnel<*> } ?: emptyList()) }
return ret
}
val AEBasePart.facingPosX: Int?
get() =
host?.location?.x?.and(side?.offsetX ?: EnumFacing.UP.frontOffsetX)
@@ -4,6 +4,7 @@ import appeng.api.networking.IGrid
import appeng.parts.p2p.PartP2PTunnel
import appeng.parts.p2p.PartP2PTunnelME
import com.projecturanus.betterp2p.network.hashP2P
import com.projecturanus.betterp2p.util.listAllGridP2P
import com.projecturanus.betterp2p.util.listTargetGridP2P
import net.minecraft.entity.player.EntityPlayer
@@ -11,8 +12,12 @@ class P2PStatus(player: EntityPlayer, grid: IGrid, val targetP2P: PartP2PTunnel<
val listP2P: MutableMap<Long, PartP2PTunnel<*>> = mutableMapOf()
init {
listTargetGridP2P(grid, player, targetP2P?.javaClass ?: PartP2PTunnelME::class.java)
.forEach { listP2P[hashP2P(it)] = it }
if (targetP2P == null) {
listAllGridP2P(grid, player).forEach { listP2P[hashP2P(it)] = it }
} else {
listTargetGridP2P(grid, player, targetP2P.javaClass)
.forEach { listP2P[hashP2P(it)] = it }
}
}
}
@@ -13,19 +13,24 @@ gui.advanced_memory_card.sortinfo4=Show Bound P2Ps only
gui.advanced_memory_card.sortinfo5=Show Unbound P2Ps only
gui.advanced_memory_card.sortinfo6=Tags are space separated and are combined w/ the AND operator.
gui.advanced_memory_card.extra.channel=Channels used: %s
gui.advanced_memory_card.mode.input=Mode: Bind Input
gui.advanced_memory_card.mode.output=Mode: Bind Output
gui.advanced_memory_card.mode.copy=Mode: Copy Output
gui.advanced_memory_card.desc.mode=Switch to %s
gui.advanced_memory_card.desc.mode.input=Input
gui.advanced_memory_card.desc.mode.output=Output
gui.advanced_memory_card.mode.input=Current Mode: Bind to §9Input
gui.advanced_memory_card.mode.input.desc.1=• Before binding, the §aselected §aP2P §7and §bbind §btarget §7have their connections removed.
gui.advanced_memory_card.mode.input.desc.2=• The §aselected P2P §7becomes the the §6output§7, while the §bbind §btarget §7becomes the §9input§7.
gui.advanced_memory_card.mode.input.desc.3=• The §aselected P2P §7becomes the same type as its new input.
gui.advanced_memory_card.mode.output=Current Mode: Bind to §6Output
gui.advanced_memory_card.mode.output.desc.1=• Before binding, the §aselected §aP2P §7and §bbind §btarget §7have their connections removed.
gui.advanced_memory_card.mode.output.desc.2=• The §aselected P2P §7becomes the the §9input§7, while the §bbind §btarget §7becomes the §6output§7.
gui.advanced_memory_card.mode.output.desc.3=• The §bbind target §7becomes the same type as its new input.
gui.advanced_memory_card.mode.copy=Current Mode: Copy §6Output
gui.advanced_memory_card.mode.copy.desc.1=• Before binding, the §bbind §btarget §7has its connections removed.
gui.advanced_memory_card.mode.copy.desc.2=• The §aselected §aP2P §7becomes the §9input§7, while the §bbind §btarget §7is added to the list of the §aselected §aP2P's §6outputs§7.
gui.advanced_memory_card.mode.copy.desc.3=• The §bbind target §7becomes the same type as its new input.
gui.advanced_memory_card.desc.not_set=Not set
gui.advanced_memory_card.desc.effect=Effect:
gui.advanced_memory_card.gui_scale.resize=Resize
gui.advanced_memory_card.gui_scale.small=Small
gui.advanced_memory_card.gui_scale.normal=Standard
gui.advanced_memory_card.gui_scale.large=Large
gui.advanced_memory_card.gui_scale.dynamic=Automatic
gui.advanced_memory_card.gui_scale.small=Current Size: Small
gui.advanced_memory_card.gui_scale.normal=Current Size: Standard
gui.advanced_memory_card.gui_scale.large=Current Size: Large
gui.advanced_memory_card.gui_scale.dynamic=Current Size: Automatic
gui.advanced_memory_card.p2p_status.bound=Bound
gui.advanced_memory_card.p2p_status.unbound=Unbound
gui.advanced_memory_card.p2p_status.input=Input
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB