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

Merged
merged 37 commits into from
May 23, 2025
Merged

tip of the day #6841

merged 37 commits into from
May 23, 2025

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.69%. Comparing base (1533e5d) to head (087edef).
Report is 44 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.69%   30.69%            
- Complexity    16793    16816    +23     
==========================================
  Files          2935     2936     +1     
  Lines        285360   285485   +125     
  Branches      49629    49642    +13     
==========================================
+ Hits          87587    87627    +40     
- Misses       191486   191566    +80     
- Partials       6287     6292     +5     

☔ 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.

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!

@exeea exeea requested a review from a team as a code owner May 19, 2025 19:56
@HammerGS
Copy link
Member

@pavelbraginskiy Have you're requests been met.

@Scoppio Scoppio removed the For New Dev Cycle This PR should be merged at the beginning of a dev cycle label May 23, 2025
Comment on lines 1 to 18
/*
* Copyright (c) 2025 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still isn't the correct new copyright notice.

@Scoppio Scoppio merged commit aab9a96 into MegaMek:master May 23, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants