Skip to content

Commit

Permalink
Use a different color for the focus in targeting mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodiologist committed Feb 24, 2024
1 parent d9f6358 commit 1f2673b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
6 changes: 4 additions & 2 deletions simalq/color.hy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'pale-red [1 (/ 7 8) (/ 7 8)]
'bright-red [1 0 0]
'red [(/ 3 4) 0 0]
'pale-orange [1 (/ 3 4) 0]
'orange [1 (/ 1 2) 0]
'dark-orange [(/ 3 4) (/ 1 2) 0]
'pale-blue [(/ 7 8) (/ 7 8) 1]
Expand All @@ -43,8 +44,9 @@
reality-fringe 'light-gray
reality-fringe-block 'dark-gray
overwrapped 'dark-gray
focus 'yellow
focus-on-dead-player 'bright-red
highlight-target 'pale-orange
highlight-player-living 'yellow
highlight-player-dead 'bright-red
message-bg 'pale-yellow

flash-label 'white
Expand Down
8 changes: 4 additions & 4 deletions simalq/commands.hy
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

(defn get-inventory-ix []
(menu G.rules.max-usables :draw (fn []
(print-main-screen G.player.pos :inventory T))))
(print-main-screen :inventory T))))

(ecase (type cmd)

Expand Down Expand Up @@ -157,7 +157,8 @@
(is-not None (setx tile-ix (if (= (len stack) 1)
0
(menu (len stack) :draw (fn []
(print-main-screen target :status-bar F :tile-list 'pickable)))))))
(print-main-screen :target target
:status-bar F :tile-list 'pickable)))))))
(info-screen (get stack tile-ix)))))

ShiftHistory (do
Expand Down Expand Up @@ -258,7 +259,6 @@

(defn animate []
(flash-map :flash-time-s .1
G.player.pos
(if magic?
color.flash-player-shot-magic
color.flash-player-shot-mundane)
Expand Down Expand Up @@ -336,7 +336,7 @@
(hy.I.simalq/main.io-mode
:draw (fn []
(hy.I.simalq/main.print-main-screen
focus :status-bar F :tile-list 'nonpickable))
:target focus :status-bar F :tile-list 'nonpickable))
:on-input (fn [key]
(nonlocal focus)
(setv dir-v (hy.I.simalq/keyboard.read-dir-key key))
Expand Down
27 changes: 15 additions & 12 deletions simalq/display.hy
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ interface elements as lists of `ColorChar`s."
(defn draw-screen [
width height
; Integers
focus
; A `Pos`
[target None]
; An optional `Pos` to focus the map. Otherwise, we use the
; player's current position.
[status-bar T]
[tile-list None]
; `None`, or the symbols `pickable` or `nonpickable`
Expand All @@ -113,8 +114,10 @@ interface elements as lists of `ColorChar`s."
(colorstr-to-width line width))))
(setv status-bar-lines (len out))
; Then the map, including overmarks.
(setv focus (or target G.player.pos))
(+= out (draw-map
focus
(bool target)
width
(- height status-bar-lines)
(or overmarks {})))
Expand Down Expand Up @@ -163,7 +166,7 @@ interface elements as lists of `ColorChar`s."
;; ** The map
;; --------------------------------------------------------------

(defn draw-map [focus width height overmarks]
(defn draw-map [focus targeting? width height overmarks]
"Return a list of colorstrs, one per line. The map will include
(typically, is centered on) `focus`, a `Pos`. `overmarks` should be
a dictionary mapping `Pos`es to pairs of `ColorChar`s to display
Expand Down Expand Up @@ -207,15 +210,15 @@ interface elements as lists of `ColorChar`s."
(setv c.bold o.bold)))
(= [mx my] [focus.x focus.y])
; Mark the focus with a special background color.
(setv c.bg
(if (and
(= p G.player.pos)
(= G.player.game-over-state 'dead))
; Use a different color if the player is dead and
; it's on the player's square. This is the most
; prominent visual indication of death.
color.focus-on-dead-player
color.focus))))
(setv c.bg (cond
targeting?
color.highlight-target
(= G.player.game-over-state 'dead)
; Use a different color if the player is dead. This
; is the most prominent visual indication of death.
color.highlight-player-dead
T
color.highlight-player-living))))
cs)
; Otherwise, we're off the map. Draw border.
(colorstr "██" color.void)))
Expand Down
5 changes: 2 additions & 3 deletions simalq/main.hy
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@

:draw (fn []
(print-main-screen
:focus G.player.pos
:messages (tuple message-queue)))

:on-input (fn [key]
Expand All @@ -198,12 +197,12 @@
(except [e CommandError]
(msg (get e.args 0)))))))

(defn print-main-screen [focus #** kwargs]
(defn print-main-screen [#** kwargs]
(print
:flush T :sep "" :end ""
B.home
(.join "\n" (map (fn [x] (bless-colorstr B x)) (draw-screen
B.width B.height focus #** kwargs)))))
B.width B.height #** kwargs)))))


(setv max-wrap-cols 75)
Expand Down
1 change: 0 additions & 1 deletion simalq/tile/player.hy
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
:!animate-hit (meth [attacker label [special-color? F] [show-ivln? T]]
"Use `flash-map` to indicate that the player's been hit."
(flash-map
@pos
(if special-color?
colors.flash-player-hit-by-special-attack
colors.flash-player-damaged)
Expand Down
12 changes: 5 additions & 7 deletions simalq/util.hy
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@
(.append message-queue (.join " " (map str args)))))


(defn flash-map [focus color ps labels flash-time-s]
(defn flash-map [color ps labels flash-time-s]
"Animate the map by briefly flashing some positions a certain color,
optionally with a text label replacing the map character. `focus`
should be a `Pos`, `ps` an iterable of `Pos` to flash, and
`labels` a dictionary mapping a subset of positions in `ps` to
2-character `str`s."
optionally with a text label replacing the map character. `ps`
should be an iterable of `Pos` to flash, and `labels` a dictionary
mapping a subset of positions in `ps` to 2-character `str`s."

(import
simalq.main [print-main-screen displaying]
Expand All @@ -74,7 +73,7 @@
(unless (and ps (displaying))
(return))

(print-main-screen focus
(print-main-screen
:status-bar T
:messages message-queue
:overmarks (dfor p ps p (lfor i (range 2)
Expand Down Expand Up @@ -198,7 +197,6 @@

(setv b (tuple (burst center (- (len amount) 1))))
(flash-map
G.player.pos
color
:ps b
:labels {}
Expand Down

0 comments on commit 1f2673b

Please sign in to comment.