Guest User

Demo with Squares

a guest
May 14th, 2012
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;;;;;; project.clj
  2. (defproject AF "1.0.0-SNAPSHOT"
  3.   :description "TODO"
  4.   :dependencies [
  5.         [org.clojure/clojure "1.3.0"]
  6.         [seesaw "1.4.1"]
  7.         [com.github.insubstantial/substance "7.1"]
  8.   ]
  9.   :dev-dependencies [
  10.         [lein-eclipse "1.0.0"]
  11.   ]
  12.   :main AF.core
  13. )
  14. ;;;;;;; end of project.cj
  15.  
  16. ;;;;;;; core.clj
  17. (ns AF.core
  18.   (:use seesaw.core)
  19.   (:import org.pushingpixels.substance.api.SubstanceLookAndFeel)
  20.   (:import org.pushingpixels.substance.api.SubstanceConstants$FocusKind)
  21.   (:gen-class))
  22.  
  23. (native!)
  24.  
  25. (def f (frame :title "Ascendant Force" :on-close :exit :size [600 :by 600]))
  26.  
  27. (defn display [content]
  28.   (config! f :content content)
  29.   content)
  30.  
  31.  
  32. (def shades ["#000" "#333" "#666" "#999" "#CCC"])
  33. (def lightest "#fff")
  34. (def dimen [90 :by 90])
  35. (defn make-box
  36.   ([shade-index] (button :background (shades shade-index) :size dimen))
  37.   ([shade-index phrase] (button
  38.                          :id (keyword phrase)
  39.                          :background (shades shade-index)
  40.                          :foreground lightest
  41.                          :listen [
  42.                                  ; :mouse-pressed #(config! % :background "#66F" :foreground "#000")
  43.                                   :mouse-entered #(config! % :foreground (shades shade-index))
  44.                                   :mouse-exited  #(config! % :foreground lightest)]
  45.                          :action (action :handler (fn [e] (config! (.getSource e) :background "#00F" :foreground lightest) (alert (str "Clicked " phrase)))
  46.                                          :name @phrase))))
  47. (def dodge (ref (str "<html>" "Dodge" "<br>")))
  48. (def control (ref (str "<html>" "Control" "<br>")))
  49. (def shield (ref (str "<html>" "Shield" "<br>")))
  50. (def endure (ref (str "<html>" "Endure" "<br>")))
  51. (defn rename-button ([btn txtref] (config! btn :text @txtref))
  52.   ([btn txtref txt2] (dosync (ref-set txtref (str @txtref txt2))(config! btn :text @txtref))))
  53. (defn shaded-boxes []
  54.                    [
  55.                     (make-box 0 dodge) (make-box 1) (make-box 2) (make-box 2) (make-box 1) (make-box 0 control)
  56.                     (make-box 1) (make-box 2) (make-box 3) (make-box 3) (make-box 2) (make-box 1)
  57.                     (make-box 2) (make-box 3) (make-box 4) (make-box 4) (make-box 3) (make-box 2)
  58.                     (make-box 2) (make-box 3) (make-box 4) (make-box 4) (make-box 3) (make-box 2)
  59.                     (make-box 1) (make-box 2) (make-box 3) (make-box 3) (make-box 2) (make-box 1)
  60.                     (make-box 0 shield) (make-box 1) (make-box 2) (make-box 2) (make-box 1) (make-box 0 endure)
  61.                    ])
  62. (defn griddy []
  63.   (let [boxes (shaded-boxes)]
  64.   (config! (boxes 0) :action (action :handler (fn [e] (config! (.getSource e) :background "#00F" :foreground "#fff"); (alert (str "Clicked " "Dodge"))
  65.                                                 (config! (boxes 5) :background (shades 0)); (boxes 5))
  66.                                                 (config! (boxes 30) :background (shades 0)); (boxes 30))
  67.                                                 (config! (boxes 35) :background (shades 0))); (boxes 35)))
  68.                                          :name "Dodge"))
  69.   (config! (boxes 5) :action (action :handler (fn [e] (config! (.getSource e) :background "#00F" :foreground "#fff"); (alert (str "Clicked " "Control"))
  70.                                                 (config! (boxes 0) :background (shades 0)); (boxes 0))
  71.                                                 (config! (boxes 30) :background (shades 0)); (boxes 30))
  72.                                                 (config! (boxes 35) :background (shades 0))); (boxes 35)))
  73.                                          :name "Control"))
  74.   (config! (boxes 30) :action (action :handler (fn [e] (config! (.getSource e) :background "#00F" :foreground "#fff"); (alert (str "Clicked " "Shield"))
  75.                                                 (config! (boxes 0) :background (shades 0)); (boxes 0))
  76.                                                 (config! (boxes 5) :background (shades 0)); (boxes 5))
  77.                                                 (config! (boxes 35) :background (shades 0))); (boxes 35)))
  78.                                          :name "Shield"))
  79.   (config! (boxes 35) :action (action :handler (fn [e] (config! (.getSource e) :background "#00F" :foreground "#fff"); (alert (str "Clicked " "Endure"))
  80.                                                 (config! (boxes 0) :background (shades 0)); (boxes 0))
  81.                                                 (config! (boxes 5) :background (shades 0)); (boxes 5))
  82.                                                 (config! (boxes 30) :background (shades 0))); (boxes 30)))
  83.                                          :name "Endure"))
  84.  (grid-panel
  85.  :id :the-grid
  86.  :border [10 10]
  87.  :hgap 1
  88.  :vgap 1
  89.  :columns 6
  90.  :items boxes )))
  91.  
  92. (def skills {"Fiery Barrage" {:desc "An artillery-like bombardment by explosive shells." :target 21}
  93.              "Freezing Shot" {:desc "A shot that encases anyone it hits in ice." :target 29}})
  94. (def defenders {"John" {:desc "A boy who's much stronger than he looks; can control the wind." :dodge 3 :control 4 :shield 2 :endure 5}
  95.                 "Rose" {:desc "A nimble magician who dabbles in dangerous studies." :dodge 4 :control 5 :shield 3 :endure 2}
  96.                 "Dave" {:desc "A talented swordsman with amazing agility." :dodge 5 :control 2 :shield 4 :endure 3}
  97.                 "Jade" {:desc "A canny sniper whose camouflage is aided by her endurance." :dodge 2 :control 3 :shield 5 :endure 4}})
  98. (defn prime []
  99.   (display (border-panel
  100.            :id :brdr
  101.            :vgap 5 :hgap 5 :border 5
  102.            :center (griddy)
  103.            :east (vertical-panel :items [(combobox :id :skill-combo :size [200 :by 32] :model (keys skills)
  104.                                                    :listen [:selection (fn [e] (config! (select (to-root f) [:#skill-desc]) :text ((skills (selection e)) :desc))
  105.                                                                          (remove! (select (to-root f) [:#brdr]) (select (to-root f) [:#the-grid]))
  106.                                                                          (config! (select (to-root f) [:#brdr]) :center (griddy))
  107.                                                                          (config! (nth (config (select (to-root f) [:#the-grid]) :items) ((skills (selection e)) :target)) :background "#f33"))])
  108.                                       (separator :orientation :horizontal :size [200 :by 10])
  109.                                       (text :id :skill-desc :size [200 :by 500] :editable? false :multi-line? true :wrap-lines? true :text "")
  110.                                      ]
  111.            )
  112.            :west (vertical-panel :items [(combobox :id :char-combo :size [200 :by 32] :model (keys defenders)
  113.                                                    :listen [:selection (fn [e] (config! (select (to-root f) [:#defender-desc]) :text ((defenders (selection e)) :desc))
  114.                                                                          (rename-button (select (to-root f) [:#Dodge]) dodge ((defenders (selection e)) :dodge))
  115.                                                                          (rename-button (select (to-root f) [:#Control]) control ((defenders (selection e)) :control))
  116.                                                                          (rename-button (select (to-root f) [:#Shield]) shield ((defenders (selection e)) :shield))
  117.                                                                          (rename-button (select (to-root f) [:#Endure]) endure ((defenders (selection e)) :endure)))])
  118.                                       (separator :orientation :horizontal :size [200 :by 10])
  119.                                       (text :id :defender-desc :size [200 :by 500] :editable? false :multi-line? true :wrap-lines? true :text "")
  120.                                      ]
  121.            )
  122.            ))
  123.   (-> f pack! show!))
  124. (defn -main [& args]
  125.   (invoke-later
  126.     (javax.swing.UIManager/setLookAndFeel "org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel")
  127.     (javax.swing.UIManager/put SubstanceLookAndFeel/FOCUS_KIND SubstanceConstants$FocusKind/NONE)
  128.    
  129.     (prime)
  130. ))
  131. ;;;;;;;end of core.clj
Advertisement
Add Comment
Please, Sign In to add comment