mirror of
https://github.com/GTNewHorizons/BetterP2P.git
synced 2026-11-24 22:04:32 +00:00
Adv. Memory Card: Add resizable GUI capability.
Part 0 of GUI overhaul. Adds a way to resize the Advanced Memory Card's GUI. 4 modes: - Small: 4 entries - Normal: 6 entries - Large: 10 entries - Dynamic (default): As many entries as the screen can fit So far only Dynamic is used with no way to switch to the others.
This commit is contained in:
1 parent
6d7bb23b80
commit
0809143b8e
7 files changed
+294
-161
No files matched your search
@@ -1,54 +1,65 @@
|
||||
package com.projecturanus.betterp2p.client.gui
|
||||
|
||||
import appeng.client.gui.widgets.MEGuiTextField
|
||||
import com.projecturanus.betterp2p.BetterP2P
|
||||
import com.projecturanus.betterp2p.MODID
|
||||
import com.projecturanus.betterp2p.capability.MemoryInfo
|
||||
import com.projecturanus.betterp2p.capability.P2PTunnelInfo
|
||||
import com.projecturanus.betterp2p.client.ClientCache
|
||||
import com.projecturanus.betterp2p.client.TextureBound
|
||||
import com.projecturanus.betterp2p.client.gui.widget.IGuiTextField
|
||||
import com.projecturanus.betterp2p.client.gui.widget.WidgetP2PDevice
|
||||
import com.projecturanus.betterp2p.client.gui.widget.WidgetScrollBar
|
||||
import com.projecturanus.betterp2p.item.BetterMemoryCardModes
|
||||
import com.projecturanus.betterp2p.client.gui.widget.*
|
||||
import com.projecturanus.betterp2p.network.*
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.gui.GuiButton
|
||||
import net.minecraft.client.gui.GuiScreen
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
import net.minecraft.client.resources.I18n
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import org.lwjgl.input.Keyboard
|
||||
import org.lwjgl.input.Mouse
|
||||
import java.util.*
|
||||
|
||||
const val GUI_WIDTH = 288
|
||||
const val GUI_TEX_HEIGHT = 200
|
||||
class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
|
||||
private val xSize = 288
|
||||
private val ySize = 242
|
||||
private val guiLeft: Int by lazy { (width - this.xSize) / 2 }
|
||||
private val guiTop: Int by lazy { (height - this.ySize) / 2 }
|
||||
private lateinit var _guiLeft: Lazy<Int>
|
||||
private var guiLeft: Int
|
||||
get() = _guiLeft.value
|
||||
set(value) {
|
||||
_guiLeft = lazyOf(value)
|
||||
}
|
||||
|
||||
private lateinit var _guiTop: Lazy<Int>
|
||||
private var guiTop: Int
|
||||
get() = _guiTop.value
|
||||
set(value) {
|
||||
_guiTop = lazyOf(value)
|
||||
}
|
||||
|
||||
private val tableX = 9
|
||||
private val tableY = 19
|
||||
|
||||
private lateinit var scrollBar: WidgetScrollBar
|
||||
private lateinit var searchBar: MEGuiTextField
|
||||
private lateinit var renameBar: IGuiTextField
|
||||
private val scale = GuiScale.DYNAMIC
|
||||
|
||||
private var infos = InfoList(msg.infos.map(::InfoWrapper), ::searchText)
|
||||
private var _ySize: Lazy<Int> = lazy { 242 }
|
||||
private var ySize: Int
|
||||
get() = _ySize.value
|
||||
set(value) {
|
||||
_ySize = lazy { value }
|
||||
}
|
||||
|
||||
private var scrollBar: WidgetScrollBar
|
||||
private lateinit var searchBar: MEGuiTextField
|
||||
|
||||
private val infos = InfoList(msg.infos.map(::InfoWrapper), ::searchText)
|
||||
|
||||
private val searchText: String
|
||||
get() = searchBar.text
|
||||
|
||||
private val widgetDevices: List<WidgetP2PDevice>
|
||||
// private var infoOnScreen: List<InfoWrapper>
|
||||
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, guiLeft + 8, guiTop + 190, 256, 20, modeString) }
|
||||
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"),
|
||||
@@ -65,34 +76,38 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
|
||||
init {
|
||||
infos.select(msg.memoryInfo.selectedEntry)
|
||||
val list = mutableListOf<WidgetP2PDevice>()
|
||||
// TODO: Expand this selection to >4 for larger screens
|
||||
for (i in 0..3) {
|
||||
list += WidgetP2PDevice(::selectedInfo, ::mode, { infos.filtered.getOrNull(i + scrollBar.currentScroll) }, 0, 0)
|
||||
}
|
||||
widgetDevices = list.toList()
|
||||
scrollBar = WidgetScrollBar(0, 0)
|
||||
col = WidgetP2PColumn(this, infos,0, 0,
|
||||
::selectedInfo, ::mode, scrollBar)
|
||||
}
|
||||
|
||||
// Note this is called on resize too.
|
||||
override fun initGui() {
|
||||
super.initGui()
|
||||
checkInfo()
|
||||
renameBar = IGuiTextField(0,0)
|
||||
renameBar.setMaxStringLength(50)
|
||||
scrollBar = WidgetScrollBar()
|
||||
searchBar = MEGuiTextField(65, 10)
|
||||
searchBar.setMaxStringLength(25)
|
||||
searchBar.x = guiLeft + 198
|
||||
searchBar.y = guiTop + 5
|
||||
val h = height.coerceAtLeast(256)
|
||||
val numEntries = scale.size(h - 75)
|
||||
ySize = (numEntries * P2P_ENTRY_HEIGHT) + 75 + (numEntries - 1)
|
||||
guiTop = (h - ySize) / 2
|
||||
guiLeft = (width - GUI_WIDTH) / 2
|
||||
|
||||
scrollBar.displayX = guiLeft + 268
|
||||
scrollBar.displayY = guiTop + 19
|
||||
scrollBar.height = 150
|
||||
scrollBar.setRange(0, infos.size.coerceIn(0..(infos.size - 4).coerceAtLeast(0)), 23)
|
||||
scrollBar.height = numEntries * P2P_ENTRY_HEIGHT + (numEntries - 1)
|
||||
scrollBar.setRange(0, infos.size.coerceIn(0, (infos.size - numEntries).coerceAtLeast(0)), 23)
|
||||
|
||||
for (i in 0..3) {
|
||||
widgetDevices[i].x = guiLeft + tableX
|
||||
widgetDevices[i].y = guiTop + tableY + 42 * i
|
||||
}
|
||||
searchBar = MEGuiTextField(100, 10)
|
||||
searchBar.setMaxStringLength(40)
|
||||
searchBar.x = guiLeft + 163
|
||||
searchBar.y = guiTop + 5
|
||||
searchBar.text = ClientCache.searchText
|
||||
|
||||
col.resize(scale, h - 75)
|
||||
col.setPosition(guiLeft + tableX, guiTop + tableY)
|
||||
|
||||
modeButton.xPosition = guiLeft + 8
|
||||
modeButton.yPosition = guiTop + ySize - 52
|
||||
|
||||
infos.refresh()
|
||||
checkInfo()
|
||||
refreshOverlay()
|
||||
@@ -117,17 +132,16 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
}
|
||||
|
||||
private fun drawInformation() {
|
||||
val x = 8
|
||||
var y = 214
|
||||
for (line in descriptionLines) {
|
||||
fontRendererObj.drawString(line, guiLeft + x, guiTop + y, 0)
|
||||
fontRendererObj.drawString(line, guiLeft + 8, modeButton.yPosition + 20 + 3, 0)
|
||||
y += fontRendererObj.FONT_HEIGHT
|
||||
}
|
||||
}
|
||||
|
||||
override fun onGuiClosed() {
|
||||
ClientCache.searchText = searchBar.text
|
||||
saveP2PChannel()
|
||||
col.onGuiClosed()
|
||||
syncMemoryInfo()
|
||||
ModNetwork.channel.sendToServer(C2SCloseGui())
|
||||
}
|
||||
@@ -137,11 +151,9 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
drawBackground()
|
||||
scrollBar.draw(this)
|
||||
searchBar.drawTextBox()
|
||||
for (widget in widgetDevices) {
|
||||
widget.render(this, mouseX, mouseY, partialTicks)
|
||||
}
|
||||
col.render(this, mouseX, mouseY, partialTicks)
|
||||
modeButton.drawButton(mc, mouseX, mouseY)
|
||||
|
||||
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())}"))
|
||||
@@ -149,8 +161,6 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
descriptionLines.clear()
|
||||
}
|
||||
drawInformation()
|
||||
if(renameBar.isVisible && !renameBar.isFocused) renameBar.setFocus(true)
|
||||
renameBar.drawTextBox()
|
||||
if (searchBar.isMouseIn(mouseX, mouseY)) {
|
||||
drawHoveringText(sortRules, guiLeft, guiTop + ySize - 40, fontRendererObj)
|
||||
}
|
||||
@@ -169,14 +179,11 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
return I18n.format("gui.advanced_memory_card.mode.${mode.name.lowercase(Locale.getDefault())}")
|
||||
}
|
||||
|
||||
private fun findInput(frequency: Long?) =
|
||||
infos.filtered.find { it.frequency == frequency && !it.output }
|
||||
|
||||
/**
|
||||
* Selects the info with the hashCode, if it exists. Otherwise,
|
||||
* deselect the entry.
|
||||
*/
|
||||
private fun selectInfo(hash: Long) {
|
||||
fun selectInfo(hash: Long) {
|
||||
infos.select(hash)
|
||||
syncMemoryInfo()
|
||||
refreshOverlay()
|
||||
@@ -195,88 +202,13 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
ClientCache.positions.addAll(infos.sorted.filter { it.frequency == selectedInfo?.frequency && it != selectedInfo }.map { arrayListOf(it.posX, it.posY, it.posZ) to it.facing })
|
||||
}
|
||||
|
||||
private fun onSelectButtonClicked(info: InfoWrapper) {
|
||||
selectInfo(info.code)
|
||||
}
|
||||
private fun onRenameButtonClicked(info:InfoWrapper,index: Int){
|
||||
if(isShiftKeyDown()) {
|
||||
return transportPlayer(info)
|
||||
}
|
||||
renameBar.isVisible = true
|
||||
renameBar.y = (this.guiTop + this.tableY) + index * 42 + 19
|
||||
renameBar.x = this.guiLeft + 60
|
||||
renameBar.w = 120
|
||||
renameBar.h = 12
|
||||
renameBar.text = info.name
|
||||
renameBar.setFocus(true,0)
|
||||
renameBar.info = info
|
||||
}
|
||||
|
||||
private fun saveP2PChannel(){
|
||||
for (widget in widgetDevices){
|
||||
widget.renderNameTextField = true
|
||||
}
|
||||
if(renameBar.info != null && renameBar.info.name != renameBar.text){
|
||||
val info:InfoWrapper = renameBar.info
|
||||
renameBar.text = renameBar.text.trim()
|
||||
ModNetwork.channel.sendToServer(C2SP2PTunnelInfo(P2PTunnelInfo(info.posX,info.posY,info.posZ,info.dim, ForgeDirection.valueOf(info.facing.name).ordinal,renameBar.text)))
|
||||
}
|
||||
renameBar.isVisible = false
|
||||
renameBar.text = ""
|
||||
renameBar.setFocus(false)
|
||||
renameBar.info = null
|
||||
}
|
||||
|
||||
private fun onBindButtonClicked(info: InfoWrapper) {
|
||||
if (infos.selectedEntry == NONE) return
|
||||
when (mode) {
|
||||
BetterMemoryCardModes.INPUT -> {
|
||||
BetterP2P.logger.debug("Bind ${info.code} as input")
|
||||
ModNetwork.channel.sendToServer(C2SLinkP2P(info.code, infos.selectedEntry))
|
||||
}
|
||||
BetterMemoryCardModes.OUTPUT -> {
|
||||
BetterP2P.logger.debug("Bind ${info.code} as output")
|
||||
ModNetwork.channel.sendToServer(C2SLinkP2P(infos.selectedEntry, info.code))
|
||||
}
|
||||
BetterMemoryCardModes.COPY -> {
|
||||
val input = findInput(selectedInfo?.frequency)
|
||||
if (input != null)
|
||||
ModNetwork.channel.sendToServer(C2SLinkP2P(input.code, info.code))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun transportPlayer(info: InfoWrapper){
|
||||
Minecraft.getMinecraft().thePlayer.closeScreen()
|
||||
ModNetwork.channel.sendToServer(C2STransportPlayer(P2PTunnelInfo(info.posX,info.posY,info.posZ,info.dim,0)))
|
||||
}
|
||||
|
||||
|
||||
override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) {
|
||||
var clickRenameButton = false
|
||||
for ((index,widget) in widgetDevices.withIndex()) {
|
||||
val info = widget.infoSupplier()
|
||||
if (info?.selectButton?.mousePressed(mc, mouseX, mouseY) == true) {
|
||||
onSelectButtonClicked(widget.infoSupplier()!!)
|
||||
} else if (info?.bindButton?.mousePressed(mc, mouseX, mouseY) == true) {
|
||||
onBindButtonClicked(widget.infoSupplier()!!)
|
||||
} else if (info?.renameButton?.mousePressed(mc, mouseX,mouseY) == true) {
|
||||
if(renameBar.info != widget.infoSupplier()!!)
|
||||
saveP2PChannel()
|
||||
widget.renderNameTextField = false
|
||||
onRenameButtonClicked(widget.infoSupplier()!!,index)
|
||||
clickRenameButton = true
|
||||
}
|
||||
}
|
||||
if(!clickRenameButton && renameBar.isVisible){
|
||||
saveP2PChannel()
|
||||
}
|
||||
col.mouseClicked(mouseX, mouseY, mouseButton)
|
||||
if (modeButton.mousePressed(mc, mouseX, mouseY)) {
|
||||
switchMode()
|
||||
}
|
||||
scrollBar.click(mouseX, mouseY)
|
||||
searchBar.mouseClicked(mouseX, mouseY, mouseButton)
|
||||
renameBar.mouseClicked(mouseX,mouseY,mouseButton)
|
||||
if (mouseButton == 1 && searchBar.isMouseIn(mouseX, mouseY)) {
|
||||
this.searchBar.text = ""
|
||||
infos.refilter()
|
||||
@@ -298,7 +230,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
// this.mouseWheelEvent(x, y, i / Math.abs(i))
|
||||
} else if (i != 0) {
|
||||
scrollBar.wheel(i)
|
||||
saveP2PChannel()
|
||||
col.finishRename()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,15 +242,29 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
private fun drawBackground() {
|
||||
bindTexture(MODID, "textures/gui/advanced_memory_card.png")
|
||||
val tessellator = Tessellator.instance
|
||||
val f = 1f / this.xSize.toFloat()
|
||||
val f1 = 1f / this.ySize.toFloat()
|
||||
val u = 0
|
||||
val v = 0
|
||||
// Draw the top part
|
||||
tessellator.startDrawingQuads()
|
||||
tessellator.addVertexWithUV(guiLeft.toDouble(), (guiTop + this.ySize).toDouble(), 0.0, (u.toFloat() * f).toDouble(), ((v + this.ySize).toFloat() * f1).toDouble())
|
||||
tessellator.addVertexWithUV(((guiLeft + this.xSize).toDouble()), ((guiTop + this.ySize).toDouble()), 0.0, ((u + this.xSize).toFloat() * f).toDouble(), ((v + this.ySize).toFloat() * f1).toDouble())
|
||||
tessellator.addVertexWithUV((guiLeft + this.xSize).toDouble(), guiTop.toDouble(), 0.0, ((u + this.xSize).toFloat() * f).toDouble(), (v.toFloat() * f1).toDouble())
|
||||
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop.toDouble(), 0.0, (u.toFloat() * f).toDouble(), (v.toFloat() * f1).toDouble())
|
||||
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop + 60.0, 0.0, 0.0, 60.0 / GUI_TEX_HEIGHT)
|
||||
tessellator.addVertexWithUV(((guiLeft + GUI_WIDTH).toDouble()), guiTop + 60.0, 0.0, 1.0, 60.0 / GUI_TEX_HEIGHT)
|
||||
tessellator.addVertexWithUV((guiLeft + GUI_WIDTH).toDouble(), guiTop.toDouble(), 0.0, 1.0, 0.0)
|
||||
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop.toDouble(), 0.0, 0.0, 0.0)
|
||||
tessellator.draw()
|
||||
// Draw P2P segments
|
||||
val p2pHeight = P2P_ENTRY_HEIGHT + 1.0
|
||||
for (i in 0 until scale.size(ySize - 75) - 2) {
|
||||
tessellator.startDrawingQuads()
|
||||
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop + 60.0 + p2pHeight * (i + 1), 0.0, 0.0, 102.0 / GUI_TEX_HEIGHT)
|
||||
tessellator.addVertexWithUV(((guiLeft + GUI_WIDTH).toDouble()), guiTop + 60.0 + p2pHeight * (i + 1), 0.0, 1.0, 102.0 / GUI_TEX_HEIGHT)
|
||||
tessellator.addVertexWithUV((guiLeft + GUI_WIDTH).toDouble(), guiTop + 60.0 + p2pHeight * i, 0.0, 1.0, 60.0 / GUI_TEX_HEIGHT)
|
||||
tessellator.addVertexWithUV(guiLeft.toDouble(), guiTop + 60.0 + p2pHeight * i, 0.0, 0.0, 60.0 / GUI_TEX_HEIGHT)
|
||||
tessellator.draw()
|
||||
}
|
||||
// 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 + 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()
|
||||
}
|
||||
|
||||
@@ -328,13 +274,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
|
||||
override fun keyTyped(char: Char, key: Int) {
|
||||
if(key == Keyboard.KEY_LSHIFT) return
|
||||
if(renameBar.isFocused){
|
||||
if(key == Keyboard.KEY_RETURN){
|
||||
saveP2PChannel()
|
||||
}else{
|
||||
renameBar.textboxKeyTyped(char, key)
|
||||
}
|
||||
}else if (!(char.isWhitespace() && searchBar.text.isEmpty()) && searchBar.textboxKeyTyped(char, key)){
|
||||
if (!col.keyTyped(char, key) && !(char.isWhitespace() && searchBar.text.isEmpty()) && searchBar.textboxKeyTyped(char, key)){
|
||||
infos.refilter()
|
||||
}
|
||||
return super.keyTyped(char, key)
|
||||
|
||||
@@ -108,6 +108,7 @@ class InfoList (initList: Collection<InfoWrapper>,
|
||||
* Updates the sorted list and applies the filter again.
|
||||
*/
|
||||
fun refresh() {
|
||||
sorted.clear()
|
||||
sorted.addAll(masterMap.values)
|
||||
resort()
|
||||
refilter()
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.projecturanus.betterp2p.client.gui.widget
|
||||
|
||||
enum class GuiScale(inline val size: (Int) -> Int) {
|
||||
SMALL({ 4 }),
|
||||
NORMAL({ 6 }),
|
||||
LARGE({ 10 }),
|
||||
DYNAMIC({ availableHeight -> availableHeight / P2P_ENTRY_HEIGHT})
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.projecturanus.betterp2p.client.gui.widget
|
||||
|
||||
import com.projecturanus.betterp2p.BetterP2P
|
||||
import com.projecturanus.betterp2p.capability.P2PTunnelInfo
|
||||
import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard
|
||||
import com.projecturanus.betterp2p.client.gui.InfoList
|
||||
import com.projecturanus.betterp2p.client.gui.InfoWrapper
|
||||
import com.projecturanus.betterp2p.item.BetterMemoryCardModes
|
||||
import com.projecturanus.betterp2p.network.*
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import org.lwjgl.input.Keyboard
|
||||
import kotlin.reflect.KProperty0
|
||||
|
||||
/**
|
||||
* WidgetP2PColumn
|
||||
*
|
||||
* A widget that contains a list of P2P entries.
|
||||
*/
|
||||
class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard,
|
||||
private val infos: InfoList,
|
||||
private var x: Int, private var y: Int,
|
||||
private val selectedInfo: KProperty0<InfoWrapper?>,
|
||||
val mode: () -> BetterMemoryCardModes,
|
||||
private var scrollBar: WidgetScrollBar) {
|
||||
|
||||
private val entries: MutableList<WidgetP2PDevice> = mutableListOf()
|
||||
private val renameBar: IGuiTextField = IGuiTextField(0,0)
|
||||
|
||||
init {
|
||||
renameBar.setMaxStringLength(50)
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize the column
|
||||
*/
|
||||
fun resize(scale: GuiScale, availableHeight: Int) {
|
||||
entries.clear()
|
||||
for (i in 0 until scale.size(availableHeight)) {
|
||||
val widget = WidgetP2PDevice( selectedInfo, mode,
|
||||
{ infos.filtered.getOrNull(i + scrollBar.currentScroll) },
|
||||
x, y + i * (P2P_ENTRY_HEIGHT + 1))
|
||||
entries.add(widget)
|
||||
}
|
||||
scrollBar.setRange(0, entries.size, 23)
|
||||
}
|
||||
|
||||
fun setPosition(x: Int, y: Int) {
|
||||
this.x = x
|
||||
this.y = y
|
||||
for ((i, entry) in entries.withIndex()) {
|
||||
entry.x = x
|
||||
entry.y = y + i * (P2P_ENTRY_HEIGHT + 1)
|
||||
}
|
||||
}
|
||||
|
||||
fun finishRename(){
|
||||
for (widget in entries){
|
||||
widget.renderNameTextField = true
|
||||
}
|
||||
if(renameBar.info != null && renameBar.info.name != renameBar.text){
|
||||
val info:InfoWrapper = renameBar.info
|
||||
renameBar.text = renameBar.text.trim()
|
||||
ModNetwork.channel.sendToServer(C2SP2PTunnelInfo(P2PTunnelInfo(info.posX,info.posY,info.posZ,info.dim, ForgeDirection.valueOf(info.facing.name).ordinal,renameBar.text)))
|
||||
}
|
||||
renameBar.isVisible = false
|
||||
renameBar.text = ""
|
||||
renameBar.setFocus(false)
|
||||
renameBar.info = null
|
||||
}
|
||||
|
||||
//private fun transportPlayer(info: InfoWrapper){
|
||||
// Minecraft.getMinecraft().thePlayer.closeScreen()
|
||||
// ModNetwork.channel.sendToServer(C2STransportPlayer(P2PTunnelInfo(info.posX,info.posY,info.posZ,info.dim,0)))
|
||||
//}
|
||||
|
||||
private fun onRenameButtonClicked(info:InfoWrapper, index: Int) {
|
||||
// if (GuiScreen.isShiftKeyDown()) {
|
||||
// transportPlayer(info)
|
||||
// }
|
||||
renameBar.isVisible = true
|
||||
renameBar.y = (this.y) + index * (P2P_ENTRY_HEIGHT + 1) + 19
|
||||
renameBar.x = this.x + 50
|
||||
renameBar.w = 120
|
||||
renameBar.h = 12
|
||||
renameBar.text = info.name
|
||||
renameBar.setFocus(true,0)
|
||||
renameBar.info = info
|
||||
}
|
||||
|
||||
private fun onSelectButtonClicked(info: InfoWrapper) {
|
||||
gui.selectInfo(info.code)
|
||||
}
|
||||
|
||||
private fun onBindButtonClicked(info: InfoWrapper) {
|
||||
if (infos.selectedEntry == NONE) return
|
||||
when (mode()) {
|
||||
BetterMemoryCardModes.INPUT -> {
|
||||
BetterP2P.logger.debug("Bind ${info.code} as input")
|
||||
ModNetwork.channel.sendToServer(C2SLinkP2P(info.code, infos.selectedEntry))
|
||||
}
|
||||
BetterMemoryCardModes.OUTPUT -> {
|
||||
BetterP2P.logger.debug("Bind ${info.code} as output")
|
||||
ModNetwork.channel.sendToServer(C2SLinkP2P(infos.selectedEntry, info.code))
|
||||
}
|
||||
BetterMemoryCardModes.COPY -> {
|
||||
val input = findInput(infos.selectedInfo?.frequency)
|
||||
if (input != null)
|
||||
ModNetwork.channel.sendToServer(C2SLinkP2P(input.code, info.code))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun findInput(frequency: Long?) =
|
||||
infos.filtered.find { it.frequency == frequency && !it.output }
|
||||
|
||||
fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) {
|
||||
var clickRenameButton = false
|
||||
for ((index,widget) in entries.withIndex()) {
|
||||
val info = widget.infoSupplier()
|
||||
if (info?.selectButton?.mousePressed(gui.mc, mouseX, mouseY) == true) {
|
||||
onSelectButtonClicked(widget.infoSupplier()!!)
|
||||
} else if (info?.bindButton?.mousePressed(gui.mc, mouseX, mouseY) == true) {
|
||||
onBindButtonClicked(widget.infoSupplier()!!)
|
||||
} else if (info?.renameButton?.mousePressed(gui.mc, mouseX,mouseY) == true) {
|
||||
if(renameBar.info != widget.infoSupplier()!!) {
|
||||
finishRename()
|
||||
}
|
||||
widget.renderNameTextField = false
|
||||
onRenameButtonClicked(widget.infoSupplier()!!, index)
|
||||
clickRenameButton = true
|
||||
}
|
||||
}
|
||||
renameBar.mouseClicked(mouseX,mouseY,mouseButton)
|
||||
if(!clickRenameButton && renameBar.isVisible) {
|
||||
finishRename()
|
||||
}
|
||||
}
|
||||
|
||||
fun keyTyped(char: Char, key: Int): Boolean {
|
||||
if(renameBar.isFocused){
|
||||
if(key == Keyboard.KEY_RETURN){
|
||||
finishRename()
|
||||
}else{
|
||||
renameBar.textboxKeyTyped(char, key)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun render(gui: GuiAdvancedMemoryCard, mouseX: Int, mouseY: Int, partialTicks: Float) {
|
||||
for (widget in entries) {
|
||||
widget.render(gui, mouseX, mouseY, partialTicks)
|
||||
}
|
||||
renameBar.drawTextBox()
|
||||
}
|
||||
|
||||
fun onGuiClosed() {
|
||||
finishRename()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.projecturanus.betterp2p.client.gui.widget
|
||||
import appeng.me.GridNode
|
||||
import appeng.parts.p2p.PartP2PTunnelME
|
||||
import appeng.tile.networking.TileCableBus
|
||||
import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard
|
||||
import com.projecturanus.betterp2p.client.gui.InfoWrapper
|
||||
import com.projecturanus.betterp2p.item.BetterMemoryCardModes
|
||||
import net.minecraft.client.gui.GuiScreen
|
||||
@@ -12,39 +13,38 @@ import net.minecraftforge.common.util.ForgeDirection
|
||||
import java.awt.Color
|
||||
import kotlin.reflect.KProperty0
|
||||
|
||||
const val P2P_ENTRY_HEIGHT: Int = 41
|
||||
const val P2P_ENTRY_WIDTH: Int = 254
|
||||
|
||||
class WidgetP2PDevice(private val selectedInfoProperty: KProperty0<InfoWrapper?>, val modeSupplier: () -> BetterMemoryCardModes, val infoSupplier: () -> InfoWrapper?, var x: Int, var y: Int): Widget() {
|
||||
private val outputColor = 0x4566ccff
|
||||
private val selectedColor = 0x4545DA75
|
||||
private val errorColor = 0x45DA4527
|
||||
private val inactiveColor = 0x45FFEA05
|
||||
|
||||
private val rowWidth = 254
|
||||
private val rowHeight = 41
|
||||
var renderNameTextField = true
|
||||
|
||||
private val selectedInfo: InfoWrapper?
|
||||
get() = selectedInfoProperty.get()
|
||||
|
||||
|
||||
fun render(gui: GuiScreen, mouseX: Int, mouseY: Int, partialTicks: Float) {
|
||||
fun render(gui: GuiAdvancedMemoryCard, mouseX: Int, mouseY: Int, partialTicks: Float) {
|
||||
val info = infoSupplier()
|
||||
if (info != null) {
|
||||
val fontRenderer = gui.mc.fontRenderer
|
||||
if (selectedInfo?.code == info.code)
|
||||
GuiScreen.drawRect(x, y, x + rowWidth, y + rowHeight, selectedColor)
|
||||
GuiScreen.drawRect(x, y, x + P2P_ENTRY_WIDTH, y + P2P_ENTRY_HEIGHT, selectedColor)
|
||||
else if (info.error) {
|
||||
// P2P output without an input
|
||||
GuiScreen.drawRect(x, y, x + rowWidth, y + rowHeight, errorColor)
|
||||
GuiScreen.drawRect(x, y, x + P2P_ENTRY_WIDTH, y + P2P_ENTRY_HEIGHT, errorColor)
|
||||
}
|
||||
else if (!info.hasChannel && info.frequency != 0.toLong()) {
|
||||
// No channel
|
||||
GuiScreen.drawRect(x, y, x + rowWidth, y + rowHeight, inactiveColor)
|
||||
GuiScreen.drawRect(x, y, x + P2P_ENTRY_WIDTH, y + P2P_ENTRY_HEIGHT, inactiveColor)
|
||||
}
|
||||
else if (selectedInfo?.frequency == info.frequency && info.frequency != 0.toLong()) {
|
||||
// Show same frequency
|
||||
GuiScreen.drawRect(x, y, x + rowWidth, y + rowHeight, outputColor)
|
||||
GuiScreen.drawRect(x, y, x + P2P_ENTRY_WIDTH, y + P2P_ENTRY_HEIGHT, outputColor)
|
||||
}
|
||||
|
||||
fontRenderer.drawString(info.description, x + 24, y + 3, 0)
|
||||
fontRenderer.drawString(I18n.format("gui.advanced_memory_card.pos", info.posX, info.posY, info.posZ, info.facing.name), x + 24, y + 12, 0)
|
||||
if(renderNameTextField) {
|
||||
@@ -90,10 +90,10 @@ class WidgetP2PDevice(private val selectedInfoProperty: KProperty0<InfoWrapper?>
|
||||
}
|
||||
|
||||
private fun drawButtons(gui: GuiScreen, info: InfoWrapper, mouseX: Int, mouseY: Int, partialTicks: Float) {
|
||||
info.renameButton.xPosition = x
|
||||
info.renameButton.width = rowWidth
|
||||
info.renameButton.yPosition = y
|
||||
info.renameButton.height = rowHeight
|
||||
info.renameButton.xPosition = x + 50
|
||||
info.renameButton.width = 120
|
||||
info.renameButton.yPosition = y + 19
|
||||
info.renameButton.height = 12
|
||||
if (!info.bindButton.enabled && info.selectButton.enabled) {
|
||||
info.bindButton.enabled = false
|
||||
info.selectButton.enabled = true
|
||||
@@ -124,6 +124,30 @@ class WidgetP2PDevice(private val selectedInfoProperty: KProperty0<InfoWrapper?>
|
||||
}
|
||||
}
|
||||
|
||||
// For a future feature ;P
|
||||
|
||||
// private fun drawIcon(gui: GuiAdvancedMemoryCard, posX: Int, posY: Int, posZ: Int, face: ForgeDirection, world: Int) {
|
||||
// val tile = DimensionManager.getWorld(world)?.getTileEntity(posX, posY, posZ)
|
||||
// if (tile is TileCableBus) {
|
||||
// val p2p = (tile.getPart(face) as? PartP2PTunnel<*>) ?: return
|
||||
// val icon: IIcon = p2p.getItemStack().getIconIndex() ?: return
|
||||
// val tessellator = Tessellator.instance
|
||||
// gui.bindTexture(MODID, "textures/gui/advanced_memory_card.png")
|
||||
// gui.mc.renderEngine.bindTexture(gui.mc.renderEngine.getResourceLocation(0))
|
||||
// GL11.glPushAttrib(GL11.GL_BLEND or GL11.GL_TEXTURE_2D or GL11.GL_COLOR)
|
||||
// GL11.glEnable(GL11.GL_BLEND)
|
||||
// GL11.glEnable(GL11.GL_TEXTURE_2D)
|
||||
// GL11.glColor3f(255f, 255f, 255f)
|
||||
// OpenGlHelper.glBlendFunc(770, 771, 1, 0)
|
||||
// tessellator.startDrawingQuads()
|
||||
// tessellator.addVertexWithUV(x.toDouble(), y + rowHeight.toDouble(), 0.0, icon.minU.toDouble(), icon.maxV.toDouble())
|
||||
// tessellator.addVertexWithUV(x + rowWidth.toDouble(), y + rowHeight.toDouble(), 0.0, icon.maxU.toDouble(), icon.maxV.toDouble())
|
||||
// tessellator.addVertexWithUV(x + rowWidth.toDouble(), y.toDouble(), 0.0, icon.maxU.toDouble(), icon.minV.toDouble())
|
||||
// tessellator.addVertexWithUV(x.toDouble(), y.toDouble(), 0.0, icon.minU.toDouble(), icon.minV.toDouble())
|
||||
// tessellator.draw()
|
||||
// GL11.glPopAttrib()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
fun getExtraInfo(world: Int, posX: Int, poxY: Int, posZ: Int, face: ForgeDirection): String {
|
||||
|
||||
@@ -3,9 +3,7 @@ package com.projecturanus.betterp2p.client.gui.widget
|
||||
import com.projecturanus.betterp2p.client.TextureBound
|
||||
import net.minecraft.client.gui.Gui
|
||||
|
||||
class WidgetScrollBar {
|
||||
var displayX = 0
|
||||
var displayY = 0
|
||||
class WidgetScrollBar(var displayX: Int, var displayY: Int) {
|
||||
var width = 12
|
||||
var height = 16
|
||||
var pageSize = 1
|
||||
@@ -42,7 +40,7 @@ class WidgetScrollBar {
|
||||
}
|
||||
|
||||
private fun applyRange() {
|
||||
currentScroll = currentScroll.coerceAtMost(maxScroll).coerceAtLeast(minScroll)
|
||||
currentScroll = currentScroll.coerceIn(minScroll, maxScroll)
|
||||
onScroll()
|
||||
}
|
||||
|
||||
@@ -62,7 +60,7 @@ class WidgetScrollBar {
|
||||
|
||||
fun wheel(delta: Int) {
|
||||
var delta = delta
|
||||
delta = (-delta).coerceAtMost(1).coerceAtLeast(-1)
|
||||
delta = (-delta).coerceIn(-1, 1)
|
||||
currentScroll += delta
|
||||
applyRange()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user