Skip to content

Tairitsu.PopUpBox

Pop-up box in the game.

PopUpBox

Classes

BattleBox

BattleBox(window: pygame.surface.Surface, player, monster, fontSize: int = BattleSettings.textSize, fontColor: Tuple[int, int, int] = (255, 255, 255), bgColor: Tuple[int, int, int, int] = (0, 0, 0, 200))
Source code in Tairitsu/PopUpBox.py
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
def __init__(self, window: pygame.surface.Surface, player, monster, fontSize: int = BattleSettings.textSize, 
             fontColor: Tuple[int, int, int] = (255, 255, 255), bgColor: Tuple[int, int, int, int] = (0, 0, 0, 200)) :
    # 初始化窗口和字体
    self.window = window
    # print(type(window))

    self.fontSize = fontSize
    self.fontColor = fontColor
    self.font = pygame.font.Font(GlobalSettings.fontPath, self.fontSize)

    self.bg = pygame.Surface((BattleSettings.boxWidth,
        BattleSettings.boxHeight), pygame.SRCALPHA)
    self.bg.fill(bgColor)

    self.target = pygame.image.load(GamePath.battle["Target"])
    self.choice = [pygame.image.load(path) for path in GamePath.battle["Choice"]]
    self.choiceIndex = 0
    self.choiceRect = self.choice[self.choiceIndex].get_rect()
    self.choice_reset()

    # 初始化相关角色的参数,没有实际操作的权力
    self.player = player
    self.playerHP = player.HP
    self.playerImg = pygame.transform.scale(player.image, 
        (BattleSettings.playerWidth, BattleSettings.playerHeight))

    self.playerX = BattleSettings.playerCoordX
    self.playerY = BattleSettings.playerCoordY

    self.monster = monster
    self.monsterHP = monster.HP
    self.monsterImg = pygame.transform.scale(monster.image, 
        (BattleSettings.monsterWidth, BattleSettings.monsterHeight))

    self.monsterX = BattleSettings.monsterCoordX
    self.monsterY = BattleSettings.monsterCoordY

    self.strikeBox = pygame.image.load(GamePath.battle["Strike"][0])
    self.strikeIndex = -1

    # 默认玩家先手

    self.attacker = 0

    # 区分放动画状态和攻击结算状态

    self.isPlayingAnimation = True
    self.currentAnimationCount = 0
    self.waitingTrigger = True
    self.isChoicing = True

    # 移动方向

    self.dir = 1

    # 是否结束

    self.isFinished = False
    self.BgmPlayer = BgmPlayer()
    self.BgmPlayer.play(GamePath.bgm["BOSS"])
Attributes
BgmPlayer instance-attribute
BgmPlayer = BgmPlayer()
attacker instance-attribute
attacker = 0
bg instance-attribute
bg = pygame.Surface((BattleSettings.boxWidth, BattleSettings.boxHeight), pygame.SRCALPHA)
choice instance-attribute
choice = [pygame.image.load(path) for path in GamePath.battle['Choice']]
choiceIndex instance-attribute
choiceIndex = 0
choiceRect instance-attribute
choiceRect = self.choice[self.choiceIndex].get_rect()
currentAnimationCount instance-attribute
currentAnimationCount = 0
dir instance-attribute
dir = 1
font instance-attribute
font = pygame.font.Font(GlobalSettings.fontPath, self.fontSize)
fontColor instance-attribute
fontColor = fontColor
fontSize instance-attribute
fontSize = fontSize
isChoicing instance-attribute
isChoicing = True
isFinished instance-attribute
isFinished = False
isPlayingAnimation instance-attribute
isPlayingAnimation = True
monster instance-attribute
monster = monster
monsterHP instance-attribute
monsterHP = monster.HP
monsterImg instance-attribute
monsterImg = pygame.transform.scale(monster.image, (BattleSettings.monsterWidth, BattleSettings.monsterHeight))
monsterX instance-attribute
monsterX = BattleSettings.monsterCoordX
monsterY instance-attribute
monsterY = BattleSettings.monsterCoordY
player instance-attribute
player = player
playerHP instance-attribute
playerHP = player.HP
playerImg instance-attribute
playerImg = pygame.transform.scale(player.image, (BattleSettings.playerWidth, BattleSettings.playerHeight))
playerX instance-attribute
playerX = BattleSettings.playerCoordX
playerY instance-attribute
playerY = BattleSettings.playerCoordY
strikeBox instance-attribute
strikeBox = pygame.image.load(GamePath.battle['Strike'][0])
strikeIndex instance-attribute
strikeIndex = -1
target instance-attribute
target = pygame.image.load(GamePath.battle['Target'])
waitingTrigger instance-attribute
waitingTrigger = True
window instance-attribute
window = window
Functions
choice_reset
choice_reset()
Source code in Tairitsu/PopUpBox.py
228
229
230
231
def choice_reset(self):
    self.choiceRect.topleft = (WindowSettings.width // 2 - self.choiceRect.width // 2,
                               WindowSettings.height - self.choiceRect.height - 120)
    self.choiceDir = 1
draw
draw()
Source code in Tairitsu/PopUpBox.py
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
def draw(self):
    # 绘制背景和文字
    if(self.player.HP == 0): return

    self.window.blit(self.bg, (BattleSettings.boxStartX,
                               BattleSettings.boxStartY))
    self.window.blit(self.playerImg, (self.playerX,
                                      self.playerY))
    self.window.blit(self.monsterImg, (self.monsterX,
                                       self.monsterY))
    self.window.blit(self.target, (WindowSettings.width // 2 - self.target.get_rect().width // 2,
                                   WindowSettings.height - self.target.get_rect().height - 120))
    self.window.blit(self.choice[self.choiceIndex], self.choiceRect)

    text = "player HP: " + str(self.playerHP)
    self.window.blit(self.font.render(text, True, self.fontColor),
    (BattleSettings.textPlayerStartX, BattleSettings.textStartY))

    text = "monster HP: " + str(self.monsterHP)
    width, _ = self.font.size(text)

    self.window.blit(self.font.render(text, True, self.fontColor),
    (BattleSettings.textMonsterEndX - width, BattleSettings.textStartY))

    # 绘制战斗过程
    if self.waitingTrigger:
        if self.isChoicing:
            self.choiceRect.left = self.choiceRect.left + self.choiceDir * BattleSettings.choiceSpeed
            if(abs(self.choiceRect.left - WindowSettings.width // 2) > self.target.get_rect().width // 2):
                self.choiceDir = -self.choiceDir
        else:
            self.waitingTrigger = False
    else:
        if self.isPlayingAnimation:
            if self.attacker == 1:
                if self.currentAnimationCount < BattleSettings.animationCount:
                    currentDir = self.dir
                else:
                    currentDir = self.dir * -1

                self.monsterX += currentDir * BattleSettings.stepSpeed

                self.currentAnimationCount += 1

                if(currentDir == 1):
                    self.playerX = BattleSettings.playerCoordX + randint(-10, 10)
                    self.playerY = BattleSettings.playerCoordY + randint(-10, 10)

                if(self.currentAnimationCount == BattleSettings.animationCount):
                    SoundFX(GamePath.sound["Damaged"])

                if self.currentAnimationCount == BattleSettings.animationCount * 2:
                    self.isPlayingAnimation = False
                    self.currentAnimationCount = 0
                    self.playerX = BattleSettings.playerCoordX
                    self.playerY = BattleSettings.playerCoordY
            else:
                if self.currentAnimationCount < BattleSettings.animationCount:
                    self.currentAnimationCount += 1
                else:
                    self.isPlayingAnimation = False
                    self.currentAnimationCount = 0
                self.strikeIndex = self.currentAnimationCount // 3
                self.strikeBox = pygame.transform.scale(
                    pygame.image.load(GamePath.battle["Strike"][self.strikeIndex]),
                    (BattleSettings.monsterWidth // 3, BattleSettings.monsterHeight)
                )
                self.window.blit(self.strikeBox, (self.monsterX + 80, self.monsterY))

        # 战斗判定以及结算

        elif not self.isFinished:
            self.get_result()

    if self.playerHP == 0 or self.monsterHP == 0:
        if self.monsterHP == 0:
            text = f"You won!"
            self.player.coin += self.monster.coin
            self.monster.coin = 0
            self.window.blit(self.font.render(text, True, self.fontColor),
                    (BattleSettings.textStartX, 
                     BattleSettings.textStartY - BattleSettings.textVerticalDist))
            self.monster.kill()
        else:
            text = f"You lost!"
            self.window.blit(self.font.render(text, True, self.fontColor),
                    (BattleSettings.textStartX, 
                     BattleSettings.textStartY - BattleSettings.textVerticalDist))
            self.player.kill()
            self.monster.kill()
            self.player.rect.topleft = (0,0)
            self.player.HP = 0

        self.isFinished = True
        self.isPlayingAnimation = False
        self.BgmPlayer.stop()
get_result
get_result()
Source code in Tairitsu/PopUpBox.py
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
def get_result(self):
    if self.attacker == 0:
        index = 0
        if(abs(self.choiceRect.centerx - WindowSettings.width // 2) < 36):
            pygame.display.set_caption("Perfect")
            index = 1
        elif(abs(self.choiceRect.centerx - WindowSettings.width // 2) < 106):
            pygame.display.set_caption("Good")
            index = 0.6
        else:
            pygame.display.set_caption("Bad")
            index = 0.2
        self.monsterHP = max(0, self.monsterHP - 
                             max(0, (int)(self.player.attack * index - self.monster.defence)))

        SoundFX(GamePath.sound["Fight"])
        self.attacker = 1
        self.dir = -1
    else:
        self.playerHP = max(0, self.playerHP - 
                             max(0, self.monster.attack - self.player.defence))
        self.attacker = 0
        self.dir = 1


    self.isPlayingAnimation = True
    self.isChoicing = (self.attacker == 0)
    self.waitingTrigger = True
    self.choice_reset()

DialogBox

DialogBox(window, npc: str, name: str, texts: list, talkType: TalkType, fps: int = 30, fontSize: int = DialogSettings.textSize, fontColor: Tuple[int, int, int] = (255, 255, 255), bgColor: Tuple[int, int, int, int] = (0, 0, 0, 255))

Dialog Box with npc showed on the left bottom side of the window

Initialize the Dialog Box

:param window: pygame.Surface :param npc: str, Path to the resource of npc :param texts: list, list of text :param fps: int, fps of the animation :param talkType: TalkType, type of the dialog :param fontSize: int :param fontColor: Tuple[int, int, int] :param bgColor: Tuple[int, int, int, int]

Source code in Tairitsu/PopUpBox.py
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
def __init__(self, window, npc: str, name: str, texts: list, talkType: TalkType, fps: int = 30,
             fontSize: int = DialogSettings.textSize, 
             fontColor: Tuple[int, int, int] = (255, 255, 255), 
             bgColor: Tuple[int, int, int, int] = (0, 0, 0, 255)):
    """
    Initialize the Dialog Box

    :param window: pygame.Surface
    :param npc: str, Path to the resource of npc
    :param texts: list, list of text
    :param fps: int, fps of the animation
    :param talkType: TalkType, type of the dialog
    :param fontSize: int
    :param fontColor: Tuple[int, int, int]
    :param bgColor: Tuple[int, int, int, int]
    """

    self.window = window
    self.texts = texts
    self.fps = fps
    self.talkType = talkType
    self.name = name

    self.fontd = fontSize
    self.fontColor = fontColor
    # self.font = pygame.font.Font(None, self.fontSize)
    self.font = pygame.font.Font(GlobalSettings.fontPath, fontSize)
    # self.font.set_bold(True)

    self.bg = pygame.Surface((DialogSettings.boxWidth,
        DialogSettings.boxHeight), pygame.SRCALPHA)
    self.bg.fill(bgColor)

    self.npc = pygame.image.load(npc)
    self.npc = pygame.transform.scale(self.npc, (DialogSettings.npcWidth,
                                DialogSettings.npcHeight))
Attributes
bg instance-attribute
bg = pygame.Surface((DialogSettings.boxWidth, DialogSettings.boxHeight), pygame.SRCALPHA)
font instance-attribute
font = pygame.font.Font(GlobalSettings.fontPath, fontSize)
fontColor instance-attribute
fontColor = fontColor
fontd instance-attribute
fontd = fontSize
fps instance-attribute
fps = fps
name instance-attribute
name = name
npc instance-attribute
npc = pygame.transform.scale(self.npc, (DialogSettings.npcWidth, DialogSettings.npcHeight))
talkType instance-attribute
talkType = talkType
texts instance-attribute
texts = texts
window instance-attribute
window = window
Functions
draw
draw()
Source code in Tairitsu/PopUpBox.py
 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
def draw(self):
    if(self.talkType == TalkType.ENDED):
        self.fps = -1
    self.window.blit(self.bg, (DialogSettings.boxStartX,
        DialogSettings.boxStartY))
    self.window.blit(self.npc, (DialogSettings.npcCoordX,
        DialogSettings.npcCoordY))
    self.window.blit(self.font.render(self.name, True,
                self.fontColor), (DialogSettings.npcCoordX,
                DialogSettings.npcCoordY - DialogSettings.textVerticalDist * 1.5))

    offset = 0
    clock = pygame.time.Clock()
    self.talkType = TalkType.TALKING
    for text in self.texts:
        # self.window.blit(self.font
        # .render(text,
        #     True, self.fontColor),
        #     (DialogSettings.textStartX, DialogSettings.textStartY + offset))
        # offset += DialogSettings.textVerticalDist * 1.5

        # Initialize the offset and height offset
        hoffset = 0
        _, text_height = self.font.size(text)
        # print("Start at" + str(star) , text)
        if((offset + text_height > DialogSettings.boxHeight * 0.95) and text != ""):
            offset = 0
            # clock.tick(1)
            # self.talkType = TalkType.WAITING
            # flag = True
            # while flag:
            #     # clock.tick(30)
            #     for event in pygame.event.get():
            #         if event.type == pygame.QUIT:
            #             running = False
            #         elif event.type == pygame.KEYDOWN:
            #             flag = False
            #             self.window.blit(self.bg, (DialogSettings.boxStartX,
            #                 DialogSettings.boxStartY))
            #             break
            # self.talkType = TalkType.TALKING

        # Start to talk by word
        # if(text == "\n"): continue
        for word in text:
            word_width, _ = self.font.size(word)
            if(word_width + hoffset > DialogSettings.boxWidth * 0.95):
                offset += DialogSettings.textVerticalDist * 0.9
                hoffset = 0
            self.window.blit(self.font.render(word, True,
                self.fontColor), (DialogSettings.textStartX + hoffset,
                DialogSettings.textStartY + offset))
            hoffset += word_width

            if(self.talkType == TalkType.TALKING and self.fps != -1):
                pygame.display.flip()
                SoundFX(GamePath.sound["Speak"])
                clock.tick(30)

        offset += DialogSettings.textVerticalDist * 0.9

    self.talkType = TalkType.ENDED

InfoBox

InfoBox(info: str, duration: int, x: int = WindowSettings.width // 2, y: int = WindowSettings.height // 3, fontSize: int = DialogSettings.textSize, fontColor: Tuple[int, int, int] = (255, 255, 255), bgColor: Tuple[int, int, int, int] = (0, 0, 0, 255))
Source code in Tairitsu/PopUpBox.py
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
def __init__(self, info: str, duration: int, 
             x: int = WindowSettings.width // 2, 
             y: int = WindowSettings.height // 3,
             fontSize: int = DialogSettings.textSize, 
             fontColor: Tuple[int, int, int] = (255, 255, 255), 
             bgColor: Tuple[int, int, int, int] = (0, 0, 0, 255)):
    self.info = info
    self.duration = duration
    self.count = 0
    # UNIX timestamp
    self.start = time.time()
    self.end = self.start + duration

    self.x = x
    self.y = y

    self.fontd = fontSize
    self.fontColor = fontColor
    # self.font = pygame.font.Font(None, self.fontSize)
    self.font = pygame.font.Font(GlobalSettings.fontPath, fontSize)
    # self.font.set_bold(True)

    self.bg = pygame.Surface((DialogSettings.boxWidth,
        DialogSettings.boxHeight), pygame.SRCALPHA)
    self.bg.fill(bgColor)
Attributes
bg instance-attribute
bg = pygame.Surface((DialogSettings.boxWidth, DialogSettings.boxHeight), pygame.SRCALPHA)
count instance-attribute
count = 0
duration instance-attribute
duration = duration
end instance-attribute
end = self.start + duration
font instance-attribute
font = pygame.font.Font(GlobalSettings.fontPath, fontSize)
fontColor instance-attribute
fontColor = fontColor
fontd instance-attribute
fontd = fontSize
info instance-attribute
info = info
start instance-attribute
start = time.time()
x instance-attribute
x = x
y instance-attribute
y = y
Functions
draw
draw(window: pygame.surface.Surface)
Source code in Tairitsu/PopUpBox.py
147
148
149
150
151
152
153
154
155
156
157
158
def draw(self, window: pygame.surface.Surface, ):
    if(time.time() > self.end):
        return
    else:
        width, height = self.font.size(self.info)
        window.blit(self.font.render(self.info, True,
                self.fontColor), 
                (
                    self.x - width // 2,
                    self.y - height // 2
                    )
                )

MenuBox

MenuBox(window: pygame.surface.Surface, fontSize: int = BattleSettings.textSize, fontColor: Tuple[int, int, int] = (255, 255, 255), bgColor: Tuple[int, int, int, int] = (61, 89, 171, 20), textVerticalDist: int = DialogSettings.menuVerticalDist, items: dict = {}, actions: list = [])
Source code in Tairitsu/PopUpBox.py
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
def __init__(self, window: pygame.surface.Surface,
             fontSize: int = BattleSettings.textSize, 
             fontColor: Tuple[int, int, int] = (255, 255, 255),
             bgColor: Tuple[int, int, int, int] = (61, 89, 171, 20),
             textVerticalDist: int = DialogSettings.menuVerticalDist,
             items: dict = {},
             actions: list = [],):

    self.window = window 
    self.fontSize = fontSize
    self.fontColor = fontColor
    self.font = pygame.font.Font(GlobalSettings.fontPath, self.fontSize)
    self.textVerticalDist = textVerticalDist

    self.bg = pygame.Surface((MainmenuSettings.boxWidth, 
                              MainmenuSettings.boxHeight),pygame.SRCALPHA)
    self.bg.fill(bgColor)
    self.selectedID = 0
    self.items = items
    self.selectRect = pygame.Surface((MainmenuSettings.boxWidth, 
                                      MainmenuSettings.boxHeight // 4),
                                     pygame.SRCALPHA)
    self.selectRect.fill((255, 255, 255, 100))
    self.selectRect_rect = self.selectRect.get_rect()
    self.selectRect_rect.topleft = (100, 100)

    self.actions = actions
Attributes
actions instance-attribute
actions = actions
bg instance-attribute
bg = pygame.Surface((MainmenuSettings.boxWidth, MainmenuSettings.boxHeight), pygame.SRCALPHA)
font instance-attribute
font = pygame.font.Font(GlobalSettings.fontPath, self.fontSize)
fontColor instance-attribute
fontColor = fontColor
fontSize instance-attribute
fontSize = fontSize
items instance-attribute
items = items
selectRect instance-attribute
selectRect = pygame.Surface((MainmenuSettings.boxWidth, MainmenuSettings.boxHeight // 4), pygame.SRCALPHA)
selectRect_rect instance-attribute
selectRect_rect = self.selectRect.get_rect()
selectedID instance-attribute
selectedID = 0
textVerticalDist instance-attribute
textVerticalDist = textVerticalDist
window instance-attribute
window = window
Functions
down
down()
Source code in Tairitsu/PopUpBox.py
484
485
486
def down(self):
    self.selectedID = min(len(self.items) - 1, self.selectedID + 1)
    SoundFX(GamePath.sound["MenuCursor"])
draw
draw()
Source code in Tairitsu/PopUpBox.py
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
def draw(self):
    self.window.blit(self.bg, 
        (MainmenuSettings.boxStartX, MainmenuSettings.boxStartY))

    offset = 0
    for id, item in enumerate(list(self.items.keys())):
        if id == self.selectedID:
            text = item + ' ' + self.items[item]
            width, height = self.font.size(text)
            delta_width = self.selectRect.get_rect().width - width
            delta_height = self.selectRect.get_rect().height - height
            self.selectRect = pygame.transform.scale(self.selectRect,
                                                      (width + math.ceil(delta_width / 2),
                                                       height + math.ceil(delta_height / 2)))
            top, left = (MainmenuSettings.textStartX, MainmenuSettings.textStartY + offset)
            delta_top, delta_left = (top - self.selectRect_rect.topleft[0],
                                     left - self.selectRect_rect.topleft[1])
            self.selectRect_rect = self.selectRect_rect.move(delta_top // 2, delta_left // 2)

            self.window.blit(self.selectRect, self.selectRect_rect)
        else:
            text = item + ' ' + self.items[item]
        self.window.blit(self.font.render(text, True, self.fontColor),
            (MainmenuSettings.textStartX, MainmenuSettings.textStartY + offset))
        offset += self.textVerticalDist
select
select(query: str | int = 0)
Source code in Tairitsu/PopUpBox.py
488
489
def select(self, query: str | int = 0):
    SoundFX(GamePath.sound["MenuSelect"])
up
up()
Source code in Tairitsu/PopUpBox.py
480
481
482
def up(self):
    self.selectedID = max(0, self.selectedID - 1)
    SoundFX(GamePath.sound["MenuCursor"])

ShoppingBox

ShoppingBox(window: pygame.surface.Surface, npc, name: str, player: Player, fontSize: int = DialogSettings.textSize, fontColor: Tuple[int, int, int] = (255, 255, 255), bgColor: Tuple[int, int, int, int] = (0, 0, 0, 150), items: dict = {}, actions: list[dict] = [])
Source code in Tairitsu/PopUpBox.py
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
def __init__(self, window: pygame.surface.Surface, npc, name: str, player: Player,
             fontSize: int = DialogSettings.textSize, 
             fontColor: Tuple[int, int, int] = (255, 255, 255), 
             bgColor: Tuple[int, int, int, int] = (0, 0, 0, 150),
             items: dict = {},
             actions: list[dict] = []):

    self.window = window
    self.fontSize = fontSize
    self.fontColor = fontColor
    self.name = name
    self.font = pygame.font.Font(GlobalSettings.fontPath, self.fontSize)

    self.bgcolor = bgColor
    self.bg = pygame.Surface((ShopSettings.boxWidth, 
                              ShopSettings.boxHeight),pygame.SRCALPHA)
    self.bg.fill(bgColor)

    self.npc = pygame.image.load(npc)
    self.npc = pygame.transform.scale(self.npc,
            (DialogSettings.npcWidth, DialogSettings.npcHeight))

    self.player = player
    self.items = items
    # self.fps = WindowSettings.fps/2
    # self.clock.tick
    self.selectedID = 0

    self.selectRect = pygame.Surface((MainmenuSettings.boxWidth, 
                                      MainmenuSettings.boxHeight // 4),
                                     pygame.SRCALPHA)
    self.selectRect.fill((255, 255, 255, 100))
    self.selectRect_rect = self.selectRect.get_rect()
    self.selectRect_rect.topleft = (100, 100)
    self.actions = actions
Attributes
actions instance-attribute
actions = actions
bg instance-attribute
bg = pygame.Surface((ShopSettings.boxWidth, ShopSettings.boxHeight), pygame.SRCALPHA)
bgcolor instance-attribute
bgcolor = bgColor
font instance-attribute
font = pygame.font.Font(GlobalSettings.fontPath, self.fontSize)
fontColor instance-attribute
fontColor = fontColor
fontSize instance-attribute
fontSize = fontSize
items instance-attribute
items = items
name instance-attribute
name = name
npc instance-attribute
npc = pygame.transform.scale(self.npc, (DialogSettings.npcWidth, DialogSettings.npcHeight))
player instance-attribute
player = player
selectRect instance-attribute
selectRect = pygame.Surface((MainmenuSettings.boxWidth, MainmenuSettings.boxHeight // 4), pygame.SRCALPHA)
selectRect_rect instance-attribute
selectRect_rect = self.selectRect.get_rect()
selectedID instance-attribute
selectedID = 0
window instance-attribute
window = window
Functions
buy
buy()
Source code in Tairitsu/PopUpBox.py
400
401
def buy(self):
    self.player.attr_update(**self.actions[self.selectedID])
draw
draw()
Source code in Tairitsu/PopUpBox.py
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
def draw(self):
    self.window.blit(self.font.render(self.name, True, self.fontColor), 
        (ShopSettings.boxStartX, ShopSettings.boxStartY - DialogSettings.textVerticalDist))
    self.window.blit(self.bg, 
        (ShopSettings.boxStartX, ShopSettings.boxStartY))
    self.window.blit(self.npc,
        (DialogSettings.npcCoordX, DialogSettings.npcCoordY))

    offset = 0
    for id, item in enumerate(list(self.items.keys())):
        if id == self.selectedID:
            text = '●' + item + ' ' + self.items[item]
            width, height = self.font.size(text)
            delta_width = self.selectRect.get_rect().width - width
            delta_height = self.selectRect.get_rect().height - height
            self.selectRect = pygame.transform.scale(self.selectRect,
                                                      (width + math.ceil(delta_width / 2),
                                                       height + math.ceil(delta_height / 2)))
            top, left = (ShopSettings.textStartX, ShopSettings.textStartY + offset)
            delta_top, delta_left = (top - self.selectRect_rect.topleft[0],
                                     left - self.selectRect_rect.topleft[1])
            self.selectRect_rect = self.selectRect_rect.move(delta_top // 2, delta_left // 2)

            self.window.blit(self.selectRect, self.selectRect_rect)
        else:
            text = '○' + item + ' ' + self.items[item]
        self.window.blit(self.font.render(text, True, self.fontColor),
            (ShopSettings.textStartX, ShopSettings.textStartY + offset))
        offset += DialogSettings.textVerticalDist
    if(offset > self.bg.get_rect()[1]):
        self.bg = pygame.transform.scale(self.bg, (self.bg.get_rect().width, offset + 50))
        self.bg.fill(self.bgcolor)


    texts = ["Coins: " + str(self.player.coin),
             "HP: " + str(self.player.HP),
             "Attack: " + str(self.player.attack),
             "Defence: " + str(self.player.defence)]

    offset = 0
    for lines in texts:
        self.window.blit(self.font.render(lines, True, self.fontColor),
            (ShopSettings.textStartX + WindowSettings.width // 5 * 2, ShopSettings.textStartY + offset))
        offset += DialogSettings.textVerticalDist