Skip to content

Commit

Permalink
🚚 deleted screens package, renamed impl object
Browse files Browse the repository at this point in the history
  • Loading branch information
asoji committed Jun 30, 2024
1 parent f32bd43 commit 1d88338
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 149 deletions.
31 changes: 15 additions & 16 deletions src/main/kotlin/gay/asoji/innerpastels/client/InnerPastelsClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package gay.asoji.innerpastels.client

import com.mojang.blaze3d.platform.InputConstants
import gay.asoji.innerpastels.InnerPastels
import gay.asoji.innerpastels.client.screens.imgui.ImGuiPanel
import gay.asoji.innerpastels.client.screens.imgui.ImGuiScreen
import gay.asoji.innerpastels.client.screens.imgui.ImGuiScreen.implGl3
import gay.asoji.innerpastels.client.screens.imgui.ImGuiScreen.implGlfw
import gay.asoji.innerpastels.client.imgui.InnerPastelsImGuiImpl
import gay.asoji.innerpastels.client.imgui.InnerPastelsImGuiImpl.implGl3
import gay.asoji.innerpastels.client.imgui.InnerPastelsImGuiImpl.implGlfw
import gay.asoji.innerpastels.client.imgui.ImGuiPanel
import gay.asoji.innerpastels.events.InputAction
import gay.asoji.innerpastels.events.KeyInputEvent
import gay.asoji.innerpastels.events.MouseInputEvent
Expand Down Expand Up @@ -41,13 +41,14 @@ class InnerPastelsClient : ClientModInitializer {
while (DEVELOPER_UI_BINDING.consumeClick()) {
if (client.player != null && client.screen == null) {
isImGuiRenderEnabled = !isImGuiRenderEnabled

implGl3.shutdown()
implGlfw.shutdown()
}
}
}

override fun onInitializeClient() {


if (FabricLoader.getInstance().isDevelopmentEnvironment) {
initializeDevKeybinds()
}
Expand All @@ -58,38 +59,36 @@ class InnerPastelsClient : ClientModInitializer {
}
implGl3.newFrame()
implGlfw.newFrame()
ImGuiScreen.imgui.newFrame()
InnerPastelsImGuiImpl.imgui.newFrame()

InnerPastelsClient.panels.forEach {
panels.forEach {
it.render(booleanArrayOf(true))
}

ImGuiScreen.imgui.render()
InnerPastelsImGuiImpl.imgui.render()
implGl3.renderDrawData(Objects.requireNonNull<DrawData>(ImGui.drawData))
}

KeyInputEvent.EVENT.register { key, scancode, action, mods ->
when (action) {
InputAction.PRESS -> ImGuiScreen.keyPressed(key, scancode, mods)
InputAction.RELEASE -> ImGuiScreen.keyReleased(key, scancode, mods)
InputAction.PRESS -> InnerPastelsImGuiImpl.keyPressed(key, scancode, mods)
InputAction.RELEASE -> InnerPastelsImGuiImpl.keyReleased(key, scancode, mods)
}
}

MouseInputEvent.EVENT.register { button, action, mods ->
val mouseX = Minecraft.getInstance().mouseHandler.xpos()
val mouseY = Minecraft.getInstance().mouseHandler.ypos()
when (action) {
InputAction.PRESS -> ImGuiScreen.mouseClicked(mouseX, mouseY, button)
InputAction.RELEASE -> ImGuiScreen.mouseReleased(mouseX, mouseY, button)
InputAction.PRESS -> InnerPastelsImGuiImpl.mouseClicked(mouseX, mouseY, button)
InputAction.RELEASE -> InnerPastelsImGuiImpl.mouseReleased(mouseX, mouseY, button)
}

InnerPastels.LOGGER.debug("$mouseX, $mouseY, $action")
}

MouseScrollInputEvent.EVENT.register{ xOffset, yOffset ->
val mouseX = Minecraft.getInstance().mouseHandler.xpos()
val mouseY = Minecraft.getInstance().mouseHandler.ypos()
ImGuiScreen.mouseScrolled(mouseX, mouseY, xOffset, yOffset)
InnerPastelsImGuiImpl.mouseScrolled(mouseX, mouseY, xOffset, yOffset)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package gay.asoji.innerpastels.client.screens.imgui

interface ImGuiPanel {
fun render(open_: BooleanArray)
package gay.asoji.innerpastels.client.imgui

interface ImGuiPanel {
fun render(open_: BooleanArray)
}
Original file line number Diff line number Diff line change
@@ -1,130 +1,110 @@
package gay.asoji.innerpastels.client.screens.imgui

import gay.asoji.innerpastels.client.InnerPastelsClient
import gln.cap.Caps
import imgui.ImGui
import imgui.MINECRAFT_BEHAVIORS
import imgui.MouseButton
import imgui.classes.Context
import imgui.impl.gl.ImplGL3
import imgui.impl.glfw.ImplGlfw
import imgui.impl.glfw.ImplGlfw.Companion.imguiKey
import imgui.internal.DrawData
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component
import org.lwjgl.glfw.GLFW
import uno.gl.GlWindow
import uno.glfw.GlfwWindow
import java.util.*


@Environment(EnvType.CLIENT)
object ImGuiScreen {
val imgui = ImGui

var implGl3: ImplGL3
var implGlfw: ImplGlfw

// Initialization for imgui.
init {
MINECRAFT_BEHAVIORS = true

val glfwWindow = GlfwWindow(Minecraft.getInstance().window.window)
val window = GlWindow(glfwWindow, Caps.Profile.CORE, true)

window.makeCurrent(true)
Context().setCurrent()

implGlfw = ImplGlfw(window, false, null)
implGl3 = ImplGL3()
}

fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean {
if (imgui.io.wantCaptureMouse) {
imgui.io.addMouseButtonEvent(MouseButton.of(button), false)
}

return imgui.io.wantCaptureMouse
}

fun mouseScrolled(mouseX: Double, mouseY: Double, scrollX: Double, scrollY: Double): Boolean {
if (imgui.io.wantCaptureMouse) {
imgui.io.mouseWheelH = scrollX.toFloat()
imgui.io.mouseWheel = scrollY.toFloat()
}

return imgui.io.wantCaptureMouse
}

fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
if (imgui.io.wantCaptureMouse) {
imgui.io.addMouseButtonEvent(MouseButton.of(button), true)
}

return imgui.io.wantCaptureMouse
}

fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
if (imgui.io.wantCaptureKeyboard) {
val key = uno.glfw.Key.of(keyCode).imguiKey

imgui.io.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0
imgui.io.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0
imgui.io.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0
imgui.io.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0

imgui.io.addKeyEvent(key, true)
imgui.io.keysData[key.index].down = true
imgui.io.setKeyEventNativeData(key, key.i, scanCode)
}

return imgui.io.wantCaptureKeyboard
}

fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
if (imgui.io.wantCaptureKeyboard) {
val key = uno.glfw.Key.of(keyCode).imguiKey

imgui.io.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0
imgui.io.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0
imgui.io.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0
imgui.io.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0

imgui.io.addKeyEvent(key, false)
imgui.io.keysData[key.index].down = false
imgui.io.setKeyEventNativeData(key, key.i, scanCode)
}

return imgui.io.wantCaptureKeyboard
}

fun charTyped(codePoint: Char, modifiers: Int): Boolean {
if (imgui.io.wantCaptureKeyboard) {
imgui.io.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0
imgui.io.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0
imgui.io.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0
imgui.io.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0

imgui.io.addInputCharacter(codePoint)
}

return imgui.io.wantCaptureKeyboard
}

fun render(guiGraphics: GuiGraphics, x: Int, y: Int, partialTicks: Float) {
// implGl3.newFrame()
// implGlfw.newFrame()
// imgui.newFrame()
//
// InnerPastelsClient.panels.forEach {
// it.render(booleanArrayOf(true))
// }
//
// imgui.render()
// implGl3.renderDrawData(Objects.requireNonNull<DrawData>(ImGui.drawData))
}
package gay.asoji.innerpastels.client.imgui

import gln.cap.Caps
import imgui.ImGui
import imgui.MINECRAFT_BEHAVIORS
import imgui.MouseButton
import imgui.classes.Context
import imgui.impl.gl.ImplGL3
import imgui.impl.glfw.ImplGlfw
import imgui.impl.glfw.ImplGlfw.Companion.imguiKey
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.Minecraft
import org.lwjgl.glfw.GLFW
import uno.gl.GlWindow
import uno.glfw.GlfwWindow


@Environment(EnvType.CLIENT)
object InnerPastelsImGuiImpl {
val imgui = ImGui
var implGl3: ImplGL3
var implGlfw: ImplGlfw

// Initialization for imgui.
init {
MINECRAFT_BEHAVIORS = true

val glfwWindow = GlfwWindow(Minecraft.getInstance().window.window)
val window = GlWindow(glfwWindow, Caps.Profile.CORE, true)

window.makeCurrent(true)
Context().setCurrent()

implGlfw = ImplGlfw(window, false, null)
implGl3 = ImplGL3()
}

fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean {
if (imgui.io.wantCaptureMouse) {
imgui.io.addMouseButtonEvent(MouseButton.of(button), false)
}

return imgui.io.wantCaptureMouse
}

fun mouseScrolled(mouseX: Double, mouseY: Double, scrollX: Double, scrollY: Double): Boolean {
if (imgui.io.wantCaptureMouse) {
imgui.io.mouseWheelH = scrollX.toFloat()
imgui.io.mouseWheel = scrollY.toFloat()
}

return imgui.io.wantCaptureMouse
}

fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
if (imgui.io.wantCaptureMouse) {
imgui.io.addMouseButtonEvent(MouseButton.of(button), true)
}

return imgui.io.wantCaptureMouse
}

fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
if (imgui.io.wantCaptureKeyboard) {
val key = uno.glfw.Key.of(keyCode).imguiKey

imgui.io.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0
imgui.io.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0
imgui.io.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0
imgui.io.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0

imgui.io.addKeyEvent(key, true)
imgui.io.keysData[key.index].down = true
imgui.io.setKeyEventNativeData(key, key.i, scanCode)
}

return imgui.io.wantCaptureKeyboard
}

fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
if (imgui.io.wantCaptureKeyboard) {
val key = uno.glfw.Key.of(keyCode).imguiKey

imgui.io.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0
imgui.io.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0
imgui.io.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0
imgui.io.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0

imgui.io.addKeyEvent(key, false)
imgui.io.keysData[key.index].down = false
imgui.io.setKeyEventNativeData(key, key.i, scanCode)
}

return imgui.io.wantCaptureKeyboard
}

fun charTyped(codePoint: Char, modifiers: Int): Boolean {
if (imgui.io.wantCaptureKeyboard) {
imgui.io.keyCtrl = modifiers and GLFW.GLFW_MOD_CONTROL != 0
imgui.io.keyShift = modifiers and GLFW.GLFW_MOD_SHIFT != 0
imgui.io.keyAlt = modifiers and GLFW.GLFW_MOD_ALT != 0
imgui.io.keySuper = modifiers and GLFW.GLFW_MOD_SUPER != 0

imgui.io.addInputCharacter(codePoint)
}

return imgui.io.wantCaptureKeyboard
}
}

0 comments on commit 1d88338

Please sign in to comment.