Skip to content

Commit e728d39

Browse files
committed
Work on getting cosmetics list working
1 parent b228504 commit e728d39

File tree

6 files changed

+110
-16
lines changed

6 files changed

+110
-16
lines changed

root.gradle.kts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,21 @@ preprocess {
88

99
"1.21.8-fabric"(1_21_08, "yarn") {
1010
"1.21.8-neoforge"(1_21_08, "srg") {
11-
1211
"1.21.5-neoforge"(1_21_05, "srg") {
1312
"1.21.5-fabric"(1_21_05, "yarn") {
14-
1513
"1.21.4-fabric"(1_21_04, "yarn") {
1614
"1.21.4-neoforge"(1_21_04, "srg") {
17-
1815
"1.21.1-neoforge"(1_21_01, "srg") {
1916
"1.21.1-fabric"(1_21_01, "yarn") {
20-
2117
"1.20.4-fabric"(1_20_04, "yarn") {
2218
"1.20.4-neoforge"(1_20_04, "srg") {
2319
"1.20.4-forge"(1_20_04, "srg") {
24-
2520
"1.20.1-forge"(1_20_01, "srg") {
2621
"1.20.1-fabric"(1_20_01, "yarn") {
27-
2822
"1.16.5-fabric"(1_16_05, "yarn") {
2923
"1.16.5-forge"(1_16_05, "srg") {
30-
31-
"1.12.2-forge"(1_12_02, "srg") {
24+
"1.12.2-forge"(1_12_02, "srg", file("versions/mappings/1.16.5-1.12.2.txt")) {
3225
"1.12.2-fabric"(1_12_02, "yarn") {
33-
3426
"1.8.9-fabric"(1_08_09, "yarn"){
3527
"1.8.9-forge"(1_08_09, "srg")
3628
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private fun createCartIcon(count: Int): PolyImage {
9494
if (image.size != ICON_SIZE) {
9595
PolyImage.setImageSize(image, ICON_SIZE)
9696
}
97-
97+
9898
return image
9999
}
100100

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,96 @@
1+
@file:Suppress("FunctionName")
2+
13
package org.polyfrost.polyplus.client.gui
24

5+
import kotlinx.coroutines.future.asCompletableFuture
6+
import org.polyfrost.polyplus.client.network.http.PolyCosmetics
7+
import org.polyfrost.polyplus.client.network.http.responses.Cosmetic
8+
import org.polyfrost.polyui.color.rgba
39
import org.polyfrost.polyui.component.Drawable
10+
import org.polyfrost.polyui.component.extensions.hide
11+
import org.polyfrost.polyui.component.extensions.ignoreLayout
412
import org.polyfrost.polyui.component.extensions.named
13+
import org.polyfrost.polyui.component.extensions.setPalette
14+
import org.polyfrost.polyui.component.impl.Block
515
import org.polyfrost.polyui.component.impl.Group
16+
import org.polyfrost.polyui.component.impl.Text
17+
import org.polyfrost.polyui.unit.Align
618
import org.polyfrost.polyui.unit.Vec2
719

20+
private const val TEST_PRICE = "12.99"
821
private const val CARD_WIDTH = 180f
922
private const val CARD_HEIGHT = 258f
1023

1124
fun CosmeticList(size: Vec2): Drawable {
1225
val columnCount = (size.x / CARD_WIDTH).toInt()
1326
val rowCount = (size.y / CARD_HEIGHT).toInt()
27+
28+
val cosmetics = mutableListOf<Cosmetic>()
29+
PolyCosmetics.getAll().asCompletableFuture().thenAccept { result ->
30+
result.onSuccess { list ->
31+
cosmetics.addAll(list.contents)
32+
}
33+
}.join()
34+
1435
return Group(
36+
children = List(rowCount) { rowIndex ->
37+
Group(
38+
children = List(columnCount) { columnIndex ->
39+
val cosmeticIndex = rowIndex * columnCount + columnIndex
40+
if (cosmeticIndex < cosmetics.size) {
41+
CosmeticCard(cosmetics[cosmeticIndex])
42+
} else {
43+
null
44+
}
45+
}.filterNotNull().toTypedArray(),
46+
47+
alignment = Align(padEdges = Vec2.ZERO, padBetween = Vec2(18f, 14f)),
48+
size = Vec2(CARD_WIDTH * columnCount, CARD_HEIGHT),
49+
)
50+
}.toTypedArray(),
51+
52+
alignment = Align(padEdges = Vec2(13f, 17f)),
1553
size = size,
1654
).named("CosmeticList")
1755
}
56+
57+
private fun CosmeticCard(cosmetic: Cosmetic): Drawable {
58+
return Block(
59+
// Tag
60+
Block(
61+
62+
).ignoreLayout().hide(),
63+
64+
// Preview
65+
Block(
66+
size = Vec2(144f, 144f),
67+
color = rgba(40, 40, 40),
68+
),
69+
70+
Group(
71+
// Name
72+
Text(
73+
text = "Cosmetic ${cosmetic.id}",
74+
fontSize = 14f
75+
),
76+
77+
// Price
78+
Text(
79+
text = "$${TEST_PRICE}",
80+
fontSize = 14f,
81+
),
82+
83+
size = Vec2(144f, 42f),
84+
alignment = Align(
85+
line = Align.Line.Start,
86+
mode = Align.Mode.Vertical,
87+
padBetween = Vec2(0f, 2f),
88+
padEdges = Vec2.ZERO
89+
),
90+
),
91+
92+
size = Vec2(CARD_WIDTH, CARD_HEIGHT),
93+
alignment = Align(main = Align.Content.Center, cross = Align.Content.Center, padEdges = Vec2.ZERO),
94+
radii = floatArrayOf(12f),
95+
).named("CosmeticCard")
96+
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.polyfrost.polyplus.client.gui
22

3+
import dev.deftu.omnicore.api.client.player
34
import dev.deftu.omnicore.api.client.screen.OmniScreen
45
import org.polyfrost.oneconfig.api.ui.v1.OCPolyUIBuilder
56
import org.polyfrost.oneconfig.api.ui.v1.UIManager
@@ -81,7 +82,9 @@ object FullscreenLockerUI {
8182

8283
size = Vec2(256f, 32f),
8384
alignment = Align(pad = Vec2(10f, 7f))
84-
).onRightClick {
85+
).onClick {
86+
polyUI.focus((this[1] as TextInput))
87+
}.onRightClick {
8588
(this[1] as TextInput).text = ""
8689
}.withBorder(1f) { page.border5 }.named("SearchField"),
8790

@@ -102,7 +105,10 @@ object FullscreenLockerUI {
102105
CartControls(cartCount),
103106

104107
// Player preview
105-
PlayerPreview(),
108+
PlayerPreview(
109+
player = player!!,
110+
size = Vec2(465f, 916f)
111+
),
106112

107113
size = Vec2(465f, 973f),
108114
alignment = Align(mode = Align.Mode.Vertical, padBetween = Vec2(0f, 12f), padEdges = Vec2(2f, 2f))
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
package org.polyfrost.polyplus.client.gui
22

3+
import net.minecraft.client.gui.inventory.GuiInventory
4+
import net.minecraft.entity.player.EntityPlayer
35
import org.polyfrost.polyui.component.Drawable
46
import org.polyfrost.polyui.component.extensions.named
5-
import org.polyfrost.polyui.component.impl.Group
7+
import org.polyfrost.polyui.unit.Vec2
68

7-
fun PlayerPreview(): Drawable {
8-
return Group(
9-
).named("PlayerPreview")
9+
fun PlayerPreview(
10+
player: EntityPlayer,
11+
size: Vec2,
12+
): Drawable {
13+
return object : Drawable(
14+
size = size
15+
) {
16+
override fun render() {
17+
// val posX = this.x.toInt()
18+
// val posY = this.y.toInt()
19+
// val width = this.width
20+
// val height = this.height
21+
// val scale = ((if (width < height) width else height) / 1.5f).toInt()
22+
// GuiInventory.drawEntityOnScreen(posX, posY, scale, 0f, 0f, player)
23+
}
24+
}.named("PlayerPreview")
1025
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
net.minecraft.client.gui.screens.inventory.InventoryScreen net.minecraft.client.gui.inventory.GuiInventory
2+
net.minecraft.client.gui.screens.inventory.InventoryScreen renderEntityInInventory() drawEntityOnScreen()

0 commit comments

Comments
 (0)