New item monitor interface prototype
This commit is contained in:
parent
3fe0a43333
commit
c7181afc43
@ -1,10 +1,14 @@
|
|||||||
package ru.dbotthepony.mc.otm.client.render;
|
package ru.dbotthepony.mc.otm.client.render;
|
||||||
|
|
||||||
public enum UVWindingOrder {
|
public enum UVWindingOrder {
|
||||||
|
NORMAL(0, 1, 2, 3), // normal operation
|
||||||
U0_V0_U1_V1(0, 1, 2, 3), // normal operation
|
U0_V0_U1_V1(0, 1, 2, 3), // normal operation
|
||||||
U0_V1_U1_V0(0, 3, 2, 1), // mirror y
|
U0_V1_U1_V0(0, 3, 2, 1), // mirror y
|
||||||
|
FLIP(0, 3, 2, 1), // mirror y
|
||||||
U1_V0_U0_V1(2, 1, 0, 3), // mirror x
|
U1_V0_U0_V1(2, 1, 0, 3), // mirror x
|
||||||
U1_V1_U0_V0(2, 3, 0, 1); // mirror both
|
FLOP(2, 1, 0, 3), // mirror x
|
||||||
|
U1_V1_U0_V0(2, 3, 0, 1), // mirror both
|
||||||
|
FLIP_FLOP(2, 3, 0, 1); // mirror both
|
||||||
|
|
||||||
public static final int U0 = 0;
|
public static final int U0 = 0;
|
||||||
public static final int V0 = 1;
|
public static final int V0 = 1;
|
||||||
|
@ -11,23 +11,26 @@ class SkinGrid(
|
|||||||
val rows: Int = 16,
|
val rows: Int = 16,
|
||||||
val columns: Int = 16,
|
val columns: Int = 16,
|
||||||
) {
|
) {
|
||||||
private var row = 0
|
var row = 0
|
||||||
private var column = 0
|
var column = 0
|
||||||
|
|
||||||
val imageWidth get() = width * columns
|
val imageWidth get() = width * columns
|
||||||
val imageHeight get() = height * rows
|
val imageHeight get() = height * rows
|
||||||
|
|
||||||
fun skip() {
|
fun skip(): SkinGrid {
|
||||||
column++
|
column++
|
||||||
|
|
||||||
if (column >= columns) {
|
if (column >= columns) {
|
||||||
jump()
|
jump()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun jump() {
|
fun jump(): SkinGrid {
|
||||||
row++
|
row++
|
||||||
column = 0
|
column = 0
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun next(): SkinElement {
|
fun next(): SkinElement {
|
||||||
@ -35,6 +38,25 @@ class SkinGrid(
|
|||||||
skip()
|
skip()
|
||||||
return element
|
return element
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun reset(): SkinGrid {
|
||||||
|
row = 0
|
||||||
|
column = 0
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun seek(row: Int, column: Int): SkinGrid {
|
||||||
|
this.row = row
|
||||||
|
this.column = column
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun get(column: Int, row: Int) = SkinElement(texture, column * width, row * height, width, height, imageWidth, imageHeight)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val WIDGETS_18 = SkinGrid(RenderHelper.WIDGETS_18, 18f, 18f)
|
||||||
|
val WIDGETS_8 = SkinGrid(RenderHelper.WIDGETS_8, 8f, 8f)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ResourceLocation.element(
|
fun ResourceLocation.element(
|
||||||
|
@ -1,52 +1,133 @@
|
|||||||
package ru.dbotthepony.mc.otm.client.screen
|
package ru.dbotthepony.mc.otm.client.screen
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
|
import net.minecraft.world.item.Items
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
import ru.dbotthepony.mc.otm.client.screen.panels.*
|
||||||
import ru.dbotthepony.mc.otm.client.screen.widget.PowerGaugePanel
|
import ru.dbotthepony.mc.otm.client.screen.widget.ProgressGaugePanel
|
||||||
import ru.dbotthepony.mc.otm.menu.ItemMonitorMenu
|
import ru.dbotthepony.mc.otm.menu.ItemMonitorMenu
|
||||||
|
|
||||||
class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Component) :
|
class ItemMonitorScreen(menu: ItemMonitorMenu, inventory: Inventory, title: Component) :
|
||||||
MatteryScreen<ItemMonitorMenu>(menu, inventory, title) {
|
MatteryScreen<ItemMonitorMenu>(menu, inventory, title) {
|
||||||
|
|
||||||
override fun makeMainFrame(): FramePanel {
|
override fun makeMainFrame(): FramePanel {
|
||||||
val frame = FramePanel(this, null, 0f, 0f, FRAME_WIDTH, FRAME_HEIGHT, getTitle())
|
val frame = object : FramePanel(this@ItemMonitorScreen, null, 0f, 0f, FRAME_WIDTH, FRAME_HEIGHT, getTitle()) {
|
||||||
|
override fun innerRender(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float) {
|
||||||
|
super.innerRender(stack, mouse_x, mouse_y, flag)
|
||||||
|
// ProgressGaugePanel.GAUGE_BACKGROUND.render(stack, 28f + 3 * 18f + 6f, (ITEM_GRID_HEIGHT + 1) * 18f + 16f + 6f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PowerGaugePanel(this, frame, menu.powerWidget, 8f, 29f)
|
val topPanel = EditablePanel(this, frame)
|
||||||
SlotPanel(this, frame, menu.batterySlot, 8f, 80f)
|
topPanel.height = ITEM_GRID_HEIGHT * 18f
|
||||||
|
topPanel.dock = Dock.TOP
|
||||||
|
|
||||||
val scrollBar = ScrollBarPanel(this, frame, 192f, 14f, 92f)
|
val bottomPanel = EditablePanel(this, frame)
|
||||||
scrollBar.setupRowMultiplier { menu.view.itemCount / GRID_WIDTH }
|
bottomPanel.height = 3 * 18f
|
||||||
|
bottomPanel.dock = Dock.TOP
|
||||||
|
bottomPanel.setDockMargin(top = 6f)
|
||||||
|
|
||||||
val gridPanel = GridPanel(this, frame, 28f, 16f, GRID_WIDTH * 18f, GRID_HEIGHT * 18f, GRID_WIDTH, GRID_HEIGHT)
|
frame.height = topPanel.height + bottomPanel.height + frame.dockPadding.top + frame.dockPadding.bottom + 6f
|
||||||
|
frame.width = 178f + frame.dockPadding.left + frame.dockPadding.right
|
||||||
|
|
||||||
for (i in 0 until GRID_WIDTH * GRID_HEIGHT) {
|
val viewScrollBar = ScrollBarPanel(this, topPanel, 28f + ITEM_GRID_WIDTH * 18f + 2f, 16f, ITEM_GRID_HEIGHT * 18f)
|
||||||
|
viewScrollBar.setupRowMultiplier { menu.view.itemCount / ITEM_GRID_WIDTH }
|
||||||
|
|
||||||
|
viewScrollBar.dock = Dock.RIGHT
|
||||||
|
viewScrollBar.setDockMargin(left = 2f)
|
||||||
|
|
||||||
|
val gridPanel = GridPanel(this, topPanel, width = ITEM_GRID_WIDTH * 18f, height = ITEM_GRID_HEIGHT * 18f, columns = ITEM_GRID_WIDTH, rows = ITEM_GRID_HEIGHT)
|
||||||
|
gridPanel.dock = Dock.FILL
|
||||||
|
|
||||||
|
for (i in 0 until ITEM_GRID_WIDTH * ITEM_GRID_HEIGHT) {
|
||||||
object : AbstractSlotPanel(this@ItemMonitorScreen, gridPanel) {
|
object : AbstractSlotPanel(this@ItemMonitorScreen, gridPanel) {
|
||||||
override fun getItemStack(): ItemStack {
|
override fun getItemStack(): ItemStack {
|
||||||
val index = i + scrollBar.getScroll(menu.view.itemCount / GRID_WIDTH) * GRID_WIDTH
|
val index = i + viewScrollBar.getScroll(menu.view.itemCount / ITEM_GRID_WIDTH) * ITEM_GRID_WIDTH
|
||||||
return menu.view.sortedView.getOrNull(index)?.stack ?: ItemStack.EMPTY
|
return menu.view.sortedView.getOrNull(index)?.stack ?: ItemStack.EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseScrolledInner(mouse_x: Double, mouse_y: Double, scroll: Double): Boolean {
|
override fun mouseScrolledInner(mouse_x: Double, mouse_y: Double, scroll: Double): Boolean {
|
||||||
return scrollBar.mouseScrolledInner(mouse_x, mouse_y, scroll)
|
return viewScrollBar.mouseScrolledInner(mouse_x, mouse_y, scroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseClickedInner(mouse_x: Double, mouse_y: Double, mouse_click_type: Int): Boolean {
|
override fun mouseClickedInner(mouse_x: Double, mouse_y: Double, mouse_click_type: Int): Boolean {
|
||||||
val index = i + scrollBar.getScroll(menu.view.itemCount / GRID_WIDTH) * GRID_WIDTH
|
val index = i + viewScrollBar.getScroll(menu.view.itemCount / ITEM_GRID_WIDTH) * ITEM_GRID_WIDTH
|
||||||
menu.view.mouseClick(index, mouse_click_type)
|
menu.view.mouseClick(index, mouse_click_type)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val craftingGrid = GridPanel(this, bottomPanel, width = 3 * 18f, height = 3 * 18f, columns = 3, rows = 3)
|
||||||
|
craftingGrid.dock = Dock.LEFT
|
||||||
|
|
||||||
|
for (i in 0 until 9) {
|
||||||
|
object : AbstractSlotPanel(this@ItemMonitorScreen, craftingGrid) {
|
||||||
|
override fun getItemStack(): ItemStack {
|
||||||
|
return ItemStack(Items.APPLE, i + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val arrowAndButtons = object : EditablePanel(this@ItemMonitorScreen, bottomPanel, width = ProgressGaugePanel.GAUGE_BACKGROUND.w) {
|
||||||
|
override fun innerRender(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float) {
|
||||||
|
ProgressGaugePanel.GAUGE_BACKGROUND.render(stack, y = height / 2f - ProgressGaugePanel.GAUGE_BACKGROUND.h / 2f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arrowAndButtons.dock = Dock.LEFT
|
||||||
|
arrowAndButtons.setDockMargin(left = 4f)
|
||||||
|
|
||||||
|
val arrowLine = EditablePanel(this, arrowAndButtons, y = 8f, height = 8f, width = arrowAndButtons.width)
|
||||||
|
|
||||||
|
val autoRefillMatchMode = SmallSquareButtonPanel(this, arrowLine)
|
||||||
|
val refillPriority = SmallSquareButtonPanel(this, arrowLine)
|
||||||
|
|
||||||
|
refillPriority.setDockMargin(2f)
|
||||||
|
|
||||||
|
autoRefillMatchMode.dock = Dock.LEFT
|
||||||
|
refillPriority.dock = Dock.LEFT
|
||||||
|
|
||||||
|
val resultAndButtons = EditablePanel(this, bottomPanel, width = 18f)
|
||||||
|
|
||||||
|
resultAndButtons.dock = Dock.LEFT
|
||||||
|
resultAndButtons.setDockMargin(left = 6f)
|
||||||
|
|
||||||
|
val craftingResultSlot = object : AbstractSlotPanel(this@ItemMonitorScreen, resultAndButtons, y = 18f) {
|
||||||
|
override fun getItemStack(): ItemStack {
|
||||||
|
return ItemStack(Items.BREAD, 666)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val whereToPutResult = SmallSquareButtonPanel(this, resultAndButtons, y = 8f)
|
||||||
|
val howMuchToCraft = SmallSquareButtonPanel(this, resultAndButtons, x = 10f, y = 8f)
|
||||||
|
|
||||||
|
val craftingHistory = GridPanel(this, bottomPanel, width = 3 * 18f, height = 3 * 18f, columns = 3, rows = 3)
|
||||||
|
craftingHistory.dock = Dock.LEFT
|
||||||
|
craftingHistory.setDockMargin(left = 4f)
|
||||||
|
|
||||||
|
for (i in 0 until 9) {
|
||||||
|
object : AbstractSlotPanel(this@ItemMonitorScreen, craftingHistory) {
|
||||||
|
override fun getItemStack(): ItemStack {
|
||||||
|
return ItemStack(Items.ARROW, 42)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val craftingHistoryScroll = ScrollBarPanel(this, bottomPanel, 0f, 0f, 0f)
|
||||||
|
craftingHistoryScroll.dock = Dock.LEFT
|
||||||
|
craftingHistoryScroll.setDockMargin(left = 2f)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val FRAME_WIDTH = 210f
|
const val FRAME_WIDTH = 240f
|
||||||
const val FRAME_HEIGHT = 110f
|
const val FRAME_HEIGHT = 210f
|
||||||
const val GRID_WIDTH = 9
|
|
||||||
const val GRID_HEIGHT = 5
|
const val ITEM_GRID_WIDTH = 9
|
||||||
|
const val ITEM_GRID_HEIGHT = 5
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,17 @@
|
|||||||
package ru.dbotthepony.mc.otm.client.screen.panels
|
package ru.dbotthepony.mc.otm.client.screen.panels
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
|
import com.sun.jna.platform.win32.WinUser.SIZE
|
||||||
import net.minecraft.client.gui.components.Button
|
import net.minecraft.client.gui.components.Button
|
||||||
import net.minecraft.client.gui.components.Button.OnPress
|
import net.minecraft.client.gui.components.Button.OnPress
|
||||||
|
import net.minecraft.client.resources.sounds.SimpleSoundInstance
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.sounds.SoundEvents
|
||||||
|
import ru.dbotthepony.mc.otm.client.minecraft
|
||||||
|
import ru.dbotthepony.mc.otm.client.render.RenderHelper
|
||||||
|
import ru.dbotthepony.mc.otm.client.render.SkinElement
|
||||||
|
import ru.dbotthepony.mc.otm.client.render.SkinGrid
|
||||||
|
import ru.dbotthepony.mc.otm.client.render.element
|
||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
|
|
||||||
open class ButtonPanel(
|
open class ButtonPanel(
|
||||||
@ -43,3 +52,110 @@ open class ButtonPanel(
|
|||||||
callback?.run()
|
callback?.run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("PropertyName")
|
||||||
|
abstract class SquareButtonPanel(
|
||||||
|
screen: MatteryScreen<*>,
|
||||||
|
parent: EditablePanel?,
|
||||||
|
x: Float = 0f,
|
||||||
|
y: Float = 0f,
|
||||||
|
width: Float,
|
||||||
|
height: Float,
|
||||||
|
var skinElement: SkinElement? = null,
|
||||||
|
val lambdaOnPress: (() -> Unit)? = null,
|
||||||
|
) : EditablePanel(screen, parent, x, y, width, height) {
|
||||||
|
protected var pressed = false
|
||||||
|
|
||||||
|
abstract val PRESSED: SkinElement
|
||||||
|
abstract val HOVERED: SkinElement
|
||||||
|
abstract val IDLE: SkinElement
|
||||||
|
|
||||||
|
var isDisabled = false
|
||||||
|
set(value) {
|
||||||
|
if (field != value) {
|
||||||
|
if (!value) {
|
||||||
|
pressed = false
|
||||||
|
trapMouseInput = false
|
||||||
|
}
|
||||||
|
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun innerRender(stack: PoseStack, mouse_x: Float, mouse_y: Float, flag: Float) {
|
||||||
|
if (pressed) {
|
||||||
|
PRESSED.render(stack, 0f, 0f, width, height)
|
||||||
|
} else if (isHovered && !isDisabled) {
|
||||||
|
HOVERED.render(stack, 0f, 0f, width, height)
|
||||||
|
} else {
|
||||||
|
IDLE.render(stack, 0f, 0f, width, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
skinElement?.render(stack, 0f, 0f, width, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mouseClickedInner(mouse_x: Double, mouse_y: Double, mouse_click_type: Int): Boolean {
|
||||||
|
if (!isDisabled) {
|
||||||
|
if (!pressed) {
|
||||||
|
minecraft.soundManager.play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0f))
|
||||||
|
}
|
||||||
|
|
||||||
|
pressed = true
|
||||||
|
trapMouseInput = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mouseReleasedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
||||||
|
if (!isDisabled && pressed) {
|
||||||
|
pressed = false
|
||||||
|
|
||||||
|
if (isHovered) {
|
||||||
|
lambdaOnPress?.invoke()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trapMouseInput = false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class LargeSquareButtonPanel(
|
||||||
|
screen: MatteryScreen<*>,
|
||||||
|
parent: EditablePanel?,
|
||||||
|
x: Float = 0f,
|
||||||
|
y: Float = 0f,
|
||||||
|
width: Float = SIZE,
|
||||||
|
height: Float = SIZE,
|
||||||
|
skinElement: SkinElement? = null,
|
||||||
|
lambdaOnPress: (() -> Unit)? = null,
|
||||||
|
) : SquareButtonPanel(screen, parent, x, y, width, height, skinElement, lambdaOnPress) {
|
||||||
|
final override val IDLE = SkinGrid.WIDGETS_18[0, 0]
|
||||||
|
final override val HOVERED = SkinGrid.WIDGETS_18[1, 0]
|
||||||
|
final override val PRESSED = SkinGrid.WIDGETS_18[2, 0]
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val SIZE = 18f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class SmallSquareButtonPanel(
|
||||||
|
screen: MatteryScreen<*>,
|
||||||
|
parent: EditablePanel?,
|
||||||
|
x: Float = 0f,
|
||||||
|
y: Float = 0f,
|
||||||
|
width: Float = SIZE,
|
||||||
|
height: Float = SIZE,
|
||||||
|
skinElement: SkinElement? = null,
|
||||||
|
lambdaOnPress: (() -> Unit)? = null,
|
||||||
|
) : SquareButtonPanel(screen, parent, x, y, width, height, skinElement, lambdaOnPress) {
|
||||||
|
final override val IDLE = SkinGrid.WIDGETS_8[0, 0]
|
||||||
|
final override val HOVERED = SkinGrid.WIDGETS_8[0, 0]
|
||||||
|
final override val PRESSED = SkinGrid.WIDGETS_8[0, 0]
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val SIZE = 8f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,13 +20,13 @@ open class DraggableCanvasPanel @JvmOverloads constructor(
|
|||||||
dragging = true
|
dragging = true
|
||||||
lastMouseX = mouse_x
|
lastMouseX = mouse_x
|
||||||
lastMouseY = mouse_y
|
lastMouseY = mouse_y
|
||||||
ignoreMouseEventBoundaries = true
|
trapMouseInput = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseReleasedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
override fun mouseReleasedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
||||||
dragging = false
|
dragging = false
|
||||||
ignoreMouseEventBoundaries = false
|
trapMouseInput = false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
|
|
||||||
var acceptMouseInput = true
|
var acceptMouseInput = true
|
||||||
var acceptKeyboardInput = true
|
var acceptKeyboardInput = true
|
||||||
var ignoreMouseEventBoundaries = false
|
var trapMouseInput = false
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun setDockMargin(left: Float = 0f, top: Float = 0f, right: Float = 0f, bottom: Float = 0f) {
|
fun setDockMargin(left: Float = 0f, top: Float = 0f, right: Float = 0f, bottom: Float = 0f) {
|
||||||
@ -654,13 +654,13 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
return children[int]
|
return children[int]
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isIgnoringMouseEventBoundaries(): Boolean {
|
fun isTrappingMouseInput(): Boolean {
|
||||||
if (ignoreMouseEventBoundaries) {
|
if (trapMouseInput) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
if (child.isIgnoringMouseEventBoundaries()) {
|
if (child.isTrappingMouseInput()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -707,7 +707,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
final override fun mouseClicked(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
final override fun mouseClicked(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
||||||
if (!isVisible() || !acceptMouseInput) return false
|
if (!isVisible() || !acceptMouseInput) return false
|
||||||
|
|
||||||
if (ignoreMouseEventBoundaries) return mouseClickedInner(mouse_x, mouse_y, flag)
|
if (trapMouseInput) return mouseClickedInner(mouse_x, mouse_y, flag)
|
||||||
|
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
if (child.mouseClickedChecked(mouse_x, mouse_y, flag)) {
|
if (child.mouseClickedChecked(mouse_x, mouse_y, flag)) {
|
||||||
@ -722,7 +722,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
fun mouseClickedChecked(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
fun mouseClickedChecked(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
||||||
if (!isVisible() || !acceptMouseInput) return false
|
if (!isVisible() || !acceptMouseInput) return false
|
||||||
|
|
||||||
if (isIgnoringMouseEventBoundaries() || withinBounds(mouse_x, mouse_y)) {
|
if (isTrappingMouseInput() || withinBounds(mouse_x, mouse_y)) {
|
||||||
if (acceptMouseInput && parent == null) screen.popup(this)
|
if (acceptMouseInput && parent == null) screen.popup(this)
|
||||||
return mouseClicked(mouse_x, mouse_y, flag)
|
return mouseClicked(mouse_x, mouse_y, flag)
|
||||||
} else if (withinExtendedBounds(mouse_x, mouse_y)) {
|
} else if (withinExtendedBounds(mouse_x, mouse_y)) {
|
||||||
@ -748,7 +748,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
final override fun mouseReleased(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
final override fun mouseReleased(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
||||||
if (!isVisible() || !acceptMouseInput) return false
|
if (!isVisible() || !acceptMouseInput) return false
|
||||||
|
|
||||||
if (ignoreMouseEventBoundaries) return mouseReleasedInner(mouse_x, mouse_y, flag)
|
if (trapMouseInput) return mouseReleasedInner(mouse_x, mouse_y, flag)
|
||||||
|
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
if (child.mouseReleasedChecked(mouse_x, mouse_y, flag)) {
|
if (child.mouseReleasedChecked(mouse_x, mouse_y, flag)) {
|
||||||
@ -762,7 +762,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
fun mouseReleasedChecked(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
fun mouseReleasedChecked(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
||||||
if (!isVisible() || !acceptMouseInput) return false
|
if (!isVisible() || !acceptMouseInput) return false
|
||||||
|
|
||||||
if (isIgnoringMouseEventBoundaries() || withinBounds(mouse_x, mouse_y)) {
|
if (isTrappingMouseInput() || withinBounds(mouse_x, mouse_y)) {
|
||||||
return mouseReleased(mouse_x, mouse_y, flag)
|
return mouseReleased(mouse_x, mouse_y, flag)
|
||||||
} else if (withinExtendedBounds(mouse_x, mouse_y)) {
|
} else if (withinExtendedBounds(mouse_x, mouse_y)) {
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
@ -789,7 +789,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
final override fun mouseDragged(mouse_x: Double, mouse_y: Double, flag: Int, drag_x: Double, drag_y: Double): Boolean {
|
final override fun mouseDragged(mouse_x: Double, mouse_y: Double, flag: Int, drag_x: Double, drag_y: Double): Boolean {
|
||||||
if (!isVisible() || !acceptMouseInput) return false
|
if (!isVisible() || !acceptMouseInput) return false
|
||||||
|
|
||||||
if (ignoreMouseEventBoundaries) return mouseDraggedInner(mouse_x, mouse_y, flag, drag_x, drag_y)
|
if (trapMouseInput) return mouseDraggedInner(mouse_x, mouse_y, flag, drag_x, drag_y)
|
||||||
|
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
if (child.mouseDraggedChecked(mouse_x, mouse_y, flag, drag_x, drag_y)) {
|
if (child.mouseDraggedChecked(mouse_x, mouse_y, flag, drag_x, drag_y)) {
|
||||||
@ -803,7 +803,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
fun mouseDraggedChecked(mouse_x: Double, mouse_y: Double, flag: Int, drag_x: Double, drag_y: Double): Boolean {
|
fun mouseDraggedChecked(mouse_x: Double, mouse_y: Double, flag: Int, drag_x: Double, drag_y: Double): Boolean {
|
||||||
if (!isVisible() || !acceptMouseInput) return false
|
if (!isVisible() || !acceptMouseInput) return false
|
||||||
|
|
||||||
if (isIgnoringMouseEventBoundaries() || withinBounds(mouse_x, mouse_y)) {
|
if (isTrappingMouseInput() || withinBounds(mouse_x, mouse_y)) {
|
||||||
return mouseDragged(mouse_x, mouse_y, flag, drag_x, drag_y)
|
return mouseDragged(mouse_x, mouse_y, flag, drag_x, drag_y)
|
||||||
} else if (withinExtendedBounds(mouse_x, mouse_y)) {
|
} else if (withinExtendedBounds(mouse_x, mouse_y)) {
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
@ -824,7 +824,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
final override fun mouseScrolled(mouse_x: Double, mouse_y: Double, scroll: Double): Boolean {
|
final override fun mouseScrolled(mouse_x: Double, mouse_y: Double, scroll: Double): Boolean {
|
||||||
if (!isVisible() || !acceptMouseInput) return false
|
if (!isVisible() || !acceptMouseInput) return false
|
||||||
|
|
||||||
if (ignoreMouseEventBoundaries) return mouseScrolledInner(mouse_x, mouse_y, scroll)
|
if (trapMouseInput) return mouseScrolledInner(mouse_x, mouse_y, scroll)
|
||||||
|
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
if (child.mouseScrolledChecked(mouse_x, mouse_y, scroll)) {
|
if (child.mouseScrolledChecked(mouse_x, mouse_y, scroll)) {
|
||||||
@ -838,7 +838,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
fun mouseScrolledChecked(mouse_x: Double, mouse_y: Double, scroll: Double): Boolean {
|
fun mouseScrolledChecked(mouse_x: Double, mouse_y: Double, scroll: Double): Boolean {
|
||||||
if (!isVisible() || !acceptMouseInput) return false
|
if (!isVisible() || !acceptMouseInput) return false
|
||||||
|
|
||||||
if (isIgnoringMouseEventBoundaries() || withinBounds(mouse_x, mouse_y)) {
|
if (isTrappingMouseInput() || withinBounds(mouse_x, mouse_y)) {
|
||||||
return mouseScrolled(mouse_x, mouse_y, scroll)
|
return mouseScrolled(mouse_x, mouse_y, scroll)
|
||||||
} else if (withinExtendedBounds(mouse_x, mouse_y)) {
|
} else if (withinExtendedBounds(mouse_x, mouse_y)) {
|
||||||
for (child in children) {
|
for (child in children) {
|
||||||
@ -917,7 +917,7 @@ open class EditablePanel @JvmOverloads constructor(
|
|||||||
mouse_y: Double
|
mouse_y: Double
|
||||||
): Boolean { // called to check whenever we are hovering at this
|
): Boolean { // called to check whenever we are hovering at this
|
||||||
if (!isVisible() || !acceptMouseInput) return false
|
if (!isVisible() || !acceptMouseInput) return false
|
||||||
if (isIgnoringMouseEventBoundaries()) return true
|
if (isTrappingMouseInput()) return true
|
||||||
|
|
||||||
val pos = localToScreen()
|
val pos = localToScreen()
|
||||||
return mouse_x >= pos.x && mouse_x <= pos.x + width && mouse_y >= pos.y && mouse_y + height <= pos.y
|
return mouse_x >= pos.x && mouse_x <= pos.x + width && mouse_y >= pos.y && mouse_y + height <= pos.y
|
||||||
|
@ -210,7 +210,7 @@ open class FramePanel(
|
|||||||
val (_, y1) = screenToLocal(mouse_x, mouse_y)
|
val (_, y1) = screenToLocal(mouse_x, mouse_y)
|
||||||
|
|
||||||
if (parent == null && y1 >= 0 && y1 <= 12) {
|
if (parent == null && y1 >= 0 && y1 <= 12) {
|
||||||
ignoreMouseEventBoundaries = true
|
trapMouseInput = true
|
||||||
dragMouseX = mouse_x
|
dragMouseX = mouse_x
|
||||||
dragMouseY = mouse_y
|
dragMouseY = mouse_y
|
||||||
dragging = true
|
dragging = true
|
||||||
@ -222,7 +222,7 @@ open class FramePanel(
|
|||||||
|
|
||||||
override fun mouseReleasedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
override fun mouseReleasedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
ignoreMouseEventBoundaries = false
|
trapMouseInput = false
|
||||||
dragging = false
|
dragging = false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -290,7 +290,7 @@ open class FramePanel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val PADDING = 4f
|
const val PADDING = 8f
|
||||||
const val PADDING_TOP = 14f
|
const val PADDING_TOP = 14f
|
||||||
|
|
||||||
val top_left_window_corner = SkinElement(RenderHelper.WIDGETS, x = 18f, y = 0f, w = 6f, h = 6f)
|
val top_left_window_corner = SkinElement(RenderHelper.WIDGETS, x = 18f, y = 0f, w = 6f, h = 6f)
|
||||||
|
@ -1,65 +1,48 @@
|
|||||||
package ru.dbotthepony.mc.otm.client.screen.panels;
|
package ru.dbotthepony.mc.otm.client.screen.panels
|
||||||
|
|
||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen;
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
open class GridPanel(
|
||||||
import javax.annotation.Nullable;
|
screen: MatteryScreen<*>,
|
||||||
|
parent: EditablePanel?,
|
||||||
|
x: Float = 0f,
|
||||||
|
y: Float = 0f,
|
||||||
|
width: Float,
|
||||||
|
height: Float,
|
||||||
|
protected var columns: Int,
|
||||||
|
protected var rows: Int
|
||||||
|
) : EditablePanel(screen, parent, x, y, width, height) {
|
||||||
|
override fun performLayout() {
|
||||||
|
var currentX = 0f
|
||||||
|
var currentY = 0f
|
||||||
|
var lineY = 0f
|
||||||
|
var index = 0
|
||||||
|
|
||||||
public class GridPanel extends EditablePanel {
|
for (row in 0 until rows) {
|
||||||
protected int grid_width;
|
var column = 0
|
||||||
protected int grid_height;
|
|
||||||
|
|
||||||
public GridPanel(
|
while (column < columns) {
|
||||||
@Nonnull MatteryScreen<?> screen,
|
val child = get(index) ?: break
|
||||||
@Nullable EditablePanel parent,
|
|
||||||
float x,
|
|
||||||
float y,
|
|
||||||
float width,
|
|
||||||
float height,
|
|
||||||
int grid_width,
|
|
||||||
int grid_height
|
|
||||||
) {
|
|
||||||
super(screen, parent, x, y, width, height);
|
|
||||||
this.grid_width = grid_width;
|
|
||||||
this.grid_height = grid_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (child.visible && child.dock === Dock.NONE) {
|
||||||
protected void performLayout() {
|
lineY = lineY.coerceAtLeast(child.height + child.dockMargin.top + child.dockMargin.bottom)
|
||||||
float current_x = 0;
|
child.setPos(currentX + child.dockMargin.left, currentY + child.dockMargin.top)
|
||||||
float current_y = 0;
|
currentX += child.width + child.dockMargin.left + child.dockMargin.right
|
||||||
float line_y = 0;
|
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
for (int row = 0; row < grid_height; row++) {
|
|
||||||
for (int column = 0; column < grid_width; column++) {
|
|
||||||
var child = get(index);
|
|
||||||
|
|
||||||
if (child == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child.getVisible() && child.getDock() == Dock.NONE) {
|
|
||||||
line_y = Math.max(line_y, child.getHeight() + child.getDockMargin().top() + child.getDockMargin().bottom());
|
|
||||||
child.setPos(current_x + child.getDockMargin().left(), current_y + child.getDockMargin().top());
|
|
||||||
current_x += child.getWidth() + child.getDockMargin().left() + child.getDockMargin().right();
|
|
||||||
} else {
|
} else {
|
||||||
column--;
|
column--
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++
|
||||||
|
column++
|
||||||
}
|
}
|
||||||
|
|
||||||
current_y += line_y;
|
currentY += lineY
|
||||||
current_x = 0;
|
currentX = 0f
|
||||||
line_y = 0;
|
lineY = 0f
|
||||||
|
|
||||||
if (get(index) == null) {
|
get(index) ?: break
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.performLayout();
|
super.performLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import java.util.function.Consumer
|
|||||||
import java.util.function.Supplier
|
import java.util.function.Supplier
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
|
||||||
open class ScrollBarPanel(screen: MatteryScreen<*>, parent: EditablePanel?, x: Float, y: Float, height: Float) :
|
open class ScrollBarPanel(screen: MatteryScreen<*>, parent: EditablePanel?, x: Float = 0f, y: Float = 0f, height: Float = 20f) :
|
||||||
EditablePanel(screen, parent, x, y, WIDTH, height) {
|
EditablePanel(screen, parent, x, y, WIDTH, height) {
|
||||||
|
|
||||||
open inner class ScrollBarButtonPanel : EditablePanel(screen, this@ScrollBarPanel, 1f, 1f, 12f, 15f) {
|
open inner class ScrollBarButtonPanel : EditablePanel(screen, this@ScrollBarPanel, 1f, 1f, 12f, 15f) {
|
||||||
@ -28,7 +28,7 @@ open class ScrollBarPanel(screen: MatteryScreen<*>, parent: EditablePanel?, x: F
|
|||||||
|
|
||||||
override fun mouseClickedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
override fun mouseClickedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
||||||
isScrolling = true
|
isScrolling = true
|
||||||
ignoreMouseEventBoundaries = true
|
trapMouseInput = true
|
||||||
lastMouseY = mouse_y
|
lastMouseY = mouse_y
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ open class ScrollBarPanel(screen: MatteryScreen<*>, parent: EditablePanel?, x: F
|
|||||||
override fun mouseReleasedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
override fun mouseReleasedInner(mouse_x: Double, mouse_y: Double, flag: Int): Boolean {
|
||||||
if (isScrolling) {
|
if (isScrolling) {
|
||||||
isScrolling = false
|
isScrolling = false
|
||||||
ignoreMouseEventBoundaries = false
|
trapMouseInput = false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user