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

Quick fix: Implementation of scrollable hotbar #68

Open
the-lightstack opened this issue Nov 9, 2021 · 4 comments
Open

Quick fix: Implementation of scrollable hotbar #68

the-lightstack opened this issue Nov 9, 2021 · 4 comments

Comments

@the-lightstack
Copy link

the-lightstack commented Nov 9, 2021

This is a quick and dirty feature to make the hotbar scrollable.
Just add the following to /src/ui/hotbar.c

this function right before the hotbar_init function

static void scrollCallback(GLFWwindow* window, double xoffset, double yoffset){
    // Y-offset is either 1 or -1 (scroll up or down)
    struct UIHotbar* self = (struct UIHotbar*)glfwGetWindowUserPointer(window);
    // Scroll left 
    if (yoffset == 1){
        if (self->index == 0){
            self->index = 9;
        }else{
            self->index -= 1;
        }
    // Scroll right
    }else if(yoffset == -1){
        self->index += 1;
        self->index = self->index % 10;
    }
    return;
}

in hotbar_init, after self->index = 0;

    glfwSetWindowUserPointer(state.window->handle,self);
    glfwSetScrollCallback(state.window->handle,scrollCallback);

As this solution is very hacky, I did not want to make this into a pull request but think this improves the game.

@mikumikudice
Copy link

Maybe open a pull request?

@the-lightstack
Copy link
Author

I feel like this would be a valuable addition, but I made use of the WindowUserPointer in a way it is not supposed to be used which would just contribute unclear code which I don't want since this is a properly structured project.

@Lampe2020
Copy link

I implemented it into my install of minecraft-weekend and the game is so much easier now, I think maybe you really could open a pull request, even though this is a bit hacky.

@the-lightstack
Copy link
Author

Ok accepted 😃 #73 Just gotta hope that the pull request gets merged some time

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

No branches or pull requests

3 participants