Skip to content

Commit 1f2673b

Browse files
committed
Use a different color for the focus in targeting mode.
1 parent d9f6358 commit 1f2673b

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

simalq/color.hy

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'pale-red [1 (/ 7 8) (/ 7 8)]
1818
'bright-red [1 0 0]
1919
'red [(/ 3 4) 0 0]
20+
'pale-orange [1 (/ 3 4) 0]
2021
'orange [1 (/ 1 2) 0]
2122
'dark-orange [(/ 3 4) (/ 1 2) 0]
2223
'pale-blue [(/ 7 8) (/ 7 8) 1]
@@ -43,8 +44,9 @@
4344
reality-fringe 'light-gray
4445
reality-fringe-block 'dark-gray
4546
overwrapped 'dark-gray
46-
focus 'yellow
47-
focus-on-dead-player 'bright-red
47+
highlight-target 'pale-orange
48+
highlight-player-living 'yellow
49+
highlight-player-dead 'bright-red
4850
message-bg 'pale-yellow
4951

5052
flash-label 'white

simalq/commands.hy

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121

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

126126
(ecase (type cmd)
127127

@@ -157,7 +157,8 @@
157157
(is-not None (setx tile-ix (if (= (len stack) 1)
158158
0
159159
(menu (len stack) :draw (fn []
160-
(print-main-screen target :status-bar F :tile-list 'pickable)))))))
160+
(print-main-screen :target target
161+
:status-bar F :tile-list 'pickable)))))))
161162
(info-screen (get stack tile-ix)))))
162163

163164
ShiftHistory (do
@@ -258,7 +259,6 @@
258259

259260
(defn animate []
260261
(flash-map :flash-time-s .1
261-
G.player.pos
262262
(if magic?
263263
color.flash-player-shot-magic
264264
color.flash-player-shot-mundane)
@@ -336,7 +336,7 @@
336336
(hy.I.simalq/main.io-mode
337337
:draw (fn []
338338
(hy.I.simalq/main.print-main-screen
339-
focus :status-bar F :tile-list 'nonpickable))
339+
:target focus :status-bar F :tile-list 'nonpickable))
340340
:on-input (fn [key]
341341
(nonlocal focus)
342342
(setv dir-v (hy.I.simalq/keyboard.read-dir-key key))

simalq/display.hy

+15-12
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ interface elements as lists of `ColorChar`s."
9494
(defn draw-screen [
9595
width height
9696
; Integers
97-
focus
98-
; A `Pos`
97+
[target None]
98+
; An optional `Pos` to focus the map. Otherwise, we use the
99+
; player's current position.
99100
[status-bar T]
100101
[tile-list None]
101102
; `None`, or the symbols `pickable` or `nonpickable`
@@ -113,8 +114,10 @@ interface elements as lists of `ColorChar`s."
113114
(colorstr-to-width line width))))
114115
(setv status-bar-lines (len out))
115116
; Then the map, including overmarks.
117+
(setv focus (or target G.player.pos))
116118
(+= out (draw-map
117119
focus
120+
(bool target)
118121
width
119122
(- height status-bar-lines)
120123
(or overmarks {})))
@@ -163,7 +166,7 @@ interface elements as lists of `ColorChar`s."
163166
;; ** The map
164167
;; --------------------------------------------------------------
165168

166-
(defn draw-map [focus width height overmarks]
169+
(defn draw-map [focus targeting? width height overmarks]
167170
"Return a list of colorstrs, one per line. The map will include
168171
(typically, is centered on) `focus`, a `Pos`. `overmarks` should be
169172
a dictionary mapping `Pos`es to pairs of `ColorChar`s to display
@@ -207,15 +210,15 @@ interface elements as lists of `ColorChar`s."
207210
(setv c.bold o.bold)))
208211
(= [mx my] [focus.x focus.y])
209212
; Mark the focus with a special background color.
210-
(setv c.bg
211-
(if (and
212-
(= p G.player.pos)
213-
(= G.player.game-over-state 'dead))
214-
; Use a different color if the player is dead and
215-
; it's on the player's square. This is the most
216-
; prominent visual indication of death.
217-
color.focus-on-dead-player
218-
color.focus))))
213+
(setv c.bg (cond
214+
targeting?
215+
color.highlight-target
216+
(= G.player.game-over-state 'dead)
217+
; Use a different color if the player is dead. This
218+
; is the most prominent visual indication of death.
219+
color.highlight-player-dead
220+
T
221+
color.highlight-player-living))))
219222
cs)
220223
; Otherwise, we're off the map. Draw border.
221224
(colorstr "██" color.void)))

simalq/main.hy

+2-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@
183183

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

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

201-
(defn print-main-screen [focus #** kwargs]
200+
(defn print-main-screen [#** kwargs]
202201
(print
203202
:flush T :sep "" :end ""
204203
B.home
205204
(.join "\n" (map (fn [x] (bless-colorstr B x)) (draw-screen
206-
B.width B.height focus #** kwargs)))))
205+
B.width B.height #** kwargs)))))
207206

208207

209208
(setv max-wrap-cols 75)

simalq/tile/player.hy

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
:!animate-hit (meth [attacker label [special-color? F] [show-ivln? T]]
8282
"Use `flash-map` to indicate that the player's been hit."
8383
(flash-map
84-
@pos
8584
(if special-color?
8685
colors.flash-player-hit-by-special-attack
8786
colors.flash-player-damaged)

simalq/util.hy

+5-7
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@
6060
(.append message-queue (.join " " (map str args)))))
6161

6262

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

7069
(import
7170
simalq.main [print-main-screen displaying]
@@ -74,7 +73,7 @@
7473
(unless (and ps (displaying))
7574
(return))
7675

77-
(print-main-screen focus
76+
(print-main-screen
7877
:status-bar T
7978
:messages message-queue
8079
:overmarks (dfor p ps p (lfor i (range 2)
@@ -198,7 +197,6 @@
198197

199198
(setv b (tuple (burst center (- (len amount) 1))))
200199
(flash-map
201-
G.player.pos
202200
color
203201
:ps b
204202
:labels {}

0 commit comments

Comments
 (0)