From 80ca06afbef944cde9d8b8d7bc384f00a17cd565 Mon Sep 17 00:00:00 2001 From: GGGuenni Date: Fri, 6 Mar 2020 15:05:42 +0100 Subject: [PATCH] ResponsePopup is now working like intended (#2089) --- core/src/com/unciv/ui/utils/ResponsePopup.kt | 25 +++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/core/src/com/unciv/ui/utils/ResponsePopup.kt b/core/src/com/unciv/ui/utils/ResponsePopup.kt index 5abe102ef2..ac1fe7c065 100644 --- a/core/src/com/unciv/ui/utils/ResponsePopup.kt +++ b/core/src/com/unciv/ui/utils/ResponsePopup.kt @@ -5,16 +5,25 @@ import kotlin.concurrent.thread //Its a popUp which will close itself after a given amount of time //Standard time is one second (in milliseconds) class ResponsePopup (message: String, screen: CameraStageBaseScreen, time: Long = 1000) : Popup(screen){ + private val visibilityTime = time init { + addGoodSizedLabel(message) + open() + //move it to the top so its not in the middle of the screen + //have to be done after open() because open() centers the popup + y = screen.stage.height - (height + padTop) + } + + private fun startTimer(){ thread (name = "ResponsePopup") { - val responsePopup = Popup(screen) - responsePopup.addGoodSizedLabel(message) - responsePopup.open() - //move it to the top so its not in the middle of the screen - //have to be done after open() because open() centers the popup - responsePopup.y = screen.stage.height - (responsePopup.height + responsePopup.padTop) - Thread.sleep(time) - responsePopup.close() + Thread.sleep(visibilityTime) + this.close() } } + + override fun setVisible(visible: Boolean) { + if (visible) + startTimer() + super.setVisible(visible) + } }