/
gui.py
660 lines (546 loc) · 28.3 KB
/
gui.py
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# -*- coding: utf-8 -*-
import urwid, time
from collections import OrderedDict
PALETTE = [("top","white","black"),
("line","white","dark green","standout"),
("line_eq","black","light gray","standout"),
("frame","white","white"),
("reversed", "standout", ""),
("common","white",""),
("uncommon","light blue",""),
("rare","yellow",""),
("unique","light magenta",""),
("set","light green",""),
("red", "dark red", ""),
("yellow", "yellow", ""),
("blue", "light blue", "")
]
class GUI(object):
def __init__(self, master):
self.master = master
self.game_screen = GameScreen(master)
self.start_screen = StartScreen(master)
self.create_screen = CreateScreen(master)
self.load_screen = None
self.help_screen = HelpScreen(master)
self.main = urwid.Padding(self.start_screen, left=2, right=2)#main screen, change it to any screen you need with self.main.original_widget
self.top = urwid.Overlay(self.main, urwid.SolidFill(u"\N{LIGHT SHADE}"),
align="center", width=("relative", 60),
valign="middle", height=("relative", 60),
min_width=120, min_height=60)
self.loop = urwid.MainLoop(self.top, PALETTE, unhandled_input=self.game_screen.handle_input)
def to_game_screen(self):
self.main.original_widget = self.game_screen
def to_create_screen(self):
self.main.original_widget = self.create_screen
def to_load_screen(self):
self.main.original_widget = self.load_screen
def to_help_screen(self):
self.main.original_widget = self.help_screen
class StartScreen(urwid.Overlay):
def __init__(self, master):
self.master = master
body = [urwid.Divider()]
new_game_button = urwid.Button("New Game")
new_game_button._label.align = "center"
urwid.connect_signal(new_game_button, "click", self.new_game)
body.append(urwid.AttrMap(new_game_button, None, focus_map="line"))
quick_game_button = urwid.Button("Quick Start")
quick_game_button._label.align = "center"
urwid.connect_signal(quick_game_button, "click", self.quick_game)
body.append(urwid.AttrMap(quick_game_button, None, focus_map="line"))
help_button = urwid.Button("Help")
help_button._label.align = "center"
urwid.connect_signal(help_button, "click", self.help)
body.append(urwid.AttrMap(help_button, None, focus_map="line"))
quit_button = urwid.Button("Quit")
quit_button._label.align = "center"
urwid.connect_signal(quit_button, "click", self.exit_program)
body.append(urwid.AttrMap(quit_button, None, focus_map="line"))
listbox = urwid.ListBox(urwid.SimpleFocusListWalker(body))
super(StartScreen, self).__init__(listbox, urwid.SolidFill(u"\N{MEDIUM SHADE}"),
align="center", width=("relative", 60),
valign="middle", height=("relative", 60),
min_width=40, min_height=16)
def new_game(self, button):
self.master.new_game()
def quick_game(self, button):
self.master.quick_game()
def help(self, button):
self.master.gui.to_help_screen()
def exit_program(self, button):
raise urwid.ExitMainLoop()
class CreateScreen(urwid.Overlay):
def __init__(self, master):
self.master = master
#list: base value, min value, max value, increment, cost
self.temp_chars = OrderedDict([("HP", [8, 4, 12, 2, 1]), ("BTH", [6, 4, 18, 1, 1]), ("STR", [6, 4, 18, 1, 1]), ("RES", [6, 4, 18, 1, 1]),
("DEX", [6, 4, 18, 1, 1]), ("MAG", [6, 4, 18, 1, 1])])
self.temp_text = {key: urwid.Text(str(self.temp_chars[key][0])) for key in self.temp_chars }
self.points = 40
self.points_text = urwid.Text("Points: {}".format(self.points))
self.name_edit = urwid.Edit("Name: ")
body = [urwid.Text("Create a new character"), urwid.Divider(), self.name_edit, self.points_text]
for c in self.temp_chars:
b_plus = urwid.Button("+")
urwid.connect_signal(b_plus, "click", self.update_char, user_args = [c, +1])
b_minus = urwid.Button("-")
urwid.connect_signal(b_minus, "click", self.update_char, user_args = [c, -1])
columns = [(3, urwid.Text(c)), (2, self.temp_text[c]), (1, urwid.AttrMap(b_minus, None, focus_map="line")), (1, urwid.AttrMap(b_plus, None, focus_map="line"))]
line = urwid.Columns(columns, dividechars=1, focus_column=3, min_width=1, box_columns=None)
body.append(line)
body.append(urwid.Divider())
start_button = urwid.Button("Start")
start_button._label.align = "center"
urwid.connect_signal(start_button, "click", self.start)
body.append(urwid.AttrMap(start_button, None, focus_map="line"))
back_button = urwid.Button("Back")
back_button._label.align = "center"
urwid.connect_signal(back_button, "click", self.back)
body.append(urwid.AttrMap(back_button, None, focus_map="line"))
listbox = urwid.ListBox(urwid.SimpleFocusListWalker(body))
super(CreateScreen, self).__init__(listbox, urwid.SolidFill(u"\N{MEDIUM SHADE}"),
align="center", width=("relative", 60),
valign="middle", height=("relative", 60),
min_width=40, min_height=16)
def update_char(self, char, value, button):
if (self.temp_chars[char][2]>=self.temp_chars[char][0] + value * self.temp_chars[char][3]>= self.temp_chars[char][1]) and self.points - value * self.temp_chars[char][4]>=0:
self.points -= value * self.temp_chars[char][4]
self.temp_chars[char][0] += value * self.temp_chars[char][3]
self.temp_text[char].set_text(str(self.temp_chars[char][0]))
self.points_text.set_text("Points: {}".format(self.points))
def start(self, button):
self.master.create_player(self.name_edit.get_edit_text()[:11], {key: self.temp_chars[key][0] for key in self.temp_chars })
def back(self, button):
self.master.gui.main.original_widget = self.master.gui.start_screen
class HelpScreen(urwid.Overlay):
def __init__(self, master):
self.master = master
text = """
write me, help!
help!
"""
utext = urwid.Text(text)
body = [utext]
back_button = urwid.Button("Back")
back_button._label.align = "center"
urwid.connect_signal(back_button, "click", self.back)
body.append(urwid.AttrMap(back_button, None, focus_map="line"))
listbox = urwid.ListBox(urwid.SimpleFocusListWalker(body))
super(HelpScreen, self).__init__(listbox, urwid.SolidFill(u"\N{MEDIUM SHADE}"),
align="center", width=("relative", 60),
valign="middle", height=("relative", 60),
min_width=40, min_height=16)
def back(self, button):
self.master.gui.main.original_widget = self.master.gui.start_screen
class GameScreen(urwid.Frame):
def __init__(self, master):
self.master = master
length = 30
self.breath_bars_length = max(3, int(0.5 * length))
self.hp_bars_length = max(3, int(0.5 * length))
widgets = [urwid.AttrMap(widget,None,"line") for widget in [ urwid.Text("")] ]
self.players_widget = SelectableListBox(urwid.SimpleListWalker(widgets))
self.screens = []
screens = ("Status", "Inventory", "Equipment", "Location", "Mission")
labels = []
for b in screens:
try:
self.screens.append({"title" : b, "widget" : SelectableListBox(urwid.SimpleListWalker(widgets)), "state" : "normal", "index" : 1, "callback" : getattr(self, "refresh_{}_widget".format(b.lower()))})
except:
continue
l = urwid.Text("{:^10}".format(b), align="center")
#urwid.connect_signal(l, "change", self.change_body)
labels.append(urwid.LineBox(urwid.AttrMap(l, None, focus_map="line")))
self.buttons_column = SelectableColumns(labels)
self.active_screen = self.screens[0]
super(GameScreen, self).__init__(urwid.LineBox(self.active_screen["widget"], title=""), urwid.LineBox(urwid.BoxAdapter(self.players_widget, 12), title=""), self.buttons_column , focus_part="header")
urwid.AttrMap(self,"frame")
def handle_input(self, input):
if input == "esc":
raise urwid.ExitMainLoop()
elif input == "down" and self.focus_position == "body":
self.focus_position = "footer"
elif input == "up" and self.focus_position == "body":
self.focus_position = "header"
elif (input == "up" and self.focus_position == "footer") or (input == "down" and self.focus_position == "header"):
self.focus_position = "body"
elif input == "right":
if self.focus_position == "header":
self.players_widget.focus_next()
elif self.focus_position == "body":
self.active_screen["widget"].focus_next()
elif self.focus_position == "footer":
self.buttons_column.focus_next()
elif input == "left":
if self.focus_position == "header":
self.players_widget.focus_previous()
elif self.focus_position == "body":
self.active_screen["widget"].focus_previous()
elif self.focus_position == "footer":
self.buttons_column.focus_previous()
elif input == "s":
self.buttons_column.focus_position = 0
elif input == "i":
self.buttons_column.focus_position = 1
elif input == "e":
self.buttons_column.focus_position = 2
elif input == "l":
self.buttons_column.focus_position = 3
elif input == "m":
self.buttons_column.focus_position = 4
elif input in (str(i) for i in xrange(1, 10)):
try:
self.players_widget.focus_position = int(input)-1
except:
pass
elif input == "enter":
self.master.tire(self.players_widget.focus_position)
def update_screen(self, protagonist):
players = protagonist.players
widgets = []
for p in players:
widgets += [urwid.AttrMap(urwid.Text(self.print_status(p),wrap='clip'), None, focus_map="line")]
self.players_widget.body[:] = widgets
index = self.players_widget.focus_position
self.active_screen = self.screens[self.buttons_column.focus_position]
self.contents["body"] = (urwid.LineBox(self.active_screen["widget"], title=""), None)
self.contents["header"][0].set_title(protagonist.name)
self.refresh_active_screen(players[index])
def refresh_active_screen(self, player):
for s in self.screens:
if self.active_screen == s:
self.contents["body"][0].set_title(s["title"])
s["callback"](player)
else:
s["state"] = "normal"
s["index"] = 1
def print_status(self, char):
status = []
#"➶""⚝""✨""⚔"❂✮ ⚝
if char.is_dead:
h = u"☠"
elif char.is_dreaming:
h = u"☾"
elif char.is_shocked:
h = u"⚡"
elif char.is_muted:
h = u"∅"
else:
h = [u"♡",u"♥"][int(time.time()*(char.world.generation+1))%2]
if char.is_catching_breath:
breath = "Breathing "
elif char.BTH >= 0:
b = "Breath"
breath = "{:<6s}:{:<3d}".format(b, char.BTH)
incipit = char.job.name + " " + str(char.job.level) if char.__class__.__name__ == "Player" else char.name + ' ' + char.race.name
status.append((None, u"{:12s} {:1s} {:^18s}\n".format(incipit, h, breath)))
hp_bars = int(round(1.*char.HP/char.max_HP * self.hp_bars_length))
if 1.*char.HP/char.max_HP <= 0.5:
status.append(("yellow", u"{:16s} ".format(hp_bars * u"\u25B0" + (self.hp_bars_length - hp_bars) * u"\u25B1")))
elif 1.*char.HP/char.max_HP <= 0.2:
status.append(("red", u"{:16s} ".format(hp_bars * u"\u25B0" + (self.hp_bars_length - hp_bars) * u"\u25B1")))
else:
status.append(("common",u"{:16s} ".format(hp_bars * u"\u25B0" + (self.hp_bars_length - hp_bars) * u"\u25B1")))
if char.is_catching_breath:
breath_bars = int( round((1.-char.is_catching_breath/char.time_to_catch_breath()) * self.breath_bars_length))
status.append(("blue",u"{:17s} ".format(breath_bars * u"\u25AE" + (self.breath_bars_length - breath_bars) * u"\u25AF")))
elif char.BTH >= 0:
breath_bars = int(round(1.*char.BTH/char.max_BTH * self.breath_bars_length))
status.append(("common",u"{:17s} ".format(breath_bars * u"\u25AE" + (self.breath_bars_length - breath_bars) * u"\u25AF")))
status.append(("common",u"{:<100s}".format(char.print_action)))
return status
def refresh_status_widget(self, player):
def toggle_strategy(button):
player.toggle_strategy()
def toggle_auto_loot(button):
player.auto_loot = not player.auto_loot
def get_hist(char):
chars_height = 6
h = []
color = ["red", "yellow", "blue"][(char-1)/2]
for i in xrange(chars_height):
if char >= chars_height-i:
h.append((color, u"\u2592\u2588\u2588 "))
elif char == chars_height-i-1:
h.append((color, u" \u2582\u2582 "))
else:
h.append((color, " "))
return h
state = ""
if player.is_dead:
state += "Dead "
if player.is_dreaming:
state += "Dreaming "
if player.is_muted:
state += "Muted "
if player.is_shocked:
state += "Shocked "
data = ["World:{:1d}/{:1d} {:>10s} {:<10s} Lev:{:2d} Exp:{:<6d} {}\n".format(player.generation, player.world.generation, player.race.name, player.job.name, player.level, player.exp, state),
"BTH:{:>3d}/{:<3d} HP:{:<11s} RTM:{:<3d}\n".format(player.BTH, player.max_BTH, str(player.HP)+"/"+str(player.max_HP), player.on_rythm),
"Abilities: {}\n".format(" - ".join(["{}: {} ({:<2d}%)".format(ab, player.all_abilities()[ab].name, int(round(player.strategy.priority[ab] * 100./sum([player.strategy.priority[k] for k in player.all_abilities()]),0))) for ab in player.all_abilities()])),
"Location: {} --> {}\n".format(player.location.name, player.master_location_path.split("/")[-1])]
chars = []
hist = [get_hist(c) for c in [player.STRmod, player.RESmod, player.MAGmod, player.DEXmod]]
chars = []
for h in zip(*hist):
h = list(h)
h.append("\n")
chars.append(h)
chars.append(u"{:^3d} {:^3d} {:^3d} {:^3d} \n".format(player.STRmod, player.RESmod, player.MAGmod, player.DEXmod))
chars.append(u"STR RES MAG DEX ")
b = urwid.Button("{}".format(player.strategy.name))
b._label.align = "center"
urwid.connect_signal(b, "click", toggle_strategy)
loot_button = urwid.Button("{}".format(player.auto_loot))
loot_button._label.align = "center"
urwid.connect_signal(loot_button, "click", toggle_auto_loot)
line = [(16, urwid.AttrMap(b, None, focus_map="line")), (24, urwid.Text("{} {}".format(player.strategy.alignment, player.strategy.target))),(10, urwid.Text("Auto Loot:")), (12, urwid.AttrMap(loot_button, None, focus_map="line"))]
columns = SelectableColumns(line, dividechars=2)
try:
index = self.active_screen["widget"].focus_position
columns.focus_position = self.active_screen["widget"].body[:][index].focus_position
except:
pass
widgets = [urwid.Columns([(60,urwid.Text(data, align='left')), (30, urwid.Text(chars, align='center'))]), columns]
self.active_screen["widget"].body[:] = widgets
def refresh_location_widget(self, player):
def dream(button):
player.protagonist.dream()
def warp(button):
player.protagonist.warp()
l = player.location
b1 = urwid.Button("Dream Stone")
b1._label.align = "center"
if l.dream_stone:
urwid.connect_signal(b1, "click", dream)
b1 = urwid.AttrMap(b1, None, focus_map="line")
b2 = urwid.Button("Dimensional Warp")
b2._label.align = "center"
if l.dimensional_warp:
urwid.connect_signal(b2, "click", warp)
b2 = urwid.AttrMap(b2, None, focus_map="line")
button_line = SelectableColumns([(20, b1), (20, b2)], dividechars = 1)
loots = ["Lootings: "] + [(loot.rarity, "{} ".format(loot.name)) for loot in l.inventory]
widgets = [button_line, urwid.Text(loots)]
try:
index = self.active_screen["widget"].focus_position
button_line.focus_position = self.active_screen["widget"].body[:][index].focus_position
except:
pass
villains = [c for c in l.characters if c.__class__.__name__ == "Villain"]
for v in villains:
widgets += [urwid.Text(self.print_status(v),wrap='clip')]
self.active_screen["widget"].body[:] = widgets
def refresh_mission_widget(self, player):
def show_missions(button):
self.active_screen["state"] = "show"
def send_mission(mission, button):
player.protagonist.start_mission(mission)
self.active_screen["state"] = "normal"
widgets = []
if self.active_screen["state"] == "normal":
b = urwid.Button("Missions List")
b._label.align = 'center'
w = urwid.AttrMap(b,None,"line")
urwid.connect_signal(b, "click", show_missions)
widgets.append(w)
mission = player.protagonist.mission
if mission != None:
description = mission.description
else:
description = "No mission selected"
data = """{}""".format(description)
widgets.append(urwid.Text(data, align='center') )
else:
missions = [m for key, m in player.protagonist.missions.iteritems() if m.requisites()]
for m in missions:
if m.id in player.protagonist.data["mission"]:
w = urwid.Text("{}".format(m.name), align="center")
text = urwid.Text("Accomplished")
line = [(32, w), text]
else:
b = urwid.Button("{}".format(m.name))
b._label.align = 'center'
text = urwid.Text("{} Exp".format(m.exp))
w = urwid.AttrMap(b,None,"line")
urwid.connect_signal(b, "click", send_mission, user_args = [m])
line = [(32, w), text]
columns = SelectableColumns(line, dividechars=2)
widgets.append(columns)
self.active_screen["widget"].body[:] = widgets
def refresh_inventory_widget(self, player):
def show_item(item, button):
self.active_screen["state"] = item.id
def back(button):
self.active_screen["state"] = "normal"
def drop_item(item, button):
player.drop(item)
def send_equip(item, button):
if not item.is_equipped:
player.equip(item)
def send_unequip(item, button):
if item.is_equipped:
player.unequip(item)
widgets = []
items = [i for i in player.inventory]
if self.active_screen["state"] == "normal":
for i in items:
bonus = ",".join([" {}: {} ".format(bns, i.bonus[bns]) for bns in i.bonus if i.bonus[bns]!=0] ) + " " + ",".join([" {}: {} ".format(ab, i.abilities[ab].name) for ab in i.abilities] )
bname = urwid.Button(i.name)
bname._label.align = 'center'
name_button = urwid.AttrMap(bname,i.rarity,"line")
urwid.connect_signal(bname, "click", show_item, user_args = [i])
if i.is_equipped:
bonus_text = urwid.Text(("line_eq", ("{:^36s}".format(bonus))))
else:
bonus_text = urwid.Text(("{:^36s}".format(bonus)))
bdrop = urwid.Button("Drop")
bdrop._label.align = 'center'
urwid.connect_signal(bdrop, "click", drop_item, user_args = [i])
if i.is_equipment:
if i.requisites(player):
if i.is_equipped:
bequip = urwid.Button("Unequip")
bequip._label.align = 'center'
urwid.connect_signal(bequip, "click", send_unequip, user_args = [i])
elif not i.is_equipped:
bequip = urwid.Button("Equip")
bequip._label.align = 'center'
urwid.connect_signal(bequip, "click", send_equip, user_args = [i])
else:
bequip = urwid.Button("Not Equipable")
bequip._label.align = 'center'
else:
bequip = urwid.Button("Use")
bequip._label.align = 'center'
line = [(22, name_button), (38, bonus_text), (18, urwid.AttrMap(bequip,None,"line")),(12, urwid.AttrMap(bdrop,None,"line"))]
columns = SelectableColumns(line, dividechars=2)
try:
index = self.active_screen["widget"].focus_position
columns.focus_position = self.active_screen["widget"].body[:][index].focus_position
except:
pass
widgets.append(columns)
else:
i = next((it for it in items if it.id == self.active_screen["state"]), None)
if i == None:
self.active_screen["state"] = "normal"
else:
name = urwid.Text((i.rarity, i.name))
widgets.append(name)
widgets.append(urwid.Text("Rarity: {}".format(i.rarity)))
bonus = ",".join([" {}: {} ".format(bns, i.bonus[bns]) for bns in i.bonus if i.bonus[bns]!=0] ) + " " + ",".join([" {}: {} ".format(ab, i.abilities[ab].name) for ab in i.abilities] )
bonus_text = urwid.Text(("{}".format(bonus)))
widgets.append(bonus_text)
for d in i.description:
widgets.append(urwid.Text(d))
bback = urwid.Button("Back")
bback._label.align = 'center'
urwid.connect_signal(bback, "click", back)
bback = urwid.AttrMap(bback, None, "line")
widgets.append(SelectableColumns([(8, bback)]))
self.active_screen["widget"].body[:] = widgets
def refresh_equipment_widget(self, player):
def open_equipment(typ, button):
self.active_screen["state"] = typ
def send_equip(item, button):
if not item.is_equipped:
player.equip(item)
self.active_screen["state"] = "normal"
def send_unequip(button):
if self.active_screen["state"] in player.equipment:
player.unequip(player.equipment[self.active_screen["state"]])
self.active_screen["state"] = "normal"
widgets = []
if self.active_screen["state"] == "normal":
t = urwid.Text("", align='center')
widgets.append(t)
for e in ["Weapon", "Armor", "Helm", "Belt", "Gloves", "Boots"]:
b = urwid.Button("{}".format(e))
b._label.align = 'center'
w = urwid.AttrMap(b,None,"line")
urwid.connect_signal(b, "click", open_equipment, user_args = [e])
if e in player.equipment:
i = player.equipment[e]
bonus = ",".join([" {}: {} ".format(bns, i.bonus[bns]) for bns in i.bonus if i.bonus[bns]!=0])
text = urwid.Text([(i.rarity, "{} ".format(i.name)), bonus])
else:
text = urwid.Text("None")
line = [(16, w), text]
columns = SelectableColumns(line, dividechars=2)
widgets.append(columns)
bonus = player.bonus.copy()
for obj in player.equipment:
for b in player.equipment[obj].bonus:
if b in bonus:
bonus[b] += player.equipment[obj].bonus[b]
t.set_text(" ".join(["{:3}: {:<2}".format(b, bonus[b]) for b in bonus]))
else:
t = urwid.Text("{}".format(self.active_screen["state"]), align='center')
widgets.append(t)
b = urwid.Button("None")
b._label.align = 'center'
w = urwid.AttrMap(b,None,"line")
urwid.connect_signal(b, "click", send_unequip)
text = urwid.Text("")
line = [(16, w), text]
columns = SelectableColumns(line, dividechars=2)
widgets.append(columns)
eqs = [i for i in player.inventory if i.type == self.active_screen["state"] and i.requisites(player)]
for i in eqs:
bonus = ",".join([" {}: {}".format(bns, i.bonus[bns]) for bns in i.bonus if i.bonus[bns]!=0]) + " " + ",".join([" {}: {} ".format(ab, i.abilities[ab].name) for ab in i.abilities] )
b = urwid.Button(i.name)
b._label.align = 'center'
text = urwid.Text("{} {}".format(bonus, "(eq)"*int(i.is_equipped)))
w = urwid.AttrMap(b,i.rarity,"line")
urwid.connect_signal(b, "click", send_equip, user_args = [i])
line = [(16, w), text]
columns = SelectableColumns(line, dividechars=2)
widgets.append(columns)
self.active_screen["widget"].body[:] = widgets
class SelectableListBox(urwid.ListBox):
def __init__(self, body):
super(SelectableListBox, self).__init__(body)
def focus_next(self):
try:
self.focus_position += 1
except:
pass
def focus_previous(self):
try:
self.focus_position -= 1
except:
pass
class InventorySelectableColumns(urwid.Columns):
def __init__(self, widget_list, index, dividechars=0):
super(InventorySelectableColumns, self).__init__(widget_list, dividechars)
self.index = InventorySelectableColumns
def focus_next(self):
try:
self.focus_position += 1
self.index += 1
except:
pass
def focus_previous(self):
try:
self.focus_position -= 1
self.index = 1
except:
pass
class SelectableColumns(urwid.Columns):
def __init__(self, widget_list, dividechars=0):
super(SelectableColumns, self).__init__(widget_list, dividechars)
def focus_next(self):
try:
self.focus_position += 1
except:
pass
def focus_previous(self):
try:
self.focus_position -= 1
except:
pass
def log(text):
with open("log.tiac", "a") as f:
f.write("{}: {}\n".format(time.time(), text))