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
|
from abc import get_cache_token
from regex import D
from Function.WorldCoords import getWorldCoords
from Setup import *
from CommonImports.colours import white, black
from Function.createText import createText
from datetime import datetime, timedelta
class DialogueUI:
def __init__(self):
self.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet commodo leo."
self.old_text = ""
self.char = 0
self.IDS = [0]
self.dialogue_list = []
self.PSA = 0
self.lastTextTime = datetime.utcnow()
self.skip = False
self.texts = []
self.drawText = []
def update(self):
return;
def draw(self, surf, agent, text, sec, ID, Xt=-10000, Yt=-10000):
if(not ID in self.IDS):
temp = []
self.PSA += sec
temp.append(text)
temp.append(self.PSA)
temp.append(agent)
temp.append(Xt == -10000 and Yt == -10000)
self.IDS.append(ID)
self.dialogue_list.append(temp)
try:
X, Y = 0, 0
try:
if(self.dialogue_list[self.char][3] == True):
X = get_display_point(self.dialogue_list[self.char][2].position)[0] + self.dialogue_list[self.char][2].width / 2
Y = get_display_point(self.dialogue_list[self.char][2].position)[1]
else:
X, Y = get_display_point((self.dialogue_list[self.char][2][0], self.dialogue_list[self.char][2][1]))
# print(get_display_point((X, Y)))
# print(get_camera_offset()[0] + SCREEN_WIDTH/2, get_camera_offset()[1] + SCREEN_HEIGHT/2)
except:
pass;
try:
if(ID == 0):
self.text = text
X, Y = get_display_point((Xt, Yt))
else:
self.text = self.dialogue_list[self.char][0]
except:
pass;
self.checkTime()
self.createDialogue()
for i in range(len(self.drawText)):
j = len(self.drawText) - i
text_rect = self.drawText[i].get_rect(center=(X, Y-(20*j)))
surf.blit(self.drawText[i], text_rect)
except:
pass;
def createDialogue(self):
if(self.text == self.old_text):
self.skip == True
else:
self.old_text == self.text
self.texts = []
self.drawText = []
self.skip == False
if(self.skip == False):
iii = 0
while iii < len(self.text):
n = 30
if iii+n < len(self.text):
self.texts.append(self.text[iii:iii+n])
else:
self.texts.append(self.text[iii:len(self.text)])
iii += n
for i in range(len(self.texts) - 1):
text = self.texts[i].split(" ")[-1]
self.texts[i+1] = self.texts[i][len(self.texts[i]) - len(text):] + self.texts[i+1]
self.texts[i] = self.texts[i][:len(self.texts[i]) - len(text) - 1]
for i in range(len(self.texts)):
self.drawText.append(createText(0, 0, 20, white, "Regular", self.texts[i])[0])
return;
def checkTime(self):
try:
if(datetime.utcnow() - self.lastTextTime >= timedelta(seconds=self.dialogue_list[self.char][1])):
if(self.char +1 < len(self.dialogue_list)):
self.char = self.char + 1
else:
self.char = 0
self.dialogue_list = []
except:
pass;
|