diff --git a/JCursor/Cursor.png b/JCursor/Cursor.png index a2428d7..18811a4 100644 Binary files a/JCursor/Cursor.png and b/JCursor/Cursor.png differ diff --git a/JCursor/Cursor1.png b/JCursor/Cursor1.png new file mode 100644 index 0000000..fb7cb9d Binary files /dev/null and b/JCursor/Cursor1.png differ diff --git a/JCursor/Cursor2.png b/JCursor/Cursor2.png new file mode 100644 index 0000000..d29d22f Binary files /dev/null and b/JCursor/Cursor2.png differ diff --git a/JCursor/CursorDrag.png b/JCursor/CursorDrag.png new file mode 100644 index 0000000..fb5bf49 Binary files /dev/null and b/JCursor/CursorDrag.png differ diff --git a/JCursor/CursorDrag1.png b/JCursor/CursorDrag1.png new file mode 100644 index 0000000..e8f2ef8 Binary files /dev/null and b/JCursor/CursorDrag1.png differ diff --git a/JCursor/CursorDrag2.png b/JCursor/CursorDrag2.png new file mode 100644 index 0000000..a1fe6f0 Binary files /dev/null and b/JCursor/CursorDrag2.png differ diff --git a/JCursor/CursorHover.png b/JCursor/CursorHover.png new file mode 100644 index 0000000..fbb32f8 Binary files /dev/null and b/JCursor/CursorHover.png differ diff --git a/JCursor/CursorHover1.png b/JCursor/CursorHover1.png new file mode 100644 index 0000000..6396253 Binary files /dev/null and b/JCursor/CursorHover1.png differ diff --git a/JCursor/CursorHover2.png b/JCursor/CursorHover2.png new file mode 100644 index 0000000..56eca39 Binary files /dev/null and b/JCursor/CursorHover2.png differ diff --git a/JCursor/JCursor.lua b/JCursor/JCursor.lua index 19eadd5..fa49655 100644 --- a/JCursor/JCursor.lua +++ b/JCursor/JCursor.lua @@ -1,12 +1,55 @@ --- STEAMODDED HEADER --- MOD_NAME: J Cursor --- MOD_ID: JCursor ---- MOD_AUTHOR: [Jie65535] ---- MOD_DESCRIPTION: Custom Cursor (./Mods/JCursor/Cursor.png) +--- MOD_AUTHOR: [Jie65535, MarioMak967] +--- MOD_DESCRIPTION: Custom Cursor (Mods/JCursor/Cursor.png CursorHover.png CursorDrag.png) ---------------------------------------------- ------------MOD CODE ------------------------- +-- The x-coordinate in the cursor's hot spot. +local HOT_X = 20 +-- The y-coordinate in the cursor's hot spot. +local HOT_Y = 4 + +local currentCursor +local function setCursor(cursor) + if currentCursor ~= cursor then + currentCursor = cursor + love.mouse.setCursor(cursor) + end +end + +local MOD_DIRECTORY = "/Mods/JCursor" +local function getCursor(state, hotx, hoty) + local filename = MOD_DIRECTORY .. "/" .. state .. ".png" + if love.filesystem.exists(filename) then + return love.mouse.newCursor(filename, hotx, hoty) + end + return nil +end + +local cursorDefault +local cursorHover +local cursorDrag +local function updateCursors() + cursorDefault = getCursor("Cursor", HOT_X, HOT_Y) + cursorHover = getCursor("CursorHover", HOT_X, HOT_Y) + cursorDrag = getCursor("CursorDrag", HOT_X, HOT_Y) + if cursorDefault then + setCursor(cursorDefault) + end +end + +function G.FUNCS.refreshCursors(arg_736_0) + sendDebugMessage("refreshCursors") + updateCursors() +end + +-- init cursors +updateCursors() + + SMODS.registerUIElement("JCursor", { { n = G.UIT.R, @@ -24,43 +67,92 @@ SMODS.registerUIElement("JCursor", { }), UIBox_button({ minw = 3.85, - button = "refreshCursor", + button = "refreshCursors", label = { "Refresh cursor" } }), + UIBox_button({ + minw = 3.85, + button = "openJCursorGithub", + label = { + "Github" + } + }), } } }) -local function getModDirectory() - return "/Mods/JCursor" -end - -local function getCursorFile() - return getModDirectory() .. "/Cursor.png" -end - -local function setCursor(filename) - cursor = love.mouse.newCursor(filename, 0, 0) - love.mouse.setCursor(cursor) -end - function G.FUNCS.openModDirectory(arg_736_0) - sendDebugMessage("openModDirectory") - love.system.openURL("file://" .. love.filesystem.getSaveDirectory() .. getModDirectory()) + url = "file://" .. love.filesystem.getSaveDirectory() .. MOD_DIRECTORY + sendDebugMessage("openModDirectory: " .. url) + love.system.openURL(url) end -function G.FUNCS.refreshCursor(arg_736_0) - sendDebugMessage("refreshCursor") - setCursor(getCursorFile()) +function G.FUNCS.openJCursorGithub(arg_736_0) + sendDebugMessage("Open Github!") + love.system.openURL("https://github.com/jie65535/JMods/tree/main/JCursor") end -local defaultCursor = getCursorFile() -if love.filesystem.exists(defaultCursor) then - setCursor(defaultCursor) + + + +local function myDrag() + if cursorDrag then + setCursor(cursorDrag) + -- sendDebugMessage("drag start!") + end end +local function myStopDrag() + if cursorDrag and cursorDefault and currentCursor == cursorDrag then + setCursor(cursorDefault) + -- sendDebugMessage("drag stop!") + end +end + + +local hoverLevel = 0 +local function myHover() + if cursorHover and currentCursor == cursorDefault and hoverLevel == 0 then + setCursor(cursorHover) + -- sendDebugMessage("hover start!") + end + hoverLevel = hoverLevel + 1 +end + +local function myStopHover() + if hoverLevel > 0 then + hoverLevel = hoverLevel - 1 + end + if cursorHover + and cursorDefault + and currentCursor == cursorHover + and hoverLevel == 0 + then + setCursor(cursorDefault) + -- sendDebugMessage("hover stop!") + end +end + +local function injectCodeBefore(originalFunction, codeToInject) + return function(...) + codeToInject(...) + return originalFunction(...) + end +end + +Node.drag = injectCodeBefore(Node.drag, myDrag) +Node.stop_drag = injectCodeBefore(Node.stop_drag, myStopDrag) +-- Node.hover = injectCodeBefore(Node.hover, myHover) +-- Node.stop_hover = injectCodeBefore(Node.stop_hover, myStopHover) + +Card.hover = injectCodeBefore(Card.hover, myHover) +Card.stop_hover = injectCodeBefore(Card.stop_hover, myStopHover) + +-- UIElement.hover = injectCodeBefore(UIElement.hover, myHover) +-- UIElement.stop_hover = injectCodeBefore(UIElement.stop_hover, myStopHover) + sendDebugMessage("JCursor loaded!") ---------------------------------------------- diff --git a/JCursor/README.md b/JCursor/README.md new file mode 100644 index 0000000..db7df58 --- /dev/null +++ b/JCursor/README.md @@ -0,0 +1,23 @@ +# J Cursor +Custom Cursor + +--- + +ModDir: `%AppData%\Balatro\Mods\JCursor\` + +Change the default cursor by replacing the following files: +- `Cursor.png` +- `CursorDrag.png` +- `CursorHover.png` + +Default cursors made by `@MarioMak967` + +--- + +Modify the top constant of Lua to determine the cursor hot spot +```lua +-- The x-coordinate in the cursor's hot spot. +local HOT_X = 20 +-- The y-coordinate in the cursor's hot spot. +local HOT_Y = 4 +``` \ No newline at end of file