-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.1.2 - Added hud modules, moved
eventListener
method to extensions
- Loading branch information
Showing
19 changed files
with
221 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
progreso-api/src/main/kotlin/org/progreso/api/module/AbstractHudModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.progreso.api.module | ||
|
||
/** | ||
* Hud module abstract class | ||
* | ||
* @param name Hud module name | ||
* @param description Hud module description | ||
* @param category Hud module category | ||
*/ | ||
abstract class AbstractHudModule( | ||
name: String, | ||
description: String, | ||
category: Category | ||
) : AbstractModule(name, description, category) { | ||
var dragging = false | ||
var dragX = 0 | ||
var dragY = 0 | ||
|
||
var x by setting("X", 0, 0..Int.MAX_VALUE) { false } | ||
var y by setting("Y", 0, 0..Int.MAX_VALUE) { false } | ||
|
||
open var width: Int = 0 | ||
open var height: Int = 0 | ||
|
||
abstract fun render() | ||
|
||
fun isHover(x: Int, y: Int) = | ||
x > this.x && x < this.x + width && y > this.y && y < this.y + height | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
progreso-client/src/main/kotlin/org/progreso/client/events/Extensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.progreso.client.events | ||
|
||
import net.minecraft.client.Minecraft | ||
import org.progreso.api.event.Event | ||
import org.progreso.api.event.EventListener | ||
import org.progreso.api.event.EventPriority | ||
import org.progreso.client.Client | ||
|
||
val mc: Minecraft = Minecraft.getMinecraft() | ||
|
||
@Suppress("RedundantSamConstructor") | ||
inline fun <reified T : Event> Any.eventListener(crossinline block: (T) -> Unit) { | ||
Client.EVENT_BUS.registerListener( | ||
instanceClass = javaClass, | ||
eventClass = T::class.java, | ||
priority = EventPriority.NORMAL, | ||
listener = EventListener<T> { | ||
block(it) | ||
} | ||
) | ||
} | ||
|
||
inline fun <reified T : Event> Any.safeEventListener(crossinline block: (T) -> Unit) { | ||
eventListener<T> { | ||
if (mc.player != null && mc.world != null) { | ||
block(it) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
progreso-client/src/main/kotlin/org/progreso/client/gui/HudEditor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.progreso.client.gui | ||
|
||
import org.progreso.api.managers.ModuleManager | ||
import org.progreso.api.module.AbstractHudModule | ||
import org.progreso.client.gui.component.components.CategoryComponent | ||
import org.progreso.client.module.Category | ||
|
||
class HudEditor : ClickGUI() { | ||
private companion object { | ||
val HUD_MODULES by lazy { | ||
ModuleManager.getModulesByCategory(Category.Hud) | ||
.filterIsInstance<AbstractHudModule>() | ||
} | ||
} | ||
|
||
override fun initialize() { | ||
components.add(Window(10, 10, COMPONENT_WIDTH).apply { | ||
x += COMPONENT_WIDTH + 10 | ||
|
||
this.components.add( | ||
CategoryComponent( | ||
Category.Hud, | ||
COMPONENT_HEIGHT, | ||
this | ||
) | ||
) | ||
}) | ||
} | ||
|
||
override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { | ||
super.drawScreen(mouseX, mouseY, partialTicks) | ||
|
||
HUD_MODULES.filter { it.dragging }.forEach { | ||
it.x = mouseX - it.dragX | ||
it.y = mouseY - it.dragY | ||
} | ||
} | ||
|
||
override fun mouseClicked(mouseX: Int, mouseY: Int, mouseButton: Int) { | ||
super.mouseClicked(mouseX, mouseY, mouseButton) | ||
|
||
HUD_MODULES.filter { it.isHover(mouseX, mouseY) }.forEach { | ||
it.dragging = true | ||
it.dragX = mouseX - it.x | ||
it.dragY = mouseY - it.y | ||
} | ||
} | ||
|
||
override fun mouseReleased(mouseX: Int, mouseY: Int, state: Int) { | ||
super.mouseReleased(mouseX, mouseY, state) | ||
|
||
HUD_MODULES.forEach { it.dragging = false } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ enum class Category : Category { | |
Movement, | ||
Render, | ||
Misc, | ||
Client | ||
Client, | ||
Hud | ||
} |
44 changes: 44 additions & 0 deletions
44
progreso-client/src/main/kotlin/org/progreso/client/module/HudModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.progreso.client.module | ||
|
||
import net.minecraft.client.Minecraft | ||
import net.minecraftforge.client.event.RenderGameOverlayEvent | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent | ||
import org.progreso.api.module.AbstractHudModule | ||
import org.progreso.client.Client | ||
import org.progreso.client.events.client.ModuleEvent | ||
import org.progreso.client.gui.ClickGUI | ||
import org.progreso.client.gui.HudEditor | ||
import org.progreso.client.util.Render2DUtil.drawRect | ||
|
||
abstract class HudModule( | ||
name: String, | ||
description: String, | ||
category: Category | ||
) : AbstractHudModule(name, description, category) { | ||
constructor(name: String, category: Category) : this(name, "", category) | ||
|
||
protected companion object { | ||
val mc: Minecraft = Minecraft.getMinecraft() | ||
} | ||
|
||
@SubscribeEvent | ||
fun onRender(event: RenderGameOverlayEvent.Text) { | ||
if (mc.currentScreen is HudEditor) { | ||
drawRect(x, y, width, height, ClickGUI.DEFAULT_RECT_COLOR) | ||
} | ||
|
||
render() | ||
} | ||
|
||
override fun onEnable() { | ||
if (Client.EVENT_BUS.post(ModuleEvent(this))) { | ||
return | ||
} | ||
} | ||
|
||
override fun onDisable() { | ||
if (Client.EVENT_BUS.post(ModuleEvent(this))) { | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
progreso-client/src/main/kotlin/org/progreso/client/module/modules/client/HudClickGUI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.progreso.client.module.modules.client | ||
|
||
import org.progreso.client.Client | ||
import org.progreso.client.module.Category | ||
import org.progreso.client.module.Module | ||
|
||
class HudClickGUI : Module("HudClickGUI", Category.Client) { | ||
init { | ||
onEnable { | ||
mc.displayGuiScreen(Client.HUD_EDITOR) | ||
toggle() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
progreso-client/src/main/kotlin/org/progreso/client/module/modules/hud/Watermark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.progreso.client.module.modules.hud | ||
|
||
import org.progreso.client.manager.managers.render.TextRenderManager | ||
import org.progreso.client.manager.managers.render.TextRenderManager.getStringWidth | ||
import org.progreso.client.module.Category | ||
import org.progreso.client.module.HudModule | ||
import org.progreso.client.util.Render2DUtil.drawString | ||
import java.awt.Color | ||
|
||
class Watermark : HudModule("Watermark", Category.Hud) { | ||
private val color by setting("Color", Color.RED) | ||
|
||
init { | ||
x = 10 | ||
y = 10 | ||
width = getStringWidth("Progreso Client") + 2 | ||
height = TextRenderManager.height + 6 | ||
} | ||
|
||
override fun render() { | ||
drawString("Progreso Client", x + 1, y + 2, color) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
progreso-client/src/main/kotlin/org/progreso/client/module/modules/movement/Sprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters