-
Notifications
You must be signed in to change notification settings - Fork 1
/
store_screen.ml
130 lines (125 loc) · 4.85 KB
/
store_screen.ml
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
open Lwt
open Lwt_react
open LTerm_widget
open Store
open Controller
let get_components c () =
let s =
(match c.storage with
| Store st -> st
| _ -> failwith "No store found in controller"
) in
let mainBox = new vbox in
let label = new label "_" in
let item = new label "_" in
let b = new button "Buy" in
let quit = ref false in
let d = new button "Done" in
d#on_click (fun () -> quit := true);
mainBox#add d;
mainBox#add label;
mainBox#add b;
for i = 0 to 1 do
let hbox = new hbox in
let button i =
if (i - 1) > 2 then
let aug = List.nth_opt s.augmentations (i-4) in
(match aug with
| Some a ->
let name = a.name in
let description =
if a.cost <= c.ship.resources.scrap then
"\n Cost: " ^ (string_of_int a.cost) ^ "\n " ^ a.description
else "\n You do not have enough scrap" in
let button = new button (name) in
button#on_click (fun () -> label#set_text (name ^ description);
item#set_text (name));
button
| None ->
let button = new button ("None") in
button#on_click (fun () -> label#set_text ("None");
item#set_text ("_"));
button
)
else
let weap = List.nth_opt s.weapons (i-1) in
(match weap with
| Some w ->
let name = w.name in
let description =
if w.cost <= c.ship.resources.scrap then
"\n Cost: " ^ (string_of_int w.cost) ^
"\n Damage: " ^ (string_of_int w.damage) ^ "\n Capacity: " ^
(string_of_int w.capacity)
else "\n You do not have enough scrap" in
let button = new button (name) in
button#on_click (fun () -> label#set_text (name ^ description);
item#set_text (name));
button
| None ->
let button = new button ("None") in
button#on_click (fun () -> label#set_text ("None");
item#set_text ("_"));
button
)
in
let t = if i = 0 then "Weapons" else "Augmentations" in
let lab = new label t in
hbox#add (button (i * 3 + 1));
hbox#add ~expand:false (new vline);
hbox#add (button (i * 3 + 2));
hbox#add ~expand:false (new vline);
hbox#add (button (i * 3 + 3));
mainBox#add ~expand:false (new hline);
mainBox#add ~expand:false lab;
mainBox#add ~expand:false (new hline);
mainBox#add hbox
done;
let box = new hbox in
let ftext = if s.fuel = 0 then ("\nNo more fuel available", "_")
else if c.ship.resources.scrap < Store.fuel_cost
then ("\nYou do not have enough scrap", "_")
else ("\nCost: " ^ string_of_int Store.fuel_cost, "Fuel") in
let fbutton = new button ("Fuel: " ^ string_of_int s.fuel ^ " available") in
fbutton#on_click (fun () -> label#set_text ("Fuel" ^ fst ftext);
item#set_text(snd ftext));
let mtext = if s.missiles = 0 then ("\nNo more missiles available", "_")
else if c.ship.resources.scrap < Store.missile_cost
then ("\nYou do not have enough scrap", "_")
else ("\nCost: " ^ string_of_int Store.missile_cost, "Missile") in
let mbutton = new button ("Missiles: " ^ string_of_int s.missiles ^
" available") in
mbutton#on_click (fun () -> label#set_text ("Missile" ^ fst mtext);
item#set_text(snd mtext));
let h1text =
if c.ship.resources.scrap < 3
then ("\nYou do not have enough scrap", "_")
else if c.ship.hull >= c.ship.max_hull
then ("\nHull already at max", "_")
else ("\nCost: 3", "1 Hull") in
let h1button = new button("Repair 1 Hull") in
h1button#on_click (fun () -> label#set_text (h1button#label ^ (fst h1text));
item#set_text (snd h1text););
let hcost = 9 * (c.ship.max_hull - c.ship.hull) * 3 / 10 in
let htext =
if c.ship.resources.scrap < hcost
then ("\nYou do not have enough scrap", "_")
else if c.ship.hull >= c.ship.max_hull
then ("\nHull already at max", "_")
else ("\nCost: " ^ string_of_int hcost, "All Hull") in
let hbutton = new button("Repair all Hull") in
hbutton#on_click (fun () -> label#set_text (hbutton#label ^ (fst htext));
item#set_text (snd htext););
let rlab = new label "Resources" in
box#add fbutton;
box#add ~expand:false (new vline);
box#add mbutton;
box#add ~expand:false (new vline);
box#add h1button;
box#add ~expand:false (new vline);
box#add hbutton;
mainBox#add ~expand:false (new hline);
mainBox#add ~expand:false rlab;
mainBox#add ~expand:false (new hline);
mainBox#add box;
(mainBox, item, b, d, quit);