Skip to content

Commit

Permalink
feat: Tip of the day!
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Sep 30, 2023
1 parent d5d7eb5 commit 3385a26
Show file tree
Hide file tree
Showing 14 changed files with 692 additions and 45 deletions.
2 changes: 2 additions & 0 deletions serverpackcreator-gui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
api(project(":serverpackcreator-api"))
api("commons-io:commons-io:2.11.0")
api("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.6.4")
api("org.jetbrains.kotlin:kotlin-reflect:1.8.20")
implementation(project(":serverpackcreator-updater"))

//New GUI
Expand All @@ -26,6 +27,7 @@ dependencies {
api("net.java.balloontip:balloontip:1.2.4.1")
api("com.github.dyorgio.runtime:run-as-root:1.2.3")
api("com.cronutils:cron-utils:9.2.1")
api("tokyo.northside:tipoftheday:0.4.2")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")
Expand Down
49 changes: 49 additions & 0 deletions serverpackcreator-gui/src/main/i18n/Gui_en_GB.properties
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ menubar.gui.menuitem.spcdir=Open installation directory
menubar.gui.menuitem.homedir=Open configs directory
menubar.gui.menuitem.serverfilesdir=Open server-files directory
menubar.gui.menuitem.licensereport=Third Party Notices
menubar.gui.menuitem.tipoftheday=Tip Of The Day
menubar.gui.config.load.message=Do you want to load the selected configuration into the current tab, or a new tab?\n\n{0}
menubar.gui.config.load.title=Load Configuration
menubar.gui.config.load.current=Current Tab
Expand Down Expand Up @@ -361,6 +362,54 @@ main.unsaved.title=Unsaved Settings!
main.tabs.config=Configs
main.tabs.logs=Logs
main.tabs.settings=Settings
tips.title=Tip Of The Day!
tips.know=Did you know...
tips.show=Show tips on startup
tips.next=Next >
tips.previous=< Previous
tips.close=Close
tip.1.content=<html>You can save the currently selected server pack configuration by pressing CTRL + S.
tip.1.name=Save quickly
tip.2.content=<html>You can open a new server pack configuration tab by pressing CTRL + T.</html>
tip.2.name=Open a new tab
tip.3.content=<html>Identified a mod which crashes servers, and therefore only required on the clientside, but not on the server side i.e. in your server pack? Submit an Improvement Request on GitHub, with the name of the mod and the link to CurseForge / Modrinth!</html>
tip.3.name=Contribute clientside mods
tip.4.content=<html>You can create server packs from zipped modpacks. Make sure all modpack contents are at the root of the ZIP-archive, and not bundled in a sub-folder inside the archive. Point the <i>Modpack Directory</i> setting of your server pack configuration at your ZIP-archive and set everything else according to your modpack. You still need to tell ServerPackCreator which directories or files to include, which Minecraft version, modloader and modloader version your modpack uses, though!</html>
tip.4.name=Zipped modpacks
tip.5.content=<html>Want to tickle some more performance out of your server? Try out Aikars Flags! Check out <i>Advanced Settings -> Use Aikars Flags</i> which will add said Aikars Flags to your server packs <i>Run Arguments</i>. Generate your server pack and run your server to see whether it improved your servers performance!</html>
tip.5.name=Custom JVM flags / run args
tip.6.content=<html>Want to keep different versions of a server pack, generated from the same modpack? Take a look at <i>Server Pack Suffix</i> which will add said suffix to the generated server pack, allowing you to try out different settings for your server pack, without loosing previous generation. Suffixes like <i>Aikars_Flags</i>, <i>With_Blueprints</i>, <i>With_BlueMap</i> to give you an idea.</html>
tip.6.name=Identify with suffixes
tip.7.content=<html>You can add server icons for quick selection by copying them to the server icon directory. In the menu at the top, click <i>View -> Open server-icon directory</i>. Any PNG-, JPG-, JPEG- and BMP-image added to said directory will be available in your server pack configs <i>Server Icon Quick select</i> dropdown. Select an image from said dropdown to quickly use it as your servers icon!</html>
tip.7.name=Server icon
tip.8.content=<html>You can add server properties for quick selection by copying them to the server properties directory. In the menu at the top, click <i>View -> Open server-properties directory</i>. Any PROPERTIES-file added to said directory will be available in your server pack configs <i>Server Properties Quick select</i> dropdown. Select an entry from said dropdown to quickly use it as your servers properties-file!</html>
tip.8.name=Shipped properties
tip.9.content=<html>You can let ServerPackCreator scan your modpack-directory and try to automatically set the Minecraft version, modloader and modloader version, as well as some commonly used directories in servers. Hit the magnifying-glass-button on the right to your <i>Modpack Directory</i>-setting.</html>
tip.9.name=Clientside detection
tip.10.content=<html>You can let ServerPackCreator copy a file or directory to a customized destination in your server pack. Say you've got a folder <i>MyAwesomeStuff</i> in your modpack configured as the Source, filling <i>Destination</i> with, say, <i>AwesomeStuff</i> will copy the aforementioned <i>Source</i> to your specified Destination inside your server pack.<br>Inclusions which specify an explicit <i>Destination</i> are marked with a <i>D</i>.</html>
tip.10.name=Advanced inclusion
tip.11.content=<html>You can filter files and directories from any <i>Source</i>-specification by providing a <i>Inclusion-Filter</i>. Any file or directory matching the Regex-expression you provided will be included in your server pack. To include everything from your specified <i>Source</i>, leave <i>Inclusion-Filter</i> empty.</html>
tip.11.name=Advanced inclusion filtering
tip.12.content=<html>You can filter files and directories from any <i>Source</i>-specification by providing an <i>Exclusion-Filter</i>. Any file or directory matching the Regex-expression you provided will be excluded from your server pack. If you leave Exclusion-Filter empty, no files or directories will be excluded from the specified Source.</html>
tip.12.name=Advanced exclusion filtering
tip.13.content=<html>Global exclusion-filters allow you to globally exclude files and directories from any source during the creation of your server pack. To specify a global exclusion-filter, add a new entry in your <i>Server-files</i>, leave <i>Source</i> empty, but fill <i>Exclusion-Filter</i> with a Regex-expression based on which files or directories should be excluded during the creation of your server pack. A global exclusion-filter will be marked with (E) in your Server-files list.</html>
tip.13.name=Global filtering
tip.14.content=<html>If ServerPackCreators default font size is too small for you, or the theme not to your liking, you can change these settings in <i>Settings -> Gui</i> to better fit your personal preferences.</html>
tip.14.name=Size matters
tip.15.content=<html>Not sure if a clientside-only mod is included in the list of clientside-only mods in your server pack config? Click the aforementioned list and hit CTRL+F and search for it! Try searching for "advan" to highlight all entries which contain that text! You can perform text-searches like that in every textarea of ServerPackCreator. Searching textfields is not possible, though, so keep that in mind.</html>
tip.15.name=Searching...
tip.16.content=<html>Need to replace some text in a textarea? Say, for example, you've got some JVM flags / run arguments you want to replace with something else? Click <i>Advanced Settings -> Run Arguments</i> and hit CTRL+R, then type in the text you want to replace as well as the text you want to place it with and hit <i>OK</i>. You can perform replace-actions like that in every textarea of ServerPackCreator. Replacing in textfields is not possible, though, so keep that in mind.</html>
tip.16.name=This to that
tip.17.content=<html>No longer need the currently selected server pack configuration? Close it by pressing CTRL+W!</html>
tip.17.name=Be gone, config!
tip.18.content=<html>You can save all currently opened server pack configurations, or in other words, all currently opened tabs with your server pack configurations, by pressing CTRL+SHIFT+S!</html>
tip.18.name=Gotta save 'em all!
tip.19.content=<html>You can open the dialog to load a server pack configuration by pressing CTRL+L.</html>
tip.19.name=Quick loading
tip.20.content=<html>You can start a server pack generation for the currently selected config-tab by pressing CTRL+G.</html>
tip.20.name=Quick generation
tip.21.content=<html>Does your server crash, with a message like "Error: could not find or load main class @user_jvm_args.txt"? This is most likely because you are trying to run the server with an incompatible Java version. Java 8 is required to run Minecraft versions 1.12 through 1.17. Java 17 is required to run Minecraft version 1.18 and up.</html>
tip.21.name=Use the right version!
# LOGS
## Error logs
configuration.title.error=This configuration has errors!
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package de.griefed.serverpackcreator.gui.utilities

import java.awt.Dimension
import java.awt.Image
import java.util.*
import javax.imageio.ImageIO
Expand Down Expand Up @@ -80,4 +81,39 @@ class ImageUtilities {
*/
fun ImageIcon.getScaledInstance(width: Int, height: Int, scaling: Int = Image.SCALE_SMOOTH): ImageIcon {
return ImageIcon(this.image.getScaledInstance(width, height, scaling))
}

/**
* Scale the image, keeping the aspect ratio, to the given [size]. By default, the width of the image will be changed to
* the desired [size]. If you want to change the height of the image to the desired [size], then set [scaleBy] to [ScaleBy.HEIGHT].
*
* @author Griefed
*/
fun ImageIcon.getAspectRatioScaledInstsance(size: Int, scaleBy: ScaleBy = ScaleBy.WIDTH, scaling: Int = Image.SCALE_SMOOTH): ImageIcon {
val imgSize = Dimension(iconWidth, iconHeight)
val widthRatio: Double
val heightRatio: Double
var newHeight = iconHeight
var newWidth = iconWidth
when (scaleBy) {
ScaleBy.WIDTH -> {
newWidth = size
widthRatio = size.toDouble() / imgSize.width
newHeight = (iconHeight * widthRatio).toInt()
}
ScaleBy.HEIGHT -> {
newHeight = size
heightRatio = size.toDouble() / imgSize.height
newWidth = (iconHeight * heightRatio).toInt()
}
}
return getScaledInstance(newWidth,newHeight,scaling)
}

/**
* @author Griefed
*/
enum class ScaleBy {
WIDTH,
HEIGHT
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ import Gui
import de.griefed.serverpackcreator.api.ApiWrapper
import de.griefed.serverpackcreator.gui.GuiProps
import de.griefed.serverpackcreator.gui.window.menu.MainMenuBar
import de.griefed.serverpackcreator.gui.window.tips.TipOfTheDayManager
import de.griefed.serverpackcreator.updater.MigrationManager
import de.griefed.serverpackcreator.updater.UpdateChecker
import java.awt.Dimension
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import javax.swing.JFrame
import javax.swing.WindowConstants
import javax.swing.event.HyperlinkEvent
import javax.swing.event.HyperlinkListener

/**
* Main Frame of ServerPackCreator, housing [MainPanel], [MainMenuBar].
Expand Down Expand Up @@ -77,6 +80,9 @@ class MainFrame(
toFront()
}
menu.displayMigrationMessages()
if (guiProps.showTipOnStartup) {
menu.showTip()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,17 @@ class MainMenuBar(
menuBar.add(updateButton)
}


/**
* @author Griefed
*/
fun displayMigrationMessages() {
about.displayMigrationMessages()
}

/**
* @author Griefed
*/
fun showTip() {
about.showTip()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class AboutMenu(
private val discord = DiscordItem(webUtilities)
private val donate = DonationsItem(webUtilities)
private val thirdparty = ThirdPartyNoticesItem(mainFrame,guiProps)
private val tipOfTheDayItem = TipOfTheDayItem(guiProps, mainFrame)

init {
add(update)
Expand All @@ -73,6 +74,8 @@ class AboutMenu(
add(donate)
add(JSeparator())
add(thirdparty)
add(JSeparator())
add(tipOfTheDayItem)
}

/**
Expand All @@ -81,4 +84,11 @@ class AboutMenu(
fun displayMigrationMessages() {
migration.displayMigrationMessages()
}

/**
* @author Griefed
*/
fun showTip() {
tipOfTheDayItem.showTip()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Copyright (C) 2023 Griefed
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.gui.window.menu.about

import de.griefed.serverpackcreator.gui.GuiProps
import de.griefed.serverpackcreator.gui.window.MainFrame
import de.griefed.serverpackcreator.gui.window.tips.TipOfTheDayManager
import javax.swing.JMenuItem

/**
* Menuitem to display the tip of the day.
*
* @author Griefed
*/
class TipOfTheDayItem(guiProps: GuiProps, mainFrame: MainFrame): JMenuItem(Gui.menubar_gui_menuitem_tipoftheday.toString()) {

private val tipManager = TipOfTheDayManager(mainFrame.frame,guiProps)

init {
this.addActionListener { showTip() }
}

/**
* @author Griefed
*/
fun showTip() {
tipManager.showTipOfTheDay()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (C) 2023 Griefed
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
* The full license can be found at https:github.com/Griefed/ServerPackCreator/blob/main/LICENSE
*/
package de.griefed.serverpackcreator.gui.window.tips

import tokyo.northside.swing.tips.DefaultTip
import javax.swing.ImageIcon

/**
* @author Griefed
*/
class CustomTip(name: String, tip: Any, private val imageResource: String): DefaultTip(name,tip) {
fun getImage(): ImageIcon? {
return try {
ImageIcon(this.javaClass.getResource(imageResource))
} catch (_: Exception) {
null
}
}
}
Loading

0 comments on commit 3385a26

Please sign in to comment.