avatar import error handling

This commit is contained in:
minjaesong
2023-08-25 17:38:15 +09:00
parent 602d5e046b
commit bfd926d7fe
6 changed files with 38 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
{
"ERROR_FILE_NOT_FOUND": "File not found.",
"GAME_32BIT_WARNING1": "It looks like youre running a 32-Bit version of Java.",
"GAME_32BIT_WARNING2": "Please download and install the latest 64-Bit Java at:",
"GAME_32BIT_WARNING3": "https://www.java.com/en/download/",

View File

@@ -1,4 +1,5 @@
{
"ERROR_FILE_NOT_FOUND": "파일을 찾을 수 없습니다.",
"GAME_32BIT_WARNING1": "32비트 버전의 Java를 사용중인 것 같습니다.",
"GAME_32BIT_WARNING2": "아래 링크에서 최신 64비트 Java를 내려받아 설치해주세요.",
"GAME_32BIT_WARNING3": "https://www.java.com/ko/download/",

View File

@@ -2,5 +2,6 @@
"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_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."
}

View File

@@ -1,5 +1,6 @@
{
"CONTEXT_THIS_IS_A_WORLD_CURRENTLY_PLAYING": "현재 플레이 중인 월드입니다.",
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_1": "1. 아바타 파일을 다음 폴더에 넣어주세요",
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_3": "2. 아바타 파일 이름을 아래에 입력하고 가져오기를 눌러주세요"
"CONTEXT_IMPORT_AVATAR_INSTRUCTION_3": "2. 아바타 파일 이름을 아래에 입력하고 가져오기를 눌러주세요",
"ERROR_AVATAR_ALREADY_EXISTS": "이미 존재하는 아바타입니다."
}

View File

@@ -61,6 +61,8 @@ class UIImportAvatar(val remoCon: UIRemoCon) : Advanceable() {
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)
private var importReturnCode = 0
init {
// addUIitem(codeBox)
// addUIitem(clearButton)
@@ -79,8 +81,15 @@ class UIImportAvatar(val remoCon: UIRemoCon) : Advanceable() {
remoCon.openUI(UILoadSavegame(remoCon))
}
goButton.clickOnceListener = { _,_ ->
val returnCode = doImport()
if (returnCode == 0) remoCon.openUI(UILoadSavegame(remoCon))
if (filenameInput.getText().isNotBlank()) {
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) {
uiItems.forEach { it.update(delta) }
pathW = App.fontGame.getWidth(App.importDir)
val textX = (Toolkit.drawWidth - pathW) / 2
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)) {
OpenFile(File(App.importDir))
}
}
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) {
batch.color = Color.WHITE
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) }
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() {
@@ -129,7 +153,7 @@ class UIImportAvatar(val remoCon: UIRemoCon) : Advanceable() {
}
private fun doImport(): Int {
val file = File("${App.importDir}/${filenameInput.getText()}")
val file = File("${App.importDir}/${filenameInput.getText().trim()}")
// check file's existence
if (!file.exists()) {

View File

@@ -73,6 +73,8 @@ class UIItemTextLineInput(
init {
}
var onKeyDown: (TerrarumKeyboardEvent) -> Unit = {}
private val labels = CommonResourcePool.getAsTextureRegionPack("inventory_category")
override val height = 24
@@ -394,6 +396,8 @@ class UIItemTextLineInput(
if (textbuf.size == 0) {
currentPlaceholderText = CodepointSequence(placeholder().toCodePoints())
}
onKeyDown(e)
}
}
else if (oldActive) { // just became deactivated