Skip to content

Commit

Permalink
Refactor menu notification, added TCTT message
Browse files Browse the repository at this point in the history
  • Loading branch information
Bombbird2001 committed Aug 10, 2023
1 parent ade4f5e commit 0cdfc73
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package com.bombbird.terminalcontrol2.screens

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.utils.Align
import com.bombbird.terminalcontrol2.global.*
import com.bombbird.terminalcontrol2.screens.settings.MainSettings
import com.bombbird.terminalcontrol2.ui.CustomDialog
import com.bombbird.terminalcontrol2.ui.MenuNotificationManager
import com.bombbird.terminalcontrol2.ui.addChangeListener
import ktx.scene2d.*

/** The main menu screen which extends [BasicUIScreen] */
class MainMenu: BasicUIScreen() {
private val menuNotificationManager: MenuNotificationManager

init {
stage.actors {
// UI Container
Expand Down Expand Up @@ -53,19 +54,7 @@ class MainMenu: BasicUIScreen() {
}
}

val prefs = Gdx.app.getPreferences(PREFS_FILE_NAME)
if (!prefs.getBoolean("beta-welcome-msg-shown", false)) {
// Show welcome message
CustomDialog("Welcome to the beta!", "Thank you for joining the beta! This is a very early version" +
" of the game, so there are likely to be bugs and issues. Please report them by emailing" +
" bombbirddev@gmail.com, or by clicking the \"Report Bug\" button in the info menu. Please include" +
" as much information as possible, including the build version (in info menu), expected behaviour" +
" and steps to reproduce the bug. Screenshots and video recordings are very helpful too.\n\n" +
"Currently, there are only 2 default airports for testing, but rest assured that more will be" +
" added as testing goes on. We hope you will enjoy the new multiplayer functionality, have fun!",
"", "Ok!", height = 800, width = 1800, fontAlign = Align.left).show(stage)
prefs.putBoolean("beta-welcome-msg-shown", true)
prefs.flush()
}
menuNotificationManager = MenuNotificationManager(stage)
menuNotificationManager.showMessages()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.bombbird.terminalcontrol2.ui

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.utils.Align
import com.bombbird.terminalcontrol2.global.PREFS_FILE_NAME
import ktx.collections.GdxArray

class MenuNotificationManager(private val stage: Stage) {
private class MenuNotification(val prefKey: String, val title: String, val message: String, val height: Int, val width: Int)

/**
* Notification array, added in order of highest to lowest priority (i.e. if a notification is shown, all
* notifications added after will not be shown even if it has not been shown ever before to the user
*/
private val notifications = GdxArray<MenuNotification>().apply {
add(
MenuNotification("beta-welcome-msg-shown", "Welcome to the beta!", "Thank you for" +
" joining the beta! This is a very early version of the game, so there are likely to be bugs and" +
" issues. Please report them by emailing bombbirddev@gmail.com, or by clicking the \"Report Bug\"" +
" button in the Pause screen or info menu. Please include as much information as possible," +
" including the build version (in info menu), expected behaviour and steps to reproduce the bug." +
" Screenshots and video recordings are very helpful too.\n\nCurrently, there are 3 default airports" +
" for testing, and more will be added as testing goes on. We hope you will enjoy the new" +
" multiplayer functionality, have fun!", 800, 1800)
)
add(
MenuNotification("tctt-added", "New airport available!", "TCTT has been added to the" +
" game. Custom datatag layouts have also been enabled: Settings => Datatag => Datatag style. As" +
" always, please report bugs encountered by clicking the \"Report Bug\" button in the Pause" +
" screen, or from the info menu. We hope you will enjoy the new map, have fun!", 600, 1400)
)
}

/** Shows the message that has not been shown before with the highest priority */
fun showMessages() {
val prefs = Gdx.app.getPreferences(PREFS_FILE_NAME)

for (i in 0 until notifications.size) {
val notif = notifications[i]
if (!prefs.getBoolean(notif.prefKey, false)) {
// Show welcome message
CustomDialog(notif.title, notif.message, "", "Ok!", height = notif.height,
width = notif.width, fontAlign = Align.left).show(stage)
break
}
}

// All messages are marked as shown
for (i in 0 until notifications.size) {
prefs.putBoolean(notifications[i].prefKey, true)
}
prefs.flush()
}
}

0 comments on commit 0cdfc73

Please sign in to comment.