Skip to content

Commit 50d44eb

Browse files
committed
feat: Display notification when a challenge is completed or level up
1 parent 9b69c56 commit 50d44eb

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/main/kotlin/com/github/ilovegamecoding/intellijcodexp/services/CodeXPService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.ilovegamecoding.intellijcodexp.services
22

33
import com.github.ilovegamecoding.intellijcodexp.listeners.CodeXPListener
4+
import com.github.ilovegamecoding.intellijcodexp.manager.CodeXPNotificationManager
45
import com.github.ilovegamecoding.intellijcodexp.model.CodeXPChallenge
56
import com.intellij.openapi.application.ApplicationManager
67
import com.intellij.openapi.components.*
@@ -264,6 +265,7 @@ class CodeXPService : PersistentStateComponent<CodeXPService.CodeXPState>, CodeX
264265
if (challenge.progress >= challenge.goal) {
265266
codeXPState.xp += challenge.rewardXP
266267
replaceChallengeWithNew(challenge, event)
268+
CodeXPNotificationManager.notifyChallengeComplete(challenge)
267269
}
268270
}
269271
}

src/main/kotlin/com/github/ilovegamecoding/intellijcodexp/toolWindow/CodeXPToolWindowFactory.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.github.ilovegamecoding.intellijcodexp.toolWindow
22

3-
import com.github.ilovegamecoding.intellijcodexp.util.StringUtil
43
import com.github.ilovegamecoding.intellijcodexp.form.CodeXPChallengeForm
54
import com.github.ilovegamecoding.intellijcodexp.form.CodeXPDashboard
65
import com.github.ilovegamecoding.intellijcodexp.listeners.CodeXPListener
6+
import com.github.ilovegamecoding.intellijcodexp.manager.CodeXPNotificationManager
77
import com.github.ilovegamecoding.intellijcodexp.model.CodeXPChallenge
88
import com.github.ilovegamecoding.intellijcodexp.services.CodeXPService
9+
import com.github.ilovegamecoding.intellijcodexp.util.StringUtil
910
import com.intellij.openapi.application.ApplicationManager
1011
import com.intellij.openapi.project.Project
1112
import com.intellij.openapi.wm.ToolWindow
@@ -172,10 +173,16 @@ class CodeXPToolWindowFactory : ToolWindowFactory {
172173
private fun updateXPInfo(codeXPService: CodeXPService, codeXPDashboard: CodeXPDashboard) {
173174
val totalXP = codeXPService.state.xp
174175
codeXPDashboard.lblTotalXP.text = StringUtil.numberToStringWithCommas(totalXP)
175-
val (currentLevel, xpIntoCurrentLevel, progressToNextLevel) = calculateLevelAndProgress(
176+
val (currentLevel, xpIntoCurrentLevel, progressToNextLevel, xpToNextLevel) = calculateLevelAndProgress(
176177
totalXP
177178
)
178179

180+
181+
val beforeLevel = codeXPDashboard.lblCurrentLevel.text.toInt()
182+
if (beforeLevel != currentLevel && beforeLevel != 0) {
183+
CodeXPNotificationManager.notifyLevelUp(currentLevel, xpToNextLevel)
184+
}
185+
179186
codeXPDashboard.lblCurrentLevel.text = StringUtil.numberToStringWithCommas(currentLevel.toLong())
180187
codeXPDashboard.lblNextLevel.text = StringUtil.numberToStringWithCommas((currentLevel + 1).toLong())
181188
codeXPDashboard.lblCurrentLevelXP.text = StringUtil.numberToStringWithCommas(xpIntoCurrentLevel)
@@ -261,7 +268,12 @@ class CodeXPToolWindowFactory : ToolWindowFactory {
261268
/**
262269
* Progress to the next level.
263270
*/
264-
val progressToNextLevel: Int
271+
val progressToNextLevel: Int,
272+
273+
/**
274+
* XP needed to reach the next level.
275+
*/
276+
val xpToNextLevel: Long
265277
)
266278

267279
/**
@@ -284,7 +296,7 @@ class CodeXPToolWindowFactory : ToolWindowFactory {
284296
val xpIntoCurrentLevel = totalXP - (xp - currentLevelXP)
285297
val progress = (xpIntoCurrentLevel / currentLevelXP) * 100
286298

287-
return LevelInfo(level, xpIntoCurrentLevel.toLong(), progress.toInt())
299+
return LevelInfo(level, xpIntoCurrentLevel.toLong(), progress.toInt(), currentLevelXP.toLong())
288300
}
289301
}
290302

0 commit comments

Comments
 (0)