From 6c9cbcdfd1079e5e1f9b92b24d4845a326ec358c Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 9 Sep 2023 17:58:31 +0900 Subject: [PATCH] analogue watch ui --- .../basegame/gui/watchface_analogue_atlas.tga | 3 + src/com/jme3/math/FastMath.java | 14 +-- .../terrarum/modulebasegame/TerrarumIngame.kt | 5 +- .../modulebasegame/ui/UIWatchLargeAnalogue.kt | 110 ++++++++++++++++++ ...TierOneWatch.kt => UIWatchLargeDigital.kt} | 11 +- .../terrarum/ui/BasicDebugInfoWindow.kt | 12 +- src/net/torvald/unicode/UniTextShortcuts.kt | 18 +-- .../gui/watches/watchface_large_analogue.kra | 3 + 8 files changed, 146 insertions(+), 30 deletions(-) create mode 100644 assets/mods/basegame/gui/watchface_analogue_atlas.tga create mode 100644 src/net/torvald/terrarum/modulebasegame/ui/UIWatchLargeAnalogue.kt rename src/net/torvald/terrarum/modulebasegame/ui/{UITierOneWatch.kt => UIWatchLargeDigital.kt} (91%) create mode 100644 work_files/graphics/gui/watches/watchface_large_analogue.kra diff --git a/assets/mods/basegame/gui/watchface_analogue_atlas.tga b/assets/mods/basegame/gui/watchface_analogue_atlas.tga new file mode 100644 index 000000000..ffc45606e --- /dev/null +++ b/assets/mods/basegame/gui/watchface_analogue_atlas.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b51abc8077d124fda6441836dd4ad94456d5c347de8f2eb4b33db28544412b6 +size 101394 diff --git a/src/com/jme3/math/FastMath.java b/src/com/jme3/math/FastMath.java index f7688a69c..be5154e02 100644 --- a/src/com/jme3/math/FastMath.java +++ b/src/com/jme3/math/FastMath.java @@ -56,19 +56,19 @@ final public class FastMath { /** The value PI as a float. (180 degrees) */ public static final float PI = (float) Math.PI; /** The value 2PI as a float. (360 degrees) */ - public static final float TWO_PI = 2.0f * PI; + public static final float TWO_PI = (float) (2.0 * Math.PI); /** The value PI/2 as a float. (90 degrees) */ - public static final float HALF_PI = 0.5f * PI; + public static final float HALF_PI = (float) (0.5 * Math.PI); /** The value PI/4 as a float. (45 degrees) */ - public static final float QUARTER_PI = 0.25f * PI; + public static final float QUARTER_PI = (float) (0.25 * Math.PI); /** The value 1/PI as a float. */ - public static final float INV_PI = 1.0f / PI; + public static final float INV_PI = (float) (1.0 / Math.PI); /** The value 1/(2PI) as a float. */ - public static final float INV_TWO_PI = 1.0f / TWO_PI; + public static final float INV_TWO_PI = (float) (2.0 / Math.PI); /** A value to multiply a degree value by, to convert it to radians. */ - public static final float DEG_TO_RAD = PI / 180.0f; + public static final float DEG_TO_RAD = (float) (Math.PI / 180.0); /** A value to multiply a radian value by, to convert it to degrees. */ - public static final float RAD_TO_DEG = 180.0f / PI; + public static final float RAD_TO_DEG = (float) (180.0 / Math.PI); /** * Returns true if the number is a power of 2 (2,4,8,16...) diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index a73b6d88c..5afa57321 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -2,7 +2,6 @@ package net.torvald.terrarum.modulebasegame import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch @@ -103,7 +102,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { batch.projectionMatrix = camera.combined } fun setCameraPosition(batch: SpriteBatch, shape: ShapeRenderer, camera: OrthographicCamera, newX: Float, newY: Float) { - camera.setToOrtho(false, App.scr.wf, App.scr.hf) + camera.setToOrtho(true, App.scr.wf, App.scr.hf) camera.update() camera.position.set((-newX + App.scr.halfw).roundToFloat(), (-newY + App.scr.halfh).roundToFloat(), 0f) camera.update() @@ -563,7 +562,7 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { uiBlur = UIFakeBlurOverlay(1f, true) uiBlur.setPosition(0,0) - uiWatchTierOne = UITierOneWatch() + uiWatchTierOne = UIWatchLargeAnalogue()//UIWatchLargeDigital() uiWatchTierOne.setAsAlwaysVisible() uiWatchTierOne.setPosition( ((drawWidth - App.scr.tvSafeActionWidth) - (uiQuickBar.posX + uiQuickBar.width) - uiWatchTierOne.width) / 2 + (uiQuickBar.posX + uiQuickBar.width), diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWatchLargeAnalogue.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWatchLargeAnalogue.kt new file mode 100644 index 000000000..ee3de4ae1 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWatchLargeAnalogue.kt @@ -0,0 +1,110 @@ +package net.torvald.terrarum.modulebasegame.ui + +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.OrthographicCamera +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.graphics.g2d.TextureRegion +import com.jme3.math.FastMath +import net.torvald.terrarum.* +import net.torvald.terrarum.gameworld.WorldTime +import net.torvald.terrarum.modulebasegame.TerrarumIngame +import net.torvald.terrarum.ui.Toolkit +import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import kotlin.math.cos +import kotlin.math.roundToInt +import kotlin.math.sin + +/** + * Created by minjaesong on 2023-09-09. + */ +class UIWatchLargeAnalogue() : UICanvas() { + + override var width = 76 + override var height = 76 + override var openCloseTime: Second = 0f + + private val atlas = TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/watchface_analogue_atlas.tga"), 16, 11) + + private val faceBack1 = TextureRegion(atlas.texture, 48, 121, 76, 33) + private val faceBack2 = TextureRegion(atlas.texture, 48, 154, 76, 44) + private val faceFore = TextureRegion(atlas.texture, 48, 44, 76, 76) + private val moon = TextureRegion(atlas.texture, 80, 0, 18, 18) + private val dialPin = TextureRegion(atlas.texture, 80, 22, 2, 2) + + private val dayNumbers = Array(30) { atlas.get(it / 11, it % 11) } // key: worldTime.calendarDay - 1 (0..29) + private val weekTexts = Array(8) { atlas.get(3 + it/4, it % 4) } // key: worldTime.dayOfWeek (0..7) + + private val minuteHandCol = Toolkit.Theme.COL_MOUSE_UP + private val hourHandCol = Toolkit.Theme.COL_SELECTED + private val seasonHandCol = Color(0xec468aff.toInt()) + + private val moondialOffX = 38f + private val moondialOffY = 38f + + private val seasonHandOffX = 53f + private val seasonHandOffY = 43f + + private val TWO_PI = 2.0 * Math.PI + + override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) { + TerrarumIngame.setCameraPosition(batch, App.shapeRender, camera, posX.toFloat(), posY.toFloat()) + + val day = INGAME.world.worldTime.calendarDay - 1 + val week = INGAME.world.worldTime.dayOfWeek + + val moonAngle = INGAME.world.worldTime.moonPhase * Math.PI + val moonX = -(15.0 * cos(moonAngle)).roundToInt().toFloat() + moondialOffX - 9 + val moonY = -(15.0 * sin(moonAngle)).roundToInt().toFloat() + moondialOffY - 9 + + val seasonAngle = ((INGAME.world.worldTime.TIME_T % WorldTime.YEAR_SECONDS) / (WorldTime.YEAR_SECONDS.toDouble()) - 0.125) * TWO_PI + val seasonX = -(7.0 * cos(seasonAngle)).toFloat() + seasonHandOffX + val seasonY = -(7.0 * sin(seasonAngle)).toFloat() + seasonHandOffY + + val minAngle = ((INGAME.world.worldTime.TIME_T % WorldTime.HOUR_SEC) / WorldTime.HOUR_SEC.toDouble() + 0.25) * TWO_PI + val minX = -(28.0 * cos(minAngle)).toFloat() + moondialOffX + val minY = -(28.0 * sin(minAngle)).toFloat() + moondialOffY + + val hourAngle = ((INGAME.world.worldTime.TIME_T % (WorldTime.HOUR_SEC * 12)) / (WorldTime.HOUR_SEC * 12).toDouble() + 0.25) * TWO_PI + val hourX = -(21.0 * cos(hourAngle)).toFloat() + moondialOffX + val hourY = -(21.0 * sin(hourAngle)).toFloat() + moondialOffY + + batch.draw(faceBack1, 0f, 11f) + batch.draw(moon, moonX, moonY) + batch.draw(faceBack2, 0f, 33f) + batch.draw(dayNumbers[day], 16f, 38f) + batch.draw(weekTexts[week], 30f, 55f) + batch.draw(faceFore, 0f, 0f) + + batch.end() + + // draw hands + App.shapeRender.inUse { + it.color = seasonHandCol + it.rectLine(seasonHandOffX, seasonHandOffY, seasonX, seasonY, 1.5f) + } + batch.inUse { + batch.draw(dialPin, seasonHandOffX - 1, seasonHandOffY - 1) + } + + App.shapeRender.inUse { + it.color = hourHandCol + it.rectLine(moondialOffX, moondialOffY, hourX, hourY, 2.5f) + it.color = minuteHandCol + it.rectLine(moondialOffX, moondialOffY, minX, minY, 2f) + } + + batch.begin() + + batch.draw(dialPin, moondialOffX - 1, moondialOffY - 1) + } + + override fun updateUI(delta: Float) { + } + + override fun dispose() { + atlas.dispose() + } + + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWatchLargeDigital.kt similarity index 91% rename from src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt rename to src/net/torvald/terrarum/modulebasegame/ui/UIWatchLargeDigital.kt index b0275d136..a7eba2f31 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITierOneWatch.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWatchLargeDigital.kt @@ -1,7 +1,6 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.Gdx -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch @@ -15,7 +14,7 @@ import kotlin.math.roundToInt /** * Created by minjaesong on 2017-06-11. */ -class UITierOneWatch() : UICanvas() { +class UIWatchLargeDigital() : UICanvas() { override var width = 160 override var height = 23 override var openCloseTime: Second = 0f @@ -24,11 +23,11 @@ class UITierOneWatch() : UICanvas() { private val ELuptime = 4f private var ELon = false - private var atlas = TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/watchface_atlas.tga"), width, height) + private val atlas = TextureRegionPack(ModMgr.getGdxFile("basegame", "gui/watchface_atlas.tga"), width, height) - private var watchFont = WatchFont - private var moonDial = TextureRegionPack(ModMgr.getGdxFile("basegame", "fonts/watch_17pxmoondial.tga"), 17, 17) - private var moonDialCount = moonDial.horizontalCount + private val watchFont = WatchFont + private val moonDial = TextureRegionPack(ModMgr.getGdxFile("basegame", "fonts/watch_17pxmoondial.tga"), 17, 17) + private val moonDialCount = moonDial.horizontalCount private val drawCol = Color(1f, 1f, 1f, UIQuickslotBar.DISPLAY_OPACITY) private val lcdLitColELoff = Color(0xc0c0c0ff.toInt()) mul drawCol diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index 87ea483c3..4fd5a466f 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -462,20 +462,20 @@ class BasicDebugInfoWindow : UICanvas() { val px = x - xis + index + 1f it.rectLine( px, - App.scr.hf - 1 - (y + pys[index]), + 1 + (y + pys[index]), px + 1f, - App.scr.hf - 1 - (y + pys[index + 1]), + 1 + (y + pys[index + 1]), 1f ) } // graph points it.color = colGraph - if (box.x < 0.5) it.circle(x + (GRAPH_CW * 0.5f) - xi, App.scr.hf - 1 - (y + bh-(box.p0.mod().goff() * bh / ymax).toFloat()), 2.5f) - it.circle(x + (GRAPH_CW * 1.5f) - xi, App.scr.hf - 1 - (y + bh-(box.p1.mod().goff() * bh / ymax).toFloat()), 2.5f) - it.circle(x + (GRAPH_CW * 2.5f) - xi, App.scr.hf - 1 - (y + bh-(box.p2.mod().goff() * bh / ymax).toFloat()), 2.5f) + if (box.x < 0.5) it.circle(x + (GRAPH_CW * 0.5f) - xi, 1 + (y + bh-(box.p0.mod().goff() * bh / ymax).toFloat()), 2.5f) + it.circle(x + (GRAPH_CW * 1.5f) - xi, 1 + (y + bh-(box.p1.mod().goff() * bh / ymax).toFloat()), 2.5f) + it.circle(x + (GRAPH_CW * 2.5f) - xi, 1 + (y + bh-(box.p2.mod().goff() * bh / ymax).toFloat()), 2.5f) it.color = colGrapi - if (box.x > 0.5) it.circle(x + (GRAPH_CW * 3.5f) - xi, App.scr.hf - 1 - (y + bh-(box.p3.mod().goff() * bh / ymax).toFloat()), 2.5f) + if (box.x > 0.5) it.circle(x + (GRAPH_CW * 3.5f) - xi, 1 + (y + bh-(box.p3.mod().goff() * bh / ymax).toFloat()), 2.5f) } diff --git a/src/net/torvald/unicode/UniTextShortcuts.kt b/src/net/torvald/unicode/UniTextShortcuts.kt index 4b6d7a2c3..d4a4f0b07 100644 --- a/src/net/torvald/unicode/UniTextShortcuts.kt +++ b/src/net/torvald/unicode/UniTextShortcuts.kt @@ -83,14 +83,16 @@ fun getKeycapFkeys(n: Int) = when (n) { fun List.toJavaString(): String { val sb = StringBuilder() - this.subList(0, this.size).forEach { - if (it > 65535) { - val u = it - 65536 - sb.append((0xD800 or (u ushr 10).and(1023)).toChar()) - sb.append((0xDC00 or (u and 1023)).toChar()) - } - else { - sb.append(it.toChar()) + synchronized(this) { + this.forEach { + if (it > 65535) { + val u = it - 65536 + sb.append((0xD800 or (u ushr 10).and(1023)).toChar()) + sb.append((0xDC00 or (u and 1023)).toChar()) + } + else { + sb.append(it.toChar()) + } } } return sb.toString() diff --git a/work_files/graphics/gui/watches/watchface_large_analogue.kra b/work_files/graphics/gui/watches/watchface_large_analogue.kra new file mode 100644 index 000000000..8bf0f9f4a --- /dev/null +++ b/work_files/graphics/gui/watches/watchface_large_analogue.kra @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2df886e7d77a5d75a06f433b084b8074626f1545c5175edacc2883bb6feaa9d +size 221962