diff --git a/desktop/src-common/advent/screens/title.clj b/desktop/src-common/advent/screens/title.clj index 3c4a95cc..73c149bd 100644 --- a/desktop/src-common/advent/screens/title.clj +++ b/desktop/src-common/advent/screens/title.clj @@ -47,6 +47,16 @@ (def do-once (atom false)) +(defn quit [screen entities] + (do (input! :set-cursor-image (utils/cursor "cursor.png" :hourglass) 0 0) + (-> entities + (assoc-in [:tweens :fade-out] + (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 + :finish (fn [entities] + (System/exit 0) + entities) + :ease tween/ease-in-cubic))))) + (defn fly-balloon [screen entities] (let [speed 0.03 pos-f (- (* (:total-time screen) speed) (int (* (:total-time screen) speed))) @@ -82,38 +92,63 @@ "Continue quest" "Begin quest")) +(defn start-playing [screen entities] + (do (input! :set-cursor-image (utils/cursor "cursor.png" :hourglass) 0 0) + (-> entities + (assoc-in [:tweens :fade-out] + (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 + :finish (fn [entities] + (utils/stop-sound (:music entities)) + (set-screen! @(resolve 'advent.core/advent) scene/scene scene/demo scene/hud dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen fade/fade-screen + ) + entities) + :ease tween/ease-in-cubic)) + (assoc-in [:tweens :fade-out-music] + (tween/tween :fade-out-music screen [:volume] 1.0 0.0 1.0))))) + +(defn make-label + ([msg] + (make-label msg (color 1.0 0.3 0.3 1.0))) + ([msg col] + (let [font (utils/get-font "ego/font.fnt")] + (-> msg + (label (style :label font col)) + (assoc :x 0 :y 0 :height 32 :origin-x 0 :origin-y 0 :z 8) + center + (doto (label! :set-alignment Align/center)))))) + +(defn stack-y [label base index] + (assoc label :y (- 280 (* 32 index)))) + (defscreen title-screen :on-show (fn [screen entities] (utils/setup-viewport screen 1280 960) (utils/load-settings!) (let [font (utils/get-font "ego/font.fnt") - start-playing (assoc (label (quest-label) (style :label font (color 1.0 0.3 0.3 1.0))) :x 0 :y 280 :height 32 :origin-x 0 :origin-y 0) - start-playing (center start-playing) - copyright (assoc (label "DEMO - Copyright Bryce Covert - Not for distribution" (style :label font (color 1.0 0.3 0.3 1.0))) :x 0 :y 0 :height 32 :origin-x 0 :origin-y 0) - copyright (center copyright) - fullscreen (assoc (label "Fullscreen" (style :label font (color 1.0 0.3 0.3 1.0))) :x 0 :y (- 280 (* 32 5)) :height 32 :origin-x 0 :origin-y 0) - fullscreen (center fullscreen) - quit (assoc (label "End quest" (style :label font (color 1.0 0.3 0.3 1.0))) :x 0 :y (- 280 (* 32 6)) :height 32 :origin-x 0 :origin-y 0) - quit (center quit) + start-playing (-> (make-label (quest-label)) + (stack-y 280 0)) + copyright (make-label "DEMO - Copyright Bryce Covert - Not for distribution") + fullscreen (-> (make-label "Fullscreen") + (stack-y 280 5)) + quit (-> (make-label "End quest") + (stack-y 280 6)) music (utils/make-music "music/intro.ogg") ui-skin (skin "ui/ui.json") - balloon (utils/make-anim "title/balloon.png" [15 30] 0.45 (range 4)) - ] - (label! start-playing :set-alignment Align/center) - (label! quit :set-alignment Align/center) - (label! fullscreen :set-alignment Align/center) + balloon (utils/make-anim "title/balloon.png" [15 30] 0.45 (range 4))] + (input! :set-cursor-image (utils/cursor "cursor.png" :hourglass) 0 0) - {:background (assoc (utils/get-texture "title/background.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0) - :cloud-background (assoc (utils/get-texture "title/clouds.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0) - :logo (assoc (utils/get-texture "title/logo.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0) + {:background (assoc (utils/get-texture "title/background.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 0) + :cloud-background (assoc (utils/get-texture "title/clouds.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 2) + :logo (assoc (utils/get-texture "title/logo.png" ) :x 0 :y 0 :scale-x 4 :scale-y 4 :origin-x 0 :origin-y 0 :z 6) :fade (assoc (utils/get-texture "black.png") - :scale-x 80 - :scale-y 80 - :opacity 1.0 - :origin-x 0 - :origin-y 0) + :scale-x 80 + :scale-y 80 + :opacity 1.0 + :origin-x 0 + :origin-y 0 + :z 100) :flying-ego (assoc (utils/get-texture "ego/flying.png") :left (flip (utils/get-texture "ego/flying.png")) :right (utils/get-texture "ego/flying.png") @@ -123,38 +158,40 @@ :origin-y 0 :path (catmull-rom-spline (map #(apply vector-2* %) [[-800 450] [1280 450] [2000 100] [0 100] [-800 300] [1280 300] [2000 450]]) true) :x 450 - :y 650) + :y 650 + :z 5) :balloon (assoc (animation->texture (assoc screen :total-time 0.0) balloon) :x 100 :y 100 :scale-x 4 :scale-y 4 :anim balloon - :path (catmull-rom-spline (map #(apply vector-2* %) [[50 50] [70 100] [100 200] [151 206] [300 225] [480 300] [560 400] [650 440] [700 550] [750 600] [860 650] [950 700] [1030 800] [1280 960] [1300 1000] [-50 1000] [-50 -50]]) true)) - :particle-clouds (assoc (particle-effect "particles/particle-clouds" :reset :start) :x 640 :y 480 ) - :ego-jet (assoc (particle-effect "particles/jet" :reset :start) :x 450 :y 650 ) + :path (catmull-rom-spline (map #(apply vector-2* %) [[50 50] [70 100] [100 200] [151 206] [300 225] [480 300] [560 400] [650 440] [700 550] [750 600] [860 650] [950 700] [1030 800] [1280 960] [1300 1000] [-50 1000] [-50 -50]]) true) + :z 3) + :particle-clouds (assoc (particle-effect "particles/particle-clouds" :reset :start) :x 640 :y 480 :z 1) + :ego-jet (assoc (particle-effect "particles/jet" :reset :start) :x 450 :y 650 :z 4) :toolbox (center (assoc (nine-patch {:region (:object (utils/get-texture "talk-bg-2.png")) :left 9 :top 9 :right 9 :bottom 9}) - :y 58 :width 500 :height 282)) + :y 58 :width 500 :height 282 + :z 7)) - :music-label (-> (label "Music" (style :label font (color 1.0 1.0 1.0 1.0))) - (assoc :x 0 :y (- 280 (* 32 1)) :height 32 :origin-x 0 :origin-y 0) - center) + :music-label (-> (make-label "Music" (color :white)) + (stack-y 280 1)) :music-volume-slider (-> (slider {:min 0 :max 100 :step 1} ui-skin :set-value (:music-volume @utils/settings)) (assoc :x (- (/ 1280 2) 150) :width 300 :y (- 280 (* 32 2)) :hover (skin! ui-skin :get "default-horizontal-hover" Slider$SliderStyle) - :default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle))) + :default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle) + :z 8)) - :sound-label (-> - (label "FX" (style :label font (color 1.0 1.0 1.0 1.0))) - (assoc :x 0 :y (- 280 (* 32 3)) :height 32 :origin-x 0 :origin-y 0) - center) + :sound-label (-> (make-label "FX" (color :white)) + (stack-y 280 3)) :sound-volume-slider (assoc (slider {:min 0 :max 100 :step 1 } ui-skin :set-value (:sound-volume @utils/settings)) - :width 300 - :x ( - (/ 1280 2) - 150) - :y (- 280 (* 32 4)) - :hover (skin! ui-skin :get "default-horizontal-hover" Slider$SliderStyle) - :default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle)) + :width 300 + :x ( - (/ 1280 2) + 150) + :y (- 280 (* 32 4)) + :z 8 + :hover (skin! ui-skin :get "default-horizontal-hover" Slider$SliderStyle) + :default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle)) :font font :music music :volume 1.0 @@ -183,7 +220,7 @@ "Windowed")) (music! (:music entities) :set-volume (utils/current-music-volume (:volume entities))) - (render! screen [(:background entities) (:particle-clouds entities) (:cloud-background entities) (:balloon entities) (:ego-jet entities) (:flying-ego entities) (:logo entities) (:toolbox entities) (:start-playing entities) (:quit entities) (:fullscreen entities) (:music-label entities) (:music-volume-slider entities) (:sound-label entities) (:sound-volume-slider entities) (:copyright entities) (:fade entities) ]) + (render! screen (sort-by :z (filter :object (vals entities))) ) entities)) :show-screen (fn [entities] @@ -214,38 +251,20 @@ entities) :on-touch-up (fn [screen [entities]] - (when-not (get-in entities [:tweens :fade-out]) (let [[x y] (utils/unproject screen)] (cond - (utils/intersects? (:start-playing entities) [x y]) - (do (input! :set-cursor-image (utils/cursor "cursor.png" :hourglass) 0 0) - (-> entities - (assoc-in [:tweens :fade-out] - (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 - :finish (fn [entities] - (utils/stop-sound (:music entities)) - (set-screen! @(resolve 'advent.core/advent) scene/scene scene/demo scene/hud dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen fade/fade-screen - ) - entities) - :ease tween/ease-in-cubic)) - (assoc-in [:tweens :fade-out-music] - (tween/tween :fade-out-music screen [:volume] 1.0 0.0 1.0)))) - (utils/intersects? (:quit entities) [x y]) - (do (input! :set-cursor-image (utils/cursor "cursor.png" :hourglass) 0 0) - (-> entities - (assoc-in [:tweens :fade-out] - (tween/tween :fade-out screen [:fade :opacity] 0.0 1.0 1.0 - :finish (fn [entities] - (System/exit 0) - entities) - :ease tween/ease-in-cubic)))) + (utils/intersects? (:start-playing entities) [x y]) + (start-playing screen entities) + + (utils/intersects? (:quit entities) [x y]) + (quit screen entities) - (utils/intersects? (:fullscreen entities) [x y]) - (utils/toggle-fullscreen!) - - :else - nil)))) + (utils/intersects? (:fullscreen entities) [x y]) + (utils/toggle-fullscreen!) + + :else + nil)))) :on-resize (fn [{:keys [viewport width height]} [entities]]