Skip to content

Commit 5780b9e

Browse files
committed
add moving animation
1 parent ae28bf9 commit 5780b9e

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/main/kotlin/com/lambda/client/module/modules/client/Notifications.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.lambda.client.event.events.RenderOverlayEvent
44
import com.lambda.client.module.Category
55
import com.lambda.client.module.Module
66
import com.lambda.client.util.color.ColorHolder
7+
import com.lambda.client.util.graphics.AnimationUtils
78
import com.lambda.client.util.graphics.GlStateUtils
89
import com.lambda.client.util.graphics.RenderUtils2D
910
import com.lambda.client.util.graphics.VertexHelper
@@ -23,6 +24,7 @@ object Notifications : Module(
2324
category = Category.CLIENT,
2425
description = "Shows notifications",
2526
alwaysListening = true,
27+
showOnArray = false,
2628
enabledByDefault = true
2729
) {
2830
private val page by setting("Page", Page.GENERAL)
@@ -39,8 +41,8 @@ object Notifications : Module(
3941
private val warningTimeout by setting("Warning Timeout", 4000, 1000..10000, 100, { page == Page.TIMEOUT })
4042
private val errorTimeout by setting("Error Timeout", 7000, 1000..10000, 100, { page == Page.TIMEOUT })
4143

42-
enum class RenderLocation(val renderDirection: Int) {
43-
BOTTOM_RIGHT(-1), BOTTOM_LEFT(-1), TOP_RIGHT(1), TOP_LEFT(1)
44+
enum class RenderLocation(val xValue:Int, val yValue: Int) {
45+
BOTTOM_RIGHT(1,-1), BOTTOM_LEFT(-1,-1), TOP_RIGHT(1,1), TOP_LEFT(-1,1)
4446
}
4547

4648
enum class NotificationMode {
@@ -75,7 +77,7 @@ object Notifications : Module(
7577
RenderLocation.TOP_RIGHT -> GL11.glTranslatef((scaledResolution.scaledWidth_double - horizontalPadding - 90).toFloat(), verticalPadding, 0f)
7678
RenderLocation.TOP_LEFT -> GL11.glTranslatef(horizontalPadding, verticalPadding, 0f)
7779
}
78-
GlStateManager.translate(0.0, index * (notificationHeight + 3.0) * renderLocation.renderDirection, 0.0)
80+
GlStateManager.translate(0.0, index * renderLocation.yValue * ((notificationHeight + 3.0) * notification.animate()), 0.0)
7981
drawNotification(vertexHelper, notification)
8082
GlStateManager.popMatrix()
8183
}
@@ -131,6 +133,12 @@ object Notifications : Module(
131133
else -> GuiColors.backGround
132134
}
133135

136+
GlStateManager.pushMatrix()
137+
val animatedPercent = notification.animate()
138+
val animationXOffset = textWidth * renderLocation.xValue *(1.0f - animatedPercent)
139+
GlStateManager.translate(animationXOffset,0.0f,0.0f)
140+
141+
134142
// Draw background
135143
RenderUtils2D.drawRectFilled(vertexHelper, Vec2d.ZERO, Vec2d(width, notificationHeight), backgroundColor)
136144

@@ -143,6 +151,8 @@ object Notifications : Module(
143151
// Draw text
144152
FontRenderAdapter.drawString(notification.text, 4.0f, textPosY, true,
145153
ColorHolder(255, 255, 255, alpha), textScale, CustomFont.isEnabled)
154+
155+
GlStateManager.popMatrix()
146156
}
147157

148158
fun addNotification(notification: Notification) {
@@ -165,4 +175,11 @@ object Notifications : Module(
165175
NotificationType.WARNING -> ColorHolder(255, 255, 0, alpha)
166176
NotificationType.ERROR -> ColorHolder(255, 0, 0, alpha)
167177
}
178+
private fun Notification.animate() : Float{
179+
return if ((System.currentTimeMillis() - startTime) < (duration.toLong() / 2)){
180+
AnimationUtils.exponentInc(AnimationUtils.toDeltaTimeFloat(startTime), 200.0f)
181+
}else{
182+
AnimationUtils.exponentDec(AnimationUtils.toDeltaTimeFloat(startTime + duration - 200), 200.0f)
183+
}
184+
}
168185
}

0 commit comments

Comments
 (0)