diff --git a/desktop/project.clj b/desktop/project.clj index 68c85857..f9108154 100644 --- a/desktop/project.clj +++ b/desktop/project.clj @@ -36,7 +36,7 @@ :warn-on-reflection true} :mobile-dev { :source-paths ["src" "src-common" "src-dev"] - :jvm-opts ["-Duse-repl=true" "-Dno-steam=true" "-Dui_scale=1.5" "-Dclojure.compiler.direct-linking=true" "-Dis-desktop=true"] + :jvm-opts ["-Duse-repl=true" "-Dui_scale=1.5" "-Dno-steam=true" "-Dclojure.compiler.direct-linking=true" "-Dis-desktop=true"] :dependencies [[com.badlogicgames.gdx/gdx-tools "1.5.3"] [org.clojure/tools.nrepl "0.2.12"] [play-clj-nrepl "0.1.0" :exclusions [play-clj]] @@ -64,6 +64,6 @@ :warn-on-reflection true} } - :aot [advent.core.desktop-launcher] + :aot [play-clj.entities advent.version advent.max-progress-bar advent.core.desktop-launcher] :main advent.core.desktop-launcher) diff --git a/desktop/src-common/advent/max_progress_bar.clj b/desktop/src-common/advent/max_progress_bar.clj new file mode 100644 index 00000000..64dd34ca --- /dev/null +++ b/desktop/src-common/advent/max_progress_bar.clj @@ -0,0 +1,28 @@ +(ns advent.max-progress-bar + (:require [play-clj.utils :as u]) + (:import [play_clj.entities ActorEntity]) + ) + +(gen-class :name advent.max-progress-bar.MaxProgressBar + :extends com.badlogic.gdx.scenes.scene2d.ui.Slider + :state state + :init init + :exposes-methods {setValue parentSetValue} + :constructors {[float float float boolean com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle float] [float float float boolean com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle]} + ) +(defn -init [min max step-size vertical style artificial-max] + [[min max step-size vertical style] artificial-max]) + +(defn -setValue [this value] + (.parentSetValue this (min value (.state this)))) + +(defn max-progress-bar + [min max step vertical? arg artificial-max] + (println min max step vertical? arg artificial-max) + (ActorEntity. + (advent.max-progress-bar.MaxProgressBar. (float min) (float max) (float step) vertical? arg (float artificial-max)))) + +(defmacro max-progress-bar! + "Calls a single method on a `slider`." + [entity k & options] + `(u/call! ^advent.max-progress-bar.MaxProgressBar (u/get-obj ~entity :object) ~k ~@options)) diff --git a/desktop/src-common/advent/saves.clj b/desktop/src-common/advent/saves.clj index 0ce4f3de..2601d44f 100644 --- a/desktop/src-common/advent/saves.clj +++ b/desktop/src-common/advent/saves.clj @@ -9,10 +9,10 @@ (def chapter-name - {:chapter-1 "Part 1: Our Tale's Beginning" - :chapter-2 "Part 2: To Be a Knight" - :chapter-3 "Part 3: In the Slammer" - :chapter-4 "Part 4: Tick the Ex-con" - :chapter-5 "Part 5: Slingshot Stew"}) + {:chapter-1 "Our Tale's Beginning" + :chapter-2 "To Be a Knight" + :chapter-3 "In the Slammer" + :chapter-4 "Tick the Ex-con" + :chapter-5 "Slingshot Stew"}) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 01d8f8b4..fd58a464 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -40,6 +40,7 @@ [advent.screens.rooms.cat-tree :as rooms.cat-tree] [advent.screens.dialogue :refer [talking-screen toast-screen tooltip-screen]] [advent.screens.inventory :refer [inventory-screen]] + [clojure.core.async :refer [put! ! chan go thread take! alts!! poll! dropping-buffer]]) (:import [com.badlogic.gdx.graphics Pixmap$Format Pixmap Pixmap$Filter Texture Texture$TextureFilter GL20 GL30] [com.badlogic.gdx.graphics.g2d TextureRegion Animation Batch] diff --git a/desktop/src-common/advent/screens/title.clj b/desktop/src-common/advent/screens/title.clj index 0a20e0d6..f13d48b5 100644 --- a/desktop/src-common/advent/screens/title.clj +++ b/desktop/src-common/advent/screens/title.clj @@ -18,6 +18,7 @@ [advent.screens.safe :as safe] [advent.screens.fade :as fade] [advent.version] + [advent.max-progress-bar :refer [max-progress-bar]] ) (:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter Color] [com.badlogic.gdx.graphics.g2d TextureRegion NinePatch] @@ -148,7 +149,7 @@ (let [button (merge (text-button msg (button-style)) (apply hash-map rest))] - (doto button save-object )))) + (doto button save-object)))) (defn set-checkbox-state [cb state] @@ -187,14 +188,26 @@ #_(#(label! % :set-width (/ (label! % :get-width) 2)))) center)))) -(defn make-slider [initial-value & rest] +(defn make-slider [min max initial-value & rest] (let [ui-skin (skin "ui/ui.json") slider (-> - (slider {:min 0 :max 100 :step 1} ui-skin :set-value initial-value) - (assoc :width 305 - :hover (skin! ui-skin :get "default-horizontal-hover" Slider$SliderStyle) - :default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle) - :z 8) + (slider {:min min :max max :step 1} ui-skin :set-value initial-value) + (assoc + :hover (skin! ui-skin :get "default-horizontal-hover" Slider$SliderStyle) + :default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle) + :z 8) + (merge (apply hash-map rest)))] + (doto slider + save-object))) + +(defn make-max-progress-bar [min max initial-value artificial-max & rest] + (let [ui-skin (skin "ui/ui.json") + slider (-> + (max-progress-bar min max 1 false (skin! ui-skin :get "default-horizontal" Slider$SliderStyle) artificial-max) + (assoc + :hover (skin! ui-skin :get "default-horizontal-hover" Slider$SliderStyle) + :default (skin! ui-skin :get "default-horizontal" Slider$SliderStyle) + :z 8) (merge (apply hash-map rest)))] (doto slider save-object))) @@ -215,40 +228,40 @@ (defn main-menu [screen] (let [start-playing-label (quest-label) is-starting? (= "Begin Quest" start-playing-label)] - (make-table (concat [[(make-button start-playing-label :key :continue-or-start) :height (* utils/ui-scale 56) :pad-bottom 4 :width (* utils/ui-scale 250)] + (make-table (concat [[(make-button start-playing-label :key :continue-or-start) :height (* utils/button-scale 56) :pad-bottom (* utils/ui-scale 4) :width (* utils/button-scale 250)] :row - [(doto (make-button "Load" :key :load) - (text-button! :set-disabled (not (seq (utils/snapshot-list))))) :height (* utils/ui-scale 56) :pad-bottom 4 :width (* utils/ui-scale 250)] + [(doto (make-button "Restore" :key :load) + (text-button! :set-disabled (not (seq (utils/snapshot-list))))) :height (* utils/button-scale 56) :pad-bottom (* utils/ui-scale 4) :width (* utils/button-scale 250)] :row [(doto (make-button "Chapters" :key :chapters) (text-button! :set-disabled (not (->> (utils/get-chapters) (vals) (filter identity) - seq)))) :height (* utils/ui-scale 56) :pad-bottom 4 :width (* utils/ui-scale 250)]] + seq)))) :height (* utils/button-scale 56) :pad-bottom (* utils/ui-scale 4) :width (* utils/button-scale 250)]] (when-not utils/mobile? [:row - [(make-button "Settings" :key :settings) :height (* utils/ui-scale 56) :pad-bottom 4 :width (* utils/ui-scale 250)] + [(make-button "Settings" :key :settings) :height (* utils/ui-scale 56) :pad-bottom (* utils/ui-scale 4) :width (* utils/ui-scale 250)] :row [(make-button "End Quest" :key :end-quest) :height (* utils/ui-scale 56) :width (* utils/ui-scale 250)]]))))) (defn chapters-menu [] - (let [chapters (utils/get-chapters) - chapter-table (table - (mapcat identity - (for [chapter [:chapter-1 :chapter-2 :chapter-3 :chapter-4 :chapter-5]] - [[(doto (make-button (if (chapter chapters) - (saves/chapter-name chapter) - "---") - :chapter (chapter chapters)) - (text-button! :set-disabled (nil? (chapter chapters)))) :height 56 :pad-bottom 4 :width 400] - :row])))] - - (make-table [[(doto (scroll-pane chapter-table - (skin "ui/ui.json")) - (scroll-pane! :set-fade-scroll-bars false)) :height 240 :width 472] - :row - [ (make-button "Back" :key :back) :height 56]]))) + (make-table [[(doto + (make-label "Our tale's beginning" label-color) + (label! :set-name "explanation")) :width (* utils/ui-scale 250) :height 40 :colspan 5] + :row + [(make-max-progress-bar 0.0 4.0 0.0 3.0 :key :current-chapter) :width (* utils/ui-scale 260) :height (* utils/ui-scale 50) :colspan 5] + :row + [(make-label "1" label-color) :height (* utils/ui-scale 32) :width 30 :pad-bottom (* utils/ui-scale 8)] + [(make-label "2" label-color) :height (* utils/ui-scale 32) :width 30 :pad-bottom (* utils/ui-scale 8)] + [(make-label "3" label-color) :height (* utils/ui-scale 32) :width 30 :pad-bottom (* utils/ui-scale 8)] + [(make-label "4" label-color) :height (* utils/ui-scale 32) :width 30 :pad-bottom (* utils/ui-scale 8)] + [(make-label "5" label-color) :height (* utils/ui-scale 32) :width 30 :pad-bottom (* utils/ui-scale 8)] + + :row + [ (make-button "Back" :key :back) :height (* utils/button-scale 56) :width (* utils/button-scale 100) :colspan 2] + [ (make-label "") :height (* utils/button-scale 56) ] + [ (make-button "Start" :key :back) :height (* utils/button-scale 56) :width (* utils/button-scale 100) :colspan 2]])) (defn settings-menu [] (let [fullscreen-button (make-checkbox "Fullscreen" (utils/is-fullscreen?) :key :toggle-fullscreen) @@ -256,11 +269,11 @@ (assoc (make-table [[(make-label "Music" label-color) :height 40] :row - [(make-slider (:music-volume @utils/settings) :key :music-volume-slider) :width 240] + [(make-slider 0 100 (:music-volume @utils/settings) :key :music-volume-slider) :width 240] :row [(make-label "FX" label-color) :height 40 :width 200] :row - [(make-slider (:sound-volume @utils/settings) :key :sound-volume-slider) :width 240] + [(make-slider 0 100 (:sound-volume @utils/settings) :key :sound-volume-slider) :width 240] :row [fullscreen-button :height 56 :width 240] :row @@ -280,7 +293,7 @@ (.setMaxCheckCount 1) (.setMinCheckCount 0) (.setUncheckLast true)) - [cell-w cell-h] [218 161] + [cell-w cell-h] (mapv #(* utils/ui-scale %) [218 161]) make-cell (fn [image] [image :width cell-w :pad 4 4 0 0 :height cell-h]) make-save-screenshot (fn [{:keys [screenshot name id state blurb] :as save}] (let [btn (doto (assoc (image-button (skin "ui/ui.json")) @@ -308,7 +321,7 @@ (scroll-pane! :set-fade-scroll-bars false))] (.setScrollFocus stage ^ScrollPane (:object scroll-pane)) [scroll-pane - :colspan 3 :height 190 :pad-bottom 4 :width 472])) + :colspan 3 :height (* utils/ui-scale 190) :pad-bottom 4 :width (* utils/ui-scale 472)])) (defn saves-menu [entities stage] (let [save-label (make-label "" label-color) @@ -320,22 +333,22 @@ :row (saves-table entities stage) :row - [delete-button :width 150 :height 56] - [(make-button "Back" :key :back) :width 150 :height 56] - [continue-button :width 150 :height 56]]) + [delete-button :width (* utils/ui-scale 150) :height (* utils/button-scale 56)] + [(make-button "Back" :key :back) :width (* utils/ui-scale 150) :height (* utils/button-scale 56)] + [continue-button :width (* utils/ui-scale 150) :height (* utils/button-scale 56)]]) :save-label save-label :delete-button delete-button :continue-button continue-button))) (defn confirm-delete [entities] - (make-table [[(make-label "Are you sure you want" label-color) :height 32 :colspan 2] + (make-table [[(make-label "Are you sure you want" label-color) :height (* utils/ui-scale 32) :colspan 2] :row - [(make-label "to delete the save" label-color) :height 32 :colspan 2] + [(make-label "to delete the save" label-color) :height (* utils/ui-scale 32) :colspan 2] :row - [(make-label (str "\"" (-> entities :selected-save :name) "\"?") label-color) :height 32 :colspan 2 :pad-bottom 4] + [(make-label (str "\"" (-> entities :selected-save :name) "\"?") label-color) :height (* utils/ui-scale 32) :colspan 2 :pad-bottom 4] :row - [(make-button "Keep" :key :dont-delete-button) :width 120 :height 56] - [(make-button "Delete" :key :confirm-delete-button) :width 120 :height 56]])) + [(make-button "Keep" :key :dont-delete-button) :width (* utils/ui-scale 120) :height (* utils/button-scale 56)] + [(make-button "Delete" :key :confirm-delete-button) :width (* utils/ui-scale 120) :height (* utils/button-scale 56)]])) (defscreen title-screen :on-show @@ -454,6 +467,15 @@ (utils/save-settings!) entities) + (= :current-chapter actor-key) + (do + (println + (label! (table! (actor! e :get-parent) :find-actor "explanation") + :set-text (saves/chapter-name (nth [:chapter-1 :chapter-2 :chapter-3 :chapter-4 :chapter-5] (int (slider! e :get-value))))) + ) + + entities) + (= :camera-man? actor-key) (do (swap! utils/settings assoc :camera-man? (check-box! e :is-checked)) (utils/save-settings!) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index 1197cc61..e9ee1b05 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -32,10 +32,11 @@ (def ui-scale (Double/parseDouble (str (or (System/getProperty "ui_scale") 1.5)))) +(def button-scale (+ 1 (* (- ui-scale 1.0) 2.0))) (def mobile? (= 1.5 ui-scale)) (def max-zoom (if mobile? 0.5 0.75)) (def min-zoom 0.95) -(def button-font-scale (if mobile? 1.0 0.5)) +(def button-font-scale (if mobile? 0.75 0.5)) (def title-label-scale (if mobile? 0.5 0.25)) (defn clear-stage [{:keys [^Stage renderer]}]