diff --git a/src/net/torvald/terrarum/tests/UITestPad1.kt b/src/net/torvald/terrarum/tests/UITestPad1.kt index 91c38ff4e..d4ee5c476 100644 --- a/src/net/torvald/terrarum/tests/UITestPad1.kt +++ b/src/net/torvald/terrarum/tests/UITestPad1.kt @@ -7,12 +7,14 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera +import com.badlogic.gdx.graphics.Pixmap +import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.ShaderProgram -import net.torvald.terrarum.App -import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.Yaml -import net.torvald.terrarum.inUse +import com.badlogic.gdx.utils.GdxRuntimeException +import net.torvald.colourutil.HUSLColorConverter +import net.torvald.terrarum.* +import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.UINSMenu @@ -23,57 +25,26 @@ val UITEST1_HEIGHT = 720 /** * Created by minjaesong on 2018-12-09. */ -class UITestPad1 : ScreenAdapter() { - - val treeStr = """ -- File - - New - - Open - - Open Recent - - yaml_example.yaml - - Yaml.kt - - Close - - Settings - - Line Separators - - CRLF - - CR - - LF -- Edit - - Undo - - Redo - - Cut - - Copy - - Paste - - Find - - Find - - Replace - - Convert Indents - - To Spaces - - Set Project Indentation - - To Tabs -- Refactor - - Refactor This - - Rename - - Extract - - Variable - - Property - - Function -""" +class UITestPad1 : TerrarumGamescreen { - lateinit var nsMenu: UINSMenu lateinit var batch: SpriteBatch lateinit var camera: OrthographicCamera + override fun inputStrobed(e: TerrarumKeyboardEvent) { + } + + + + lateinit var colourPickerPixmap: Pixmap + lateinit var colourPickerTex: Texture + + private var hue = 0f override fun show() { Gdx.input.inputProcessor = UITestPad1Controller(this) - nsMenu = UINSMenu( - "Menu", - 96, - Yaml(treeStr) - ) - batch = SpriteBatch() + + batch = FlippingSpriteBatch() camera = OrthographicCamera(UITEST1_WIDTH.toFloat(), UITEST1_HEIGHT.toFloat()) camera.setToOrtho(true, UITEST1_WIDTH.toFloat(), UITEST1_HEIGHT.toFloat()) @@ -82,58 +53,63 @@ class UITestPad1 : ScreenAdapter() { resize(UITEST1_WIDTH, UITEST1_HEIGHT) - nsMenu.setPosition(0, 0) - nsMenu.setAsAlwaysVisible() + colourPickerPixmap = Pixmap(cmapSize, cmapSize, Pixmap.Format.RGBA8888) + colourPickerTex = Texture(colourPickerPixmap) + } val bgCol = Color(.62f, .79f, 1f, 1f) - var _dct = 0f + + + private val cmapSize = 16 + private val cmapSize2 = cmapSize * 2f + private val cmapDrawSize = 256f override fun render(delta: Float) { Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle()) - // UPDATE - nsMenu.update(delta) + hue += delta * 8f + if (hue > 360f) hue -= 360f + + for (y in 0 until cmapSize) { for (x in 0 until cmapSize) { + val saturation = x * 100f / (cmapSize - 1f) + val luma = 100f - y * 100f / (cmapSize - 1f) + val rgb = HUSLColorConverter.hsluvToRgb(floatArrayOf(hue, saturation, luma)) + colourPickerPixmap.setColor(rgb[0], rgb[1], rgb[2], 1f) + colourPickerPixmap.drawPixel(x, y) + }} - // RENDER batch.inUse { - batch.color = bgCol - Toolkit.fillArea(batch, 0, 0, 2048, 2048) - - nsMenu.render(batch, camera) - - batch.color = if (nsMenu.mouseOnTitleBar()) - Color.LIME - else - Color.FIREBRICK - App.fontGame.draw(batch, "Mouse: ${Terrarum.mouseScreenX}, ${Terrarum.mouseScreenY}", 8f, 740 - 28f) + colourPickerTex.dispose() + colourPickerTex = Texture(colourPickerPixmap) + colourPickerTex.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear) + batch.draw(colourPickerTex, 10f, 10f, + cmapDrawSize, cmapDrawSize, + 1f / cmapSize2, 1f - 1f / cmapSize2, + 1f - 1f / cmapSize2, 1f / cmapSize2 + ) } - - _dct = (_dct + delta*2) % 10f - //nsMenu.setPosition(_dct.toInt(), _dct.toInt()) - } - - - - - override fun pause() { - super.pause() - } - - override fun resume() { - super.resume() } override fun resize(width: Int, height: Int) { - super.resize(width, height) + } + + override fun pause() { + } + + override fun resume() { + } + + override fun hide() { } override fun dispose() { - super.dispose() + try { colourPickerTex.dispose() } catch (e: GdxRuntimeException) {} + try { colourPickerPixmap.dispose() } catch (e: GdxRuntimeException) {} } @@ -141,12 +117,10 @@ class UITestPad1 : ScreenAdapter() { class UITestPad1Controller(val host: UITestPad1) : InputAdapter() { override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { - host.nsMenu.touchDragged(screenX, screenY, pointer) return true } override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - host.nsMenu.touchDown(screenX, screenY, pointer, button) return true } } @@ -159,6 +133,9 @@ fun main(args: Array) { appConfig.useVsync(false) appConfig.setResizable(false) appConfig.setWindowedMode(UITEST1_WIDTH, UITEST1_HEIGHT) + appConfig.useOpenGL3(true, 3, 2) + + App.scr = TerrarumScreenSize(UITEST1_WIDTH, UITEST1_HEIGHT) Lwjgl3Application(App(appConfig, UITestPad1()), appConfig) } \ No newline at end of file