district_overlay.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. """District boundaries, editable corners, NPC movement and scrollable controls."""
  2. import pygame
  3. import colorsys
  4. import copy
  5. from npc_preview import NpcPreview
  6. from const.window import WINDOW_W, TOOL_PANEL_WIDTH, MAP_AT, MAP_W, MAP_H, GAME_SQUARE
  7. class DistrictOverlay:
  8. COLORS = [(100, 200, 255), (255, 190, 85), (180, 140, 255), (100, 235, 155), (255, 130, 170)]
  9. TOP = 524
  10. PAGE_SIZE = 6
  11. def __init__(self, app):
  12. self.app = app
  13. self.enabled = False
  14. self.hidden = set()
  15. self.offset = 0
  16. self.expanded = set()
  17. self.editing = None
  18. self.moving_npc = None
  19. self.drag = None
  20. self.drag_before = None
  21. self.scroll_drag = False
  22. self.scroll_grab = 0
  23. self.create_mode = None
  24. self.create_start = None
  25. self.create_end = None
  26. self.render_models = False
  27. self.solo_npc = None
  28. self.models = NpcPreview(app)
  29. self.hidden_before_focus = None
  30. def toggle(self):
  31. self.enabled = not self.enabled
  32. if self.enabled:
  33. self.app.tools.visible = True
  34. self.app.tools.choose("paint")
  35. else:
  36. self.finish_drag()
  37. self.editing = self.moving_npc = None
  38. self.create_mode = self.create_start = self.create_end = None
  39. def toggle_models(self):
  40. if not self.enabled:
  41. self.toggle()
  42. self.render_models = not self.render_models
  43. self.solo_npc = None
  44. def focus_region(self, index):
  45. self.solo_npc = None
  46. self.finish_drag()
  47. closing = index in self.expanded
  48. if self.hidden_before_focus is not None:
  49. self.hidden = self.hidden_before_focus
  50. self.hidden_before_focus = None
  51. self.expanded = set() if closing else {index}
  52. if not closing:
  53. self.hidden_before_focus = set(self.hidden)
  54. self.hidden.discard(index)
  55. self.offset = 0
  56. self.editing = self.moving_npc = None
  57. self.create_mode = self.create_start = self.create_end = None
  58. self.app.selection.cancel()
  59. def add_rect(self):
  60. return pygame.Rect(WINDOW_W + 12, self.TOP + 326, TOOL_PANEL_WIDTH - 44, 20)
  61. def start_add(self):
  62. self.npc_template = None
  63. self.finish_drag()
  64. self.create_mode = ("npc", next(iter(self.expanded))) if self.expanded else ("region", None)
  65. self.create_start = self.create_end = None
  66. self.editing = self.moving_npc = None
  67. self.app.selection.cancel()
  68. self.app.menu.notify("点击地图放置怪物,然后输入名称" if self.expanded else "在地图拖动框选新区域;Esc 取消")
  69. def ask_name(self, initial=""):
  70. name = self.app.menu.dialog("askstring", title="怪物名称", prompt="输入 game/npc 中的怪物名称(不含 .json):", initialvalue=initial)
  71. if name is None:
  72. return None
  73. name = name.strip()
  74. if not name:
  75. self.app.menu.notify("名称不能为空,未修改")
  76. return None
  77. return name
  78. @staticmethod
  79. def copy_rect(rect):
  80. return pygame.Rect(rect.right - 188, rect.y + 8, 28, 28)
  81. def copy_npc(self, index, n):
  82. self.finish_drag()
  83. self.npc_template = copy.deepcopy(self.app.map_json["districts"][index]["npcs"][n])
  84. self.create_mode = ("npc", index)
  85. self.editing = self.moving_npc = None
  86. self.app.menu.notify("点击地图放置怪物副本;Esc 取消")
  87. def rename_npc(self, index, n):
  88. npc = self.app.map_json["districts"][index]["npcs"][n]
  89. name = self.ask_name(npc.get("name", ""))
  90. if name is not None:
  91. self.app.menu.edit(lambda: npc.update(name=name))
  92. self.models.errors.pop(name, None)
  93. @staticmethod
  94. def npc_color(index, n):
  95. hue = (n * 0.61803398875 + index * 0.19) % 1
  96. return tuple(round(c * 255) for c in colorsys.hsv_to_rgb(hue, 0.65, 1))
  97. @staticmethod
  98. def delete_rect(rect):
  99. return pygame.Rect(rect.right - 100, rect.y + 8, 28, 28)
  100. def delete_entry(self, kind, index, value=None):
  101. self.solo_npc = None
  102. self.finish_drag()
  103. self.app.menu.finish_stroke()
  104. if kind == "region":
  105. self.app.menu.edit(lambda: self.app.map_json["districts"].pop(index))
  106. self.expanded.clear()
  107. self.hidden.clear()
  108. self.hidden_before_focus = None
  109. self.editing = None
  110. self.app.menu.notify("已删除区域及其怪物;Ctrl+Z 撤销")
  111. else:
  112. self.app.menu.edit(lambda: self.app.map_json["districts"][index]["npcs"].pop(value))
  113. self.app.menu.notify("已删除怪物;Ctrl+Z 撤销")
  114. self.moving_npc = None
  115. self.create_mode = self.create_start = self.create_end = None
  116. self.list_rows()
  117. @staticmethod
  118. def solo_rect(rect):
  119. return pygame.Rect(rect.right - 154, rect.y + 8, 48, 28)
  120. def toggle_solo(self, index, n):
  121. self.finish_drag()
  122. self.solo_npc = None if self.solo_npc == (index, n) else (index, n)
  123. self.moving_npc = None
  124. self.app.menu.notify("显示全部怪物" if self.solo_npc is None else "仅显示怪物 %d;再次点击恢复全部" % (n + 1))
  125. def npc_visible(self, index, n):
  126. return not self.render_models or self.solo_npc is None or self.solo_npc == (index, n)
  127. def entries(self):
  128. districts = self.app.map_json.get("districts", [])
  129. self.expanded.intersection_update(range(len(districts)))
  130. if self.editing is not None and self.editing >= len(districts):
  131. self.editing = None
  132. if self.moving_npc is not None:
  133. i, n = self.moving_npc
  134. if i >= len(districts) or n >= len(districts[i].get("npcs", [])):
  135. self.moving_npc = None
  136. if self.create_mode is not None and self.create_mode[0] == "npc" and self.create_mode[1] >= len(districts):
  137. self.create_mode = None
  138. result = []
  139. for index, district in enumerate(self.app.map_json.get("districts", [])):
  140. try:
  141. square = district["square"]
  142. coords = tuple(int(square[k]) for k in ("x1", "y1", "x2", "y2"))
  143. if coords[0] > coords[2] or coords[1] > coords[3]:
  144. continue
  145. result.append((index, coords))
  146. except (KeyError, TypeError, ValueError):
  147. continue
  148. return result
  149. def list_entries(self):
  150. result = []
  151. for index, coords in self.entries():
  152. if self.expanded and index not in self.expanded:
  153. continue
  154. result.append(("region", index, coords))
  155. if index in self.expanded:
  156. for n, npc in enumerate(self.app.map_json["districts"][index].get("npcs", [])):
  157. result.append(("npc", index, n))
  158. return result
  159. def list_rows(self):
  160. entries = self.list_entries()
  161. self.offset = max(0, min(self.offset, max(0, len(entries) - self.PAGE_SIZE)))
  162. return [(kind, index, value, pygame.Rect(WINDOW_W + 12 + (24 if kind == "npc" else 0), self.TOP + 34 + i * 48, TOOL_PANEL_WIDTH - 44 - (24 if kind == "npc" else 0), 44))
  163. for i, (kind, index, value) in enumerate(entries[self.offset:self.offset + self.PAGE_SIZE])]
  164. def rows(self):
  165. return [(index, value, rect) for kind, index, value, rect in self.list_rows() if kind == "region"]
  166. def interacting(self):
  167. return self.enabled and (self.editing is not None or self.moving_npc is not None or self.drag is not None or self.create_mode is not None)
  168. def corners(self, index):
  169. square = self.app.map_json["districts"][index]["square"]
  170. sx, sy = self.app.scroll_grid_at
  171. return [(xkey, ykey, pygame.Rect(
  172. MAP_AT[0] + (square[xkey] + (xkey == "x2") - sx) * GAME_SQUARE - 6,
  173. MAP_AT[1] + (square[ykey] + (ykey == "y2") - sy) * GAME_SQUARE - 6, 12, 12))
  174. for xkey, ykey in [("x1", "y1"), ("x2", "y1"), ("x1", "y2"), ("x2", "y2")]]
  175. def npc_rect(self, index, n):
  176. npc = self.app.map_json["districts"][index]["npcs"][n]
  177. sx, sy = self.app.scroll_grid_at
  178. return pygame.Rect(MAP_AT[0] + (npc["x"] - sx) * GAME_SQUARE + 8,
  179. MAP_AT[1] + (npc["y"] - sy) * GAME_SQUARE + 8, 24, 24)
  180. def finish_drag(self, cancel=False):
  181. if self.drag_before is not None:
  182. before = self.drag_before
  183. self.drag_before = self.drag = None
  184. if cancel:
  185. self.app.restore_document(before)
  186. else:
  187. self.app.menu.record(before)
  188. def handle_map_event(self, event):
  189. if not self.enabled:
  190. return False
  191. self.entries()
  192. if self.scroll_drag:
  193. if event.type == pygame.MOUSEMOTION:
  194. self.scroll_to(event.pos[1] - self.scroll_grab)
  195. elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
  196. self.scroll_drag = False
  197. self.app.menu.block_pointer = True
  198. return True
  199. if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
  200. self.finish_drag(cancel=True)
  201. self.editing = self.moving_npc = None
  202. self.create_mode = self.create_start = self.create_end = None
  203. return True
  204. if self.create_mode is not None:
  205. kind, index = self.create_mode
  206. if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
  207. cell = self.app.selection.cell(event.pos)
  208. if cell is None:
  209. return False
  210. if kind == "region":
  211. self.create_start = self.create_end = cell
  212. else:
  213. template = getattr(self, "npc_template", None)
  214. name = template.get("name", "") if template is not None else self.ask_name()
  215. if name is not None:
  216. node = copy.deepcopy(template) if template is not None else dict(name=name)
  217. node.update(x=cell[0], y=cell[1])
  218. self.app.menu.edit(lambda: self.app.map_json["districts"][index].setdefault("npcs", []).append(node))
  219. self.models.errors.pop(name, None)
  220. self.offset = max(0, len(self.list_entries()) - self.PAGE_SIZE)
  221. self.npc_template = None
  222. self.create_mode = None
  223. self.app.menu.block_pointer = True
  224. return True
  225. if kind == "region" and self.create_start is not None and event.type in (pygame.MOUSEMOTION, pygame.MOUSEBUTTONUP):
  226. self.create_end = self.app.selection.cell(event.pos, clamp=True)
  227. if event.type == pygame.MOUSEBUTTONUP and event.button == 1:
  228. x1, x2 = sorted((self.create_start[0], self.create_end[0]))
  229. y1, y2 = sorted((self.create_start[1], self.create_end[1]))
  230. self.app.menu.edit(lambda: self.app.map_json.setdefault("districts", []).append(dict(square=dict(x1=x1, y1=y1, x2=x2, y2=y2), npcs=[])))
  231. self.create_mode = self.create_start = self.create_end = None
  232. self.offset = max(0, len(self.list_entries()) - self.PAGE_SIZE)
  233. self.app.menu.block_pointer = True
  234. return True
  235. if self.drag is not None:
  236. if event.type in (pygame.MOUSEMOTION, pygame.MOUSEBUTTONUP):
  237. if event.type == pygame.MOUSEBUTTONUP and event.button != 1:
  238. return True
  239. if self.drag[0] == "corner":
  240. _, index, xkey, ykey = self.drag
  241. square = self.app.map_json["districts"][index]["square"]
  242. for axis, key, origin, scroll, limit in [
  243. (0, xkey, MAP_AT[0], self.app.scroll_grid_at[0], self.app.map_size[0]),
  244. (1, ykey, MAP_AT[1], self.app.scroll_grid_at[1], self.app.map_size[1])]:
  245. value = round((event.pos[axis] - origin) / GAME_SQUARE) + scroll - (key.endswith("2"))
  246. low = 0 if key.endswith("1") else square[key[0] + "1"]
  247. high = square[key[0] + "2"] if key.endswith("1") else limit - 1
  248. square[key] = max(low, min(high, value))
  249. else:
  250. _, index, n = self.drag
  251. cell = self.app.selection.cell(event.pos, clamp=True)
  252. npc = self.app.map_json["districts"][index]["npcs"][n]
  253. npc["x"], npc["y"] = cell
  254. if event.type == pygame.MOUSEBUTTONUP:
  255. self.finish_drag()
  256. self.app.menu.block_pointer = True
  257. return True
  258. if event.type == pygame.KEYDOWN:
  259. return True
  260. if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
  261. if not pygame.Rect(MAP_AT, (MAP_W, MAP_H)).collidepoint(event.pos):
  262. return False
  263. drag = None
  264. if self.editing is not None and self.editing not in self.hidden:
  265. for xkey, ykey, rect in self.corners(self.editing):
  266. if rect.collidepoint(event.pos):
  267. drag = ("corner", self.editing, xkey, ykey)
  268. break
  269. if self.moving_npc is not None:
  270. index, n = self.moving_npc
  271. if index not in self.hidden and self.npc_visible(index, n) and self.npc_rect(index, n).collidepoint(event.pos):
  272. drag = ("npc", index, n)
  273. if drag:
  274. self.app.menu.finish_stroke()
  275. self.drag_before = self.app.document_snapshot()
  276. self.drag = drag
  277. return self.interacting()
  278. return False
  279. def handle_event(self, event):
  280. if not self.enabled:
  281. return False
  282. pos = getattr(event, "pos", pygame.mouse.get_pos())
  283. if pos[0] < WINDOW_W or pos[1] < self.TOP:
  284. return False
  285. if event.type == pygame.MOUSEWHEEL:
  286. self.offset -= event.y
  287. self.rows()
  288. return True
  289. if event.type == pygame.MOUSEBUTTONDOWN:
  290. if event.button == 1 and self.add_rect().collidepoint(pos):
  291. self.start_add()
  292. return True
  293. track, thumb = self.scrollbar()
  294. if event.button == 1 and track.collidepoint(pos):
  295. self.scroll_drag = True
  296. self.scroll_grab = pos[1] - thumb.y if thumb.collidepoint(pos) else thumb.height // 2
  297. self.scroll_to(pos[1] - self.scroll_grab)
  298. return True
  299. if event.button in (4, 5):
  300. self.offset += -1 if event.button == 4 else 1
  301. self.rows()
  302. elif event.button == 1:
  303. for kind, index, value, rect in self.list_rows():
  304. if rect.collidepoint(pos):
  305. if self.delete_rect(rect).collidepoint(pos):
  306. self.delete_entry(kind, index, value)
  307. return True
  308. if kind == "npc":
  309. if self.copy_rect(rect).collidepoint(pos):
  310. self.copy_npc(index, value)
  311. return True
  312. if self.render_models and self.solo_rect(rect).collidepoint(pos):
  313. self.toggle_solo(index, value)
  314. return True
  315. if pos[0] >= rect.right - 34:
  316. self.moving_npc = (index, value)
  317. self.editing = None
  318. self.hidden.discard(index)
  319. self.app.selection.cancel()
  320. else:
  321. self.rename_npc(index, value)
  322. elif pos[0] >= rect.right - 34:
  323. self.focus_region(index)
  324. elif pos[0] >= rect.right - 68:
  325. self.editing = None if self.editing == index else index
  326. self.moving_npc = None
  327. self.hidden.discard(index)
  328. self.app.selection.cancel()
  329. else:
  330. if index in self.hidden:
  331. self.hidden.remove(index)
  332. else:
  333. self.hidden.add(index)
  334. return True
  335. return False
  336. def scrollbar(self):
  337. self.list_rows()
  338. total = len(self.list_entries())
  339. track = pygame.Rect(WINDOW_W + TOOL_PANEL_WIDTH - 22, self.TOP + 34, 12, self.PAGE_SIZE * 48 - 4)
  340. height = max(24, int(track.height * min(1, self.PAGE_SIZE / max(1, total))))
  341. y = track.y + round((track.height - height) * self.offset / max(1, total - self.PAGE_SIZE))
  342. return track, pygame.Rect(track.x, y, track.width, height)
  343. def scroll_to(self, top):
  344. track, thumb = self.scrollbar()
  345. maximum = max(0, len(self.list_entries()) - self.PAGE_SIZE)
  346. fraction = (top - track.y) / max(1, track.height - thumb.height)
  347. self.offset = round(max(0, min(1, fraction)) * maximum)
  348. def draw_map(self):
  349. if not self.enabled:
  350. return
  351. overlay = pygame.Surface((MAP_W, MAP_H), pygame.SRCALPHA)
  352. sx, sy = self.app.scroll_grid_at
  353. for index, (x1, y1, x2, y2) in self.entries():
  354. if index in self.hidden or self.expanded and index not in self.expanded:
  355. continue
  356. color = self.COLORS[index % len(self.COLORS)]
  357. # Coordinates are inclusive grid-cell bounds, as used by the game.
  358. rect = pygame.Rect((x1 - sx) * GAME_SQUARE, (y1 - sy) * GAME_SQUARE,
  359. (x2 - x1 + 1) * GAME_SQUARE, (y2 - y1 + 1) * GAME_SQUARE)
  360. pygame.draw.rect(overlay, color + (20,), rect)
  361. pygame.draw.rect(overlay, color + (240,), rect, 3)
  362. visible = rect.clip(overlay.get_rect())
  363. if visible.width > 48 and visible.height > 24:
  364. label = self.app.text_font.render("区域 %d" % (index + 1), True, color)
  365. overlay.blit(label, (visible.x + 5, visible.y + 5))
  366. if index == self.editing:
  367. for xkey, ykey, handle in self.corners(index):
  368. pygame.draw.rect(overlay, color, handle.move(-MAP_AT[0], -MAP_AT[1]))
  369. if index in self.expanded:
  370. for n, npc in sorted(enumerate(self.app.map_json["districts"][index].get("npcs", [])), key=lambda pair: pair[1].get("y", 0)):
  371. if not self.npc_visible(index, n):
  372. continue
  373. icon = self.npc_rect(index, n).move(-MAP_AT[0], -MAP_AT[1])
  374. npc_color = self.npc_color(index, n) if self.render_models else color
  375. rendered = self.render_models and self.models.draw(overlay, npc, (sx, sy), npc_color)
  376. if not rendered:
  377. self.monster_icon(overlay, icon, color)
  378. if self.moving_npc == (index, n):
  379. pygame.draw.rect(overlay, (255, 255, 255), icon.inflate(6, 6), 2)
  380. overlay.blit(self.app.text_font.render(str(n + 1), True, npc_color), (icon.right + 3, icon.top))
  381. if self.render_models:
  382. pygame.draw.rect(overlay, (8, 12, 18, 255), rect.inflate(4, 4), 10)
  383. pygame.draw.rect(overlay, color + (255,), rect, 6)
  384. pygame.draw.rect(overlay, (245, 250, 255, 255), rect, 1)
  385. if self.create_mode is not None:
  386. if self.create_mode[0] == "region" and self.create_start is not None:
  387. x1, x2 = sorted((self.create_start[0], self.create_end[0]))
  388. y1, y2 = sorted((self.create_start[1], self.create_end[1]))
  389. rect = pygame.Rect((x1 - sx) * GAME_SQUARE, (y1 - sy) * GAME_SQUARE,
  390. (x2 - x1 + 1) * GAME_SQUARE, (y2 - y1 + 1) * GAME_SQUARE)
  391. pygame.draw.rect(overlay, (255, 220, 70, 50), rect)
  392. pygame.draw.rect(overlay, (255, 220, 70), rect, 2)
  393. elif self.create_mode[0] == "npc":
  394. cell = self.app.selection.cell(pygame.mouse.get_pos())
  395. if cell is not None:
  396. icon = pygame.Rect((cell[0] - sx) * GAME_SQUARE + 8, (cell[1] - sy) * GAME_SQUARE + 8, 24, 24)
  397. self.monster_icon(overlay, icon, (255, 220, 60))
  398. self.app.screen.blit(overlay, MAP_AT)
  399. @staticmethod
  400. def monster_icon(surface, icon, color):
  401. pygame.draw.rect(surface, color, icon, border_radius=5)
  402. pygame.draw.polygon(surface, color, [(icon.left, icon.top + 6), (icon.left - 3, icon.top - 5), (icon.left + 8, icon.top)])
  403. pygame.draw.polygon(surface, color, [(icon.right, icon.top + 6), (icon.right + 3, icon.top - 5), (icon.right - 8, icon.top)])
  404. for dx in (-5, 5):
  405. pygame.draw.circle(surface, (25, 30, 38), (icon.centerx + dx, icon.centery - 2), 3)
  406. def draw_panel(self):
  407. if not self.enabled:
  408. return
  409. screen, font = self.app.screen, self.app.text_font
  410. title = "区域显示(坐标含两端格)"
  411. screen.blit(font.render(title, True, (235, 238, 243)), (WINDOW_W + 12, self.TOP))
  412. if not self.entries():
  413. screen.blit(font.render("当前地图没有 districts 区域", True, (170, 180, 195)), (WINDOW_W + 12, self.TOP + 40))
  414. for kind, index, value, rect in self.list_rows():
  415. color = self.COLORS[index % len(self.COLORS)]
  416. if kind == "npc" and self.render_models:
  417. color = self.npc_color(index, value)
  418. pygame.draw.rect(screen, (48, 54, 65), rect)
  419. if kind == "region":
  420. x1, y1, x2, y2 = value
  421. box = pygame.Rect(rect.x + 8, rect.y + 14, 16, 16)
  422. pygame.draw.rect(screen, color, box, 1)
  423. if index not in self.hidden:
  424. pygame.draw.lines(screen, color, False, [(box.x + 3, box.y + 8), (box.x + 6, box.y + 12), (box.x + 13, box.y + 3)], 2)
  425. label = "区域 %d (%d,%d)-(%d,%d)" % (index + 1, x1, y1, x2, y2)
  426. screen.blit(font.render(label, True, color), (rect.x + 32, rect.y + 14), pygame.Rect(0, 0, rect.width - 134, 18))
  427. edit = pygame.Rect(rect.right - 66, rect.y + 8, 28, 28)
  428. expand = pygame.Rect(rect.right - 32, rect.y + 8, 28, 28)
  429. pygame.draw.rect(screen, (22, 26, 33) if self.editing == index else (60, 68, 80), edit)
  430. pygame.draw.rect(screen, color, edit, 1)
  431. pygame.draw.rect(screen, color, (edit.x + 6, edit.y + 6, 16, 16), 1)
  432. for dx, dy in [(4, 4), (19, 4), (4, 19), (19, 19)]:
  433. pygame.draw.rect(screen, color, (edit.x + dx, edit.y + dy, 5, 5))
  434. pygame.draw.rect(screen, color, expand, 1)
  435. cx, cy = expand.center
  436. points = [(cx - 6, cy + 3), (cx + 6, cy + 3), (cx, cy - 4)] if index in self.expanded else [(cx - 6, cy - 3), (cx + 6, cy - 3), (cx, cy + 4)]
  437. pygame.draw.polygon(screen, color, points)
  438. else:
  439. npc = self.app.map_json["districts"][index]["npcs"][value]
  440. label = "%d. %s" % (value + 1, npc.get("name", "NPC"))
  441. image = font.render(label, True, color)
  442. screen.blit(image, (rect.x + 14, rect.y + 4), pygame.Rect(0, 0, rect.width - 200, 18))
  443. if self.render_models:
  444. solo = self.solo_rect(rect)
  445. selected = self.solo_npc == (index, value)
  446. pygame.draw.rect(screen, (22, 26, 33) if selected else (60, 68, 80), solo)
  447. pygame.draw.rect(screen, color, solo, 1)
  448. caption = font.render("全部" if selected else "单显", True, color)
  449. screen.blit(caption, caption.get_rect(center=solo.center))
  450. screen.blit(font.render("(%s, %s)" % (npc.get("x"), npc.get("y")), True, color), (rect.x + 14, rect.y + 23))
  451. button = self.copy_rect(rect)
  452. pygame.draw.rect(screen, color, button, 1)
  453. pygame.draw.rect(screen, color, (button.x+6, button.y+6, 12, 12), 1)
  454. pygame.draw.rect(screen, color, (button.x+10, button.y+10, 12, 12), 1)
  455. rename = pygame.Rect(rect.right - 66, rect.y + 8, 28, 28)
  456. pygame.draw.rect(screen, color, rename, 1)
  457. pygame.draw.line(screen, color, (rename.x + 7, rename.y + 21), (rename.x + 21, rename.y + 7), 3)
  458. move = pygame.Rect(rect.right - 32, rect.y + 8, 28, 28)
  459. pygame.draw.rect(screen, (22, 26, 33) if self.moving_npc == (index, value) else (60, 68, 80), move)
  460. pygame.draw.rect(screen, color, move, 1)
  461. cx, cy = move.center
  462. pygame.draw.line(screen, color, (cx - 8, cy), (cx + 8, cy), 2)
  463. pygame.draw.line(screen, color, (cx, cy - 8), (cx, cy + 8), 2)
  464. for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
  465. pygame.draw.polygon(screen, color, [(cx + dx * 10, cy + dy * 10), (cx + dx * 5 - dy * 3, cy + dy * 5 + dx * 3), (cx + dx * 5 + dy * 3, cy + dy * 5 - dx * 3)])
  466. delete = self.delete_rect(rect)
  467. red = (255, 135, 135)
  468. pygame.draw.rect(screen, (70, 38, 44), delete)
  469. pygame.draw.rect(screen, red, delete, 1)
  470. pygame.draw.rect(screen, red, (delete.x + 8, delete.y + 10, 12, 12), 1)
  471. pygame.draw.line(screen, red, (delete.x + 6, delete.y + 7), (delete.x + 22, delete.y + 7), 2)
  472. pygame.draw.line(screen, red, (delete.x + 11, delete.y + 4), (delete.x + 17, delete.y + 4), 2)
  473. track, thumb = self.scrollbar()
  474. pygame.draw.rect(screen, (20, 24, 30), track)
  475. pygame.draw.rect(screen, (130, 147, 169), thumb, border_radius=3)
  476. add = self.add_rect()
  477. pygame.draw.rect(screen, (53, 65, 81), add)
  478. pygame.draw.rect(screen, (145, 164, 187), add, 1)
  479. image = font.render("[+] 添加怪物" if self.expanded else "[+] 添加区域", True, (230, 235, 245))
  480. screen.blit(image, image.get_rect(center=add.center))