Get rid of tab positions, since they should be at top anyway
This commit is contained in:
parent
a50fcaceaa
commit
a142e4da98
@ -19,32 +19,26 @@ class DriveViewerScreen(menu: DriveViewerMenu, inventory: Inventory, title: Comp
|
||||
|
||||
val views = ArrayList<EditablePanel>()
|
||||
val settings = ArrayList<EditablePanel>()
|
||||
val viewButton = frame.addTab(FramePanel.Position.TOP)
|
||||
val settingsButton = frame.addTab(FramePanel.Position.TOP)
|
||||
|
||||
viewButton.bindOnOpen {
|
||||
frame.Tab(onOpen = {
|
||||
for (panel in views) {
|
||||
panel.visible = true
|
||||
}
|
||||
}
|
||||
|
||||
viewButton.bindOnClose {
|
||||
}, onClose = {
|
||||
for (panel in views) {
|
||||
panel.visible = false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
settingsButton.bindOnOpen {
|
||||
frame.Tab(onOpen = {
|
||||
for (panel in settings) {
|
||||
panel.visible = true
|
||||
}
|
||||
}
|
||||
|
||||
settingsButton.bindOnClose {
|
||||
}, onClose = {
|
||||
for (panel in settings) {
|
||||
panel.visible = false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
views.add(PowerGaugePanel(this, frame, menu.powerWidget, 8f, 16f))
|
||||
views.add(BatterySlotPanel(this, frame, menu.batterySlot, 8f, 67f))
|
||||
|
@ -94,8 +94,8 @@ class EnergyCounterScreen(menu: EnergyCounterMenu, inventory: Inventory, title:
|
||||
|
||||
val limitsPanels = frame.fetchChildren().filter { !infoPanels.contains(it) }
|
||||
|
||||
val informationTab = frame.addTab(FramePanel.Position.TOP)
|
||||
val limitsTab = frame.addTab(FramePanel.Position.TOP)
|
||||
val informationTab = frame.Tab()
|
||||
val limitsTab = frame.Tab()
|
||||
|
||||
informationTab.showHidePanels(infoPanels)
|
||||
limitsTab.showHidePanels(limitsPanels)
|
||||
|
@ -35,8 +35,8 @@ class MatterPanelScreen(
|
||||
|
||||
scrollBar.dock = Dock.RIGHT
|
||||
|
||||
frame.addTab(FramePanel.Position.TOP, open = { isPatternView = true })
|
||||
frame.addTab(FramePanel.Position.TOP, open = { isPatternView = false })
|
||||
frame.Tab(onOpen = { isPatternView = true })
|
||||
frame.Tab(onOpen = { isPatternView = false })
|
||||
|
||||
val canvas = object : EditablePanel(this@MatterPanelScreen, frame, width = GRID_WIDTH * AbstractSlotPanel.SIZE) {
|
||||
init {
|
||||
|
@ -22,37 +22,14 @@ open class FramePanel(
|
||||
) : EditablePanel(screen, parent, x, y, width, height), NarratableEntry {
|
||||
constructor(screen: MatteryScreen<*>, width: Float, height: Float, title: Component) : this(screen, null, 0f, 0f, width, height, title)
|
||||
|
||||
enum class Position(val width: Float, val height: Float, val active_width: Float, val active_height: Float) {
|
||||
TOP(28f, 28f, 28f, 32f),
|
||||
// TODO: а оно вообще нужно?
|
||||
LEFT(28f, 28f, 32f, 28f),
|
||||
RIGHT(28f, 28f, 32f, 28f),
|
||||
BOTTOM(28f, 28f, 28f, 32f);
|
||||
}
|
||||
open inner class Tab(var onOpen: Runnable? = null, var onClose: Runnable? = null) :
|
||||
EditablePanel(this@FramePanel.screen, this@FramePanel, 0f, 0f, 28f, 28f) {
|
||||
|
||||
open inner class FrameTabPanel(position: Position, on_open: Runnable? = null, on_close: Runnable? = null) :
|
||||
EditablePanel(
|
||||
this@FramePanel.screen,
|
||||
this@FramePanel,
|
||||
0f,
|
||||
0f,
|
||||
position.width,
|
||||
position.height
|
||||
) {
|
||||
|
||||
val frameTabPosition: Position = position
|
||||
var isActive = false
|
||||
var isActive = tabs.isEmpty()
|
||||
var initial = false
|
||||
|
||||
var onOpen: Runnable? = on_open
|
||||
var onClose: Runnable? = on_close
|
||||
|
||||
open fun bindOnOpen(value: Runnable?) {
|
||||
onOpen = value
|
||||
}
|
||||
|
||||
open fun bindOnClose(value: Runnable?) {
|
||||
onClose = value
|
||||
init {
|
||||
tabs.add(this)
|
||||
}
|
||||
|
||||
fun showHidePanels(input: List<EditablePanel>) {
|
||||
@ -70,39 +47,37 @@ open class FramePanel(
|
||||
}
|
||||
|
||||
override fun innerRender(stack: PoseStack, mouseX: Float, mouseY: Float, partialTick: Float) {
|
||||
if (frameTabPosition == Position.TOP) {
|
||||
val width: Float
|
||||
val height: Float
|
||||
val width: Float
|
||||
val height: Float
|
||||
|
||||
if (isActive) {
|
||||
width = frameTabPosition.active_width
|
||||
height = frameTabPosition.active_height
|
||||
RECTANGLE.middle.render(stack, 2f, 2f, width - 4, height - 2)
|
||||
} else {
|
||||
width = frameTabPosition.width
|
||||
height = frameTabPosition.height
|
||||
tabBackground.render(stack, 2f, 2f, width - 4, height - 2)
|
||||
if (isActive) {
|
||||
width = TAB_WIDTH_ACTIVE
|
||||
height = TAB_HEIGHT_ACTIVE
|
||||
RECTANGLE.middle.render(stack, 2f, 2f, width - 4, height - 2)
|
||||
} else {
|
||||
width = TAB_WIDTH
|
||||
height = TAB_HEIGHT
|
||||
TAB_BACKGROUND.render(stack, 2f, 2f, width - 4, height - 2)
|
||||
}
|
||||
|
||||
RECTANGLE.top.renderW(stack, 3f, 0f, width - 6)
|
||||
RECTANGLE.left.renderH(stack, 0f, 3f, (height - if (isActive) if (initial) 2 else 4 else 3))
|
||||
|
||||
RECTANGLE.right.renderH(stack, width - RECTANGLE.right.w, 3f, (height - if (isActive) 4 else 3))
|
||||
|
||||
RECTANGLE.topLeft.render(stack, 0f, 0f)
|
||||
RECTANGLE.topRight.render(stack, width - RECTANGLE.topRight.w, 0f)
|
||||
|
||||
if (isActive) {
|
||||
if (!initial) {
|
||||
TAB_LEFT_CONNECTION.render(stack, 0f, height - TAB_LEFT_CONNECTION.h - 1)
|
||||
}
|
||||
|
||||
RECTANGLE.top.renderW(stack, 3f, 0f, width - 6)
|
||||
RECTANGLE.left.renderH(stack, 0f, 3f, (height - if (isActive) if (initial) 2 else 4 else 3))
|
||||
|
||||
RECTANGLE.right.renderH(stack, width - RECTANGLE.right.w, 3f, (height - if (isActive) 4 else 3))
|
||||
|
||||
RECTANGLE.topLeft.render(stack, 0f, 0f)
|
||||
RECTANGLE.topRight.render(stack, width - RECTANGLE.topRight.w, 0f)
|
||||
|
||||
if (isActive) {
|
||||
if (!initial) {
|
||||
tabLeftConnection.render(stack, 0f, height - tabLeftConnection.h - 1)
|
||||
}
|
||||
|
||||
tabRightConnection.render(
|
||||
stack,
|
||||
width - tabRightConnection.w,
|
||||
height - tabLeftConnection.h - 1
|
||||
)
|
||||
}
|
||||
TAB_RIGHT_CONNECTION.render(
|
||||
stack,
|
||||
width - TAB_RIGHT_CONNECTION.w,
|
||||
height - TAB_LEFT_CONNECTION.h - 1
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,34 +94,7 @@ open class FramePanel(
|
||||
return true
|
||||
}
|
||||
|
||||
for (tab in tabsTop) {
|
||||
if (tab !== this) {
|
||||
if (tab.isActive) {
|
||||
tab.onClose()
|
||||
tab.isActive = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (tab in tabsLeft) {
|
||||
if (tab !== this) {
|
||||
if (tab.isActive) {
|
||||
tab.onClose()
|
||||
tab.isActive = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (tab in tabsRight) {
|
||||
if (tab !== this) {
|
||||
if (tab.isActive) {
|
||||
tab.onClose()
|
||||
tab.isActive = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (tab in tabsBottom) {
|
||||
for (tab in tabs) {
|
||||
if (tab !== this) {
|
||||
if (tab.isActive) {
|
||||
tab.onClose()
|
||||
@ -163,35 +111,11 @@ open class FramePanel(
|
||||
}
|
||||
}
|
||||
|
||||
protected val tabsTop = ArrayList<FrameTabPanel>()
|
||||
protected val tabsLeft = ArrayList<FrameTabPanel>()
|
||||
protected val tabsRight = ArrayList<FrameTabPanel>()
|
||||
protected val tabsBottom = ArrayList<FrameTabPanel>()
|
||||
|
||||
@JvmOverloads
|
||||
fun addTab(position: Position, open: Runnable? = null, close: Runnable? = null): FrameTabPanel {
|
||||
val tab = FrameTabPanel(position, open, close)
|
||||
doAddTab(tab)
|
||||
return tab
|
||||
}
|
||||
|
||||
protected fun doAddTab(tab: FrameTabPanel) {
|
||||
if (tabsTop.size == 0 && tabsLeft.size == 0 && tabsRight.size == 0 && tabsBottom.size == 0) {
|
||||
tab.isActive = true
|
||||
}
|
||||
|
||||
when (tab.frameTabPosition) {
|
||||
Position.TOP -> tabsTop.add(tab)
|
||||
Position.LEFT -> tabsLeft.add(tab)
|
||||
Position.RIGHT -> tabsRight.add(tab)
|
||||
Position.BOTTOM -> tabsBottom.add(tab)
|
||||
}
|
||||
}
|
||||
protected val tabs = ArrayList<Tab>()
|
||||
|
||||
override fun performLayout() {
|
||||
for (i in tabsTop.indices) {
|
||||
val tab = tabsTop[i]
|
||||
tab.setPos(i * Position.TOP.width, -Position.TOP.height)
|
||||
for ((i, tab) in tabs.withIndex()) {
|
||||
tab.setPos(i * TAB_WIDTH, -TAB_HEIGHT)
|
||||
tab.initial = i == 0
|
||||
}
|
||||
|
||||
@ -289,8 +213,13 @@ open class FramePanel(
|
||||
padding = DockProperty(-3f, -3f, -3f, -3f)
|
||||
)
|
||||
|
||||
val tabRightConnection = WidgetLocation.WIDGETS.element(x = 30f, y = 0f, w = 3f, h = 5f)
|
||||
val tabLeftConnection = WidgetLocation.WIDGETS.element(x = 33f, y = 0f, w = 3f, h = 5f)
|
||||
val tabBackground = WidgetLocation.WIDGETS.element(x = 30f, y = 6f, w = 6f, h = 6f)
|
||||
val TAB_RIGHT_CONNECTION = WidgetLocation.WIDGETS.element(x = 30f, y = 0f, w = 3f, h = 5f)
|
||||
val TAB_LEFT_CONNECTION = WidgetLocation.WIDGETS.element(x = 33f, y = 0f, w = 3f, h = 5f)
|
||||
val TAB_BACKGROUND = WidgetLocation.WIDGETS.element(x = 30f, y = 6f, w = 6f, h = 6f)
|
||||
|
||||
const val TAB_HEIGHT = 28f
|
||||
const val TAB_WIDTH = 28f
|
||||
const val TAB_HEIGHT_ACTIVE = 32f
|
||||
const val TAB_WIDTH_ACTIVE = 28f
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user