Skip to content

Commit f432d0d

Browse files
committed
refactor: Add constants and comments, update display text
1 parent 29f9ace commit f432d0d

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/main/kotlin/com/github/ilovegamecoding/intellijcodexp/managers/CodeXPUIManager.kt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.github.ilovegamecoding.intellijcodexp.models.CodeXPConfiguration
88
import com.github.ilovegamecoding.intellijcodexp.models.CodeXPDialog
99
import com.github.ilovegamecoding.intellijcodexp.models.CodeXPLevel
1010
import com.github.ilovegamecoding.intellijcodexp.services.CodeXPService
11+
import com.github.ilovegamecoding.intellijcodexp.utils.StringUtil
1112
import com.intellij.openapi.actionSystem.CommonDataKeys
1213
import com.intellij.openapi.actionSystem.DataContext
1314
import com.intellij.openapi.application.ApplicationManager
@@ -19,7 +20,6 @@ import java.awt.Color
1920
import java.awt.Dimension
2021
import java.awt.Font
2122
import java.awt.Point
22-
import java.awt.event.ActionListener
2323
import java.awt.event.MouseAdapter
2424
import java.awt.event.MouseMotionAdapter
2525
import javax.swing.*
@@ -43,19 +43,35 @@ object CodeXPUIManager : CodeXPEventListener, CodeXPListener {
4343
private var currentXPGainValue: Int = 0
4444

4545
/**
46-
* The message bus for the plugin
46+
* The message bus for the plugin.
4747
*/
4848
private val messageBus = ApplicationManager.getApplication().messageBus
4949

5050
/**
51-
* The connection to the message bus
51+
* The connection to the message bus.
5252
*/
5353
private val connection = messageBus.connect()
5454

55+
/**
56+
* The IDE frame.
57+
*/
5558
private lateinit var ide: JLayeredPane
59+
60+
/**
61+
* Dialog area for displaying dialogs in the IDE.
62+
*/
5663
private lateinit var dialogArea: JPanel
64+
65+
/**
66+
* Timers for each dialog.
67+
*/
5768
private val dialogTimers: MutableMap<CodeXPDialog, Timer> = mutableMapOf()
5869

70+
/**
71+
* Dialog duration.
72+
*/
73+
private val dialogDuration: Int = 4000
74+
5975
init {
6076
connection.subscribe(CodeXPEventListener.CODEXP_EVENT, this)
6177
connection.subscribe(CodeXPListener.CODEXP, this)
@@ -73,8 +89,8 @@ object CodeXPUIManager : CodeXPEventListener, CodeXPListener {
7389
showDialog(
7490
CodeXPDialog.createDialog(
7591
"Level Up!",
76-
"Congratulations! You have reached level ${levelInfo.level}!",
77-
"XP to next level: ${levelInfo.totalXPForNextLevel}xp"
92+
"Congratulations! You are now level ${StringUtil.numberToStringWithCommas(levelInfo.level.toLong())}!",
93+
"XP to next level: ${StringUtil.numberToStringWithCommas(levelInfo.totalXPForNextLevel)} xp"
7894
)
7995
)
8096
}
@@ -87,8 +103,8 @@ object CodeXPUIManager : CodeXPEventListener, CodeXPListener {
87103
showDialog(
88104
CodeXPDialog.createDialog(
89105
"Challenge Completed!",
90-
"Congratulations! You have completed '${challenge.name}'!",
91-
"XP gained: ${challenge.rewardXP}xp"
106+
"Congratulations! You have completed ${challenge.name.lowercase()}!",
107+
"XP earned: ${StringUtil.numberToStringWithCommas(challenge.rewardXP)} xp"
92108
)
93109
)
94110
}
@@ -247,7 +263,7 @@ object CodeXPUIManager : CodeXPEventListener, CodeXPListener {
247263
* Show the progress window for 3 seconds.
248264
*/
249265
private fun showDialog(dialog: CodeXPDialog) {
250-
dialogTimers[dialog] = Timer(3000, ActionListener { hideDialog(dialog) })
266+
dialogTimers[dialog] = Timer(dialogDuration) { hideDialog(dialog) }
251267
dialogTimers[dialog]?.start()
252268
dialog.show()
253269

src/main/kotlin/com/github/ilovegamecoding/intellijcodexp/models/CodeXPDialog.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import com.intellij.util.ui.JBUI
55
import java.awt.*
66
import javax.swing.*
77

8+
/**
9+
* CodeXPDialog class
10+
*
11+
* This class is used to create a dialog that is shown in the dialog area.
12+
*/
813
class CodeXPDialog(
914
/**
1015
* Dialog title.
@@ -31,10 +36,15 @@ class CodeXPDialog(
3136
*/
3237
private var content: JPanel
3338

39+
/**
40+
* Show dialog duration.
41+
*/
42+
private val showDuration = 2000
43+
3444
/**
3545
* Fade animation duration.
3646
*/
37-
private val fadeDurationMillis = 1000
47+
private val fadeDuration = 1000
3848

3949
/**
4050
* Animation step millis.
@@ -44,7 +54,7 @@ class CodeXPDialog(
4454
/**
4555
* Animation fade step.
4656
*/
47-
private val fadeStep = 192.0 * stepMillis / fadeDurationMillis
57+
private val fadeStep = 192.0 * stepMillis / fadeDuration
4858

4959
init {
5060
val lblTitle = JLabel().apply {
@@ -142,7 +152,7 @@ class CodeXPDialog(
142152

143153
if (alpha >= 192) {
144154
(event.source as Timer).stop()
145-
Timer(1000) { hide() }.apply {
155+
Timer(showDuration) { hide() }.apply {
146156
isRepeats = false
147157
start()
148158
}

0 commit comments

Comments
 (0)