Skip to content

Commit

Permalink
Added code for custom cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
Death7Bed committed Sep 15, 2023
1 parent 0a1d763 commit 5cb1b29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Binary file added source/core/assets/images/ui/mouse_effect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,54 +1,62 @@
package com.csse3200.game.components.mainmenu;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Cursor;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.csse3200.game.GdxGame;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A ui component for displaying the Main menu.
*/
public class MainMenuDisplay extends UIComponent {

private static final Logger logger = LoggerFactory.getLogger(MainMenuDisplay.class);
private static final float Z_INDEX = 2f;
private Table table;
private Table table1;




@Override
public void create() {
super.create();
addActors();
}


private void addActors() {
/**
* Loads a custom cursor image and sets it as the system cursor.
*
* This method loads an image file named "mouse_effect.png" from the "images/ui" directory
* and sets it as the system cursor. After setting the custom cursor, it disposes of the
* Pixmap object used for loading the cursor image to release system resources.
*
* @param none
* @return none
*/
// Load the custom cursor image
Pixmap cursorPixmap = new Pixmap(Gdx.files.internal("images/ui/mouse_effect.png"));
Cursor customCursor = Gdx.graphics.newCursor(cursorPixmap, 0, 0);
Gdx.graphics.setCursor(customCursor);
cursorPixmap.dispose(); // Dispose of the Pixmap to release resources

table = new Table();
table1=new Table();
table1 = new Table();
table.setFillParent(true);
table1.setFillParent(true);

Image title =
new Image(
ServiceLocator.getResourceService()
.getAsset("images/background/background1.png", Texture.class));
title.setWidth(Gdx.graphics.getWidth());
title.setHeight(Gdx.graphics.getHeight());
title.setPosition(0,0);



title.setPosition(0, 0);

TextButton startBtn = new TextButton("Start", skin);
TextButton loadBtn = new TextButton("Help", skin);
Expand Down Expand Up @@ -87,13 +95,11 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
new ChangeListener() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {

logger.debug("Exit button clicked");
entity.getEvents().trigger("exit");
}
});


table.add(title);
table1.row();
table1.add(startBtn).padTop(30f);
Expand All @@ -108,7 +114,6 @@ public void changed(ChangeEvent changeEvent, Actor actor) {
stage.addActor(table1);
}


@Override
public void draw(SpriteBatch batch) {
// draw is handled by the stage
Expand All @@ -124,4 +129,4 @@ public void dispose() {
table.clear();
super.dispose();
}
}
}

0 comments on commit 5cb1b29

Please sign in to comment.