mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
avatar import error handling
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"ERROR_FILE_NOT_FOUND": "File not found.",
|
||||||
"GAME_32BIT_WARNING1": "It looks like you’re running a 32-Bit version of Java.",
|
"GAME_32BIT_WARNING1": "It looks like you’re running a 32-Bit version of Java.",
|
||||||
"GAME_32BIT_WARNING2": "Please download and install the latest 64-Bit Java at:",
|
"GAME_32BIT_WARNING2": "Please download and install the latest 64-Bit Java at:",
|
||||||
"GAME_32BIT_WARNING3": "https://www.java.com/en/download/",
|
"GAME_32BIT_WARNING3": "https://www.java.com/en/download/",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"ERROR_FILE_NOT_FOUND": "파일을 찾을 수 없습니다.",
|
||||||
"GAME_32BIT_WARNING1": "32비트 버전의 Java를 사용중인 것 같습니다.",
|
"GAME_32BIT_WARNING1": "32비트 버전의 Java를 사용중인 것 같습니다.",
|
||||||
"GAME_32BIT_WARNING2": "아래 링크에서 최신 64비트 Java를 내려받아 설치해주세요.",
|
"GAME_32BIT_WARNING2": "아래 링크에서 최신 64비트 Java를 내려받아 설치해주세요.",
|
||||||
"GAME_32BIT_WARNING3": "https://www.java.com/ko/download/",
|
"GAME_32BIT_WARNING3": "https://www.java.com/ko/download/",
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
"CONTEXT_THIS_IS_A_WORLD_CURRENTLY_PLAYING": "This is a world currently playing.",
|
"CONTEXT_THIS_IS_A_WORLD_CURRENTLY_PLAYING": "This is a world currently playing.",
|
||||||
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_1": "1. Place the Avatar file into the following directory:",
|
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_1": "1. Place the Avatar file into the following directory:",
|
||||||
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_2": "",
|
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_2": "",
|
||||||
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_3": "2. Enter the name of the file below, then press Import"
|
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_3": "2. Enter the name of the file below, then press Import",
|
||||||
|
"ERROR_AVATAR_ALREADY_EXISTS": "The Avatar already exists."
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"CONTEXT_THIS_IS_A_WORLD_CURRENTLY_PLAYING": "현재 플레이 중인 월드입니다.",
|
"CONTEXT_THIS_IS_A_WORLD_CURRENTLY_PLAYING": "현재 플레이 중인 월드입니다.",
|
||||||
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_1": "1. 아바타 파일을 다음 폴더에 넣어주세요",
|
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_1": "1. 아바타 파일을 다음 폴더에 넣어주세요",
|
||||||
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_3": "2. 아바타 파일 이름을 아래에 입력하고 가져오기를 눌러주세요"
|
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_3": "2. 아바타 파일 이름을 아래에 입력하고 가져오기를 눌러주세요",
|
||||||
|
"ERROR_AVATAR_ALREADY_EXISTS": "이미 존재하는 아바타입니다."
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,8 @@ class UIImportAvatar(val remoCon: UIRemoCon) : Advanceable() {
|
|||||||
private val goButton = UIItemTextButton(this,
|
private val goButton = UIItemTextButton(this,
|
||||||
{ Lang["MENU_IO_IMPORT"] }, drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
|
{ Lang["MENU_IO_IMPORT"] }, drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
|
||||||
|
|
||||||
|
private var importReturnCode = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// addUIitem(codeBox)
|
// addUIitem(codeBox)
|
||||||
// addUIitem(clearButton)
|
// addUIitem(clearButton)
|
||||||
@@ -79,8 +81,15 @@ class UIImportAvatar(val remoCon: UIRemoCon) : Advanceable() {
|
|||||||
remoCon.openUI(UILoadSavegame(remoCon))
|
remoCon.openUI(UILoadSavegame(remoCon))
|
||||||
}
|
}
|
||||||
goButton.clickOnceListener = { _,_ ->
|
goButton.clickOnceListener = { _,_ ->
|
||||||
val returnCode = doImport()
|
if (filenameInput.getText().isNotBlank()) {
|
||||||
if (returnCode == 0) remoCon.openUI(UILoadSavegame(remoCon))
|
importReturnCode = doImport()
|
||||||
|
if (importReturnCode == 0) remoCon.openUI(UILoadSavegame(remoCon))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset importReturnCode if the text input has changed
|
||||||
|
filenameInput.onKeyDown = { _ ->
|
||||||
|
importReturnCode = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +101,6 @@ class UIImportAvatar(val remoCon: UIRemoCon) : Advanceable() {
|
|||||||
override fun updateUI(delta: Float) {
|
override fun updateUI(delta: Float) {
|
||||||
uiItems.forEach { it.update(delta) }
|
uiItems.forEach { it.update(delta) }
|
||||||
|
|
||||||
|
|
||||||
pathW = App.fontGame.getWidth(App.importDir)
|
pathW = App.fontGame.getWidth(App.importDir)
|
||||||
val textX = (Toolkit.drawWidth - pathW) / 2
|
val textX = (Toolkit.drawWidth - pathW) / 2
|
||||||
textY = (App.scr.height - height) / 2 + descStartY + (1) * lh
|
textY = (App.scr.height - height) / 2 + descStartY + (1) * lh
|
||||||
@@ -102,10 +110,18 @@ class UIImportAvatar(val remoCon: UIRemoCon) : Advanceable() {
|
|||||||
if (mouseOnLink && Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)) {
|
if (mouseOnLink && Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)) {
|
||||||
OpenFile(File(App.importDir))
|
OpenFile(File(App.importDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val textboxIndices = (1..3)
|
private val textboxIndices = (1..3)
|
||||||
|
|
||||||
|
private val errorMessages = listOf(
|
||||||
|
Lang["ERROR_GENERIC_TEXT"], // -1
|
||||||
|
"", // 0
|
||||||
|
Lang["ERROR_FILE_NOT_FOUND"], // 1
|
||||||
|
Lang["ERROR_AVATAR_ALREADY_EXISTS"], // 2
|
||||||
|
)
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
batch.color = Color.WHITE
|
batch.color = Color.WHITE
|
||||||
val textboxWidth = textboxIndices.maxOf { App.fontGame.getWidth(Lang["CONTEXT_IMPORT_AVATAR_INSTRUCTION_$it"]) }
|
val textboxWidth = textboxIndices.maxOf { App.fontGame.getWidth(Lang["CONTEXT_IMPORT_AVATAR_INSTRUCTION_$it"]) }
|
||||||
@@ -120,6 +136,14 @@ class UIImportAvatar(val remoCon: UIRemoCon) : Advanceable() {
|
|||||||
|
|
||||||
|
|
||||||
uiItems.forEach { it.render(batch, camera) }
|
uiItems.forEach { it.render(batch, camera) }
|
||||||
|
|
||||||
|
|
||||||
|
if (importReturnCode != 0) {
|
||||||
|
batch.color = Toolkit.Theme.COL_RED
|
||||||
|
val tby = filenameInput.posY
|
||||||
|
val btny = backButton.posY
|
||||||
|
Toolkit.drawTextCentered(batch, App.fontGame, errorMessages[importReturnCode + 1], Toolkit.drawWidth, 0, (tby + btny) / 2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
@@ -129,7 +153,7 @@ class UIImportAvatar(val remoCon: UIRemoCon) : Advanceable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun doImport(): Int {
|
private fun doImport(): Int {
|
||||||
val file = File("${App.importDir}/${filenameInput.getText()}")
|
val file = File("${App.importDir}/${filenameInput.getText().trim()}")
|
||||||
|
|
||||||
// check file's existence
|
// check file's existence
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ class UIItemTextLineInput(
|
|||||||
init {
|
init {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var onKeyDown: (TerrarumKeyboardEvent) -> Unit = {}
|
||||||
|
|
||||||
private val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
|
private val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
|
||||||
|
|
||||||
override val height = 24
|
override val height = 24
|
||||||
@@ -394,6 +396,8 @@ class UIItemTextLineInput(
|
|||||||
if (textbuf.size == 0) {
|
if (textbuf.size == 0) {
|
||||||
currentPlaceholderText = CodepointSequence(placeholder().toCodePoints())
|
currentPlaceholderText = CodepointSequence(placeholder().toCodePoints())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onKeyDown(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (oldActive) { // just became deactivated
|
else if (oldActive) { // just became deactivated
|
||||||
|
|||||||
Reference in New Issue
Block a user