-
Notifications
You must be signed in to change notification settings - Fork 0
/
dNewChar.py
248 lines (184 loc) · 9.66 KB
/
dNewChar.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
import npyscreen, curses
import yaml
import dCharSheet as charSheet
from dboxwidget import *
from yamlLoader import *
class NewCharRace(npyscreen.FormBaseNew):
def create(self):
races = [race["Name"] for race in race_descriptions]
# TODO: Make it relative to window size, resize method
self.pRace = self.add(OptionSelector, name="Race", values=races, rely=3, relx=5, max_width=20)
self.pRace.setParent(self)
self.optionDisplay = self.add(OptionDisplay, descriptions=race_descriptions, name="Details", autowrap=True, rely=2, relx=-60, contained_widget_arguments={'color': 'WARNING', 'widgets_inherit_color': True})
self.optionDisplay.updateDescription(0)
self.pRace.handlers.update({
curses.KEY_UP: self.updateDescription,
curses.KEY_DOWN: self.updateDescription,
curses.KEY_LEFT: self.updateDescription,
curses.KEY_RIGHT: self.updateDescription,
curses.ascii.TAB: self.updateDescription
})
def updateDescription(self, key):
if key in [curses.KEY_UP, curses.KEY_LEFT]:
self.pRace.h_cursor_line_up(key)
elif key in [curses.KEY_DOWN, curses.KEY_RIGHT]:
self.pRace.h_cursor_line_down(key)
self.optionDisplay.updateDescription(self.pRace.cursor_line)
self.optionDisplay.display()
def nextForm(self, index):
charSheet.getCharSheet().raceIndex = index
race_desc = race_descriptions[index]
race_desc = [i for sublist in race_desc for i in sublist]
if "Subraces" in race_descriptions[index].keys():
change_to = "NEW_CHAR_SUBRACE"
elif "Draconic Ancestry" in race_descriptions[index].keys():
change_to = "NEW_CHAR_DRACONIC_ANCESTRY"
else:
change_to = "NEW_CHAR_CLASS"
self.parentApp.change_form(change_to)
class OptionSelector(npyscreen.MultiLineAction):
def __init__(self, *args, **kwargs):
super(OptionSelector, self).__init__(*args, **kwargs)
def setParent(self, parent):
self.parent = parent
def actionHighlighted(self, act_on_this, key_press):
self.parent.nextForm(self.values.index(act_on_this))
class OptionDisplay(dBoxTitle):
_contained_widget = npyscreen.Pager
def __init__(self, *args, descriptions=None, **kwargs):
super(OptionDisplay, self).__init__(*args, **kwargs)
self.descriptions = descriptions
def updateDescription(self, index):
self.values = [": ".join(d) for d in self.descriptions[index]["Details"]]
# Pad list of values with empty entries between real entries
self.values = [self.values[int(i/2)] if i%2==0 else '' for i in range(len(self.values)*2-1)]
self.entry_widget.setValuesWrap(list(self.values))
class NewCharSubRace(npyscreen.FormBaseNew):
def create(self):
race_index = charSheet.getCharSheet().raceIndex
subraces = [subrace["Name"] for subrace in race_descriptions[race_index]["Subraces"]]
self.pRace = self.add(OptionSelector, name="Race", values=subraces, rely=3, relx=5, max_width=20)
self.pRace.setParent(self)
self.optionDisplay = self.add(OptionDisplay, descriptions=race_descriptions[race_index]["Subraces"], name="Details", autowrap=True, rely=2, relx=-60, contained_widget_arguments={'color': 'WARNING', 'widgets_inherit_color': True})
self.optionDisplay.updateDescription(0)
self.pRace.handlers.update({
curses.KEY_UP: self.updateDescription,
curses.KEY_DOWN: self.updateDescription,
curses.KEY_LEFT: self.updateDescription,
curses.KEY_RIGHT: self.updateDescription,
curses.ascii.TAB: self.updateDescription
})
def updateDescription(self, key):
if key in [curses.KEY_UP, curses.KEY_LEFT]:
self.pRace.h_cursor_line_up(key)
elif key in [curses.KEY_DOWN, curses.KEY_RIGHT]:
self.pRace.h_cursor_line_down(key)
self.optionDisplay.updateDescription(self.pRace.cursor_line)
self.optionDisplay.display()
def nextForm(self, index):
charSheet.getCharSheet().subraceIndex = index
change_to = "NEW_CHAR_CLASS"
self.parentApp.change_form(change_to)
class NewCharDraconicAncestry(npyscreen.FormBaseNew):
def create(self):
#subraces = [subrace["Name"] for subrace in race_descriptions[race_index]["Subraces"]]
#self.pRace = self.add(OptionSelector, name="Race", values=subraces, rely=3, relx=5, max_width=20)
#self.pRace.setParent(self)
ancestries = race_descriptions[race_index]["Draconic Ancestry"]
ancestries = [[s.ljust(20, " ") for s in row] for row in ancestries]
ancestries = ["".join(row) for row in ancestries]
# Add padding line to separate header from content
ancestries[1:1] = ['-'*60]
self.table = self.add(npyscreen.MultiLineAction,
name = "Draconic Ancestries",
values = ancestries,
relx = 5, rely = 3
)
self.table.cursor_line = 2
self.table.handlers.update({
curses.KEY_UP: self.checkLine,
curses.KEY_LEFT: self.checkLine,
curses.ascii.NL: self.nextForm,
curses.ascii.CR: self.nextForm
})
def checkLine(self, key):
if self.table.cursor_line > 2:
self.table.h_cursor_line_up(key)
def nextForm(self, key):
charSheet.getCharSheet().draconicAncestryIndex = self.table.cursor_line - 1
change_to = "NEW_CHAR_CLASS"
self.parentApp.change_form(change_to)
class NewCharClass(npyscreen.FormBaseNew):
def create(self):
# TODO: Menu select
classes = [cls["Name"] for cls in class_descriptions]
self.pClass = self.add(OptionSelector, name="Race", values=classes, rely=3, relx=5, max_width=20)
self.pClass.setParent(self)
self.optionDisplay = self.add(OptionDisplay, descriptions=class_descriptions, name="Details", autowrap=True, rely=2, relx=-60, contained_widget_arguments={'color': 'WARNING', 'widgets_inherit_color': True})
self.optionDisplay.updateDescription(0)
self.pClass.handlers.update({
curses.KEY_UP: self.updateDescription,
curses.KEY_DOWN: self.updateDescription,
curses.KEY_LEFT: self.updateDescription,
curses.KEY_RIGHT: self.updateDescription,
curses.ascii.TAB: self.updateDescription
})
def updateDescription(self, key):
if key in [curses.KEY_UP, curses.KEY_LEFT]:
self.pClass.h_cursor_line_up(key)
elif key in [curses.KEY_DOWN, curses.KEY_RIGHT]:
self.pClass.h_cursor_line_down(key)
self.optionDisplay.updateDescription(self.pClass.cursor_line)
self.optionDisplay.display()
self.parentApp.setNextForm("NEW_CHAR_STATS")
def nextForm(self, index):
charSheet.getCharSheet().classIndex = index
change_to = "NEW_CHAR_STATS"
self.parentApp.change_form(change_to)
class NewCharStats(npyscreen.Form):
def create(self):
relx = 5
rely = 3
self.strField = self.add(npyscreen.TitleText, name='STR', value='10', field_width=20, relx=relx, rely=rely)
self.dexField = self.add(npyscreen.TitleText, name='DEX', value='10', field_width=20, relx=relx)
self.conField = self.add(npyscreen.TitleText, name='CON', value='10', field_width=20, relx=relx)
self.intField = self.add(npyscreen.TitleText, name='INT', value='10', field_width=20, relx=relx)
self.wisField = self.add(npyscreen.TitleText, name='WIS', value='10', field_width=20, relx=relx)
self.chaField = self.add(npyscreen.TitleText, name='CHA', value='10', field_width=20, relx=relx)
def afterEditing(self):
charSheet.getCharSheet().setStats(newStats = {
'STR': self.strField.value,
'DEX': self.dexField.value,
'CON': self.conField.value,
'INT': self.intField.value,
'WIS': self.wisField.value,
'CHA': self.chaField.value
})
self.parentApp.setNextForm("NEW_CHAR_BACKGROUND")
class NewCharBackground(npyscreen.FormBaseNew):
def create(self):
relx = 5
rely = 3
backgrounds = [background["Name"] for background in background_descriptions]
self.pBackgrounds = self.add(OptionSelector, name="Background", values=backgrounds, rely=3, relx=5, max_width=20)
self.pBackgrounds.setParent(self)
self.optionDisplay = self.add(OptionDisplay, descriptions=background_descriptions, name="Details", autowrap=True, rely=2, relx=-60, contained_widget_arguments={'color': 'WARNING', 'widgets_inherit_color': True})
self.optionDisplay.updateDescription(0)
self.pBackgrounds.handlers.update({
curses.KEY_UP: self.updateDescription,
curses.KEY_DOWN: self.updateDescription,
curses.KEY_LEFT: self.updateDescription,
curses.KEY_RIGHT: self.updateDescription,
curses.ascii.TAB: self.updateDescription
})
def updateDescription(self, key):
if key in [curses.KEY_UP, curses.KEY_LEFT]:
self.pBackgrounds.h_cursor_line_up(key)
elif key in [curses.KEY_DOWN, curses.KEY_RIGHT]:
self.pBackgrounds.h_cursor_line_down(key)
self.optionDisplay.updateDescription(self.pBackgrounds.cursor_line)
self.optionDisplay.display()
def nextForm(self, index):
charSheet.getCharSheet().backgroundIndex = index
change_to = None
self.parentApp.change_form(change_to)