Actual tabs sprites, and all 4 sprite states for them

This commit is contained in:
DBotThePony 2023-07-29 16:30:56 +07:00
parent 1346a3774d
commit ff308ee67a
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 74 additions and 44 deletions

View File

@ -11,6 +11,7 @@ object WidgetLocation {
val SLOT_BACKGROUNDS = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/slot_backgrounds.png"), 72f, 72f) val SLOT_BACKGROUNDS = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/slot_backgrounds.png"), 72f, 72f)
val MISC = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/misc.png"), 64f, 64f) val MISC = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/misc.png"), 64f, 64f)
val TABS = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/tabs.png"), 224f, 64f)
val PATTERN_PANEL_TABS = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/pattern_panel_tabs.png"), 60f, 23f) val PATTERN_PANEL_TABS = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/pattern_panel_tabs.png"), 60f, 23f)
val CHECKBOX = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/checkbox.png"), 30f, 60f) val CHECKBOX = MatteryAtlas(ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/widgets/checkbox.png"), 30f, 60f)

View File

@ -34,7 +34,6 @@ open class FramePanel<out S : Screen>(
var inactiveIcon: IGUIRenderable? = null, var inactiveIcon: IGUIRenderable? = null,
) : AbstractButtonPanel<S>(this@FramePanel.screen, this@FramePanel, 0f, 0f, 28f, 28f) { ) : AbstractButtonPanel<S>(this@FramePanel.screen, this@FramePanel, 0f, 0f, 28f, 28f) {
var isActive = tabs.isEmpty() var isActive = tabs.isEmpty()
var initial = false
init { init {
tabs.add(this) tabs.add(this)
@ -54,44 +53,59 @@ open class FramePanel<out S : Screen>(
} }
} }
protected fun tabIndex(): Int {
return tabs.indexOf(this)
}
override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) { override fun innerRender(graphics: GuiGraphics, mouseX: Float, mouseY: Float, partialTick: Float) {
val width: Float
val height: Float
if (isActive) { if (isActive) {
width = TAB_WIDTH_ACTIVE if (tabIndex() == 0) {
height = TAB_HEIGHT_ACTIVE if (isDisabled) {
RECTANGLE.middle.render(graphics, 2f, 2f, width - 4, height - 2) TAB_ACTIVE0_DISABLED.render(graphics, x = -2f)
} else if (isPressed) {
TAB_ACTIVE0_PRESSED.render(graphics, x = -2f)
} else if (isHovered) {
TAB_ACTIVE0_HOVERED.render(graphics, x = -2f)
} else { } else {
width = TAB_WIDTH TAB_ACTIVE0_IDLE.render(graphics, x = -2f)
height = TAB_HEIGHT }
TAB_BACKGROUND.render(graphics, 2f, 2f, width - 4, height - 2) } else {
if (isDisabled) {
TAB_ACTIVE_DISABLED.render(graphics, x = -2f)
} else if (isPressed) {
TAB_ACTIVE_PRESSED.render(graphics, x = -2f)
} else if (isHovered) {
TAB_ACTIVE_HOVERED.render(graphics, x = -2f)
} else {
TAB_ACTIVE_IDLE.render(graphics, x = -2f)
}
} }
RECTANGLE.top.render(graphics, 3f, 0f, width = width - 6) activeIcon?.render(graphics, x = width / 2f - 1f, y = height / 2f + 1f, gravity = RenderGravity.CENTER_CENTER)
RECTANGLE.left.render(graphics, 0f, 3f, height = (height - if (isActive) if (initial) 2 else 4 else 3)) } else {
if (tabIndex() == 0) {
RECTANGLE.right.render(graphics, width - RECTANGLE.right.width, 3f, height = (height - if (isActive) 4 else 3)) if (isDisabled) {
TAB_INACTIVE0_DISABLED.render(graphics)
RECTANGLE.topLeft.render(graphics, 0f, 0f) } else if (isPressed) {
RECTANGLE.topRight.render(graphics, width - RECTANGLE.topRight.width, 0f) TAB_INACTIVE0_PRESSED.render(graphics)
} else if (isHovered) {
if (isActive) { TAB_INACTIVE0_HOVERED.render(graphics)
if (!initial) { } else {
TAB_LEFT_CONNECTION.render(graphics, 0f, height - TAB_LEFT_CONNECTION.height - 1) TAB_INACTIVE0_IDLE.render(graphics)
}
} else {
if (isDisabled) {
TAB_INACTIVE_DISABLED.render(graphics)
} else if (isPressed) {
TAB_INACTIVE_PRESSED.render(graphics)
} else if (isHovered) {
TAB_INACTIVE_HOVERED.render(graphics)
} else {
TAB_INACTIVE_IDLE.render(graphics)
}
} }
TAB_RIGHT_CONNECTION.render( inactiveIcon?.render(graphics, x = width / 2f - 1f, y = height / 2f + 1f, gravity = RenderGravity.CENTER_CENTER)
graphics,
width - TAB_RIGHT_CONNECTION.width,
height - TAB_LEFT_CONNECTION.height - 1
)
val skinActive = activeIcon ?: return
skinActive.render(graphics, TAB_WIDTH_ACTIVE / 2f, TAB_HEIGHT_ACTIVE / 2f, gravity = RenderGravity.CENTER_CENTER)
} else {
val skinInactive = inactiveIcon ?: return
skinInactive.render(graphics, width / 2f, TAB_HEIGHT_ACTIVE / 2f, gravity = RenderGravity.CENTER_CENTER)
} }
} }
@ -118,6 +132,11 @@ open class FramePanel<out S : Screen>(
onOpen() onOpen()
} }
} }
override fun onRemoved() {
super.onRemoved()
tabs.remove(this)
}
} }
inner class CloseButton : AbstractButtonPanel<S>(screen, this@FramePanel, this@FramePanel.width - CLOSE_BUTTON.width, 0f, CLOSE_BUTTON.width, CLOSE_BUTTON.height) { inner class CloseButton : AbstractButtonPanel<S>(screen, this@FramePanel, this@FramePanel.width - CLOSE_BUTTON.width, 0f, CLOSE_BUTTON.width, CLOSE_BUTTON.height) {
@ -200,8 +219,7 @@ open class FramePanel<out S : Screen>(
override fun performLayout() { override fun performLayout() {
for ((i, tab) in tabs.withIndex()) { for ((i, tab) in tabs.withIndex()) {
tab.setPos(i * TAB_WIDTH, -TAB_HEIGHT) tab.setPos(i * 28f, -28f)
tab.initial = i == 0
} }
closeButton?.setPos(width - CLOSE_BUTTON.width, 0f) closeButton?.setPos(width - CLOSE_BUTTON.width, 0f)
@ -385,9 +403,25 @@ open class FramePanel<out S : Screen>(
padding = DockProperty(-3f, -3f, -3f, -3f) padding = DockProperty(-3f, -3f, -3f, -3f)
) )
val TAB_RIGHT_CONNECTION = WidgetLocation.MISC.sprite(x = 30f, y = 0f, width = 3f, height = 5f) val TAB_INACTIVE0_IDLE = WidgetLocation.TABS.sprite(x = 26f * 0f, width = 26f, height = 32f)
val TAB_LEFT_CONNECTION = WidgetLocation.MISC.sprite(x = 33f, y = 0f, width = 3f, height = 5f) val TAB_INACTIVE0_HOVERED = WidgetLocation.TABS.sprite(x = 26f * 1f, width = 26f, height = 32f)
val TAB_BACKGROUND = WidgetLocation.MISC.sprite(x = 30f, y = 6f, width = 6f, height = 6f) val TAB_INACTIVE0_PRESSED = WidgetLocation.TABS.sprite(x = 26f * 2f, width = 26f, height = 32f)
val TAB_INACTIVE0_DISABLED = WidgetLocation.TABS.sprite(x = 26f * 3f, width = 26f, height = 32f)
val TAB_INACTIVE_IDLE = WidgetLocation.TABS.sprite(x = 26f * 0f, y = 32f, width = 26f, height = 32f)
val TAB_INACTIVE_HOVERED = WidgetLocation.TABS.sprite(x = 26f * 1f, y = 32f, width = 26f, height = 32f)
val TAB_INACTIVE_PRESSED = WidgetLocation.TABS.sprite(x = 26f * 2f, y = 32f, width = 26f, height = 32f)
val TAB_INACTIVE_DISABLED = WidgetLocation.TABS.sprite(x = 26f * 3f, y = 32f, width = 26f, height = 32f)
val TAB_ACTIVE0_IDLE = WidgetLocation.TABS.sprite(x = 26f * 4f + 30f * 0f, width = 30f, height = 32f)
val TAB_ACTIVE0_HOVERED = WidgetLocation.TABS.sprite(x = 26f * 4f + 30f * 1f, width = 30f, height = 32f)
val TAB_ACTIVE0_PRESSED = WidgetLocation.TABS.sprite(x = 26f * 4f + 30f * 2f, width = 30f, height = 32f)
val TAB_ACTIVE0_DISABLED = WidgetLocation.TABS.sprite(x = 26f * 4f + 30f * 3f, width = 30f, height = 32f)
val TAB_ACTIVE_IDLE = WidgetLocation.TABS.sprite(x = 26f * 4f + 30f * 0f, y = 32f, width = 30f, height = 32f)
val TAB_ACTIVE_HOVERED = WidgetLocation.TABS.sprite(x = 26f * 4f + 30f * 1f, y = 32f, width = 30f, height = 32f)
val TAB_ACTIVE_PRESSED = WidgetLocation.TABS.sprite(x = 26f * 4f + 30f * 2f, y = 32f, width = 30f, height = 32f)
val TAB_ACTIVE_DISABLED = WidgetLocation.TABS.sprite(x = 26f * 4f + 30f * 3f, y = 32f, width = 30f, height = 32f)
val CLOSE_BUTTON = WidgetLocation.MISC.sprite(x = 51f, y = 0f, width = 13f, height = 14f) val CLOSE_BUTTON = WidgetLocation.MISC.sprite(x = 51f, y = 0f, width = 13f, height = 14f)
val CLOSE_BUTTON_HOVERED = WidgetLocation.MISC.sprite(x = 51f, y = 14f, width = 13f, height = 14f) val CLOSE_BUTTON_HOVERED = WidgetLocation.MISC.sprite(x = 51f, y = 14f, width = 13f, height = 14f)
@ -396,10 +430,5 @@ open class FramePanel<out S : Screen>(
val HELP_BUTTON = WidgetLocation.MISC.sprite(x = 40f, y = 0f, width = 11f, height = 14f) val HELP_BUTTON = WidgetLocation.MISC.sprite(x = 40f, y = 0f, width = 11f, height = 14f)
val HELP_BUTTON_HOVERED = WidgetLocation.MISC.sprite(x = 40f, y = 14f, width = 11f, height = 14f) val HELP_BUTTON_HOVERED = WidgetLocation.MISC.sprite(x = 40f, y = 14f, width = 11f, height = 14f)
val HELP_BUTTON_PRESSED = WidgetLocation.MISC.sprite(x = 40f, y = 28f, width = 11f, height = 14f) val HELP_BUTTON_PRESSED = WidgetLocation.MISC.sprite(x = 40f, y = 28f, width = 11f, height = 14f)
const val TAB_HEIGHT = 28f
const val TAB_WIDTH = 28f
const val TAB_HEIGHT_ACTIVE = 32f
const val TAB_WIDTH_ACTIVE = 28f
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB