-
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.
- Loading branch information
Showing
14 changed files
with
300 additions
and
143 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/me/imtoggle/quickswitch/mixin/ModConfigPageMixin.java
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,36 @@ | ||
package me.imtoggle.quickswitch.mixin; | ||
|
||
import cc.polyfrost.oneconfig.config.elements.OptionPage; | ||
import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; | ||
import cc.polyfrost.oneconfig.utils.InputHandler; | ||
import me.imtoggle.quickswitch.Selector; | ||
import me.imtoggle.quickswitch.config.ModConfig; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(value = ModConfigPage.class, remap = false) | ||
public class ModConfigPageMixin { | ||
|
||
@Shadow @Final private OptionPage page; | ||
|
||
@ModifyVariable(method = "draw", at = @At("STORE"), ordinal = 2) | ||
private int optionY(int value) { | ||
if (this.page.mod == ModConfig.INSTANCE.mod) { | ||
return value + 48; | ||
} | ||
return value; | ||
} | ||
|
||
@Inject(method = "drawStatic", at = @At("HEAD"), cancellable = true) | ||
private void drawSelector(long vg, int x, int y, InputHandler inputHandler, CallbackInfoReturnable<Integer> cir) { | ||
if (this.page.mod == ModConfig.INSTANCE.mod) { | ||
Selector.INSTANCE.draw(vg, x + 32, y + 16, inputHandler); | ||
cir.setReturnValue(64); | ||
} | ||
} | ||
} |
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
52 changes: 0 additions & 52 deletions
52
src/main/kotlin/me/imtoggle/quickswitch/KeyBindsRenderer.kt
This file was deleted.
Oops, something went wrong.
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,93 @@ | ||
package me.imtoggle.quickswitch | ||
|
||
import cc.polyfrost.oneconfig.config.elements.BasicOption | ||
import cc.polyfrost.oneconfig.events.EventManager | ||
import cc.polyfrost.oneconfig.events.event.RawMouseEvent | ||
import cc.polyfrost.oneconfig.gui.elements.BasicButton | ||
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe | ||
import cc.polyfrost.oneconfig.renderer.asset.SVG | ||
import cc.polyfrost.oneconfig.utils.InputHandler | ||
import cc.polyfrost.oneconfig.utils.color.ColorPalette | ||
import me.imtoggle.quickswitch.config.KeyBindEntry | ||
import me.imtoggle.quickswitch.config.ModConfig | ||
import me.imtoggle.quickswitch.element.ItemTypeElement | ||
import me.imtoggle.quickswitch.element.KeyBindElement | ||
|
||
@Suppress("UnstableAPIUsage") | ||
object MainRenderer : BasicOption(null, null, "", "", "", "", 2) { | ||
private val PLUS = SVG("/assets/plus.svg") | ||
private val addButton = BasicButton(32, 32, PLUS, BasicButton.ALIGNMENT_CENTER, ColorPalette.PRIMARY) | ||
|
||
var keyElements = ArrayList<KeyBindElement>() | ||
|
||
var removeQueue = ArrayList<KeyBindElement>() | ||
|
||
var dragging: ItemTypeElement? = null | ||
var currentHeight = 0 | ||
var target = -1 | ||
var xOffset = 0f | ||
var yOffset = 0f | ||
var checkChange = false | ||
|
||
init { | ||
addButton.setClickAction { | ||
val entry = KeyBindEntry() | ||
ModConfig.entries.add(entry) | ||
entry.onAdd() | ||
} | ||
EventManager.INSTANCE.register(this) | ||
} | ||
|
||
@Subscribe | ||
private fun onMouse(event: RawMouseEvent) { | ||
if (event.button == 0 && event.state == 0) { | ||
checkChange = true | ||
} | ||
} | ||
|
||
override fun getHeight(): Int = currentHeight | ||
|
||
override fun draw(vg: Long, x: Int, y: Int, inputHandler: InputHandler) { | ||
var renderY = y | ||
for (element in keyElements) { | ||
element.draw(vg, x.toFloat(), renderY.toFloat(), inputHandler) | ||
renderY += 96 | ||
} | ||
if (inputHandler.isMouseDown) { | ||
tryDraw(dragging, vg, inputHandler.mouseX() - xOffset, inputHandler.mouseY() - yOffset, inputHandler) | ||
} | ||
if (checkChange) { | ||
checkChange = false | ||
dragging?.let { | ||
for (element in keyElements) { | ||
if (element.hovered) { | ||
element.addItem(it.id, target, false) | ||
} | ||
} | ||
dragging = null | ||
} | ||
inputHandler.stopBlockingInput() | ||
} | ||
for (element in removeQueue) { | ||
keyElements.remove(element) | ||
element.entry.onRemove() | ||
} | ||
removeQueue.clear() | ||
addButton.draw(vg, x.toFloat(), renderY.toFloat(), inputHandler) | ||
|
||
currentHeight = renderY - y + 32 | ||
} | ||
|
||
fun tryDraw(element: ItemTypeElement?, vg: Long, x: Float, y: Float, inputHandler: InputHandler) { | ||
element?.let { | ||
inputHandler.blockAllInput() | ||
it.draw(vg, inputHandler.mouseX() - xOffset, inputHandler.mouseY() - yOffset, inputHandler) | ||
} | ||
} | ||
|
||
override fun keyTyped(key: Char, keyCode: Int) { | ||
for (element in keyElements) { | ||
element.keyBindButton.isKeyTyped(keyCode) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,18 @@ | ||
package me.imtoggle.quickswitch | ||
|
||
import cc.polyfrost.oneconfig.config.elements.BasicOption | ||
import cc.polyfrost.oneconfig.events.EventManager | ||
import cc.polyfrost.oneconfig.events.event.RawMouseEvent | ||
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe | ||
import cc.polyfrost.oneconfig.utils.InputHandler | ||
import me.imtoggle.quickswitch.element.ItemTypeElement | ||
|
||
object Selector : BasicOption(null, null, "", "", "", "", 2) { | ||
object Selector { | ||
|
||
var elements: Array<ItemTypeElement> = Array(ItemTypes.entries.size) { ItemTypeElement(it, true) } | ||
var elements: Array<ItemTypeElement> = Array(ItemTypes.entries.size) { ItemTypeElement(it, 0) } | ||
|
||
var adding: ItemTypeElement? = null | ||
|
||
var xOffset = 0f | ||
var yOffset = 0f | ||
var stop = false | ||
|
||
init { | ||
EventManager.INSTANCE.register(this) | ||
} | ||
|
||
@Subscribe | ||
private fun onMouse(event: RawMouseEvent) { | ||
if (event.button == 0 && event.state == 0) { | ||
adding = null | ||
stop = true | ||
} | ||
} | ||
|
||
override fun getHeight(): Int = 48 | ||
|
||
override fun draw(vg: Long, x: Int, y: Int, inputHandler: InputHandler) { | ||
fun draw(vg: Long, x: Int, y: Int, inputHandler: InputHandler) { | ||
var renderX = x | ||
for (element in elements) { | ||
element.draw(vg, renderX.toFloat(), y.toFloat(), inputHandler) | ||
renderX += 48 | ||
} | ||
if (inputHandler.isMouseDown) { | ||
adding?.let { | ||
inputHandler.blockAllInput() | ||
it.draw(vg, inputHandler.mouseX() - xOffset, inputHandler.mouseY() - yOffset, inputHandler) | ||
} | ||
} | ||
if (stop) { | ||
inputHandler.stopBlockingInput() | ||
stop = 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
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
Oops, something went wrong.