diff --git a/desktop/resources/cursor.png b/desktop/resources/cursor.png index 7624436c..a079a4ae 100644 Binary files a/desktop/resources/cursor.png and b/desktop/resources/cursor.png differ diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index bc88fd9d..0556043f 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -7,6 +7,7 @@ [advent.pathfind] [advent.actions :as actions] [advent.zone :as zone] + [advent.utils :as utils] [advent.screens.dialogue :refer [talking-screen]] [clojure.core.async :refer [put! ! chan go thread take! alts!!]]) (:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter] @@ -15,7 +16,6 @@ (def +screen-width+ 320) (def +screen-height+ 240) -(def +num-cursors+ 4) (defprotocol IMouseIn (mouse-in? [this location])) @@ -34,20 +34,8 @@ (actions/walk-to entities :ego [x y]))))) -(def +all-cursors+ [:main :touch :look :talk :right :down :left :up]) -(defn cursor [filename which] - (let [scale 2 - base-cursor (pixmap filename) - target-width (* 16 scale) - target-height (* 16 scale) - resized (Pixmap. target-width target-height (.getFormat base-cursor)) - index (.indexOf +all-cursors+ which)] - (Pixmap/setFilter Pixmap$Filter/NearestNeighbour) - (pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16 - 0 0 target-width target-height) - resized )) (defn left-click [screen entities] (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)}) @@ -111,7 +99,7 @@ :on-show (fn [screen entities] (update! screen :renderer (stage) :camera (orthographic)) - (let [_ (input! :set-cursor-image (cursor "cursor.png" :main) 0 0) + (let [_ (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0) sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21) sheep (animation 0.15 (for [i (flatten [(repeat 10 0) 1 2 3 4 5 6 7 4 5 6 7 8 9 10 (repeat 25 11) (repeat 15 12)])] (aget sheep-sheet 0 i))) @@ -225,11 +213,11 @@ (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] (if-let [mouse-override (first (filter #(mouse-in? % [x y]) (get-in entities [:background :mouse-overrides])))] (when (not (get-in entities [:cursor :override])) - (do (input! :set-cursor-image (cursor "cursor.png" (cursor-override mouse-override)) 0 0) + (do (input! :set-cursor-image (utils/cursor "cursor.png" (cursor-override mouse-override)) 0 0) (assoc-in entities [:cursor :override] mouse-override))) (when (get-in entities [:cursor :override]) - (do (input! :set-cursor-image (cursor "cursor.png" :main) 0 0) + (do (input! :set-cursor-image (utils/cursor "cursor.png" :main) 0 0) (assoc-in entities [:cursor :override] nil)))))) :on-touch-down (fn [screen [entities]] diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index 7419e10e..05baafd0 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -2,8 +2,25 @@ (:require [play-clj.core :refer :all] [play-clj.ui :refer :all] [play-clj.utils :refer :all] - [play-clj.g2d :refer :all])) + [play-clj.g2d :refer :all]) + (:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter] + [com.badlogic.gdx.graphics.g2d TextureRegion] + [java.lang Object])) (defn log-coords [screen entities] (let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})] (println (:input-x screen) (:input-y screen) "->" x y))) + +(def +all-cursors+ [:main :touch :look :talk :right :down :left :up]) + +(defn cursor [filename which] + (let [scale 2 + base-cursor (pixmap filename) + target-width (* 16 scale) + target-height (* 16 scale) + resized (Pixmap. target-width target-height (.getFormat base-cursor)) + index (.indexOf +all-cursors+ which)] + (Pixmap/setFilter Pixmap$Filter/NearestNeighbour) + (pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16 + 0 0 target-width target-height) + resized ))