mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
analogue watch ui
This commit is contained in:
BIN
assets/mods/basegame/gui/watchface_analogue_atlas.tga
LFS
Normal file
BIN
assets/mods/basegame/gui/watchface_analogue_atlas.tga
LFS
Normal file
Binary file not shown.
@@ -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...)
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -83,14 +83,16 @@ fun getKeycapFkeys(n: Int) = when (n) {
|
||||
|
||||
fun List<Int>.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()
|
||||
|
||||
BIN
work_files/graphics/gui/watches/watchface_large_analogue.kra
LFS
Normal file
BIN
work_files/graphics/gui/watches/watchface_large_analogue.kra
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user