mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
screenshot delete button, element: check if key was consumed
This commit is contained in:
parent
0a86f61e85
commit
9fd1688b39
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.data.text.events.click
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.input.mouse.MouseActions
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.input.mouse.MouseButtons
|
||||||
|
import glm_.vec2.Vec2i
|
||||||
|
|
||||||
|
class ClickCallbackClickEvent(val callback: () -> Unit) : ClickEvent {
|
||||||
|
|
||||||
|
override fun onClick(guiRenderer: GUIRenderer, position: Vec2i, button: MouseButtons, action: MouseActions) {
|
||||||
|
if (button != MouseButtons.LEFT || action != MouseActions.PRESS) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,7 @@ class CopyToClipboardClickEvent(
|
|||||||
if (button != MouseButtons.LEFT || action != MouseActions.PRESS) {
|
if (button != MouseButtons.LEFT || action != MouseActions.PRESS) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (guiRenderer.connection.profiles.gui.confirmation.copyToClipboard) {
|
if (!guiRenderer.connection.profiles.gui.confirmation.copyToClipboard) {
|
||||||
guiRenderer.renderWindow.window.clipboardText = text
|
guiRenderer.renderWindow.window.clipboardText = text
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class OpenFileClickEvent(
|
|||||||
if (button != MouseButtons.LEFT || action != MouseActions.PRESS) {
|
if (button != MouseButtons.LEFT || action != MouseActions.PRESS) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (guiRenderer.connection.profiles.gui.confirmation.openFile) {
|
if (!guiRenderer.connection.profiles.gui.confirmation.openFile) {
|
||||||
DesktopUtil.openFile(path)
|
DesktopUtil.openFile(path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class OpenURLClickEvent(
|
|||||||
if (button != MouseButtons.LEFT || action != MouseActions.PRESS) {
|
if (button != MouseButtons.LEFT || action != MouseActions.PRESS) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (guiRenderer.connection.profiles.gui.confirmation.openURL) {
|
if (!guiRenderer.connection.profiles.gui.confirmation.openURL) {
|
||||||
DesktopUtil.openURL(url)
|
DesktopUtil.openURL(url)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class SendMessageClickEvent(
|
|||||||
if (button != MouseButtons.LEFT || action != MouseActions.PRESS) {
|
if (button != MouseButtons.LEFT || action != MouseActions.PRESS) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (guiRenderer.connection.profiles.gui.confirmation.sendMessage) {
|
if (!guiRenderer.connection.profiles.gui.confirmation.sendMessage) {
|
||||||
guiRenderer.connection.util.sendChatMessage(message)
|
guiRenderer.connection.util.sendChatMessage(message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -113,42 +113,48 @@ open class ButtonElement(
|
|||||||
cacheUpToDate = false
|
cacheUpToDate = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions) {
|
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
if (button != MouseButtons.LEFT) {
|
if (button != MouseButtons.LEFT) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
if (action != MouseActions.PRESS) {
|
if (action != MouseActions.PRESS) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
submit()
|
submit()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKey(key: KeyCodes, type: KeyChangeTypes) {
|
override fun onKey(key: KeyCodes, type: KeyChangeTypes): Boolean {
|
||||||
if (!hovered) {
|
if (!hovered) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
if (key != KeyCodes.KEY_ENTER) {
|
if (key != KeyCodes.KEY_ENTER) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
if (type != KeyChangeTypes.PRESS) {
|
if (type != KeyChangeTypes.PRESS) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
submit()
|
submit()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseEnter(position: Vec2i) {
|
override fun onMouseEnter(position: Vec2i): Boolean {
|
||||||
hovered = true
|
hovered = true
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseLeave() {
|
override fun onMouseLeave(): Boolean {
|
||||||
hovered = false
|
hovered = false
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun submit() {
|
open fun submit() {
|
||||||
|
@ -171,12 +171,13 @@ open class TextElement(
|
|||||||
renderInfo.currentLineNumber = 0
|
renderInfo.currentLineNumber = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions) {
|
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean {
|
||||||
if (action != MouseActions.PRESS || button != MouseButtons.LEFT) {
|
if (action != MouseActions.PRESS || button != MouseButtons.LEFT) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
val text = getTextComponentAt(position) ?: return
|
val text = getTextComponentAt(position) ?: return false
|
||||||
text.clickEvent?.onClick(guiRenderer, position, button, action)
|
text.clickEvent?.onClick(guiRenderer, position, button, action)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTextComponentAt(position: Vec2i): TextComponent? {
|
private fun getTextComponentAt(position: Vec2i): TextComponent? {
|
||||||
|
@ -92,8 +92,9 @@ open class TextFlowElement(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onScroll(position: Vec2i, scrollOffset: Vec2d) {
|
override fun onScroll(position: Vec2i, scrollOffset: Vec2d): Boolean {
|
||||||
this.scrollOffset += scrollOffset.y.toInt()
|
this.scrollOffset += scrollOffset.y.toInt()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
@ -180,9 +181,10 @@ open class TextFlowElement(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions) {
|
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean {
|
||||||
val pair = getAt(position) ?: return
|
val pair = getAt(position) ?: return false
|
||||||
pair.first.textElement.onMouseAction(pair.second, button, action)
|
pair.first.textElement.onMouseAction(pair.second, button, action)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAt(position: Vec2i): Pair<TextFlowLineElement, Vec2i>? {
|
private fun getAt(position: Vec2i): Pair<TextFlowLineElement, Vec2i>? {
|
||||||
|
@ -96,7 +96,7 @@ class MarkTextElement(
|
|||||||
super.forceRender(offset, consumer, options)
|
super.forceRender(offset, consumer, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKey(key: KeyCodes, type: KeyChangeTypes) {
|
override fun onKey(key: KeyCodes, type: KeyChangeTypes): Boolean {
|
||||||
super.onKey(key, type)
|
super.onKey(key, type)
|
||||||
|
|
||||||
val controlDown = guiRenderer.isKeyDown(ModifierKeys.CONTROL)
|
val controlDown = guiRenderer.isKeyDown(ModifierKeys.CONTROL)
|
||||||
@ -104,7 +104,7 @@ class MarkTextElement(
|
|||||||
when (key) {
|
when (key) {
|
||||||
KeyCodes.KEY_A -> {
|
KeyCodes.KEY_A -> {
|
||||||
if (!controlDown) {
|
if (!controlDown) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
mark(0, chatComponent.message.length)
|
mark(0, chatComponent.message.length)
|
||||||
}
|
}
|
||||||
@ -114,8 +114,9 @@ class MarkTextElement(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCodes.KEY_ESCAPE -> unmark()
|
KeyCodes.KEY_ESCAPE -> unmark()
|
||||||
else -> return
|
else -> return true
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun copy() {
|
fun copy() {
|
||||||
|
@ -121,13 +121,14 @@ class TextInputElement(
|
|||||||
onChange()
|
onChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCharPress(char: Int) {
|
override fun onCharPress(char: Int): Boolean {
|
||||||
if (_value.length >= maxLength || !editable) {
|
if (_value.length >= maxLength || !editable) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
cursorTick = CURSOR_TICK_ON_ACTION
|
cursorTick = CURSOR_TICK_ON_ACTION
|
||||||
insert(char.toChar().toString())
|
insert(char.toChar().toString())
|
||||||
forceApply()
|
forceApply()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun mark(mark: Boolean, right: Boolean, modify: Int) {
|
private fun mark(mark: Boolean, right: Boolean, modify: Int) {
|
||||||
@ -168,9 +169,9 @@ class TextInputElement(
|
|||||||
textElement.unmark()
|
textElement.unmark()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKey(key: KeyCodes, type: KeyChangeTypes) {
|
override fun onKey(key: KeyCodes, type: KeyChangeTypes): Boolean {
|
||||||
if (type == KeyChangeTypes.RELEASE) {
|
if (type == KeyChangeTypes.RELEASE) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
val controlDown = guiRenderer.isKeyDown(ModifierKeys.CONTROL)
|
val controlDown = guiRenderer.isKeyDown(ModifierKeys.CONTROL)
|
||||||
val shiftDown = guiRenderer.isKeyDown(ModifierKeys.SHIFT)
|
val shiftDown = guiRenderer.isKeyDown(ModifierKeys.SHIFT)
|
||||||
@ -189,12 +190,12 @@ class TextInputElement(
|
|||||||
}
|
}
|
||||||
KeyCodes.KEY_BACKSPACE -> {
|
KeyCodes.KEY_BACKSPACE -> {
|
||||||
if (_value.isEmpty() || !editable) {
|
if (_value.isEmpty() || !editable) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
if (textElement.marked) {
|
if (textElement.marked) {
|
||||||
insert("")
|
insert("")
|
||||||
} else if (_pointer == 0) {
|
} else if (_pointer == 0) {
|
||||||
return
|
return true
|
||||||
} else {
|
} else {
|
||||||
val delete = if (controlDown) calculateWordPointer(false) else -1
|
val delete = if (controlDown) calculateWordPointer(false) else -1
|
||||||
_value.delete(_pointer + delete, _pointer)
|
_value.delete(_pointer + delete, _pointer)
|
||||||
@ -204,12 +205,12 @@ class TextInputElement(
|
|||||||
}
|
}
|
||||||
KeyCodes.KEY_DELETE -> {
|
KeyCodes.KEY_DELETE -> {
|
||||||
if (_value.isEmpty() || !editable) {
|
if (_value.isEmpty() || !editable) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
if (textElement.marked) {
|
if (textElement.marked) {
|
||||||
insert("")
|
insert("")
|
||||||
} else if (_pointer == _value.length) {
|
} else if (_pointer == _value.length) {
|
||||||
return
|
return true
|
||||||
} else {
|
} else {
|
||||||
val delete = if (controlDown) calculateWordPointer(true) else 1
|
val delete = if (controlDown) calculateWordPointer(true) else 1
|
||||||
_value.delete(_pointer, _pointer + delete)
|
_value.delete(_pointer, _pointer + delete)
|
||||||
@ -221,7 +222,7 @@ class TextInputElement(
|
|||||||
if (!shiftDown) {
|
if (!shiftDown) {
|
||||||
textElement.unmark()
|
textElement.unmark()
|
||||||
}
|
}
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
val modify = if (controlDown) {
|
val modify = if (controlDown) {
|
||||||
calculateWordPointer(false)
|
calculateWordPointer(false)
|
||||||
@ -235,7 +236,7 @@ class TextInputElement(
|
|||||||
if (!shiftDown && _pointer == _value.length) {
|
if (!shiftDown && _pointer == _value.length) {
|
||||||
textElement.unmark()
|
textElement.unmark()
|
||||||
}
|
}
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
val modify = if (controlDown) {
|
val modify = if (controlDown) {
|
||||||
calculateWordPointer(true)
|
calculateWordPointer(true)
|
||||||
@ -256,11 +257,13 @@ class TextInputElement(
|
|||||||
else -> return textElement.onKey(key, type)
|
else -> return textElement.onKey(key, type)
|
||||||
}
|
}
|
||||||
forceApply()
|
forceApply()
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions) {
|
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean {
|
||||||
if (action != MouseActions.PRESS) {
|
if (action != MouseActions.PRESS) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
val leftText = TextElement(guiRenderer, value, background = false)
|
val leftText = TextElement(guiRenderer, value, background = false)
|
||||||
leftText.prefMaxSize = Vec2i(position.x, size.y)
|
leftText.prefMaxSize = Vec2i(position.x, size.y)
|
||||||
@ -282,6 +285,7 @@ class TextInputElement(
|
|||||||
}
|
}
|
||||||
this._pointer = pointer
|
this._pointer = pointer
|
||||||
forceSilentApply()
|
forceSilentApply()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onChildChange(child: Element) {
|
override fun onChildChange(child: Element) {
|
||||||
|
@ -75,32 +75,36 @@ abstract class Menu(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseLeave() {
|
override fun onMouseLeave(): Boolean {
|
||||||
activeElement?.onMouseLeave()
|
activeElement?.onMouseLeave()
|
||||||
activeElement = null
|
activeElement = null
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseMove(position: Vec2i) {
|
override fun onMouseMove(position: Vec2i): Boolean {
|
||||||
val pair = getAt(position)
|
val pair = getAt(position)
|
||||||
|
|
||||||
if (activeElement != pair?.first) {
|
if (activeElement != pair?.first) {
|
||||||
activeElement?.onMouseLeave()
|
activeElement?.onMouseLeave()
|
||||||
pair?.first?.onMouseEnter(pair.second)
|
pair?.first?.onMouseEnter(pair.second)
|
||||||
activeElement = pair?.first
|
activeElement = pair?.first
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
pair?.first?.onMouseMove(pair.second)
|
pair?.first?.onMouseMove(pair.second)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseEnter(position: Vec2i) {
|
override fun onMouseEnter(position: Vec2i): Boolean {
|
||||||
val pair = getAt(position)
|
val pair = getAt(position)
|
||||||
pair?.first?.onMouseEnter(pair.second)
|
pair?.first?.onMouseEnter(pair.second)
|
||||||
activeElement = pair?.first
|
activeElement = pair?.first
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions) {
|
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean {
|
||||||
val (element, delta) = getAt(position) ?: return
|
val (element, delta) = getAt(position) ?: return true
|
||||||
element.onMouseAction(delta, button, action)
|
element.onMouseAction(delta, button, action)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onChildChange(child: Element) {
|
override fun onChildChange(child: Element) {
|
||||||
@ -155,8 +159,7 @@ abstract class Menu(
|
|||||||
super.tick()
|
super.tick()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKey(key: KeyCodes, type: KeyChangeTypes) {
|
override fun onKey(key: KeyCodes, type: KeyChangeTypes): Boolean {
|
||||||
super.onKey(key, type)
|
|
||||||
if (type != KeyChangeTypes.RELEASE && key == KeyCodes.KEY_TAB) {
|
if (type != KeyChangeTypes.RELEASE && key == KeyCodes.KEY_TAB) {
|
||||||
var element: Element?
|
var element: Element?
|
||||||
var initialIndex = elements.indexOf(activeElement)
|
var initialIndex = elements.indexOf(activeElement)
|
||||||
@ -170,33 +173,36 @@ abstract class Menu(
|
|||||||
index = 0
|
index = 0
|
||||||
}
|
}
|
||||||
if (index == initialIndex) {
|
if (index == initialIndex) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
element = elements.getOrNull(index) ?: return
|
element = elements.getOrNull(index) ?: return true
|
||||||
if (element.canFocus) {
|
if (element.canFocus) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
activeElement?.onMouseLeave()
|
activeElement?.onMouseLeave()
|
||||||
element.onMouseEnter(Vec2i.EMPTY)
|
element.onMouseEnter(Vec2i.EMPTY)
|
||||||
activeElement = element
|
activeElement = element
|
||||||
return // no passthrough the key to current active element
|
return true // no passthrough the key to current active element
|
||||||
}
|
}
|
||||||
activeElement?.onKey(key, type)
|
activeElement?.onKey(key, type)
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCharPress(char: Int) {
|
override fun onCharPress(char: Int): Boolean {
|
||||||
super.onCharPress(char)
|
|
||||||
activeElement?.onCharPress(char)
|
activeElement?.onCharPress(char)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onScroll(position: Vec2i, scrollOffset: Vec2d) {
|
override fun onScroll(position: Vec2i, scrollOffset: Vec2d): Boolean {
|
||||||
val (element, delta) = getAt(position) ?: return
|
val (element, delta) = getAt(position) ?: return true
|
||||||
element.onScroll(delta, scrollOffset)
|
element.onScroll(delta, scrollOffset)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reset() {
|
private fun reset() {
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu.confirmation
|
||||||
|
|
||||||
|
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||||
|
import de.bixilon.minosoft.data.text.TextComponent
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.elements.input.button.ButtonElement
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class DeleteScreenshotDialog(
|
||||||
|
guiRenderer: GUIRenderer,
|
||||||
|
private val screenshot: File,
|
||||||
|
) : AbstractConfirmationMenu(
|
||||||
|
guiRenderer,
|
||||||
|
"Do you want to delete this screenshot?",
|
||||||
|
TextComponent(screenshot.name, color = VALUE_COLOR),
|
||||||
|
) {
|
||||||
|
|
||||||
|
override fun createButtons(): Array<ButtonElement> {
|
||||||
|
return arrayOf(
|
||||||
|
ButtonElement(guiRenderer, "§cSure, delete it") {
|
||||||
|
DefaultThreadPool += { screenshot.delete() }
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
initButtons()
|
||||||
|
}
|
||||||
|
}
|
@ -118,31 +118,26 @@ class LayoutedGUIElement<T : LayoutedElement>(
|
|||||||
}
|
}
|
||||||
// move out
|
// move out
|
||||||
this.lastPosition = INVALID_MOUSE_POSITION
|
this.lastPosition = INVALID_MOUSE_POSITION
|
||||||
elementLayout.onMouseLeave()
|
return elementLayout.onMouseLeave()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
val delta = position - offset
|
val delta = position - offset
|
||||||
this.lastPosition = delta
|
this.lastPosition = delta
|
||||||
|
|
||||||
if (lastPosition.isOutside(offset, size)) {
|
if (lastPosition.isOutside(offset, size)) {
|
||||||
elementLayout.onMouseEnter(delta)
|
return elementLayout.onMouseEnter(delta)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elementLayout.onMouseMove(delta)
|
return elementLayout.onMouseMove(delta)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCharPress(char: Int): Boolean {
|
override fun onCharPress(char: Int): Boolean {
|
||||||
elementLayout.onCharPress(char)
|
return elementLayout.onCharPress(char)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKeyPress(type: KeyChangeTypes, key: KeyCodes): Boolean {
|
override fun onKeyPress(type: KeyChangeTypes, key: KeyCodes): Boolean {
|
||||||
val mouseButton = MouseButtons[key]
|
val mouseButton = MouseButtons[key]
|
||||||
if (mouseButton == null) {
|
if (mouseButton == null) {
|
||||||
elementLayout.onKey(key, type)
|
return elementLayout.onKey(key, type)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val position = lastPosition
|
val position = lastPosition
|
||||||
@ -151,8 +146,7 @@ class LayoutedGUIElement<T : LayoutedElement>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val mouseAction = MouseActions[type] ?: return false
|
val mouseAction = MouseActions[type] ?: return false
|
||||||
elementLayout.onMouseAction(position, mouseButton, mouseAction)
|
return elementLayout.onMouseAction(position, mouseButton, mouseAction)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onScroll(scrollOffset: Vec2d): Boolean {
|
override fun onScroll(scrollOffset: Vec2d): Boolean {
|
||||||
@ -160,8 +154,7 @@ class LayoutedGUIElement<T : LayoutedElement>(
|
|||||||
if (lastPosition == INVALID_MOUSE_POSITION) {
|
if (lastPosition == INVALID_MOUSE_POSITION) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
elementLayout.onScroll(position, scrollOffset)
|
return elementLayout.onScroll(position, scrollOffset)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClose() {
|
override fun onClose() {
|
||||||
|
@ -34,12 +34,13 @@ abstract class AbstractChatElement(guiRenderer: GUIRenderer) : Element(guiRender
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onScroll(position: Vec2i, scrollOffset: Vec2d) {
|
override fun onScroll(position: Vec2i, scrollOffset: Vec2d): Boolean {
|
||||||
val size = messages.size
|
val size = messages.size
|
||||||
if (position.y > size.y || position.x > messages.size.x) {
|
if (position.y > size.y || position.x > messages.size.x) {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
messages.onScroll(position, scrollOffset)
|
messages.onScroll(position, scrollOffset)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
|
@ -133,11 +133,13 @@ class ChatElement(guiRenderer: GUIRenderer) : AbstractChatElement(guiRenderer) {
|
|||||||
messages.onClose()
|
messages.onClose()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCharPress(char: Int) {
|
override fun onCharPress(char: Int): Boolean {
|
||||||
if (char == '§'.code) {
|
if (char == '§'.code) {
|
||||||
return input.onCharPress('&'.code)
|
input.onCharPress('&'.code)
|
||||||
|
} else {
|
||||||
|
input.onCharPress(char)
|
||||||
}
|
}
|
||||||
input.onCharPress(char)
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun submit() {
|
private fun submit() {
|
||||||
@ -154,23 +156,24 @@ class ChatElement(guiRenderer: GUIRenderer) : AbstractChatElement(guiRenderer) {
|
|||||||
guiRenderer.gui.pop()
|
guiRenderer.gui.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onKey(key: KeyCodes, type: KeyChangeTypes) {
|
override fun onKey(key: KeyCodes, type: KeyChangeTypes): Boolean {
|
||||||
if (type != KeyChangeTypes.RELEASE) {
|
if (type != KeyChangeTypes.RELEASE) {
|
||||||
when (key) {
|
when (key) {
|
||||||
KeyCodes.KEY_ENTER -> {
|
KeyCodes.KEY_ENTER -> {
|
||||||
return submit()
|
submit()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
KeyCodes.KEY_PAGE_UP -> {
|
KeyCodes.KEY_PAGE_UP -> {
|
||||||
messages.scrollOffset++
|
messages.scrollOffset++
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
KeyCodes.KEY_PAGE_DOWN -> {
|
KeyCodes.KEY_PAGE_DOWN -> {
|
||||||
messages.scrollOffset--
|
messages.scrollOffset--
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
KeyCodes.KEY_UP -> {
|
KeyCodes.KEY_UP -> {
|
||||||
if (historyIndex <= 0) {
|
if (historyIndex <= 0) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
val size = history.size
|
val size = history.size
|
||||||
if (historyIndex > size) {
|
if (historyIndex > size) {
|
||||||
@ -183,11 +186,11 @@ class ChatElement(guiRenderer: GUIRenderer) : AbstractChatElement(guiRenderer) {
|
|||||||
val size = history.size
|
val size = history.size
|
||||||
historyIndex++
|
historyIndex++
|
||||||
if (historyIndex > size) {
|
if (historyIndex > size) {
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
if (historyIndex == size) {
|
if (historyIndex == size) {
|
||||||
input.value = ""
|
input.value = ""
|
||||||
return
|
return true
|
||||||
}
|
}
|
||||||
input.value = history[historyIndex]
|
input.value = history[historyIndex]
|
||||||
}
|
}
|
||||||
@ -195,11 +198,14 @@ class ChatElement(guiRenderer: GUIRenderer) : AbstractChatElement(guiRenderer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
input.onKey(key, type)
|
input.onKey(key, type)
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions) {
|
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean {
|
||||||
val pair = getAt(position) ?: return
|
val pair = getAt(position) ?: return false
|
||||||
pair.first.onMouseAction(pair.second, button, action)
|
pair.first.onMouseAction(pair.second, button, action)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAt(position: Vec2i): Pair<Element, Vec2i>? {
|
private fun getAt(position: Vec2i): Pair<Element, Vec2i>? {
|
||||||
|
@ -82,9 +82,10 @@ class InternalChatElement(guiRenderer: GUIRenderer) : AbstractChatElement(guiRen
|
|||||||
guiRenderer.gui.pop() // pop normal chat
|
guiRenderer.gui.pop() // pop normal chat
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions) {
|
override fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions): Boolean {
|
||||||
val pair = getAt(position) ?: return
|
val pair = getAt(position) ?: return false
|
||||||
pair.first.onMouseAction(pair.second, button, action)
|
pair.first.onMouseAction(pair.second, button, action)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAt(position: Vec2i): Pair<Element, Vec2i>? {
|
private fun getAt(position: Vec2i): Pair<Element, Vec2i>? {
|
||||||
|
@ -22,14 +22,14 @@ import glm_.vec2.Vec2i
|
|||||||
|
|
||||||
interface InputElement {
|
interface InputElement {
|
||||||
|
|
||||||
fun onMouseMove(position: Vec2i) {}
|
fun onMouseMove(position: Vec2i) = false
|
||||||
fun onMouseEnter(position: Vec2i) {}
|
fun onMouseEnter(position: Vec2i) = false
|
||||||
fun onMouseLeave() {}
|
fun onMouseLeave() = false
|
||||||
fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions) {}
|
fun onMouseAction(position: Vec2i, button: MouseButtons, action: MouseActions) = false
|
||||||
fun onScroll(position: Vec2i, scrollOffset: Vec2d) {}
|
fun onScroll(position: Vec2i, scrollOffset: Vec2d) = false
|
||||||
|
|
||||||
fun onKey(key: KeyCodes, type: KeyChangeTypes) {}
|
fun onKey(key: KeyCodes, type: KeyChangeTypes) = false
|
||||||
fun onCharPress(char: Int) {}
|
fun onCharPress(char: Int) = false
|
||||||
|
|
||||||
// ToDo: drag
|
// ToDo: drag
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,12 @@ import de.bixilon.kutil.time.TimeUtil
|
|||||||
import de.bixilon.minosoft.data.text.BaseComponent
|
import de.bixilon.minosoft.data.text.BaseComponent
|
||||||
import de.bixilon.minosoft.data.text.ChatColors
|
import de.bixilon.minosoft.data.text.ChatColors
|
||||||
import de.bixilon.minosoft.data.text.TextComponent
|
import de.bixilon.minosoft.data.text.TextComponent
|
||||||
|
import de.bixilon.minosoft.data.text.events.click.ClickCallbackClickEvent
|
||||||
import de.bixilon.minosoft.data.text.events.click.OpenFileClickEvent
|
import de.bixilon.minosoft.data.text.events.click.OpenFileClickEvent
|
||||||
import de.bixilon.minosoft.data.text.events.hover.TextHoverEvent
|
import de.bixilon.minosoft.data.text.events.hover.TextHoverEvent
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu.confirmation.DeleteScreenshotDialog
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.PixelTypes
|
import de.bixilon.minosoft.gui.rendering.system.base.PixelTypes
|
||||||
import de.bixilon.minosoft.terminal.RunConfiguration
|
import de.bixilon.minosoft.terminal.RunConfiguration
|
||||||
import glm_.vec2.Vec2i
|
import glm_.vec2.Vec2i
|
||||||
@ -73,22 +76,20 @@ class ScreenshotTaker(
|
|||||||
ImageIO.write(bufferedImage, "png", file)
|
ImageIO.write(bufferedImage, "png", file)
|
||||||
|
|
||||||
renderWindow.connection.util.sendDebugMessage(BaseComponent(
|
renderWindow.connection.util.sendDebugMessage(BaseComponent(
|
||||||
"§aScreenshot saved to ",
|
"§aScreenshot saved: ",
|
||||||
TextComponent(file.name).apply {
|
TextComponent(file.name).apply {
|
||||||
color = ChatColors.WHITE
|
color = ChatColors.WHITE
|
||||||
underline()
|
underline()
|
||||||
clickEvent = OpenFileClickEvent(file.slashPath)
|
clickEvent = OpenFileClickEvent(file.slashPath)
|
||||||
hoverEvent = TextHoverEvent("Click to open")
|
hoverEvent = TextHoverEvent("Click to open")
|
||||||
},
|
},
|
||||||
// "\n",
|
" ",
|
||||||
// TextComponent("[DELETE]").apply {
|
TextComponent("[DELETE]").apply {
|
||||||
// color = ChatColors.RED
|
color = ChatColors.RED
|
||||||
// bold()
|
bold()
|
||||||
// clickEvent = ClickEvent(ClickEvent.ClickEventActions.OPEN_CONFIRMATION, {
|
clickEvent = ClickCallbackClickEvent { DeleteScreenshotDialog(renderWindow.renderer[GUIRenderer] ?: return@ClickCallbackClickEvent, file).open() }
|
||||||
// TODO()
|
hoverEvent = TextHoverEvent("Click to delete screenshot")
|
||||||
// })
|
},
|
||||||
// hoverEvent = ClickEvent(ClickEvent.HoverEventActions.SHOW_TEXT, "Click to delete screenshot")
|
|
||||||
// },
|
|
||||||
))
|
))
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
exception.fail()
|
exception.fail()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user