mouse overrides.

This commit is contained in:
2015-03-07 09:19:03 -08:00
parent 183b369441
commit cc2cb0e0a3
5 changed files with 20 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@@ -1 +1 @@
{:sound-volume 45.0, :music-volume 53.0}
{:sound-volume 60.0, :music-volume 57.0}

View File

@@ -1,12 +1,17 @@
(ns advent.screens.rooms
(:require [advent.zone :as zone]))
(:require [advent.zone :as zone])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.utils.viewport FitViewport]
[com.badlogic.gdx.scenes.scene2d Actor Stage]
[java.lang Object]))
(defn make-entity [id entity]
(merge entity
{:mouse-in? (fn [entities x y]
(let [{entity-x :x entity-y :y width :width scale-x :scale-x scale-y :scale-y height :height region :object} (get-in entities [:room :entities id])
width (or width (.getRegionWidth region))
height (or height (.getRegionHeight region))]
width (or width (if (isa? TextureRegion region) (.getRegionWidth region) 0))
height (or height (if (isa? TextureRegion region) (.getRegionHeight region) 0))]
((zone/box entity-x entity-y (+ entity-x (* width (or 1 scale-x))) (+ entity-y (* height (or scale-y 1)))) x y)))}
(when (or (:scripts entity) (:script entity))
{:get-script (fn [cursor [x y]]

View File

@@ -91,6 +91,7 @@
entities))
:on-ui-changed
(fn [screen [entities]]
(println "HER")
(swap! utils/settings
assoc
:music-volume (slider! (:music-volume-slider entities) :get-value)

View File

@@ -17,7 +17,7 @@
(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 :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :watch :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot])
(def +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :watch :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main])
(def settings (atom {:music-volume 50.0
:sound-volume 75.0}))
@@ -125,9 +125,14 @@
(assoc entity :x (vector-2! v :x) :y (vector-2! v :y)))))))
(defn find-override [entities [x y]]
(first (filter #(and ((:mouse-in? %) entities x y)
(:cursor %))
(get-in entities [:room :interactions]))))
(first (concat (filter #(and ((:mouse-in? %) entities x y)
(:override %))
(get-in entities [:room :interactions]))
(filter #(and (:mouse-in? %)
((:mouse-in? %) entities x y))
(vals (get-in entities [:room :entities])))
(filter #(and ((:mouse-in? %) entities x y))
(get-in entities [:room :interactions])))))
@@ -198,6 +203,6 @@
(let [last-pos (unproject screen (get-in entities [:cursor :last-pos]))]
(if (get-in entities [:state :active?])
(if-let [mouse-override (find-override entities last-pos)]
(assoc-in entities [:cursor :override] (:cursor mouse-override))
(assoc-in entities [:cursor :override] (or (:cursor mouse-override) :active-main))
(assoc-in entities [:cursor :override] nil))
entities)))