Skip to content

Commit

Permalink
fixes for achievement dialog and prevent prefs NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Oct 22, 2024
1 parent 26d7112 commit c2bd666
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
5 changes: 2 additions & 3 deletions client/src/main/java/util/AchievementsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,9 @@ public static void unlockAchievement(Achievement achievement)
return;
}

ScreenCache.getAchievementsDialog().refresh(false);

achievements.putBoolean(registryLocation, true);


ScreenCache.getAchievementsDialog().refresh(false);
ImageIcon icon = getIconForAchievement(registryLocation);

MainScreen screen = ScreenCache.getMainScreen();
Expand Down
6 changes: 5 additions & 1 deletion client/src/main/java/util/RegistryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public static void clearNode(Preferences node)

public static Document getAttributeXml(Preferences node, String key)
{
String attribute = node.get(key, "");
String attribute = node.get(key, null);
if (attribute == null) {
return null;
}

return XmlUtil.getDocumentFromXmlString(attribute);
}

Expand Down
37 changes: 18 additions & 19 deletions client/src/main/kotlin/screen/AchievementsDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,21 @@ class AchievementsDialog : JFrame(), MouseMotionListener, MouseListener, ActionL
btnLeft.isOpaque = false
btnLeft.font = Font("Segoe UI Symbol", Font.BOLD, 24)
btnLeft.border = EmptyBorder(0, 0, 0, 0)
btnLeft.setBounds(11, 158, 30, 50)
btnLeft.setBounds(25, 158, 30, 50)
contentPane.add(btnLeft)
btnLeft.addActionListener(this)
btnRight.isOpaque = false
btnRight.background = Color.WHITE
btnRight.font = Font("Segoe UI Symbol", Font.BOLD, 24)
btnRight.border = EmptyBorder(0, 0, 0, 0)
btnRight.setBounds(680, 158, 30, 50)
btnRight.setBounds(645, 158, 30, 50)
contentPane.add(btnRight)
btnRight.addActionListener(this)

btnLeft.isEnabled = false

for (page in pages) {
page.setBounds(56, 56, 615, 255)
page.setBounds(56, 56, 590, 255)
contentPane.add(page)
}

Expand All @@ -142,16 +142,11 @@ class AchievementsDialog : JFrame(), MouseMotionListener, MouseListener, ActionL
achievementExplanation.text = ""

updatePagination()
redrawStars()
animateTestTube()
refresh(true)
}

private fun populateBadgeListAndAddMotionListeners() {
pages.forEach { page ->
for (badge in page.badges) {
badge.addMouseMotionListener(this)
}
}
getAllChildComponentsForType<AchievementBadge>().forEach { it.addMouseMotionListener(this) }
}

private fun populateStarListAndAddMouseListeners() {
Expand All @@ -171,7 +166,9 @@ class AchievementsDialog : JFrame(), MouseMotionListener, MouseListener, ActionL
}

private fun updateTestTube() {
progressShowing = getAchievementsEarned()
testTube.icon = getTubeIconForIndex(getAchievementsEarned())
redrawStars()
}

private fun getTubeIconForIndex(i: Int): ImageIcon {
Expand All @@ -181,14 +178,15 @@ class AchievementsDialog : JFrame(), MouseMotionListener, MouseListener, ActionL

private fun redrawStars() {
getAllChildComponentsForType<RewardStar>().forEach { star ->
if (star.isUnlocked(progressShowing)) {
if (star.isUnlocked(getAchievementsEarned())) {
star.setIcon(Images.REWARD_UNLOCKED)
val hoverDesc: String = star.getHoverDesc()
star.setToolTipText(hoverDesc)
star.setToolTipText(star.hoverDesc)
} else {
star.setIcon(Images.REWARD_LOCKED)
star.setToolTipText("Locked")
}

star.repaint()
}
}

Expand All @@ -200,6 +198,8 @@ class AchievementsDialog : JFrame(), MouseMotionListener, MouseListener, ActionL
}

getAllChildComponentsForType<AchievementBadge>().forEach { it.toggle() }

updateTitle()
repaint()
}

Expand Down Expand Up @@ -292,12 +292,11 @@ class AchievementsDialog : JFrame(), MouseMotionListener, MouseListener, ActionL
btnLeft.isEnabled = currentPage > 0
btnRight.isEnabled = currentPage < pages.size - 1

pages.forEachIndexed { i, page ->
page.isVisible = i == currentPage
pages.forEachIndexed { i, page -> page.isVisible = i == currentPage }
updateTitle()
}

if (i == currentPage) {
title.text = page.getTitle()
}
}
private fun updateTitle() {
title.text = pages[currentPage].getTitle()
}
}
2 changes: 1 addition & 1 deletion client/src/main/kotlin/screen/AchievementsPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import bean.AchievementBadge
import javax.swing.JPanel
import utils.Achievement

const val MAX_PER_PAGE = 40
const val MAX_PER_PAGE = 36

fun makeAchievementPanels() =
Achievement.entries.chunked(MAX_PER_PAGE).mapIndexed { ix, badges ->
Expand Down

0 comments on commit c2bd666

Please sign in to comment.