Skip to content

Commit 4192e9c

Browse files
committed
Clean up and fix a bunch of UI stuff
1 parent 1e34428 commit 4192e9c

File tree

9 files changed

+127
-17
lines changed

9 files changed

+127
-17
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.polyfrost.polyplus.client.gui
2+
3+
import org.polyfrost.polyui.component.Drawable
4+
import org.polyfrost.polyui.component.extensions.events
5+
import org.polyfrost.polyui.component.extensions.named
6+
import org.polyfrost.polyui.component.extensions.setPalette
7+
import org.polyfrost.polyui.component.impl.Button
8+
import org.polyfrost.polyui.component.impl.Group
9+
import org.polyfrost.polyui.component.impl.Text
10+
import org.polyfrost.polyui.event.Event
11+
import org.polyfrost.polyui.event.State
12+
import org.polyfrost.polyui.unit.Align
13+
import org.polyfrost.polyui.unit.Vec2
14+
15+
fun CartControls(count: State<Int>): Drawable {
16+
var checkoutButton: Drawable? = null
17+
18+
val countListener = countListener@ { count: Int ->
19+
var text = checkoutButton?.get(0)
20+
if (text !is Text) {
21+
text = checkoutButton?.get(1)
22+
}
23+
24+
if (text == null) {
25+
return@countListener false
26+
}
27+
28+
(text as? Text)?.text = createCheckoutButtonText(count)
29+
false
30+
}
31+
32+
count.listen(countListener)
33+
return Group(
34+
Button(
35+
text = "Cart",
36+
radii = floatArrayOf(6f),
37+
padding = Vec2(42.75f, 5.5f),
38+
size = Vec2(146f, 32f)
39+
).named("CartButton"),
40+
Button(
41+
text = createCheckoutButtonText(count.value),
42+
radii = floatArrayOf(6f),
43+
padding = Vec2(75.5f, 5.5f),
44+
size = Vec2(306f, 32f)
45+
).setPalette { brand.fg }.named("CheckoutButton").also { checkoutButton = it },
46+
size = Vec2(465f, 32f),
47+
alignment = Align(padBetween = Vec2(13f, 0f))
48+
).events {
49+
Event.Lifetime.Removed then {
50+
count.removeListener(countListener)
51+
Unit
52+
}
53+
}.named("CartControls")
54+
}
55+
56+
private fun createCheckoutButtonText(count: Int): String {
57+
return if (count > 0) {
58+
"Checkout $count items"
59+
} else {
60+
"Checkout"
61+
}
62+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.polyfrost.polyplus.client.gui
2+
3+
import org.polyfrost.polyui.component.Drawable
4+
import org.polyfrost.polyui.component.extensions.named
5+
import org.polyfrost.polyui.component.impl.Group
6+
import org.polyfrost.polyui.unit.Vec2
7+
8+
private const val CARD_WIDTH = 180f
9+
private const val CARD_HEIGHT = 258f
10+
11+
fun CosmeticList(size: Vec2): Drawable {
12+
val columnCount = (size.x / CARD_WIDTH).toInt()
13+
val rowCount = (size.y / CARD_HEIGHT).toInt()
14+
return Group(
15+
size = size,
16+
).named("CosmeticList")
17+
}

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.polyfrost.oneconfig.api.ui.v1.OCPolyUIBuilder
55
import org.polyfrost.oneconfig.api.ui.v1.UIManager
66
import org.polyfrost.polyplus.PolyPlusConstants
77
import org.polyfrost.polyui.animate.SetAnimation
8+
import org.polyfrost.polyui.color.rgba
89
import org.polyfrost.polyui.component.Drawable
910
import org.polyfrost.polyui.component.extensions.disable
1011
import org.polyfrost.polyui.component.extensions.named
@@ -18,6 +19,7 @@ import org.polyfrost.polyui.component.impl.Group
1819
import org.polyfrost.polyui.component.impl.Image
1920
import org.polyfrost.polyui.component.impl.Text
2021
import org.polyfrost.polyui.component.impl.TextInput
22+
import org.polyfrost.polyui.event.State
2123
import org.polyfrost.polyui.unit.Align
2224
import org.polyfrost.polyui.unit.Vec2
2325
import org.polyfrost.polyui.utils.image
@@ -35,17 +37,20 @@ object FullscreenLockerUI {
3537
val builder = OCPolyUIBuilder.create()
3638
.blurs()
3739
.atResolution(DESIGNED_WIDTH, DESIGNED_HEIGHT)
38-
.renderer(uiManager.renderer)
39-
.translatorDelegate("assets/${PolyPlusConstants.ID}")
40+
.backgroundColor(rgba(21, 21, 21))
41+
.size(1499f, 1080f)
42+
.translatorDelegate("assets/${PolyPlusConstants.ID}/lang")
43+
as OCPolyUIBuilder
4044

45+
val cartCount = State(0)
4146
val polyUI = builder.make(
4247
Group(
4348
// Header
4449
Group(
4550
// Left
4651
Group(
4752
// TODO: Implement navigation history
48-
Image("assets/oneconfig/ico/left-arrow.svg".image()).disable().onClick {
53+
Image("/assets/polyplus/ico/left-arrow.svg".image()).disable().onClick {
4954
// val prev = previous.removeLastOrNull() ?: return@onClick false
5055
// if (previous.isEmpty()) prevArrow?.disable()
5156
// val current = current
@@ -54,7 +59,7 @@ object FullscreenLockerUI {
5459
// nextArrow?.disable(false)
5560
false
5661
}.named("Back").bindTo(::backArrow),
57-
Image("assets/oneconfig/ico/right-arrow.svg".image()).disable().onClick {
62+
Image("/assets/polyplus/ico/right-arrow.svg".image()).disable().onClick {
5863
// val nextDrawable = next.removeLastOrNull() ?: return@onClick false
5964
// if (next.isEmpty()) nextArrow?.disable()
6065
// openPage(nextDrawable, clearNext = false)
@@ -66,43 +71,48 @@ object FullscreenLockerUI {
6671

6772
// Right
6873
Block(
69-
Image("assets/oneconfig/ico/search.svg".image()).named("SearchIcon"),
74+
Image("/assets/polyplus/ico/search.svg".image()).named("SearchIcon"),
7075
TextInput(
7176
placeholder = "polyplus.search.placeholder",
72-
visibleSize = Vec2(256f, 32f)
77+
visibleSize = Vec2(210f, 12f)
7378
).onChange { text: String ->
7479
// TODO: Filter cosmetics list based on search input
7580
false
76-
}.named("SearchInput")
81+
}.named("SearchInput"),
82+
83+
size = Vec2(256f, 32f),
84+
alignment = Align(pad = Vec2(10f, 7f))
7785
).onRightClick {
7886
(this[1] as TextInput).text = ""
79-
}.withBorder(1f) { page.border5 }.named("SearchField")
87+
}.withBorder(1f) { page.border5 }.named("SearchField"),
88+
89+
size = Vec2(1482f, 78f),
90+
alignment = Align(main = Align.Content.SpaceBetween, line = Align.Line.Center),
8091
),
8192

8293
// Content
8394
Group(
8495
// Cosmetic list
85-
Group(),
96+
CosmeticList(
97+
size = Vec2(972f, 802f),
98+
),
8699

87100
// Sidebar
88101
Group(
89102
// Purchasing options
90-
Group(
91-
92-
),
103+
CartControls(cartCount),
93104

94105
// Player preview
95-
Group()
106+
PlayerPreview(),
96107
),
97108
),
98109

99110
size = Vec2(1499f, 1080f),
100111
),
101112
)
102113

103-
val screen = uiManager.createPolyUIScreen(polyUI, DESIGNED_WIDTH, DESIGNED_HEIGHT, false, true) { }
104114
polyUI.window = uiManager.createWindow()
105-
return screen
115+
return uiManager.createPolyUIScreen(polyUI, DESIGNED_WIDTH, DESIGNED_HEIGHT, false, true) { }
106116
}
107117

108118
private fun Drawable.bindTo(ref: KMutableProperty0<Drawable?>): Drawable {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ object LockerUI {
2525
private fun LockerPage(): Drawable {
2626
return Group(
2727
// Cosmetics List
28-
Group(
29-
visibleSize = Vec2(610f, 614f),
28+
CosmeticList(
29+
size = Vec2(610f, 614f),
3030
),
3131

3232
// Right sidebar
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.polyfrost.polyplus.client.gui
2+
3+
import org.polyfrost.polyui.component.Drawable
4+
import org.polyfrost.polyui.component.extensions.named
5+
import org.polyfrost.polyui.component.impl.Group
6+
7+
fun PlayerPreview(): Drawable {
8+
return Group(
9+
).named("PlayerPreview")
10+
}
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
polyplus.locker.title=Locker
2+
polyplus.search.placeholder=Search cosmetics...

0 commit comments

Comments
 (0)