Skip to content

Commit 86d41d7

Browse files
committed
More UI stuff
1 parent ce561dd commit 86d41d7

File tree

4 files changed

+92
-22
lines changed

4 files changed

+92
-22
lines changed
Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,62 @@
1+
@file:Suppress("FunctionName")
2+
13
package org.polyfrost.polyplus.client.gui
24

35
import org.polyfrost.polyui.component.Drawable
46
import org.polyfrost.polyui.component.extensions.events
57
import org.polyfrost.polyui.component.extensions.named
8+
import org.polyfrost.polyui.component.extensions.namedId
9+
import org.polyfrost.polyui.component.extensions.onClick
610
import org.polyfrost.polyui.component.extensions.setPalette
7-
import org.polyfrost.polyui.component.impl.Button
11+
import org.polyfrost.polyui.component.extensions.withHoverStates
12+
import org.polyfrost.polyui.component.impl.Block
813
import org.polyfrost.polyui.component.impl.Group
14+
import org.polyfrost.polyui.component.impl.Image
915
import org.polyfrost.polyui.component.impl.Text
16+
import org.polyfrost.polyui.data.PolyImage
1017
import org.polyfrost.polyui.event.Event
1118
import org.polyfrost.polyui.event.State
1219
import org.polyfrost.polyui.unit.Align
1320
import org.polyfrost.polyui.unit.Vec2
21+
import org.polyfrost.polyui.utils.image
1422

1523
fun CartControls(count: State<Int>): Drawable {
24+
var cartButton: Drawable? = null
1625
var checkoutButton: Drawable? = null
1726

1827
val countListener = countListener@ { count: Int ->
19-
var text = checkoutButton?.get(0)
20-
if (text !is Text) {
21-
text = checkoutButton?.get(1)
28+
cartButton?.let {
29+
updateCartIcon(it, count)
2230
}
2331

24-
if (text == null) {
25-
return@countListener false
32+
checkoutButton?.let {
33+
updateCheckoutButtonText(it, count)
2634
}
2735

28-
(text as? Text)?.text = createCheckoutButtonText(count)
2936
false
3037
}
3138

3239
count.listen(countListener)
40+
41+
val currentCartCount = count.value
3342
return Group(
34-
Button(
43+
PlusButton(
44+
image = createCartIconPath(currentCartCount).image(),
3545
text = "Cart",
3646
radii = floatArrayOf(6f),
37-
padding = Vec2(42.75f, 5.5f),
3847
size = Vec2(146f, 32f)
39-
).named("CartButton"),
40-
Button(
41-
text = createCheckoutButtonText(count.value),
48+
).named("CartButton").also { cartButton = it },
49+
PlusButton(
50+
image = "/assets/polyplus/ico/shopping-bag.svg".image(),
51+
text = createCheckoutButtonText(currentCartCount),
4252
radii = floatArrayOf(6f),
43-
padding = Vec2(75.5f, 5.5f),
4453
size = Vec2(306f, 32f)
45-
).setPalette { brand.fg }.named("CheckoutButton").also { checkoutButton = it },
54+
).onClick {
55+
count.value++
56+
Unit
57+
}.setPalette { brand.fg }.named("CheckoutButton").also { checkoutButton = it },
4658
size = Vec2(465f, 32f),
47-
alignment = Align(padBetween = Vec2(13f, 0f))
59+
alignment = Align(padBetween = Vec2(13f, 0f), padEdges = Vec2.ZERO, wrap = Align.Wrap.NEVER)
4860
).events {
4961
Event.Lifetime.Removed then {
5062
count.removeListener(countListener)
@@ -53,10 +65,57 @@ fun CartControls(count: State<Int>): Drawable {
5365
}.named("CartControls")
5466
}
5567

68+
private fun PlusButton(
69+
image: PolyImage,
70+
text: String,
71+
radii: FloatArray,
72+
padding: Vec2 = Vec2(12f, 6f),
73+
size: Vec2 = Vec2.ZERO,
74+
): Block {
75+
return Block(
76+
Image(image).named("Icon"),
77+
Text(text, fontSize = 12f),
78+
radii = radii,
79+
size = size,
80+
alignment = Align(main = Align.Content.Center, wrap = Align.Wrap.NEVER, pad = padding)
81+
).withHoverStates().namedId("PlusButton")
82+
}
83+
84+
private fun createCartIconPath(count: Int): String {
85+
if (true) {
86+
// Just until the rest are done
87+
return "/assets/polyplus/ico/shopping-cart/0.svg"
88+
}
89+
90+
return when {
91+
count <= 0 -> "/assets/polyplus/ico/shopping-cart/0.svg"
92+
count in 1..9 -> "/assets/polyplus/ico/shopping-cart/$count.svg"
93+
else -> "/assets/polyplus/ico/shopping-cart/9+.svg"
94+
}
95+
}
96+
97+
private fun updateCartIcon(button: Drawable, count: Int) {
98+
var icon = button[0]
99+
if (icon !is Image) {
100+
icon = button[1]
101+
}
102+
103+
(icon as? Image)?.image = createCartIconPath(count).image()
104+
}
105+
56106
private fun createCheckoutButtonText(count: Int): String {
57107
return if (count > 0) {
58108
"Checkout $count items"
59109
} else {
60110
"Checkout"
61111
}
62112
}
113+
114+
private fun updateCheckoutButtonText(button: Drawable, count: Int) {
115+
var text = button[0]
116+
if (text !is Text) {
117+
text = button[1]
118+
}
119+
120+
(text as? Text)?.text = createCheckoutButtonText(count)
121+
}

src/main/kotlin/org/polyfrost/polyplus/client/gui/FullscreenLockerUI.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.polyfrost.polyplus.client.gui
22

3-
import net.minecraft.client.gui.GuiScreen
3+
import dev.deftu.omnicore.api.client.screen.OmniScreen
44
import org.polyfrost.oneconfig.api.ui.v1.OCPolyUIBuilder
55
import org.polyfrost.oneconfig.api.ui.v1.UIManager
66
import org.polyfrost.polyplus.PolyPlusConstants
7-
import org.polyfrost.polyui.animate.SetAnimation
87
import org.polyfrost.polyui.color.rgba
98
import org.polyfrost.polyui.component.Drawable
109
import org.polyfrost.polyui.component.extensions.disable
@@ -32,7 +31,7 @@ object FullscreenLockerUI {
3231
private var backArrow: Drawable? = null
3332
private var forwardArrow: Drawable? = null
3433

35-
fun create(): GuiScreen {
34+
fun create(): OmniScreen {
3635
val uiManager = UIManager.INSTANCE
3736
val builder = OCPolyUIBuilder.create()
3837
.blurs()
@@ -42,7 +41,7 @@ object FullscreenLockerUI {
4241
.translatorDelegate("assets/${PolyPlusConstants.ID}/lang")
4342
as OCPolyUIBuilder
4443

45-
val cartCount = State(0)
44+
val cartCount = State(3)
4645
val polyUI = builder.make(
4746
Group(
4847
// Header
@@ -86,15 +85,15 @@ object FullscreenLockerUI {
8685
(this[1] as TextInput).text = ""
8786
}.withBorder(1f) { page.border5 }.named("SearchField"),
8887

89-
size = Vec2(1482f, 78f),
90-
alignment = Align(main = Align.Content.SpaceBetween, line = Align.Line.Center),
88+
size = Vec2(1482f, 36f),
89+
alignment = Align(main = Align.Content.SpaceBetween, cross = Align.Content.Center, line = Align.Line.Center, padEdges = Vec2(0f, 21f)),
9190
),
9291

9392
// Content
9493
Group(
9594
// Cosmetic list
9695
CosmeticList(
97-
size = Vec2(972f, 802f),
96+
size = Vec2(1010f, 973f),
9897
),
9998

10099
// Sidebar
@@ -104,7 +103,13 @@ object FullscreenLockerUI {
104103

105104
// Player preview
106105
PlayerPreview(),
106+
107+
size = Vec2(465f, 973f),
108+
alignment = Align(mode = Align.Mode.Vertical, padBetween = Vec2(0f, 12f), padEdges = Vec2(2f, 2f))
107109
),
110+
111+
size = Vec2(1499f, 973f),
112+
alignment = Align(padEdges = Vec2.ZERO, padBetween = Vec2(24f, 0f))
108113
),
109114

110115
size = Vec2(1499f, 1080f),
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)