dlg_pveFunc.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from game.ui.ui import UIInstance
  2. import pygame
  3. from game.file_loader.fileLoader import load_png
  4. from game.music import music_loader
  5. import game.const.game as G
  6. import game.const.window as W
  7. class DlgPveFunc(UIInstance):
  8. def __init__(self):
  9. super().__init__("game", "dlg_pveFuncRouge")
  10. self.rect.x = 619
  11. self.rect.y = 537 + G.H_INCREMENT
  12. self.exitBtn = ExitBtn()
  13. W,H = self.rect.size
  14. # 创建一个W+200,H 的surface
  15. self.imageNew = pygame.Surface((W+G.W_INCREMENT,H), pygame.SRCALPHA, 32)
  16. from game.level.level import current_level
  17. self.imageNew.fill((20, 174, 227, 255), (0, 3, W+G.W_INCREMENT, H))
  18. self.imageNew.fill((106,40,126, 255), (0, 3, W+G.W_INCREMENT, 3+H))
  19. #self.imageNew.fill((122, 211, 245, 255), (5, 3, 190, H))
  20. self.imageNew.blit(self.image, (G.W_INCREMENT,0))
  21. self.image = self.imageNew
  22. def update(self):
  23. super().update()
  24. self.exitBtn.update()
  25. def draw(self, screen: pygame.Surface):
  26. super().draw(screen)
  27. self.exitBtn.draw(screen)
  28. class ExitBtn(pygame.sprite.Sprite):
  29. def __init__(self):
  30. super().__init__()
  31. self.image_on = load_png("res/img/ui/common/btn_leave_0_2.png")
  32. self.image_down = load_png("res/img/ui/common/btn_leave_0_3.png")
  33. # 默认图片为空
  34. self.defaultImage = pygame.Surface((self.image_on.get_width(), self.image_on.get_height()), pygame.SRCALPHA, 32)
  35. self.rect = self.image_on.get_rect()
  36. self.rect.x = 732 + G.W_INCREMENT
  37. self.rect.y = 545 + G.H_INCREMENT
  38. self.mouseOn = False # 鼠标是否在按钮上
  39. self.mouseDown = False # 鼠标是否按下
  40. self.mouseUp = False # 鼠标是否抬起
  41. def update(self):
  42. mousePos = pygame.mouse.get_pos()
  43. mouseState = pygame.mouse.get_pressed()
  44. if self.rect.collidepoint(mousePos):
  45. self.mouseOn = True
  46. if mouseState[0]:
  47. self.mouseDown = True
  48. else:
  49. if self.mouseDown:
  50. self.mouseUp = True
  51. self.mouseDown = False
  52. else:
  53. self.mouseOn = False
  54. self.mouseDown = False
  55. if self.mouseOn:
  56. if self.mouseDown:
  57. self.image = self.image_down
  58. else:
  59. self.image = self.image_on
  60. else:
  61. self.image = self.defaultImage
  62. if self.mouseUp:
  63. self.mouseUp = False # 退出游戏
  64. # app_task = tk.Tk()
  65. # roguetest.App(app_task)
  66. W.PAGE = W.Page.HOME
  67. W.MENU.refresh()
  68. music_loader.play("rogue_menu.mp3", 0.7)
  69. # pygame.event.post(pygame.event.Event(pygame.QUIT))
  70. return True
  71. return False
  72. def draw(self, screen: pygame.Surface):
  73. screen.blit(self.image, self.rect)