Skip to content

tip of the day #6841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open

tip of the day #6841

wants to merge 34 commits into from

Conversation

exeea
Copy link
Collaborator

@exeea exeea commented Apr 7, 2025

add common Tip Of The Day implementation with i18n support.

@exeea exeea requested a review from rjhancock April 7, 2025 02:25
Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 0% with 134 lines in your changes missing coverage. Please review.

Project coverage is 30.21%. Comparing base (f36f9cf) to head (f164e0c).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
megamek/src/megamek/common/util/TipOfTheDay.java 0.00% 93 Missing ⚠️
...gamek/src/megamek/client/ui/swing/util/UIUtil.java 0.00% 33 Missing ⚠️
...egamek/src/megamek/client/ui/swing/MegaMekGUI.java 0.00% 7 Missing ⚠️
.../src/megamek/common/internationalization/I18n.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6841      +/-   ##
============================================
- Coverage     30.23%   30.21%   -0.03%     
+ Complexity    15803    15794       -9     
============================================
  Files          2885     2886       +1     
  Lines        283320   283445     +125     
  Branches      49340    49353      +13     
============================================
- Hits          85674    85636      -38     
- Misses       192047   192207     +160     
- Partials       5599     5602       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@exeea exeea requested a review from rjhancock April 7, 2025 02:43
Copy link
Member

@pavelbraginskiy pavelbraginskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On lower-resolution screens the tip is too large relative to the splash.

@rjhancock
Copy link
Collaborator

On lower-resolution screens the tip is too large relative to the splash.

That would be due to the hints. What they do internally is essentially double the size of the render and scale it down. On HiDPI/Retina screens they show correctly. On "normal" screens they are twice the size.

Or that is my theory on it anyways.

@rjhancock
Copy link
Collaborator

Instead of rending to a Graphics context, why not render to a Swing object that can be inserted somewhere on the screen?

@exeea
Copy link
Collaborator Author

exeea commented Apr 7, 2025

Originally I did that with a layeredpane but I was getting very bad aliasing and ugly stroke. This was the most visually pleasing approach.

@exeea exeea requested a review from pavelbraginskiy April 8, 2025 00:04
Copy link
Collaborator

@rjhancock rjhancock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The license header needs to be updated to the correct version and you'll need to update latest master into this and fix the calls to the Internationalization class to I18N.

Almost there.

@rjhancock rjhancock added the For New Dev Cycle This PR should be merged at the beginning of a dev cycle label Apr 17, 2025
@IllianiBird IllianiBird removed the For New Dev Cycle This PR should be merged at the beginning of a dev cycle label Apr 26, 2025
@HammerGS HammerGS requested a review from Copilot April 26, 2025 19:57
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces a new "Tip Of The Day" implementation with internationalization support and updates the screen resolution scaling utilities used within the UI.

  • Added the TipOfTheDay class to display a daily/random tip with word wrapping and styling
  • Refactored UIUtil to improve resolution scale factor computations and simplify splash component creation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
megamek/src/megamek/common/util/TipOfTheDay.java Implements tip of the day functionality with i18n support and custom drawing
megamek/src/megamek/client/ui/swing/util/UIUtil.java Enhances resolution scaling methods and simplifies splash image sizing

@exeea exeea requested review from Copilot and HammerGS April 26, 2025 22:14
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a "Tip Of The Day" feature with internationalization support, including methods to retrieve today's tip and a random tip, along with rendering logic for word-wrapped tip text. In addition, UI scaling helpers in UIUtil.java have been updated to improve resolution and DPI scaling.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
megamek/src/megamek/common/util/TipOfTheDay.java Implements the Tip Of The Day functionality, including tip selection and rendering.
megamek/src/megamek/client/ui/swing/util/UIUtil.java Adds new methods for monitor and resolution scaling and updates splash component logic.

} catch (Exception e) {
// When we get an exception, we've found all tips
return count - 1;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has to be a better way to do this to get the number of tips.

Copy link
Collaborator Author

@exeea exeea Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see many other options:
a) or we store, in the file, also the number of tips in a dedicated key=value pair (making the i18n file store also numeric constants, that has to be kept updated while adding/removing tips)
b) or we ditch the key=value file format, and we use a dedicated file for specifically only the tips, one per line, and we use the lines count to know how many tips we have

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you get the ResourceBundle you're using, you would be able to get the list of its keys. From there you could filter it to keys that contain TipOfTheDay.tip (maybe change it to be longer/more specific so there's no false positives?). This would also give the list of tips, and wouldn't require them to be numbered sequentially. Something like:

ResourceBundle bundle = I18n.getInstance().getResourceBundle(bundleName);
Enumeration<String> keys = bundle.getKeys();

?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking making a resource file JUST for the tips for easier translation and just get the keys that way.

The ResourceBundle will handle I18N for us anyways and I plan to update the I18N class itself to be more dynamic in nature with ability to have defaults for the class as well as add in additional bundles as needed. A way to keep the resource files smaller and easier to manage for translations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then, let's do a dedicated file without Key=Value pairs structure

rjhancock
rjhancock previously approved these changes Apr 28, 2025
@rjhancock rjhancock added the For New Dev Cycle This PR should be merged at the beginning of a dev cycle label Apr 28, 2025
@exeea exeea requested a review from a team as a code owner April 28, 2025 06:43
psikomonkie
psikomonkie previously approved these changes Apr 29, 2025
Copy link
Collaborator

@psikomonkie psikomonkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it!

In the future, I'd love to see an enhancement that lets values within the tip be dynamically replaced - like tip.7=You can press "{HOTKEY:VIEW_TOGGLE_ISOMETRIC}" to switch between top view and isometric view. and then TipOfTheDayJava would replace that with the actual hotkey before returning it to the player. That's for another day though,

I think this is a wonderful foundation for this feature and I'm excited to see this eventually get added to MegaMekLab and MekHQ as well.

@exeea
Copy link
Collaborator Author

exeea commented Apr 29, 2025

I think this is a wonderful foundation for this feature and I'm excited to see this eventually get added to MegaMekLab and MekHQ as well.

The PR for MML is already up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For New Dev Cycle This PR should be merged at the beginning of a dev cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants