mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
working quickbar and piemenu
This commit is contained in:
3073
assets/getlightdata
3073
assets/getlightdata
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,8 @@ package net.torvald.terrarum
|
||||
import net.torvald.dataclass.CircularArray
|
||||
import net.torvald.imagefont.GameFontBase
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Terrarum.HALFH
|
||||
import net.torvald.terrarum.Terrarum.HALFW
|
||||
import net.torvald.terrarum.Terrarum.delta
|
||||
import net.torvald.terrarum.concurrent.ThreadParallel
|
||||
import net.torvald.terrarum.console.*
|
||||
@@ -187,10 +189,7 @@ class StateInGame : BasicGameState() {
|
||||
|
||||
// pie menu
|
||||
uiPieMenu = UIHandler(UIPieMenu())
|
||||
uiPieMenu.setPosition(
|
||||
(Terrarum.WIDTH - uiPieMenu.UI.width) / 2,
|
||||
(Terrarum.HEIGHT - uiPieMenu.UI.height) / 2
|
||||
)
|
||||
uiPieMenu.setPosition(HALFW, HALFH)
|
||||
|
||||
// vital metre
|
||||
// fill in getter functions by
|
||||
|
||||
@@ -15,7 +15,7 @@ internal object TestGetLight : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
val x = args[1].toInt()
|
||||
val y = args[2].toInt()
|
||||
val l = LightmapRenderer.getLightRawPos(16, 16)
|
||||
val l = LightmapRenderer.getLightRawPos(x, y)
|
||||
EchoConsole.execute(l.toString())
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ object ItemSlotImageBuilder {
|
||||
const val COLOR_BLACK = 1
|
||||
const val COLOR_WHITE = 2
|
||||
|
||||
private val colourBlack = Color(0x40, 0x40, 0x40, 0xEE)
|
||||
private val colourWhite = Color(0xC0, 0xC0, 0xC0, 0xEE)
|
||||
private val colourBlack = Color(0x40, 0x40, 0x40)
|
||||
private val colourWhite = Color(0xC0, 0xC0, 0xC0)
|
||||
|
||||
private val numberFont = SpriteSheetFont(
|
||||
SpriteSheet("./assets/graphics/fonts/numeric_small.tga", 5, 8),
|
||||
|
||||
@@ -18,7 +18,8 @@ class UIPieMenu : UICanvas {
|
||||
|
||||
private val slotCount = UIQuickBar.SLOT_COUNT
|
||||
|
||||
private val slotDistanceFromCentre = cellSize * 2.7
|
||||
private val slotDistanceFromCentre: Double
|
||||
get() = cellSize * 2.7 * handler!!.scale
|
||||
override var width: Int = cellSize * 7
|
||||
override var height: Int = width
|
||||
|
||||
@@ -42,13 +43,11 @@ class UIPieMenu : UICanvas {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
val centrePoint = Vector2(width / 2.0, height / 2.0)
|
||||
|
||||
// draw radial thingies
|
||||
for (i in 0..slotCount - 1) {
|
||||
// set position
|
||||
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
|
||||
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre).setDirection(angle) + centrePoint
|
||||
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre).setDirection(-angle)// + centrePoint
|
||||
|
||||
// draw cells
|
||||
val color = if (i == selection)
|
||||
@@ -56,13 +55,16 @@ class UIPieMenu : UICanvas {
|
||||
else
|
||||
ItemSlotImageBuilder.COLOR_BLACK
|
||||
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageBuilder.produceLarge(color, i + 1)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(color, i + 1)
|
||||
|
||||
g.drawImage(
|
||||
if (i == selection)
|
||||
ItemSlotImageBuilder.produceLarge(color, i + 1)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(color, i + 1),
|
||||
slotCentrePoint.x.toFloat() - (cellSize / 2f),
|
||||
slotCentrePoint.y.toFloat() - (cellSize / 2f)
|
||||
image,
|
||||
slotCentrePoint.x.toFloat() - (image.width / 2) + Terrarum.HALFW,
|
||||
slotCentrePoint.y.toFloat() - (image.width / 2) + Terrarum.HALFH,
|
||||
Color(1f, 1f, 1f, handler!!.opacity * UIQuickBar.finalOpacity)
|
||||
)
|
||||
|
||||
// TODO draw item
|
||||
@@ -72,8 +74,8 @@ class UIPieMenu : UICanvas {
|
||||
override fun processInput(gc: GameContainer, delta: Int, input: Input) {
|
||||
if (handler!!.isOpened || handler!!.isOpening) {
|
||||
val cursorPos = Vector2(input.mouseX.toDouble(), input.mouseY.toDouble())
|
||||
val centre = Vector2(Terrarum.WIDTH / 2.0, Terrarum.HEIGHT / 2.0)
|
||||
val deg = (centre - cursorPos).direction.toFloat()
|
||||
val centre = Vector2(Terrarum.HALFW.toDouble(), Terrarum.HALFH.toDouble())
|
||||
val deg = -(centre - cursorPos).direction.toFloat()
|
||||
|
||||
selection = Math.round(deg * slotCount / FastMath.TWO_PI)
|
||||
if (selection < 0) selection += 10
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
|
||||
import net.torvald.terrarum.Millisec
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
@@ -28,10 +29,12 @@ class UIQuickBar : UICanvas, MouseControlled {
|
||||
get() = Terrarum.ingame!!.player?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
set(value) { Terrarum.ingame!!.player?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value) }
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
|
||||
for (i in 0..SLOT_COUNT - 1) {
|
||||
val color = if (i == selection)
|
||||
ItemSlotImageBuilder.COLOR_WHITE
|
||||
@@ -45,7 +48,8 @@ class UIQuickBar : UICanvas, MouseControlled {
|
||||
else
|
||||
ItemSlotImageBuilder.produce(color, i + 1),
|
||||
startPointX + (CELL_SIZE + gutter).times(i).toFloat(),
|
||||
startPointY.toFloat()
|
||||
startPointY.toFloat(),
|
||||
Color(1f, 1f, 1f, handler!!.opacity * 0.8f)
|
||||
)
|
||||
// draw items
|
||||
|
||||
@@ -89,6 +93,8 @@ class UIQuickBar : UICanvas, MouseControlled {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val finalOpacity = 0.8f
|
||||
|
||||
const val SLOT_COUNT = 10
|
||||
const val CELL_SIZE = 32
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user