             [Hud {:game-state game-state}]
             [MapUI {:game-state game-state}]]]]]]])))
 
+
+(defn cp437->unicode
+  [c]
+  (case (int c)
+      0 \ 
+      3 \u2665
+    179 \u2502
+    219 \u2588
+    220 \u2584
+    249 "·"
+    250 \u00B7
+    c))
+
+(zc/def-component Histogram
+  [this]
+  (let [{:keys [title histogram value]} (zc/props this)
+        group-size (get histogram "group-size")
+        caret-x (+ (int (/ value group-size)) 1)
+        max-count (reduce (fn [m data](max m (get data "count"))) 0 (get histogram "data"))
+        height 6]
+    (zc/csx
+      [:view {} [
+        [:text {:style {:left 1}} [title]]
+        ; histogram
+        [:view {:style {:width 8 :height height :top 1 :left 1
+                        :border-left 1 :border-bottom 1
+                        :position :absolute
+                        :display :flex :align-items :flex-end}} 
+               (for [[index data] (map-indexed vector (sort-by #(get % "group") (get histogram "data")))
+                     :when (get data "group")
+                     :let [group (get data "group")
+                           count (get data "count")
+                           x (+ 1 (/ group group-size))
+                           bar-height (max 1 (* (- height 2) (/ count max-count)))
+                           bg (rcolor/color->rgb
+                                (if (< group (inc value) (+ group group-size 1))
+                                  :highlight
+                                  :dark-gray))]]
+                 ; histogram bar
+                 (zc/csx [:view {:style {:width 1 :height bar-height
+                                         :position :absolute
+                                         :left index
+                                         :bottom 0
+                                         :background-color bg}} []]))]
+        ; caret
+        [:text {:style {:top (dec height) :left (inc caret-x)
+                        :color (rcolor/color->rgb :highlight)}} ["^"]]]])))
+
+(defn rockpick->render-map
+  [layers]
+  (let [layer (first layers)]
+    (log/info "layer" (vec layer))
+    (reduce concat
+            []
+            (map-indexed (fn [y line]
+                           (log/info "line" (vec line))
+                           (map-indexed (fn [x tile]
+                                          ;(log/info "tile" tile x y)
+                                          {:c (cp437->unicode (get tile :ch))
+                                           :fg [(get-in tile [:fg :r])
+                                                (get-in tile [:fg :g])
+                                                (get-in tile [:fg :b])]
+                                           :bg [(get-in tile [:bg :r])
+                                                (get-in tile [:bg :g])
+                                                (get-in tile [:bg :b])]
+                                           :x  x
+                                           :y  y})
+                                        line))
+                         layer))))
+
+(zc/def-component Start
+  [this]
+  (zc/csx
+    [:terminal {} [
+      [:group {:id :app} [
+        [:layer {:id :map} [
+          [zcui/Image {:src "/home/santos/src/robinson/images/robinson-mainmenu.jpg"}]]]
+        [:layer {:id :ui} [
+              [:view {:style {:color [255 255 255 255]
+                              :background-color [0 0 0 0]
+                              :position :fixed
+                              :top 20
+                              :left 30}} [
+                [:text {} [
+                  [:text {} ["Press "]]
+                  [Highlight {}  ["space "]]
+                  [:text {} ["to play"]]]]
+                [:text {} [[Highlight {} ["c"]] [:text  {} [" - configure"]]]]]]]]]]]]))
+
+(zc/def-component Configure
+  [this]
+  (let [{:keys [state]} (zc/props this)]
+    (zc/csx
+	  [:terminal {} [
+		[:group {:id :app} [
+		  [:layer {:id :ui} [
+			[:view {:style {:position :fixed
+							:top 30
+							:left 20}} [
+			  [:text {} ["Configure"]]
+			  [:text {} ["f - font"]]]]]]]]]])))
+
+(zc/def-component ConfigureFont
+  [this]
+  (let [{:keys [state]} (zc/props this)
+        font   (get-in state [:fonts (get state :new-font (get (rc/get-settings state) :font))])]
+    (zc/csx
+	  [:terminal {} [
+		[:group {:id :app} [
+		  [:layer {:id :ui} [
+			[:view {:style {:position-type :absolute
+							:position-top 30
+							:position-left 20}} [
+			  [:text {} ["Configure Font"]]
+			  [:text {} ["Font: " (get font :name)]]
+			  [:text {} ["n - next font" (get font :name)]]
+			  [:text {} ["p - previous font" (get font :name)]]
+			  [:text {} ["s - save and apply" (get font :name)]]]]]]]]]])))
+
+(zc/def-component EnterName
+  [this]
+  (let [{:keys [game-state]} (zc/props this)
+        player-name (get-in game-state [:world :player :name])]
+    (zc/csx
+	  [:terminal {} [
+		[:group {:id :app} [
+		  [:layer {:id :ui} [
+			[:view {:style {:top 10
+							:left 30
+                            :width 80
+                            :display :flex
+                            :flex-direction :row}} [
+              [:text {:style {:width 5}} ["Name:"]]
+              [:view {:style {:position :relative} } [
+			    [zcui/Input {:value player-name
+                             :focused true}]]]]]]]]]]])))
+
+(zc/def-component StartInventory
+  [this]
+  (let [{:keys [game-state]} (zc/props this)
+        player-name      (get-in game-state [:world :player :name])
+        selected-hotkeys (get-in game-state [:world :selected-hotkeys])
+        start-inventory  (sg/start-inventory)]
+    (zc/csx
+	  [:terminal {} [
+		[:group {:id :app} [
+		  [:layer {:id :ui} [
+            [:view {:style {:align-items :center
+                            :justify-content :center
+                            :position :fixed
+                            :top 2
+                            :left 0}} [
+              [SelectItemList {:title "Choose up to three things to take with you:"
+                               :selected-hotkeys selected-hotkeys
+                               :use-applicable true
+                               :items start-inventory}]]]]]]]]])))
+
 (def loading-index (atom 0))
 (def loading-tidbits
   ["rat swarm"

            [:view {:style {:position :fixed
                            :top 10
                            :left 36}} [
              [:text {} ["Connection Failed."]]]]]]]]]])))


(zc/def-component GameOverDead
  [this]


(zc/def-component ActionChoices
  [this]
  (let [{:keys [game-state]} (zc/props this)
        abilities (get-in game-state [:world :action-select])
        height (if (seq abilities)
                 (+ 3 (* 3 (count abilities)))
                 4)]  
    (zc/csx [zcui/Popup {:style {:top -5
                                 :color (rcolor/color->rgb :black)
                                 :background-color (rcolor/color->rgb :white)}} [
                (if (seq abilities)
                  (zc/csx [MultiSelect {:title "Choose Action"
                                        :items
                                          (concat
                                            (mapcat
                                              (fn [ability]
                                                [{:name (get ability :name)
                                                  :hotkey (get ability :hotkey)}
                                                 {:name (get ability :description)}
                                                 {:name ""}])
                                              abilities)
                                            [{:name ""}
                                             {:name "Select hotkey or press Esc to exit."}])}])
                (zc/csx
                  [:view {} [
                    [:text {} ["Nothing to do."]]
                    [:text {} [""]]
                    [:text {} [
                      [:text {} ["Press "]]
                      [Highlight {} ["Esc "]]
                      [:text {} ["to exit."]]]]]]))]])))

(zc/def-component Describe
  [this]
