-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfoPanel.fs
214 lines (171 loc) · 5.96 KB
/
InfoPanel.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
module InfoPanel
open World
open Controls
open Entities
open System
type Row = World -> (string * System.ConsoleColor option)
type Column = Row list
type Panel = Column * Column * Column
let addRow r (column: Column) =
r :: column
let fieldColumn : Column =
[]
// Field name
|> addRow (fun w ->
let f = (w.Item cursor).field
f
|> Fields.getName
|> duplet <| (Fields.getColor f |> Some) )
// Defensive bonus
|> addRow (fun w ->
let f = (w.Item cursor).field
sprintf "Defensive Bonus: %i%%" (f.defensiveBonus * 100.0 |> int)
|> duplet <| None)
// Movement cost to square
|> addRow (fun w ->
match (w.Item cursor).state with
| MoveableSquare cost ->
sprintf "Movement Cost: %i" cost
|> duplet <| None
| _ -> ("", None))
|> addRow (fun x -> ("", None))
|> List.rev
let entityColumn : Column =
[]
// Entity name
|> addRow (fun w ->
match (w.Item cursor).entity with
| Some entity ->
let infoString =
match box entity with
| :? ICombat as e ->
sprintf "%s (HP: %i)" entity.Name e.Health
| :? Base as e ->
sprintf "%s (CP: %i/%i)" entity.Name e.CapturePoints Constants.maxCapturePoints
| _ ->
sprintf "%s" entity.Name
(infoString, Entities.getTeamColor entity.Team |> Some)
| None -> ("", None))
|> addRow (fun w ->
match (w.Item cursor).entity with
| Some entity ->
let infoString =
match box entity with
| :? ICombat as e ->
sprintf "W: %s A: %s" (e.Weapon |> getUnionCaseName) (e.Armor |> getUnionCaseName)
| :? Base as e ->
match e.Inhabitant with
| Some inhabitant ->
sprintf "Inhabitant: %s" inhabitant.Name
| None -> ""
| _ ->
sprintf "%s" entity.Name
infoString
|> duplet <| (Entities.getTeamColor entity.Team |> Some)
| None -> ("", None))
|> addRow (fun w ->
let victimSquare = (w.Item cursor)
let damage =
maybe {
let! victimEntity = victimSquare.entity
let! victim = tryCoerce<ICombat> victimEntity
let! attackerSquare = w.TryGetMarkedSquare ()
let! attackerEntity = (snd attackerSquare).entity
let! attacker = tryCoerce<ICombat> attackerEntity
if attackerEntity.Team <> victimEntity.Team then
return
attacker
|> Entities.damageAgainst victim victimSquare.field
|> sprintf "Damage against unit %i"
}
match damage with
| Some s -> (s, None)
| None -> ("", None)
)
|> addRow (fun x -> ("", None))
|> List.rev
let lastColumn : Column =
[]
|> addRow (fun w -> ("Day: " + string Rounds.currentRound, None))
|> addRow (fun x -> ("", None))
|> addRow (fun x -> ("", None))
|> addRow (fun x -> ("", None))
|> List.rev
let panel = (fieldColumn, entityColumn, lastColumn)
let columnSize = 26
let printPanelRow (s: string) (c: System.ConsoleColor option list) =
let print c s =
match c with
| Some c -> System.Console.ForegroundColor <- c
| None -> System.Console.ResetColor ()
printf "%s" s
Terminal.print None c.[0] s.[0..25]
Terminal.printWithBackground System.ConsoleColor.White (s.[26] |> string)
Terminal.print None c.[1] s.[27..51]
Terminal.printWithBackground System.ConsoleColor.White (s.[52] |> string)
Terminal.print None c.[2] s.[53..]
let rec drawPanel (world: World) (panel: Panel) =
match panel with
| (x::xs, y::ys, z::zs) ->
let rows =
[x; y; z]
|> List.map (fun f -> f world)
|> List.map (fun (s, c) ->
let leftPadded = s.PadLeft (s.Length + 1)
let allPadded = leftPadded.PadRight columnSize
(allPadded, c))
let panelString =
rows
|> List.map fst
|> List.toArray
|> duplet " "
|> System.String.Join
let colors =
rows
|> List.map snd
printPanelRow panelString colors
drawPanel world (xs, ys, zs)
| _ -> ()
type InfoPanel (world : World) =
let splitter =
String.init 80 (fun _ -> "*")
|> String.mapi (fun i c ->
if i % 26 = 0 && i < 78 || i = 79 then '|' else c)
let mutable counter = 0
let mutable lastKey = ' '
(*
let drawField (square : Square) =
let col =
match square.field.fgcol with
| Some c -> c
| None -> square.field.bgcol
square.field
|> Fields.getName
|> Terminal.printLine (Some col)
match square.entity with
| Some e ->
match box e with
| :? ICombat as e' ->
Terminal.printLine (Some (e.Team |> getTeamColor))
<| sprintf "%s (HP: %i)" e.Name e'.Health
| None -> Terminal.printLine None ""
*)
member __.Draw key s =
match key with
| Some k -> lastKey <- k
| None -> ()
System.Console.SetCursorPosition (0, 18)
System.Console.ResetColor ()
let currentSquare = world.Item cursor
Terminal.printWithForeground System.ConsoleColor.White splitter
panel
|> drawPanel world
(*
currentSquare |> drawField
counter.ToString ()
|> Terminal.printLine None
//printfn "Last keypress: %c" lastKey
printfn "%s" s
*)
Terminal.printWithForeground System.ConsoleColor.White splitter
counter <- counter + 1