load app using apploader -- no more black screen on app load

This commit is contained in:
minjaesong
2017-08-01 23:55:48 +09:00
parent 5c2b1e7586
commit aa238eb65c
19 changed files with 668 additions and 88 deletions

View File

@@ -0,0 +1,124 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.gameactors.Second
/**
* Created by minjaesong on 2017-08-01.
*/
class UIItemList<Item: UIItem>(
parentUI: UICanvas,
val itemList: ArrayList<Item>,
override var posX: Int,
override var posY: Int,
override val width: Int,
override val height: Int,
var selectable: Boolean = false,
val defaultSelection: Int? = null, // negative: INVALID, positive: valid, null: no select
// copied directly from UIItemTextButton
val activeCol: Color = Color(0xfff066_ff.toInt()),
val activeBackCol: Color = Color(0),
val activeBackBlendMode: String = BlendMode.NORMAL,
val highlightCol: Color = Color(0x00f8ff_ff),
val highlightBackCol: Color = Color(0xb0b0b0_ff.toInt()),
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
val inactiveCol: Color = Color(0xc0c0c0_ff.toInt()),
val backgroundCol: Color = Color(0x242424_80),
val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false
) : UIItem(parentUI) {
init {
itemList.forEachIndexed { index, item ->
item.posX = this.posX
item.posY = if (index == 0) this.posY else itemList[index - 1].posY + itemList[index - 1].height + this.posY
}
}
var selectedIndex: Int? = defaultSelection
val selectedButton: UIItem?
get() = if (selectedIndex != null) itemList[selectedIndex!!] else null
private var highlightY: Double? = if (selectedIndex != null) itemList[selectedIndex!!].posY.toDouble() else null
private val highlighterMoveDuration: Second = 0.1f
private var highlighterMoveTimer: Second = 0f
private var highlighterMoving = false
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) {
highlighterMoveTimer += delta
if (selectedIndex != null) {
highlightY = UIUtils.moveQuick(
highlighterYStart!!,
highlighterYEnd!!,
highlighterMoveTimer.toDouble(),
highlighterMoveDuration.toDouble()
)
}
if (highlighterMoveTimer > highlighterMoveDuration) {
highlighterMoveTimer = 0f
highlighterYStart = highlighterYEnd
highlightY = highlighterYEnd
highlighterMoving = false
}
}
itemList.forEachIndexed { index, item ->
item.update(delta)
if (item.mousePushed && index != selectedIndex) {
val oldIndex = selectedIndex
if (kinematic) {
highlighterYStart = itemList[selectedIndex!!].posY.toDouble()
selectedIndex = index
highlighterMoving = true
highlighterYEnd = itemList[selectedIndex!!].posY.toDouble()
}
else {
selectedIndex = index
highlightY = itemList[selectedIndex!!].posY.toDouble()
}
selectionChangeListener?.invoke(oldIndex, index)
}
//item.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
}
}
override fun render(batch: SpriteBatch) {
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode)
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
batch.color = highlightBackCol
BlendMode.resolve(highlightBackBlendMode)
if (highlightY != null) {
batch.fillRect(posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
}
itemList.forEach { it.render(batch) }
batch.color = backgroundCol
}
override fun dispose() {
itemList.forEach { it.dispose() }
}
}

View File

@@ -0,0 +1,80 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.floor
class UIItemModuleInfoCell(
parent: UICanvas,
var moduleName: String,
override val width: Int,
override var posX: Int,
override var posY: Int
) : UIItem(parent) {
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2
private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4
override fun render(batch: SpriteBatch) {
if (ModMgr.moduleInfo.containsKey(moduleName)) {
val modInfo = ModMgr.moduleInfo[moduleName]!!
// print load order index
batch.color = Color(0x7f7f7fff)
var strlen = Terrarum.fontSmallNumbers.getWidth(modInfo.order.toString())
Terrarum.fontSmallNumbers.draw(batch,
modInfo.order.toString(),
(numberAreaWidth - strlen).div(2f).floor(),
(height - Terrarum.fontSmallNumbers.H).div(2f).floor()
)
// print module name
batch.color = Color.WHITE
Terrarum.fontGame.draw(batch,
"${modInfo.properName} (${modInfo.version})",
numberAreaWidth.toFloat(),
0f
)
// print author name
strlen = Terrarum.fontGame.getWidth(modInfo.author)
Terrarum.fontGame.draw(batch,
modInfo.author,
width - strlen.toFloat(),
0f
)
// print description
Terrarum.fontGame.draw(batch,
modInfo.description,
numberAreaWidth.toFloat(),
Terrarum.fontGame.lineHeight
)
// print releasedate
strlen = Terrarum.fontGame.getWidth(modInfo.releaseDate)
Terrarum.fontGame.draw(batch,
modInfo.releaseDate,
width - strlen.toFloat(),
Terrarum.fontGame.lineHeight
)
}
else {
batch.color = Color(0xff8080_ff.toInt())
val str = "InternalError: no such module: '$moduleName'"
val strlen = Terrarum.fontSmallNumbers.getWidth(str)
Terrarum.fontSmallNumbers.draw(batch,
str,
(width - numberAreaWidth - strlen).div(2f).floor() + numberAreaWidth,
(height - Terrarum.fontSmallNumbers.H).div(2f).floor()
)
}
}
override fun dispose() {
}
}

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.floor
class UIItemTextArea(
parentUI: UICanvas,
@@ -11,10 +12,14 @@ class UIItemTextArea(
override val width: Int,
override val height: Int,
val lineGap: Int = 0,
val lineCount: Int = ((height + lineGap) / Terrarum.fontGame.lineHeight).toInt()
val lineCount: Int = ((height + lineGap) / Terrarum.fontGame.lineHeight).toInt(),
val align: UIItemTextArea.Align = Align.LEFT
) : UIItem(parentUI) {
enum class Align {
LEFT, CENTRE, RIGHT
}
@@ -34,11 +39,16 @@ class UIItemTextArea(
}
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))
val textWidth = Terrarum.fontGame.getWidth(entireText[i])
when (align) {
Align.LEFT -> Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
Align.CENTRE -> Terrarum.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
Align.RIGHT -> Terrarum.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
}
}
}

View File

@@ -58,8 +58,9 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
menubar.selectedIndex = menubar.defaultSelection
this.setAsClose()
Thread.sleep(50)
menubar.selectedIndex = menubar.defaultSelection
superMenu.setAsOpen()
}
@@ -90,6 +91,7 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
if (drawTextArea) {
batch.color = Color.WHITE
textArea.render(batch)
}
}

View File

@@ -3,7 +3,9 @@ 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.Terrarum
import net.torvald.terrarum.gameactors.Second
import net.torvald.terrarum.langpack.Lang
class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
@@ -31,31 +33,64 @@ class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
defaultSelection = null
)
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,
align = UIItemTextArea.Align.CENTRE
)*/
private val localeList = Lang.languageList.toList().sorted()
private val textArea = UIItemTextButtonList(this,
localeList.map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }.toTypedArray(),
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
textAreaWidth, textAreaHeight,
textAreaWidth = textAreaWidth,
readFromLang = false,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
)
init {
uiItems.add(menubar)
//textArea.entireText = Lang.languageList.toList().sorted().map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }
////////////////////////////
uiItems.add(menubar)
// attach listeners
textArea.selectionChangeListener = { _, newSelectionIndex ->
Terrarum.gameLocale = localeList[newSelectionIndex]
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
menubar.selectedIndex = menubar.defaultSelection
this.setAsClose()
Thread.sleep(50)
menubar.selectedIndex = menubar.defaultSelection
superMenu.setAsOpen()
}
}
override fun updateUI(delta: Float) {
menubar.update(delta)
textArea.update(delta)
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
batch.color = Color.WHITE
textArea.render(batch)
}
override fun doOpening(delta: Float) {

View File

@@ -0,0 +1,116 @@
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.Terrarum
import net.torvald.terrarum.gameactors.Second
import net.torvald.terrarum.langpack.Lang
/**
* Created by minjaesong on 2017-08-01.
*/
/*class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() {
val menuLabels = arrayOf(
"MENU_LABEL_RETURN"
)
override var width: Int = UITitleRemoConRoot.remoConWidth
override var height: Int = UITitleRemoConRoot.getRemoConHeight(menuLabels)
override var openCloseTime: Second = 0f
private val moduleListWidth = Terrarum.WIDTH / 2
private val moduleList = UIItemList<UIItemModuleInfoCell>(
this,
menuLabels,
0, UITitleRemoConRoot.menubarOffY,
this.width, this.height,
textAreaWidth = this.width,
readFromLang = true,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
)
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,
align = UIItemTextArea.Align.CENTRE
)*/
private val localeList = Lang.languageList.toList().sorted()
private val textArea = UIItemTextButtonList(this,
localeList.map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }.toTypedArray(),
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
textAreaWidth, textAreaHeight,
textAreaWidth = textAreaWidth,
readFromLang = false,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
)
init {
uiItems.add(menubar)
//textArea.entireText = Lang.languageList.toList().sorted().map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }
////////////////////////////
// attach listeners
textArea.selectionChangeListener = { _, newSelectionIndex ->
Terrarum.gameLocale = localeList[newSelectionIndex]
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
menubar.selectedIndex = menubar.defaultSelection
superMenu.setAsOpen()
}
}
override fun updateUI(delta: Float) {
menubar.update(delta)
textArea.update(delta)
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
batch.color = Color.WHITE
textArea.render(batch)
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
}
}*/

View File

@@ -70,13 +70,15 @@ class UITitleRemoConRoot : UICanvas() {
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_LANGUAGE")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
remoConLanguage.setAsOpen()
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_CREDITS")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
remoConCredits.setAsOpen()
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> System.exit(0) }
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> Thread.sleep(50); System.exit(0) }
}
override fun updateUI(delta: Float) {