Skip to content

Commit

Permalink
Merge pull request #252 from Nemrav/cursors
Browse files Browse the repository at this point in the history
Add cursor support
  • Loading branch information
Nemrav authored Jan 17, 2025
2 parents fec44c0 + d250c10 commit bc8a7de
Show file tree
Hide file tree
Showing 12 changed files with 962 additions and 11 deletions.
76 changes: 76 additions & 0 deletions extension/doc_classes/CursorSingleton.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="CursorSingleton" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<brief_description>
</brief_description>
<description>
This singleton handles the dataloading and access to the windows .cur and .ani cursors found in the [code]/cursors[/code] folder. The functionality for setting and animating the cursors is done by the CursorManager gd script.
</description>
<tutorials>
</tutorials>
<methods>
<method name="generate_resolution">
<return type="void" />
<param index="0" name="cursor_name" type="StringName" default="&quot;normal&quot;" />
<param index="1" name="base_resolution_index" type="int" default="0" />
<param index="2" name="target_resolution" type="Vector2" default="Vector2(64, 64)" />
<description>
Takes the cursor image at [param base_resolution_index] then scales it to [param target_resolution] then saves it to the image as an extra resolution option.
</description>
</method>
<method name="get_animation_length" qualifiers="const">
<return type="int" />
<param index="0" name="cursor_name" type="StringName" default="&quot;normal&quot;" />
<description>
Returns the length of the sequence for the cursor [param cursor_name]. This will be greater than or equal to the number of animation frames.
</description>
</method>
<method name="get_display_rates" qualifiers="const">
<return type="PackedFloat32Array" />
<param index="0" name="cursor_name" type="StringName" default="&quot;normal&quot;" />
<description>
Returns an array containing how long each frame should last for an animated cursor [param cursor_name]. The size of this array will be the same as the size of the sequence array.
</description>
</method>
<method name="get_frames" qualifiers="const">
<return type="ImageTexture[]" />
<param index="0" name="cursor_name" type="StringName" default="&quot;normal&quot;" />
<param index="1" name="resolution_index" type="int" default="0" />
<description>
Returns an array of [ImageTexture] animation frames given a [param cursor_name] and a [param resolution_index].
</description>
</method>
<method name="get_hotspots" qualifiers="const">
<return type="PackedVector2Array" />
<param index="0" name="cursor_name" type="StringName" default="&quot;normal&quot;" />
<param index="1" name="resolution_index" type="int" default="0" />
<description>
Returns an array of cursor click positions given a [param cursor_name] and [param resolution_index].
</description>
</method>
<method name="get_resolutions" qualifiers="const">
<return type="PackedVector2Array" />
<param index="0" name="cursor_name" type="StringName" default="&quot;normal&quot;" />
<description>
Returns an array of all the image resolutions contained in the cursor.
</description>
</method>
<method name="get_sequence" qualifiers="const">
<return type="PackedInt32Array" />
<param index="0" name="cursor_name" type="StringName" default="&quot;normal&quot;" />
<description>
Returns a list of frame indices used to produce an animation.
</description>
</method>
<method name="load_cursors">
<return type="int" enum="Error" />
<description>
Loads the cursors from the [code]/cursors[/code] folder. This function must be called before any other cursor related function.
</description>
</method>
</methods>
<members>
<member name="cursor_names" type="StringName[]" setter="" getter="get_cursor_names" default="[]">
A list of cursor file names.
</member>
</members>
</class>
9 changes: 9 additions & 0 deletions extension/src/openvic-extension/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "openvic-extension/classes/MapMesh.hpp"
#include "openvic-extension/singletons/AssetManager.hpp"
#include "openvic-extension/singletons/Checksum.hpp"
#include "openvic-extension/singletons/CursorSingleton.hpp"
#include "openvic-extension/singletons/GameSingleton.hpp"
#include "openvic-extension/singletons/LoadLocalisation.hpp"
#include "openvic-extension/singletons/MapItemSingleton.hpp"
Expand All @@ -33,6 +34,7 @@ using namespace godot;
using namespace OpenVic;

static Checksum* _checksum_singleton = nullptr;
static CursorSingleton* _cursor_singleton = nullptr;
static LoadLocalisation* _load_localisation = nullptr;
static GameSingleton* _game_singleton = nullptr;
static MapItemSingleton* _map_item_singleton = nullptr;
Expand All @@ -50,6 +52,10 @@ void initialize_openvic_types(ModuleInitializationLevel p_level) {
_checksum_singleton = memnew(Checksum);
Engine::get_singleton()->register_singleton("Checksum", Checksum::get_singleton());

ClassDB::register_class<CursorSingleton>();
_cursor_singleton = memnew(CursorSingleton);
Engine::get_singleton()->register_singleton("CursorSingleton", CursorSingleton::get_singleton());

ClassDB::register_class<LoadLocalisation>();
_load_localisation = memnew(LoadLocalisation);
Engine::get_singleton()->register_singleton("LoadLocalisation", LoadLocalisation::get_singleton());
Expand Down Expand Up @@ -117,6 +123,9 @@ void uninitialize_openvic_types(ModuleInitializationLevel p_level) {
Engine::get_singleton()->unregister_singleton("Checksum");
memdelete(_checksum_singleton);

Engine::get_singleton()->unregister_singleton("CursorSingleton");
memdelete(_cursor_singleton);

Engine::get_singleton()->unregister_singleton("LoadLocalisation");
memdelete(_load_localisation);

Expand Down
Loading

0 comments on commit bc8a7de

Please sign in to comment.