Skip to content

Commit a5378ce

Browse files
committed
Moved everything to native rendering
1 parent 04de9a1 commit a5378ce

11 files changed

Lines changed: 253 additions & 148 deletions

File tree

src/main/java/com/github/freedownloadhere/killauravideo/GlobalManager.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.freedownloadhere.killauravideo
33
import com.github.freedownloadhere.killauravideo.rendering.RenderUtils
44
import com.github.freedownloadhere.killauravideo.ui.core.Core
55
import com.github.freedownloadhere.killauravideo.ui.core.render.JavaNativeRendering
6+
import com.github.freedownloadhere.killauravideo.ui.core.render.RenderingBackend
67
import com.github.freedownloadhere.killauravideo.utils.EntityPositions
78
import com.github.freedownloadhere.killauravideo.utils.KeybindMap
89
import net.minecraft.client.Minecraft
@@ -65,11 +66,14 @@ object GlobalManager {
6566
private var tempInit = false
6667
@SubscribeEvent
6768
fun renderWorldEvent(e: RenderWorldLastEvent) {
68-
if(!tempInit) {
69-
val sw = Minecraft.getMinecraft().displayWidth.toFloat()
70-
val sh = Minecraft.getMinecraft().displayHeight.toFloat()
71-
JavaNativeRendering.nInit(sw, sh)
72-
tempInit = true
73-
}
69+
if(tempInit) return
70+
val sw = Minecraft.getMinecraft().displayWidth.toFloat()
71+
val sh = Minecraft.getMinecraft().displayHeight.toFloat()
72+
RenderingBackend.init(sw, sh)
73+
RenderingBackend.loadTexture(
74+
"checkmark",
75+
"/assets/killauravideo/textures/gui/check.png"
76+
)
77+
tempInit = true
7478
}
7579
}

src/main/java/com/github/freedownloadhere/killauravideo/ui/basic/UIIcon.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.github.freedownloadhere.killauravideo.ui.basic
22

3+
import com.github.freedownloadhere.killauravideo.ui.core.render.RenderingBackend
34
import com.github.freedownloadhere.killauravideo.ui.core.render.UINewRenderer
45
import com.github.freedownloadhere.killauravideo.ui.interfaces.layout.ILayoutPost
6+
import com.github.freedownloadhere.killauravideo.ui.util.UIColorEnum
57
import com.github.freedownloadhere.killauravideo.ui.util.UIConfig
68
import net.minecraft.util.ResourceLocation
79

@@ -12,18 +14,20 @@ class UIIcon(config: UIConfig): UI(config), ILayoutPost {
1214
LARGE(50.0)
1315
}
1416

15-
companion object {
16-
var iconLocation = ResourceLocation("killauravideo", "textures/gui/check.png")
17-
}
18-
1917
var scale: Scale = Scale.MEDIUM
2018
override var hidden: Boolean = false
2119

2220
override fun renderCallback(info: UINewRenderer.RenderInfo) {
23-
// GlStateManager.pushMatrix()
24-
// GlStateManager.scale(width, height, 0.0)
25-
// renderer.drawRect(iconLocation, filled = true)
26-
// GlStateManager.popMatrix()
21+
RenderingBackend.drawRect(
22+
(info.absX + relX).toFloat(),
23+
(info.absY + relY).toFloat(),
24+
info.layer * 0.01f,
25+
width.toFloat(), height.toFloat(),
26+
UIColorEnum.BOX_SECONDARY, UIColorEnum.BOX_TERNARY,
27+
info.config.rounding.toFloat(),
28+
info.config.bordering.toFloat(),
29+
"checkmark"
30+
)
2731
}
2832

2933
override fun layoutPostCallback() {

src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UIButton.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class UIButton(config: UIConfig): UI(config), IUniqueParent<UIText>, ILayoutPost
3333
}
3434

3535
override fun mouseEventCallback(mouseInfo: MouseInfo) {
36-
if(mouseInfo.lastLeftClicked?.ui == this && mouseInfo.isClicked && cooldownLeft == 0L) {
36+
if(mouseInfo.lcmInstant?.ui == this && cooldownLeft == 0L) {
3737
onClick()
3838
cooldownLeft = cooldown
3939
color = UIColorEnum.BOX_TERNARY

src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UICheckbox.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class UICheckbox(config: UIConfig): UI(config), IUniqueParent<UIIcon>, IDrawable
2828
override var padding: Double = config.padding
2929

3030
override fun mouseEventCallback(mouseInfo: MouseInfo) {
31-
if(mouseInfo.lastLeftClicked?.ui == this && mouseInfo.isClicked) {
31+
if(mouseInfo.lcmInstant?.ui == this) {
3232
checked = !checked
3333
onCheck()
3434
}

src/main/java/com/github/freedownloadhere/killauravideo/ui/composite/UISlider.kt

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.freedownloadhere.killauravideo.ui.composite
22

33
import com.github.freedownloadhere.killauravideo.ui.basic.UI
44
import com.github.freedownloadhere.killauravideo.ui.core.io.MouseInfo
5+
import com.github.freedownloadhere.killauravideo.ui.core.render.RenderingBackend
56
import com.github.freedownloadhere.killauravideo.ui.core.render.UINewRenderer
67
import com.github.freedownloadhere.killauravideo.ui.interfaces.io.IGrabbable
78
import com.github.freedownloadhere.killauravideo.ui.interfaces.io.IMouseEvent
@@ -34,10 +35,10 @@ class UISlider(config: UIConfig): UI(config), IPadded, IDrawable, ILayoutPost, I
3435
var segmentCount: Int = 5
3536

3637
override fun mouseEventCallback(mouseInfo: MouseInfo) {
37-
if(mouseInfo.lastLeftClicked?.ui != this)
38+
if(mouseInfo.lcmGrabbed?.ui != this)
3839
return
39-
val relX = mouseInfo.lastX - mouseInfo.lastLeftClicked!!.absX
40-
position = relX / width
40+
val relX = mouseInfo.lastX - mouseInfo.lcmGrabbed!!.absX
41+
position = (relX / width).coerceIn(0.0, 1.0)
4142
if(segmented) {
4243
val segmentLength = 1.0 / segmentCount
4344
position = floor(position / segmentLength) * segmentLength
@@ -47,28 +48,40 @@ class UISlider(config: UIConfig): UI(config), IPadded, IDrawable, ILayoutPost, I
4748

4849
override var hidden: Boolean = false
4950
override fun renderCallback(info: UINewRenderer.RenderInfo) {
50-
val tess = Tessellator.getInstance()
51-
val wr = tess.worldRenderer
52-
val lineWidth = GL11.glGetFloat(GL11.GL_LINE_WIDTH)
53-
val sliderCol = UIColorEnum.ACCENT
54-
val barCol = UIColorEnum.TEXT_SECONDARY
55-
GL11.glLineWidth(2.0f)
56-
wr.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR)
57-
wr.pos(0.0, 0.5 * height - 1.0, 0.0).color(barCol.r, barCol.g, barCol.b, barCol.a).endVertex()
58-
wr.pos(width, 0.5 * height - 1.0, 0.0).color(barCol.r, barCol.g, barCol.b, barCol.a).endVertex()
59-
tess.draw()
51+
RenderingBackend.drawLine(
52+
info.absX.toFloat() + relX.toFloat() + 0.0f,
53+
info.absY.toFloat() + relY.toFloat() + 0.5f * height.toFloat() - 1.0f,
54+
info.layer * 0.01f,
55+
info.absX.toFloat() + relX.toFloat() + width.toFloat(),
56+
info.absY.toFloat() + relY.toFloat() + 0.5f * height.toFloat() - 1.0f,
57+
info.layer * 0.01f,
58+
UIColorEnum.TEXT_SECONDARY,
59+
2.0f
60+
)
61+
6062
for(i in 0..segmentCount) {
61-
wr.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR)
62-
wr.pos((width * i) / segmentCount, height * 0.25, 0.0).color(barCol.r, barCol.g, barCol.b, barCol.a).endVertex()
63-
wr.pos((width * i) / segmentCount, height * 0.75, 0.0).color(barCol.r, barCol.g, barCol.b, barCol.a).endVertex()
64-
tess.draw()
63+
RenderingBackend.drawLine(
64+
info.absX.toFloat() + relX.toFloat() + (width.toFloat() * i) / segmentCount,
65+
info.absY.toFloat() + relY.toFloat() + height.toFloat() * 0.25f,
66+
info.layer * 0.01f,
67+
info.absX.toFloat() + relX.toFloat() + (width.toFloat() * i) / segmentCount,
68+
info.absY.toFloat() + relY.toFloat() + height.toFloat() * 0.75f,
69+
info.layer * 0.01f,
70+
UIColorEnum.TEXT_SECONDARY,
71+
2.0f
72+
)
6573
}
66-
GL11.glLineWidth(4.0f)
67-
wr.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR)
68-
wr.pos(width * position, 0.0, 0.0).color(sliderCol.r, sliderCol.g, sliderCol.b, sliderCol.a).endVertex()
69-
wr.pos(width * position, height, 0.0).color(sliderCol.r, sliderCol.g, sliderCol.b, sliderCol.a).endVertex()
70-
tess.draw()
71-
GL11.glLineWidth(lineWidth)
74+
75+
RenderingBackend.drawLine(
76+
info.absX.toFloat() + relX.toFloat() + width.toFloat() * position.toFloat(),
77+
info.absY.toFloat() + relY.toFloat() + 0.0f,
78+
info.layer * 0.01f,
79+
info.absX.toFloat() + relX.toFloat() + width.toFloat() * position.toFloat(),
80+
info.absY.toFloat() + relY.toFloat() + height.toFloat(),
81+
info.layer * 0.01f,
82+
UIColorEnum.ACCENT,
83+
4.0f
84+
)
7285
}
7386

7487
override fun layoutPostCallback() {

src/main/java/com/github/freedownloadhere/killauravideo/ui/containers/UIBox.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class UIBox(config: UIConfig): UI(config), ILayoutPost, IParent, IDrawa
2323
override fun renderCallback(info: UINewRenderer.RenderInfo) = uiBoxDraw(info, baseColor)
2424

2525
override fun mouseEventCallback(mouseInfo: MouseInfo) {
26-
if(mouseInfo.lastLeftClicked?.ui == this && canBeMoved) {
26+
if(canBeMoved && mouseInfo.lcmGrabbed?.ui == this) {
2727
relX += mouseInfo.dX
2828
relY += mouseInfo.dY
2929
}

src/main/java/com/github/freedownloadhere/killauravideo/ui/core/Core.kt

Lines changed: 97 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -39,102 +39,114 @@ class Core: GuiScreen() {
3939
// topLevelUI = verticalBox {
4040
// relX = 300.0
4141
// relY = 300.0
42-
// padding = 0.0
43-
// spacing = 0.0
4442
// + text("Very Large") { scale = UIText.Scale.VERY_LARGE }
4543
// + text("Large") { scale = UIText.Scale.LARGE }
4644
// + text("Medium") { scale = UIText.Scale.MEDIUM }
4745
// + text("Small") { scale = UIText.Scale.SMALL }
4846
// + text("Very Small") { scale = UIText.Scale.VERY_SMALL }
4947
// }
5048

49+
topLevelUI = verticalBox {
50+
val ka = GlobalManager.clientInstance!!.moduleMap.module("killaura") as Killaura
51+
52+
+ centerBox {
53+
child = text("Killaura") {
54+
scale = UIText.Scale.SMALL
55+
}
56+
width = 200.0
57+
}
58+
59+
+ verticalBox {
60+
padding = 0.0
61+
hidden = true
62+
63+
+ horizontalBox {
64+
placeLeft()
65+
+ text("Toggled") {
66+
scale = UIText.Scale.SMALL
67+
}
68+
placeRight()
69+
+ checkbox {
70+
checked = ka.toggled
71+
child.scale = UIIcon.Scale.SMALL
72+
onCheck = { ka.toggle() }
73+
}
74+
}
75+
76+
+ verticalBox {
77+
spacing = 5.0
78+
79+
val minReach = 3.0
80+
val maxReach = 6.0
81+
82+
+ horizontalBox {
83+
padding = 0.0
84+
hidden = true
85+
placeLeft()
86+
+ text("Reach") {
87+
scale = UIText.Scale.SMALL
88+
}
89+
placeRight()
90+
+ text {
91+
scale = UIText.Scale.SMALL
92+
source = { ka.limiter.maxReach.toString() }
93+
}
94+
}
95+
+ horizontalBox {
96+
padding = 0.0
97+
hidden = true
98+
placeLeft()
99+
+ text {
100+
source = { minReach.toString() }
101+
scale = UIText.Scale.SMALL
102+
baseColor = UIColorEnum.TEXT_SECONDARY
103+
}
104+
placeRight()
105+
+ text {
106+
source = { maxReach.toString() }
107+
scale = UIText.Scale.SMALL
108+
baseColor = UIColorEnum.TEXT_SECONDARY
109+
}
110+
}
111+
+ slider {
112+
minValue = minReach
113+
maxValue = maxReach
114+
segmented = true
115+
segmentCount = 6
116+
selectedValue = ka.limiter.maxReach
117+
clickAction = { ka.limiter.maxReach = selectedValue }
118+
}
119+
}
120+
}
121+
}
122+
123+
51124
// topLevelUI = verticalBox {
52-
// val ka = GlobalManager.clientInstance!!.moduleMap.module("killaura") as Killaura
53-
//
54-
// + centerBox {
55-
// child = text("Killaura") {
56-
// scale = UIText.Scale.SMALL
57-
// }
58-
// width = 200.0
125+
// canBeMoved = true
126+
// + verticalBox {
127+
// baseColor = UIColorEnum.BOX_SECONDARY
128+
// + text { source = {"Mouse Info Info"}; scale = UIText.Scale.LARGE }
59129
// }
60-
//
61130
// + verticalBox {
62-
// padding = 0.0
63-
// hidden = true
64-
//
65-
// + horizontalBox {
66-
// placeLeft()
67-
// + text("Toggled") {
68-
// scale = UIText.Scale.SMALL
69-
// }
70-
// placeRight()
71-
// + checkbox {
72-
// checked = ka.toggled
73-
// child.scale = UIIcon.Scale.SMALL
74-
// onCheck = { ka.toggle() }
75-
// }
76-
// }
77-
//
78-
// + verticalBox {
79-
// spacing = 5.0
80-
//
81-
// val minReach = 3.0
82-
// val maxReach = 6.0
83-
//
84-
// + horizontalBox {
85-
// padding = 0.0
86-
// hidden = true
87-
// placeLeft()
88-
// + text("Reach") {
89-
// scale = UIText.Scale.SMALL
90-
// }
91-
// placeRight()
92-
// + text {
93-
// scale = UIText.Scale.SMALL
94-
// source = { ka.limiter.maxReach.toString() }
95-
// }
96-
// }
97-
// + horizontalBox {
98-
// padding = 0.0
99-
// hidden = true
100-
// placeLeft()
101-
// + text {
102-
// source = { minReach.toString() }
103-
// scale = UIText.Scale.SMALL
104-
// baseColor = UIColorEnum.TEXT_SECONDARY
105-
// }
106-
// placeRight()
107-
// + text {
108-
// source = { maxReach.toString() }
109-
// scale = UIText.Scale.SMALL
110-
// baseColor = UIColorEnum.TEXT_SECONDARY
111-
// }
112-
// }
113-
//// + slider {
114-
//// minValue = minReach
115-
//// maxValue = maxReach
116-
//// segmented = true
117-
//// segmentCount = 6
118-
//// selectedValue = ka.limiter.maxReach
119-
//// clickAction = { ka.limiter.maxReach = selectedValue }
120-
//// }
121-
// }
131+
// + text { source = {"DX: ${mouseInfo.dX}"} }
132+
// + text { source = {"DY: ${mouseInfo.dY}"} }
133+
// + text { source = {"LastX: ${mouseInfo.lastX}"} }
134+
// + text { source = {"LastY: ${mouseInfo.lastY}"} }
135+
// + text { source = {"Left Click"} }
136+
// + text { source = {"Hold time: ${mouseInfo.lcmHoldTime}"} }
137+
// + text { source = {"Instant: ${mouseInfo.lcmInstant?.ui?.hashCode()}"}; scale = UIText.Scale.SMALL }
138+
// + text { source = {"Current: ${mouseInfo.lcmCurrent?.ui?.hashCode()}"}; scale = UIText.Scale.SMALL }
139+
// + text { source = {"Grabbed: ${mouseInfo.lcmGrabbed?.ui?.hashCode()}"}; scale = UIText.Scale.SMALL }
140+
// + text { source = {"Hovered: ${mouseInfo.lcmHovered?.ui?.hashCode()}"}; scale = UIText.Scale.SMALL }
141+
// + text { source = {"Right Click"} }
142+
// + text { source = {"Hold time: ${mouseInfo.rcmHoldTime}"} }
143+
// + text { source = {"Instant: ${mouseInfo.rcmInstant?.ui?.hashCode()}"}; scale = UIText.Scale.SMALL }
144+
// + text { source = {"Current: ${mouseInfo.rcmCurrent?.ui?.hashCode()}"}; scale = UIText.Scale.SMALL }
145+
// + text { source = {"Grabbed: ${mouseInfo.rcmGrabbed?.ui?.hashCode()}"}; scale = UIText.Scale.SMALL }
146+
// + text { source = {"Hovered: ${mouseInfo.rcmHovered?.ui?.hashCode()}"}; scale = UIText.Scale.SMALL }
122147
// }
123148
// }
124149

125-
topLevelUI = verticalBox {
126-
canBeMoved = true
127-
+ text { source = {"Mouse Info Info"}; scale = UIText.Scale.LARGE }
128-
+ text { source = {"DX: ${mouseInfo.dX}"} }
129-
+ text { source = {"DY: ${mouseInfo.dY}"} }
130-
+ text { source = {"LastX: ${mouseInfo.lastX}"} }
131-
+ text { source = {"LastY: ${mouseInfo.lastY}"} }
132-
+ text { source = {"Last left clicked:"} }
133-
+ text { source = {"${mouseInfo.lastLeftClicked?.ui}"}; scale = UIText.Scale.SMALL }
134-
+ text { source = {"Current hovered:"} }
135-
+ text { source = {"${mouseInfo.currentHovered?.ui}"}; scale = UIText.Scale.SMALL }
136-
}
137-
138150
interactionManager = InteractionManager(mouseInfo, topLevelUI, config)
139151
renderer = UINewRenderer(config)
140152
}
@@ -146,6 +158,8 @@ class Core: GuiScreen() {
146158

147159
JavaNativeRendering.nUpdateScreenSize(width.toFloat(), height.toFloat())
148160

161+
interactionManager.handleMouseInput()
162+
149163
if(topLevelUI is ILayout)
150164
(topLevelUI as ILayout).applyLayout()
151165

@@ -154,10 +168,6 @@ class Core: GuiScreen() {
154168
renderer.renderEverything(topLevelUI)
155169
}
156170

157-
override fun handleMouseInput() {
158-
interactionManager.handleMouseInput()
159-
}
160-
161171
override fun keyTyped(typedChar: Char, keyCode: Int) {
162172
super.keyTyped(typedChar, keyCode)
163173
interactionManager.handleKeyTyped(typedChar, keyCode)

0 commit comments

Comments
 (0)