Skip to content
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

feat: Main menu refactor; many things to GUI layer; UI controller #333

Draft
wants to merge 10 commits into
base: release/0.10.0.0
Choose a base branch
from

Conversation

EttyKitty
Copy link
Collaborator

@EttyKitty EttyKitty commented Dec 27, 2024

Summary by Sourcery

Refactor the main menu and move view-related calculations to the GUI layer using a UI controller.

New Features:

  • Introduce a UI controller object to manage UI interactions and screen fading.

Enhancements:

  • Remove view offset calculations from drawing code and replace them with fixed coordinates.
  • Implement helper functions for hit detection based on screen coordinates.
  • Prevent interactions during screen fading and other UI events using a cooldown system.

Copy link
Contributor

sourcery-ai bot commented Dec 27, 2024

Reviewer's Guide by Sourcery

This pull request refactors the main menu, moves several components to the GUI layer, and introduces a UI controller.

File-Level Changes

Change Details Files
Removed view coordinates and used hardcoded coordinates for drawing UI elements.
  • Replaced view coordinates with hardcoded values in draw_text_transformed and draw_sprite functions.
  • Removed variables xx and yy, which stored view coordinates.
objects/obj_popup/Draw_0.gml
Replaced point-and-click checks with collision functions.
  • Used scr_hit function for button and mouse interaction checks.
  • Removed manual calculations of mouse position relative to view coordinates.
objects/obj_popup/Draw_0.gml
objects/obj_popup/Mouse_50.gml
Refactored mouse interaction logic for equipment changes.
  • Simplified mouse interaction logic using scr_hit function.
  • Removed manual mouse position checks and view coordinate calculations.
objects/obj_popup/Mouse_50.gml
Removed unnecessary view coordinate calculations and hardcoded UI positions.
  • Removed view coordinate variables xx and yy.
  • Used hardcoded coordinates for creating and positioning UI elements.
objects/obj_ingame_menu/Step_0.gml
objects/obj_ingame_menu/Create_0.gml
Simplified button highlighting logic.
  • Removed complex mouse position calculations.
  • Used scr_hit function for button highlighting.
objects/obj_new_button/Step_0.gml
objects/obj_new_button/Draw_64.gml
Refactored main menu initialization and transitions.
  • Simplified stage and timer management.
  • Used screen_fade_transition for smoother transitions between rooms.
  • Removed unnecessary calculations and hardcoded values for UI elements.
objects/obj_main_menu/Step_0.gml
objects/obj_main_menu/Create_0.gml
objects/obj_main_menu/Draw_0.gml
objects/obj_main_menu/Alarm_3.gml
objects/obj_main_menu_buttons/Step_0.gml
objects/obj_main_menu_buttons/Draw_0.gml
objects/obj_main_menu_buttons/Mouse_50.gml
Added screen fade in on game start.
  • Added screen_fade_in function call on game start to create a fade-in effect.
  • Added a global variable to track whether the fade-in has already happened.
objects/obj_main_menu/Create_0.gml
Added UI controller object and helper functions.
  • Created obj_ui_controller object to manage UI interactions.
  • Added helper functions for screen fading and interaction cooldowns.
  • Added interaction forbid functionality to prevent unwanted UI interactions during transitions.
objects/obj_popup/obj_popup.yy
objects/obj_ingame_menu/obj_ingame_menu.yy
objects/obj_lol_version/obj_lol_version.yy
objects/obj_main_menu/obj_main_menu.yy
objects/obj_main_menu_buttons/obj_main_menu_buttons.yy
objects/obj_new_button/obj_new_button.yy
objects/obj_saveload/obj_saveload.yy
rooms/Main_Menu/Main_Menu.yy
scripts/scr_hit/scr_hit.gml
scripts/scr_controller_helpers/scr_controller_helpers.gml
scripts/__init_global/__init_global.gml
objects/obj_saveload/Draw_64.gml
objects/obj_ingame_menu/Draw_64.gml
objects/obj_new_button/Draw_64.gml
objects/obj_screen_fade/Draw_64.gml
objects/obj_interaction_cooldown/obj_interaction_cooldown.yy
objects/obj_screen_fade/obj_screen_fade.yy
objects/obj_ui_controller/obj_ui_controller.yy
scripts/scr_ui_controller_helpers/scr_ui_controller_helpers.gml
objects/obj_screen_fade/Create_0.gml
scripts/scr_ui_controller_helpers/scr_ui_controller_helpers.yy
objects/obj_interaction_cooldown/Step_0.gml
objects/obj_ui_controller/Create_0.gml
objects/obj_interaction_cooldown/Create_0.gml
Implemented screen fade transitions.
  • Used screen_fade_transition function for button clicks and room transitions.
  • Added visual effects for fading in and out.
objects/obj_main_menu_buttons/Draw_0.gml
objects/obj_main_menu/Draw_0.gml
objects/obj_saveload/Draw_64.gml
Added a loading splash screen.
  • Added a loading splash screen with a progress bar and status text.
  • Replaced the old loading bar with a new graphical one.
objects/obj_saveload/Draw_64.gml
Updated save/load menu.
  • Updated the save/load menu with new graphics and layout.
  • Added a back button to the save/load menu in the main menu.
objects/obj_saveload/Draw_64.gml
objects/obj_saveload/Create_0.gml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @EttyKitty - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -119,19 +120,24 @@ word_from_duke2="blank";
mess_alpha=0;
out_of_date=0;

Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider using an enum for menu stages

Using an enum for the menu stages would make the code more maintainable and self-documenting than using magic numbers.

Suggested implementation:

enum MenuStage {
    INITIAL,
    NO_LEGAL,
    HAS_LEGAL
}

randomize();

// fade=80;
away=0;
hi=0;
info=0;
mess_alpha=0;
out_of_date=0;
stage = MenuStage.INITIAL;

if (last_legal == 0) then stage = MenuStage.NO_LEGAL;
if (last_legal != 0) {
    alarm[2] = 1;
    stage = MenuStage.HAS_LEGAL;
    tim1 = -50;
    tim2 = 424;
}

tim1=0;

You'll need to:

  1. Update any other code that checks the stage variable to use the MenuStage enum values instead of numbers
  2. Make sure any code that sets the stage variable uses the enum values

@@ -0,0 +1,69 @@
if (button_id = 1) {
wid = 142 * scaling;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Cache scaled dimensions in Create event

The scaled width and height calculations could be moved to the Create event since scaling doesn't change during runtime.

Suggested implementation:

if (button_id = 1) {
    wid = button_widths[0];
    hei = button_heights[0];
} else if (button_id = 2) {
    wid = button_widths[1];
    hei = button_heights[1];
} else if (button_id = 3) {
    wid = button_widths[2];
    hei = button_heights[2];
} else if (button_id = 4) {
    wid = button_widths[3];
    hei = button_heights[3];
}

You'll need to add this code to the Create event (Create_0.gml):

// Cache scaled button dimensions
button_widths[0] = 142 * scaling;
button_heights[0] = 43 * scaling;
button_widths[1] = 142 * scaling;
button_heights[1] = 43 * scaling;
button_widths[2] = 115 * scaling;
button_heights[2] = 43 * scaling;
button_widths[3] = 108 * scaling;
button_heights[3] = 42 * scaling;

draw_rectangle(x2 + 1317, y2 + 113, x2 + 1461, y2 + 146, 0);
draw_set_alpha(1);

if (mouse_left >= 1) and(!instance_exists(obj_popup)) and(cooldown <= 0) { // Load
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider extracting repeated button interaction logic into a reusable function

The same pattern of checking mouse_left, obj_popup existence and cooldown appears multiple times. This could be encapsulated in a helper function like check_button_interaction() to reduce duplication and improve maintainability.

Suggested implementation:

// Helper function to check button interaction and handle hover effect
function check_button_interaction(x1, y1, x2, y2) {
    var is_hovering = scr_hit(x1, y1, x2, y2);
    var can_interact = (mouse_left >= 1) && (!instance_exists(obj_popup)) && (cooldown <= 0);

    if (is_hovering) {
        draw_set_alpha(0.1);
        draw_set_color(c_white);
        draw_rectangle(x1, y1, x2, y2, 0);
        draw_set_alpha(1);
    }

    return is_hovering && can_interact;
}

if (check_button_interaction(x2 + 1317, y2 + 113, x2 + 1461, y2 + 146)) {

You'll need to:

  1. Update all other similar button interaction checks in the file to use the new check_button_interaction() function
  2. Make sure the cooldown variable is accessible where the function is defined
  3. Consider moving this helper function to a separate script file if it could be useful in other parts of the game

@EttyKitty EttyKitty marked this pull request as draft December 27, 2024 03:17
@EttyKitty EttyKitty added PR: Feature Adds something new and removed PR: Feature labels Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Feature Adds something new PR: Major Coding Big enough to possibly clash with other PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant