161 lines
6.4 KiB
Clojure
161 lines
6.4 KiB
Clojure
(ns advent.screens.splash
|
|
(:require [clojure.string :as str]
|
|
[play-clj.core :refer :all]
|
|
[play-clj.math :refer :all]
|
|
[play-clj.ui :refer :all]
|
|
[play-clj.utils :refer :all]
|
|
[play-clj.g2d :refer :all]
|
|
[advent.utils :as utils]
|
|
[clojure.tools.logging :as log]
|
|
[advent.saves :as saves]
|
|
[advent.tween :as tween]
|
|
[advent.steam :as steam]
|
|
[advent.screens.title :as title]
|
|
)
|
|
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter Color]
|
|
[com.badlogic.gdx.graphics.g2d TextureRegion]
|
|
[play_clj.entities NinePatchEntity]
|
|
[com.badlogic.gdx.utils.viewport FitViewport]
|
|
[com.badlogic.gdx.scenes.scene2d.ui Slider$SliderStyle Widget ButtonGroup TextButton$TextButtonStyle CheckBox$CheckBoxStyle CheckBox Button]
|
|
[com.badlogic.gdx.scenes.scene2d Group Actor]
|
|
[play_clj.entities ActorEntity]
|
|
[com.badlogic.gdx.utils Align]
|
|
[com.badlogic.gdx.scenes.scene2d.utils NinePatchDrawable TextureRegionDrawable]
|
|
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
|
|
InputMultiplexer InputProcessor Net Preferences Screen]))
|
|
|
|
(defn fade-in [screen e thing then]
|
|
(assoc-in e [:tweens :fade-in]
|
|
(tween/tween :fade-in screen [thing :opacity] 0.0 1.0 0.5
|
|
:finish then
|
|
:ease tween/ease-in-quadratic)))
|
|
|
|
(defn fade-out [screen e thing then]
|
|
(assoc-in e [:tweens :fade-out]
|
|
(tween/tween :fade-out screen [thing :opacity] 1.0 0.0 0.5
|
|
:finish then
|
|
:ease tween/ease-out-quadratic)))
|
|
|
|
(defn get-texture [path]
|
|
(let [atlas-name (str/replace path #".png" "")
|
|
atlas (texture-atlas "packed-pop-logo/pack.atlas")]
|
|
(texture (texture-atlas! atlas :find-region atlas-name))))
|
|
|
|
(defn make-anim-seq [file [w h] speed frames]
|
|
(animation speed (map #(get-texture (str file "_" (inc %) ".png")) frames)))
|
|
|
|
(defn animate [entity screen]
|
|
(if (:anim entity)
|
|
(merge entity (animation->texture (update-in screen [:total-time] #(- (or % 0) (:anim-start entity 0))) (:anim entity)))
|
|
entity))
|
|
|
|
|
|
(defn update-from-step [screen {:keys [current-step steps] :as entities}]
|
|
(if current-step
|
|
(if (>= (or (:total-time screen) 0.0) (+ (:duration current-step) (:started current-step)))
|
|
(assoc entities :current-step nil)
|
|
entities)
|
|
|
|
(let [[current-step & steps] steps]
|
|
(if current-step
|
|
(assoc ((:do current-step) screen entities)
|
|
:current-step (assoc current-step
|
|
:started (:total-time screen))
|
|
:steps steps)
|
|
entities))))
|
|
|
|
(def steps
|
|
[{:can-skip false
|
|
:do (fn [screen entities]
|
|
(fade-in screen entities :dbhlogo identity))
|
|
:duration 1.0}
|
|
{:can-skip true
|
|
:do (fn [screen entities]
|
|
entities)
|
|
:duration 2.0}
|
|
{:can-skip false
|
|
:do (fn [screen entities]
|
|
(fade-out screen entities :dbhlogo identity))
|
|
:duration 2.0}
|
|
{:can-skip true
|
|
:do (fn [screen entities]
|
|
(utils/play-music (:pop-music entities))
|
|
(-> entities
|
|
(assoc-in [:pop-logo :anim-start] (:total-time screen))
|
|
(assoc-in [:pop-logo :anim] (get-in entities [:pop-logo :main-anim]))))
|
|
:duration 10.0}
|
|
{:can-skip false
|
|
:do (fn [screen entities]
|
|
(utils/stop-music (:pop-music entities))
|
|
|
|
(log/info "clearing assets" (into [] (.getAssetNames *asset-manager*)) (.getDiagnostics *asset-manager*))
|
|
(.clear *asset-manager* )
|
|
(log/info "cleared assets" (into [] (.getAssetNames *asset-manager*)) (.getDiagnostics *asset-manager*))
|
|
(set-screen! @(resolve 'advent.core/advent) title/title-screen)
|
|
entities)
|
|
:duration 0.0}])
|
|
|
|
|
|
(defscreen splash-screen
|
|
:on-show
|
|
(fn [screen entities options]
|
|
(println screen)
|
|
(utils/setup-viewport screen 1280 960)
|
|
(log/info "Starting splash screen.")
|
|
|
|
(graphics! :set-cursor (utils/cursor "cursor.png" :hourglass))
|
|
|
|
(let [screen (assoc screen :total-time 0)
|
|
#_#_pop-anim (make-anim-seq "POPPixelLogo_02" [320 240] 0.05 (range 200))
|
|
entities {:background (assoc (utils/get-texture "black.png")
|
|
:scale-x 80
|
|
:scale-y 80
|
|
:opacity 1.0
|
|
:origin-x 0
|
|
:origin-y 0
|
|
:z 0)
|
|
:pop-logo (assoc (utils/get-texture "black.png")
|
|
:x 0 :y 0
|
|
:origin-x 0 :origin-y 0
|
|
:scale-x 4 :scale-y 4
|
|
:z 1)
|
|
:dbhlogo (assoc (utils/get-texture "dbh.png") :x 0 :y 0 :origin-x 0 :origin-y 0 :z 1 :opacity 0.0)
|
|
:steps steps
|
|
:pop-music (utils/make-music "music/POPPixelLogo2Audiomix_mixdown.ogg")
|
|
:current-step nil}]
|
|
(music! (:pop-music entities) :set-volume (utils/current-music-volume 1.0))
|
|
entities))
|
|
|
|
|
|
:on-render
|
|
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
|
|
#_(steam/update)
|
|
(.apply viewport)
|
|
(clear!)
|
|
(let [entities (utils/apply-tweens screen entities (:tweens entities))
|
|
#_#_entities (update-in entities [:pop-logo] animate screen)
|
|
entities (if (and (:queued-skip? entities) (get-in entities [:current-step :can-skip]))
|
|
(assoc entities :queued-skip? false :current-step nil)
|
|
entities)
|
|
entities (update-from-step screen entities)]
|
|
(render! screen (sort-by :z (filter :object (vals entities))) )
|
|
entities))
|
|
|
|
:show-screen (fn [entities]
|
|
entities)
|
|
|
|
:on-touch-up (fn [screen entities options]
|
|
(if (get-in entities [:current-step :can-skip])
|
|
(assoc entities :current-step nil :queued-skip? false)
|
|
(assoc entities :queued-skip? true)))
|
|
|
|
:on-key-up
|
|
(fn [screen entities options]
|
|
(when (= (key-code :escape) (:key screen))
|
|
(utils/toggle-fullscreen!))
|
|
nil)
|
|
|
|
:on-resize (fn [{:keys [^FitViewport viewport]} entities {:keys [width height]} ]
|
|
(.update viewport width height false)
|
|
nil))
|