/
launch.py
279 lines (248 loc) · 11.4 KB
/
launch.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
from PyQt4 import QtCore, QtGui
import sys
from time import strftime
from lib import resources_rc
from lib.main_window_ui import Ui_MainWindow
from lib.host_window_ui import Ui_host_window
from lib.connect_window_ui import Ui_connect_window
from lib.options_add_monster_ui import Ui_monsters_options
from lib.functions import *
log_out = open("stdout.log", "a")
log_out.write("\n--------------\n{0}\n--------------\n".format(strftime("%A %d %B %Y %H:%M:%S")))
sys.stderr = log_out
print = log
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class main_window(Ui_MainWindow):
'''
This class inherits the Ui_Mainwindow class. The inheritance is
used to add bindings to launch the host/connect window dialog
'''
def __init__(self, MainWindow):
self.main_window = MainWindow
self.setupUi(self.main_window)
self.ui_connect = Ui_connect_window()
self.ui_add_monster = Ui_monsters_options()
self.main_window.resize(1280, 720)
self.dock_campain.hide()
self.dock_client.hide()
self.toolbox_hexa_tabs.hide()
self.actionHost_Game.triggered.connect(self.launch_host_game)
self.actionConnect_to.triggered.connect(self.launch_connect_window)
self.actionNew_Campain.triggered.connect(self.new_campain)
self.actionAdd_Monsters.triggered.connect(self.add_monsters)
self.button_rollatable.clicked.connect(self.set_encounter_table)
self.button_rollamonster.clicked.connect(self.set_monster_stats)
self.line_treasure_value.returnPressed.connect(self.set_treasure)
self.button_generate_npc.clicked.connect(self.set_npc)
self.button_clear_text.clicked.connect(self.clear_generated_npc)
self.button_disease_generate.clicked.connect(self.set_disease)
self.button_poison_generate.clicked.connect(self.set_poison)
self.list_of_encounters = ["_"]*12
self.treasure_value = self.line_treasure_value.text()
# slider for chance encounters on encounters tab
self.slider_value = 10
# hook up slider change to setter functions
self.slider_chanceofencounter.valueChanged[int].connect(self.changevalue)
def changevalue(self, value):
self.slider_value = value
def launch_host_game(self):
'''
This method will launch the host window as a dialog.
'''
host_dialog = QtGui.QDialog()
ui = Ui_host_window()
ui.setupUi(host_dialog)
host_dialog.exec_()
def new_campain(self):
self.dock_campain.hide()
self.display_disease.clear()
self.display_generated_npc.clear()
self.display_gems.clear()
self.display_jewels.clear()
self.display_magicitems.clear()
self.display_plant.clear()
self.display_poison.clear()
self.lineedit_numberofcoins_copper.clear()
self.lineedit_numberofcoins_silver.clear()
self.lineedit_numberofcoins_electrum.clear()
self.lineedit_numberofcoins_gold.clear()
self.lineedit_numberofcoins_platinum.clear()
self.label_nameofrolledmonster_1.setText("_")
self.label_nameofrolledmonster_2.setText("_")
self.label_nameofrolledmonster_3.setText("_")
self.label_nameofrolledmonster_4.setText("_")
self.label_nameofrolledmonster_5.setText("_")
self.label_nameofrolledmonster_6.setText("_")
self.label_nameofrolledmonster_7.setText("_")
self.label_nameofrolledmonster_8.setText("_")
self.label_nameofrolledmonster_9.setText("_")
self.label_nameofrolledmonster_10.setText("_")
self.label_nameofrolledmonster_11.setText("_")
self.label_nameofrolledmonster_12.setText("_")
self.dock_campain.show()
def launch_connect_window(self):
'''
This method will launch the connect window dialog
'''
connect_dialog = QtGui.QDialog()
self.ui_connect.setupUi(connect_dialog)
self.ui_connect.button_connect.clicked.connect(self.launch_dock_client)
connect_dialog.exec_()
if self.ui_connect.button_connect.isDown():
connect_dialog.close()
def launch_dock_client(self):
self.dock_client.show()
host_ip = self.ui_connect.line_host_ip.text()
port = self.ui_connect.line_port.text()
name = self.ui_connect.line_name.text()
def set_encounter_table(self):
environment = str(self.combo_environmentofencounter.currentText())
self.list_of_encounters = get_random_encounters_table(get_monster_dict_xml(),environment)
self.label_nameofrolledmonster_1.setText(self.list_of_encounters[0])
self.label_nameofrolledmonster_2.setText(self.list_of_encounters[1])
self.label_nameofrolledmonster_3.setText(self.list_of_encounters[2])
self.label_nameofrolledmonster_4.setText(self.list_of_encounters[3])
self.label_nameofrolledmonster_5.setText(self.list_of_encounters[4])
self.label_nameofrolledmonster_6.setText(self.list_of_encounters[5])
self.label_nameofrolledmonster_7.setText(self.list_of_encounters[6])
self.label_nameofrolledmonster_8.setText(self.list_of_encounters[7])
self.label_nameofrolledmonster_9.setText(self.list_of_encounters[8])
self.label_nameofrolledmonster_10.setText(self.list_of_encounters[9])
self.label_nameofrolledmonster_11.setText(self.list_of_encounters[10])
self.label_nameofrolledmonster_12.setText(self.list_of_encounters[11])
def set_monster_stats(self):
chance_of_encounter = self.slider_value
chosen_monster = get_a_monster(self.list_of_encounters, chance_of_encounter)
life, ac, movement, attacks, damages, number_met, save_poison, save_wands,\
save_paralysis, save_dragon, save_spells, moral, treasure, alignment,\
xp_value = get_a_monster_stats(get_monster_dict_xml(), chosen_monster)
self.group_statsofrolledmonster.setTitle("Stats of Rolled Monster : {0}".format(chosen_monster))
self.monster_ac_value.setText(ac)
self.monster_movement_value.setText(movement)
self.monster_attack_value.setText(attacks)
self.monster_damages_value.setText(damages)
self.monster_moral_value.setText(moral)
self.monster_treasure_value.setText(treasure)
self.monster_alignment_value.setText(alignment)
self.monster_xp_value.setText(xp_value)
self.monster_saves_poison_value.setText(save_poison)
self.monster_saves_wands_value.setText(save_wands)
self.monster_saves_paralysis_value.setText(save_paralysis)
self.monster_saves_dragonbreath_value.setText(save_dragon)
self.monster_saves_spells_value.setText(save_spells)
def set_treasure(self):
"""
This method sets up the generated treasure
"""
#Variables used
self.treasure_value = self.line_treasure_value.text()
has_gems = self.check_gems.isChecked()
has_jewels = self.check_jewels.isChecked()
has_magic = self.check_magic_items.isChecked()
gem_string = ""
jewel_string = ""
magic_string = ""
#try to convert to an int, if it is a string, returns 0 and doesn't generate a treasure
try:
treasure_value = int(self.treasure_value)
except ValueError:
self.line_treasure_value.setText("")
treasure_value = 0
pass
#generate treasure, returns a dict where keys are "pieces", "jewels", "gems", "magic_items"
treasure = get_treasure(treasure_value, has_magic, has_gems, has_jewels)
#formatting gems, magic items and jewels asserting we have all keys in the dict
try:
for gem_tuple in treasure["gems"]:
gem_string += "{0} : {1}\n".format(gem_tuple[0], gem_tuple[1])
for jewel_tuple in treasure["jewels"]:
jewel_string += "{0} : {1}\n".format(jewel_tuple[0], jewel_tuple[1])
for magic_item in treasure["magic_items"]:
magic_string += magic_item + "\n"
except KeyError:
if not has_gems:
gem_string = ""
if not has_jewels:
jewel_string = ""
if not has_magic:
magic_string = ""
#sets the text in the lineedits and plaintextviewers
self.display_gems.setPlainText(gem_string)
self.display_jewels.setPlainText(jewel_string)
self.display_magicitems.setPlainText(magic_string)
self.lineedit_numberofcoins_platinum.setText(str(treasure["pieces"][0]))
self.lineedit_numberofcoins_gold.setText(str(treasure["pieces"][1]))
self.lineedit_numberofcoins_electrum.setText(str(treasure["pieces"][2]))
self.lineedit_numberofcoins_silver.setText(str(treasure["pieces"][3]))
self.lineedit_numberofcoins_copper.setText(str(treasure["pieces"][4]))
pass
def set_npc(self):
"""
This method adds generated npcs
"""
print("set_npc")
alignment = str(self.combobox_alignmentofnpc.currentText())
print(alignment)
gender = str(self.combobox_genderofnpc.currentText())
print(gender)
race = str(self.combobox_raceofnpc.currentText())
print(race)
class_ = str(self.combobox_classofnpc.currentText())
print(class_)
stats = str(self.combobox_statsofnpc.currentText())
print(stats)
level = int(self.slider_levelofnpc.value())
print(level)
generated_npc = generate_npc(alignment, gender, race, class_, level, stats)
print(generated_npc)
self.display_generated_npc.append(generated_npc + "\n")
pass
def clear_generated_npc(self):
"""
This method clears the generated npcs
"""
self.display_generated_npc.clear()
pass
def set_disease(self):
"""
This method sets up the generated disease
"""
region = self.combobox_disease_region.currentText()
sequels = self.combobox_disease_sequels.currentText()
source = self.combobox_disease_source.currentText()
generated_disease = generate_disease(source, region, sequels)
self.display_disease.setText(generated_disease)
pass
def set_poison(self):
"""
This method sets up the generated poison
"""
type_ = self.combobox_poison_type.currentText()
category = self.combobox_poison_category.currentText()
price = self.lineedit_poison_price.text()
generated_poison = generate_poison(type_, category, price)
self.display_poison.setText(generated_poison)
pass
def add_monsters(self):
"""
This method will launch the add monsters window dialog
"""
add_monster_dialog = QtGui.QDialog()
self.ui_add_monster.setupUi(add_monster_dialog)
add_monster_dialog.exec_()
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = main_window(MainWindow)
MainWindow.show()
sys.exit(app.exec_())