RemoCons fully working; also fixed my stupidity

This commit is contained in:
minjaesong
2017-07-26 17:03:22 +09:00
parent 5990da1d26
commit 5c2b1e7586
18 changed files with 1011 additions and 32 deletions

View File

@@ -77,9 +77,9 @@ abstract class UICanvas(
}
/** Override this for the actual update */
/** Override this for the actual update. You must update uiItems by yourself. */
abstract fun updateUI(delta: Float)
/** Override this for the actual render */
/** Override this for the actual render. You must render uiItems by yourself. */
abstract fun renderUI(batch: SpriteBatch, camera: Camera)
/**

View File

@@ -85,6 +85,8 @@ class UIInventory(
"GAME_GENRE_MISC"
//"GAME_INVENTORY_FAVORITES",
),
posX = 0,
posY = 0,
width = categoryWidth,
height = height - controlHelpHeight,
verticalGutter = itemStripGutterH,

View File

@@ -0,0 +1,79 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
class UIItemTextArea(
parentUI: UICanvas,
override var posX: Int,
override var posY: Int,
override val width: Int,
override val height: Int,
val lineGap: Int = 0,
val lineCount: Int = ((height + lineGap) / Terrarum.fontGame.lineHeight).toInt()
) : UIItem(parentUI) {
var entireText: List<String> = listOf("") // placeholder
var scrollPos = 0
fun setWallOfText(listOfString: List<String>) {
entireText = listOfString
}
override fun update(delta: Float) {
super.update(delta)
if (scrollPos > entireText.size - lineCount) scrollPos = entireText.size - lineCount
if (scrollPos < 0) scrollPos = 0
}
override fun render(batch: SpriteBatch) {
batch.color = Color.WHITE
for (i in scrollPos until minOf(lineCount + scrollPos, entireText.size)) {
val yPtr = i - scrollPos
Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
}
}
override fun keyDown(keycode: Int): Boolean {
return super.keyDown(keycode)
}
override fun keyUp(keycode: Int): Boolean {
return super.keyUp(keycode)
}
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
return super.mouseMoved(screenX, screenY)
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return super.touchDragged(screenX, screenY, pointer)
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return super.touchDown(screenX, screenY, pointer, button)
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return super.touchUp(screenX, screenY, pointer, button)
}
override fun scrolled(amount: Int): Boolean {
scrollPos += amount * 3
if (scrollPos > entireText.size - lineCount) scrollPos = entireText.size - lineCount
if (scrollPos < 0) scrollPos = 0
return super.scrolled(amount)
}
override fun dispose() {
}
}

View File

@@ -17,6 +17,8 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
class UIItemTextButtonList(
parentUI: UICanvas,
labelsList: Array<String>,
override var posX: Int,
override var posY: Int,
override var width: Int,
override var height: Int,
val verticalGutter: Int = 0,
@@ -51,13 +53,15 @@ class UIItemTextButtonList(
val pregap = (width - textAreaWidth - iconsWithGap) / 2 + iconsWithGap
val postgap = (width - textAreaWidth - iconsWithGap) / 2
val buttons = labelsList.mapIndexed { index, s ->
val height = this.height - UIItemTextButton.height
if (!kinematic) {
UIItemTextButton(
parentUI, s,
posX = 0,
posY = verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(),
posX = posX,
posY = posY + verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(),
width = width,
readFromLang = readFromLang,
activeCol = activeCol,
@@ -74,8 +78,8 @@ class UIItemTextButtonList(
else {
UIItemTextButton(
parentUI, s,
posX = 0,
posY = verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(),
posX = posX,
posY = posY + verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(),
width = width,
readFromLang = readFromLang,
activeCol = activeCol,
@@ -91,8 +95,26 @@ class UIItemTextButtonList(
}
}
override var posX = 0
/*override var posX = 0
set(value) {
buttons.forEach {
val oldPosX = field
val newPosX = value
it.posX = (newPosX - oldPosX)
}
field = value
}
override var posY = 0
set(value) {
buttons.forEach {
val oldPosY = field
val newPosY = value
it.posY = (newPosY - oldPosY)
}
field = value
}*/
var selectedIndex: Int? = defaultSelection
val selectedButton: UIItemTextButton?
@@ -104,6 +126,8 @@ class UIItemTextButtonList(
private var highlighterYStart = highlightY
private var highlighterYEnd = highlightY
/** (oldIndex: Int?, newIndex: Int) -> Unit */
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
override fun update(delta: Float) {
if (highlighterMoving) {
@@ -131,6 +155,8 @@ class UIItemTextButtonList(
if (btn.mousePushed && index != selectedIndex) {
val oldIndex = selectedIndex
if (kinematic) {
highlighterYStart = buttons[selectedIndex!!].posY.toDouble()
selectedIndex = index
@@ -141,6 +167,8 @@ class UIItemTextButtonList(
selectedIndex = index
highlightY = buttons[selectedIndex!!].posY.toDouble()
}
selectionChangeListener?.invoke(oldIndex, index)
}
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
@@ -148,6 +176,7 @@ class UIItemTextButtonList(
}
override fun render(batch: SpriteBatch) {
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode)
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())

View File

@@ -3,6 +3,8 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.CreditSingleton
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.Second
class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
@@ -20,9 +22,20 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
override var openCloseTime: Second = 0f
private val textAreaHMargin = 48
private val textAreaWidth = (Terrarum.WIDTH * 0.75).toInt()
private val textAreaHeight = Terrarum.HEIGHT - textAreaHMargin * 2
private val textArea = UIItemTextArea(this,
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
textAreaWidth, textAreaHeight
)
private var drawTextArea = true
private val menubar = UIItemTextButtonList(
this,
menuLabels,
0, UITitleRemoConRoot.menubarOffY,
this.width, this.height,
textAreaWidth = this.width,
readFromLang = true,
@@ -30,26 +43,55 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
defaultSelection = 0 // show CREDITS
)
init {
uiItems.add(menubar)
uiItems.add(textArea)
////////////////////////////
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
menubar.selectedIndex = menubar.defaultSelection
this.setAsClose()
superMenu.setAsOpen()
}
menubar.selectionChangeListener = { _, newIndex ->
textArea.scrollPos = 0
if (newIndex == menuLabels.indexOf("MENU_LABEL_CREDITS")) {
textArea.setWallOfText(CreditSingleton.credit)
drawTextArea = true
}
else if (newIndex == menuLabels.indexOf("MENU_CREDIT_GPL_DNT")) {
textArea.setWallOfText(CreditSingleton.gpl3)
drawTextArea = true
}
else {
drawTextArea = false
}
}
}
override fun updateUI(delta: Float) {
menubar.update(delta)
if (drawTextArea) {
textArea.update(delta)
}
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
if (drawTextArea) {
textArea.render(batch)
}
}
override fun doOpening(delta: Float) {

View File

@@ -20,6 +20,7 @@ class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
private val menubar = UIItemTextButtonList(
this,
menuLabels,
0, UITitleRemoConRoot.menubarOffY,
this.width, this.height,
textAreaWidth = this.width,
readFromLang = true,
@@ -34,8 +35,16 @@ class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
uiItems.add(menubar)
////////////////////////////
uiItems.add(menubar)
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
menubar.selectedIndex = menubar.defaultSelection
this.setAsClose()
superMenu.setAsOpen()
}

View File

@@ -33,6 +33,7 @@ class UITitleRemoConRoot : UICanvas() {
private val menubar = UIItemTextButtonList(
this,
menuLabels,
0, menubarOffY,
this.width, this.height,
textAreaWidth = this.width,
readFromLang = true,
@@ -51,8 +52,8 @@ class UITitleRemoConRoot : UICanvas() {
init {
remoConLanguage.setPosition(0, menubarOffY)
remoConCredits.setPosition(0, menubarOffY)
remoConLanguage.setPosition(0, 0)
remoConCredits.setPosition(0, 0)
@@ -62,10 +63,10 @@ class UITitleRemoConRoot : UICanvas() {
////////////////////////////
uiItems.add(menubar)
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_LANGUAGE")].clickOnceListener = { _, _, _ ->
this.setAsClose()