jsettlers / settlers-remake

A Remake of "The Settlers III" for Windows, Linux, Mac and Android
http://www.settlers-android-clone.com
MIT License
356 stars 101 forks source link

Replace default cursor with the cursor of the original Settlers III #95

Open andreas-eberle opened 9 years ago

andreas-eberle commented 9 years ago

Idea

It would be nice to have the original cursors available in the Swing UI.

A First Simple Implementation

A first implementation could be to add the following code to the end of the SwingManagedJSettlers.startJogl() method.

        Image cursor = ImageProvider.getInstance().getImage(new OriginalImageLink(EImageLinkType.SETTLER, 2, 20, 0));
        BufferedImage cursorImage = ((SingleImage) cursor).generateBufferedImage();
        Cursor settlersCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "Settlers Cursor");
        jsettlersWnd.setCursor(settlersCursor);

However, this makes it impossible to changed the cursor depending on what the user is doing. E.g. when the user is scrolling over the map, the cursor changes in the original game.

@michaelzangl: Where could we introduce a logic like this? I think it would only be needed on the SwingUI as a cursor makes no sense on Android. I think we could provide the BufferedImages to that code location, but we need access to a java.awt.Component to be able to set the cursor.

michaelzangl commented 9 years ago

We already have a tooltip-API (UIPanel#getDescription(x, y)). We could simply change the return type of the tooltip from String to a (String, ECursorType)-tuple.

andreas-eberle commented 9 years ago

Well, but the cursor image does not only depend on the position, but also on the current "mouse action". For example, when scrolling over the map, the cursor image changes as soon, as the user holds the right mouse button pressed. Would this be manageable in this method?

Or should we rather subscribe to the mouse events somewhere else?

andreas-eberle commented 9 years ago

The two most important cursors are:

justangel commented 9 years ago

EImageLinkType.SETTLER, 2, 20, 1) If selected soldiers and the cursor is over enemy targets: units/buildings

justangel commented 9 years ago

EImageLinkType.SETTLER, 2, 20, 6) while saving the game, switching between menus, etc.

adamjryan commented 9 years ago

How about a solution much like the one for the side panel's content pane. There would be a cursor event that panels can raise and they all go to a single handler which decides what state the mouse cursor should be in. It would sit at a high enough level that it has access to the root panels and mouse listeners. It should then have all the information needed to determine the correct state and the logic can then be kept in one place. The event would need to have a few parameters such as the source.