nonebot-plugin-bugu 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nonebot_plugin_bugu/__init__.py +31 -0
- nonebot_plugin_bugu/api.py +282 -0
- nonebot_plugin_bugu/collection.py +166 -0
- nonebot_plugin_bugu/commands.py +234 -0
- nonebot_plugin_bugu/config.py +91 -0
- nonebot_plugin_bugu/draw.py +406 -0
- nonebot_plugin_bugu/features/__init__.py +0 -0
- nonebot_plugin_bugu/features/collection.py +247 -0
- nonebot_plugin_bugu/features/common.py +100 -0
- nonebot_plugin_bugu/features/flowers/__init__.py +0 -0
- nonebot_plugin_bugu/features/flowers/data.py +167 -0
- nonebot_plugin_bugu/features/flowers/render.py +300 -0
- nonebot_plugin_bugu/features/flowers/reply.py +123 -0
- nonebot_plugin_bugu/features/neighbors/__init__.py +0 -0
- nonebot_plugin_bugu/features/neighbors/data.py +143 -0
- nonebot_plugin_bugu/features/neighbors/render.py +225 -0
- nonebot_plugin_bugu/features/neighbors/reply.py +149 -0
- nonebot_plugin_bugu/features/recipes/__init__.py +0 -0
- nonebot_plugin_bugu/features/recipes/data.py +313 -0
- nonebot_plugin_bugu/features/recipes/render.py +371 -0
- nonebot_plugin_bugu/features/recipes/reply.py +219 -0
- nonebot_plugin_bugu/features/recipes/search.py +151 -0
- nonebot_plugin_bugu/features/starsea/__init__.py +0 -0
- nonebot_plugin_bugu/features/starsea/data.py +267 -0
- nonebot_plugin_bugu/features/starsea/render.py +579 -0
- nonebot_plugin_bugu/features/starsea/reply.py +356 -0
- nonebot_plugin_bugu/features/starsea/search.py +271 -0
- nonebot_plugin_bugu/fonts.py +152 -0
- nonebot_plugin_bugu/runtime.py +109 -0
- nonebot_plugin_bugu/values.py +87 -0
- nonebot_plugin_bugu-0.2.0.dist-info/METADATA +257 -0
- nonebot_plugin_bugu-0.2.0.dist-info/RECORD +35 -0
- nonebot_plugin_bugu-0.2.0.dist-info/WHEEL +4 -0
- nonebot_plugin_bugu-0.2.0.dist-info/entry_points.txt +3 -0
- nonebot_plugin_bugu-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
"""星海地图卡片:区域底图 + 点位详情。
|
|
2
|
+
|
|
3
|
+
两张图都遵循布谷工具箱的深色星空主题,等级沿用站点配色
|
|
4
|
+
(S 金 / A 紫 / B 蓝 / C 灰)。传入 ``collected`` 时会在图标上标绿勾、
|
|
5
|
+
在图例里显示收集进度。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
from typing import Dict, List, Optional, Sequence, Set, Tuple
|
|
12
|
+
|
|
13
|
+
from ...draw import (
|
|
14
|
+
BG_BOTTOM,
|
|
15
|
+
CREAM,
|
|
16
|
+
DIM,
|
|
17
|
+
FAINT,
|
|
18
|
+
LINE,
|
|
19
|
+
SPECIALTY_BLUE,
|
|
20
|
+
TILE_BG,
|
|
21
|
+
TYPE_CHIP_INK,
|
|
22
|
+
YELLOW,
|
|
23
|
+
Draw,
|
|
24
|
+
DrawError,
|
|
25
|
+
bold_text,
|
|
26
|
+
check_mark,
|
|
27
|
+
chip,
|
|
28
|
+
draw_paragraph,
|
|
29
|
+
finish,
|
|
30
|
+
fit_text,
|
|
31
|
+
grade_color,
|
|
32
|
+
icon_disc,
|
|
33
|
+
number_badge,
|
|
34
|
+
open_image,
|
|
35
|
+
require_pillow,
|
|
36
|
+
resize,
|
|
37
|
+
resolve_fontset,
|
|
38
|
+
rounded,
|
|
39
|
+
star,
|
|
40
|
+
text_width,
|
|
41
|
+
wrap_text,
|
|
42
|
+
)
|
|
43
|
+
from ...fonts import FontSet
|
|
44
|
+
from .data import SeaMap, SeaPoint, Species, StarSeaData
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def ordered_points(sea_map: SeaMap) -> List[SeaPoint]:
|
|
48
|
+
"""给点位编号的顺序(和文字版保持一致)。"""
|
|
49
|
+
return sea_map.ordered_points()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _map_kinds(data: StarSeaData, sea_map: SeaMap) -> List[str]:
|
|
53
|
+
kinds: List[str] = []
|
|
54
|
+
for point in sea_map.points:
|
|
55
|
+
for species in data.species_of(point):
|
|
56
|
+
if species.kind_name not in kinds:
|
|
57
|
+
kinds.append(species.kind_name)
|
|
58
|
+
return kinds
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _legend_meta(
|
|
62
|
+
data: StarSeaData, point: SeaPoint, collected: Optional[Set[int]]
|
|
63
|
+
) -> str:
|
|
64
|
+
species = data.species_of(point)
|
|
65
|
+
if not species:
|
|
66
|
+
return point.type_name or "特殊点位"
|
|
67
|
+
kinds: List[str] = []
|
|
68
|
+
for sp in species:
|
|
69
|
+
if sp.kind_name not in kinds:
|
|
70
|
+
kinds.append(sp.kind_name)
|
|
71
|
+
meta = f"{'/'.join(kinds[:3])} · {len(species)} 种"
|
|
72
|
+
if collected:
|
|
73
|
+
done = sum(1 for sp in species if sp.id in collected)
|
|
74
|
+
meta += f" · 已收 {done}/{len(species)}"
|
|
75
|
+
return meta
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def render_map_card(
|
|
79
|
+
data: StarSeaData,
|
|
80
|
+
sea_map: SeaMap,
|
|
81
|
+
image_bytes: Optional[bytes],
|
|
82
|
+
*,
|
|
83
|
+
fonts: Optional[FontSet] = None,
|
|
84
|
+
width: int = 1200,
|
|
85
|
+
collected: Optional[Set[int]] = None,
|
|
86
|
+
) -> bytes:
|
|
87
|
+
"""渲染区域地图:底图 + 编号点位 + 图例。"""
|
|
88
|
+
require_pillow()
|
|
89
|
+
font_set = resolve_fontset(fonts)
|
|
90
|
+
|
|
91
|
+
base = open_image(image_bytes, "地图底图")
|
|
92
|
+
if base is None:
|
|
93
|
+
raise DrawError("地图底图下载失败")
|
|
94
|
+
|
|
95
|
+
pad = 40
|
|
96
|
+
map_x = pad
|
|
97
|
+
map_top = 116
|
|
98
|
+
max_w = width - pad * 2
|
|
99
|
+
scale = min(max_w / base.width, 760 / base.height)
|
|
100
|
+
map_w = max(1, round(base.width * scale))
|
|
101
|
+
map_h = max(1, round(base.height * scale))
|
|
102
|
+
|
|
103
|
+
points = ordered_points(sea_map)
|
|
104
|
+
cols = 3
|
|
105
|
+
rows = max(1, math.ceil(len(points) / cols))
|
|
106
|
+
row_h = 56
|
|
107
|
+
|
|
108
|
+
from PIL import Image, ImageDraw
|
|
109
|
+
|
|
110
|
+
estimate = map_top + map_h + 26 + 34 + rows * row_h + 60 + 300
|
|
111
|
+
content = Image.new("RGBA", (width, estimate), (0, 0, 0, 0))
|
|
112
|
+
draw = ImageDraw.Draw(content)
|
|
113
|
+
|
|
114
|
+
# ---- 标题区
|
|
115
|
+
title_font = font_set.get(40, True)
|
|
116
|
+
bold_text(
|
|
117
|
+
draw,
|
|
118
|
+
(pad, 28),
|
|
119
|
+
fit_text(draw, sea_map.display_name, title_font, max_w - 260),
|
|
120
|
+
title_font,
|
|
121
|
+
font_set,
|
|
122
|
+
)
|
|
123
|
+
subtitle = f"{len(points)} 个点位 · {len(_map_kinds(data, sea_map))} 个大类 · {sea_map.code}"
|
|
124
|
+
draw.text((pad, 80), subtitle, font=font_set.get(18), fill=DIM)
|
|
125
|
+
draw.text(
|
|
126
|
+
(width - pad, 40),
|
|
127
|
+
"星海地图 · 布谷工具箱",
|
|
128
|
+
font=font_set.get(16),
|
|
129
|
+
fill=FAINT,
|
|
130
|
+
anchor="rt",
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# ---- 底图
|
|
134
|
+
map_img = resize(base, (map_w, map_h))
|
|
135
|
+
content.alpha_composite(rounded(map_img, 18), (map_x, map_top))
|
|
136
|
+
draw.rounded_rectangle(
|
|
137
|
+
[map_x, map_top, map_x + map_w - 1, map_top + map_h - 1],
|
|
138
|
+
18,
|
|
139
|
+
outline=LINE,
|
|
140
|
+
width=2,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
# ---- 编号点位
|
|
144
|
+
badge_font = font_set.get(17, True)
|
|
145
|
+
for index, point in enumerate(points, start=1):
|
|
146
|
+
px = map_x + point.x / 100 * map_w
|
|
147
|
+
py = map_top + point.y / 100 * map_h
|
|
148
|
+
offset = 18 if index < 10 else 22
|
|
149
|
+
bx = min(max(px + offset, map_x + offset), map_x + map_w - offset)
|
|
150
|
+
by = min(max(py - offset, map_top + offset), map_top + map_h - offset)
|
|
151
|
+
draw.line([(px, py), (bx, by)], fill=(*YELLOW, 170), width=2)
|
|
152
|
+
number_badge(draw, bx, by, index, badge_font, special=point.special)
|
|
153
|
+
|
|
154
|
+
# ---- 图例
|
|
155
|
+
cursor = map_top + map_h + 26
|
|
156
|
+
bold_text(draw, (pad, cursor), "点位图例", font_set.get(19, True), font_set, fill=YELLOW)
|
|
157
|
+
cursor += 34
|
|
158
|
+
|
|
159
|
+
col_w = (width - pad * 2) // cols
|
|
160
|
+
name_font = font_set.get(19, True)
|
|
161
|
+
meta_font = font_set.get(15)
|
|
162
|
+
small_badge_font = font_set.get(15, True)
|
|
163
|
+
for i, point in enumerate(points):
|
|
164
|
+
col = i // rows
|
|
165
|
+
row = i % rows
|
|
166
|
+
x = pad + col * col_w
|
|
167
|
+
y = cursor + row * row_h
|
|
168
|
+
number_badge(draw, x + 15, y + 16, i + 1, small_badge_font, special=point.special, radius=15)
|
|
169
|
+
bold_text(
|
|
170
|
+
draw,
|
|
171
|
+
(x + 40, y),
|
|
172
|
+
fit_text(draw, point.name, name_font, col_w - 52),
|
|
173
|
+
name_font,
|
|
174
|
+
font_set,
|
|
175
|
+
)
|
|
176
|
+
draw.text(
|
|
177
|
+
(x + 40, y + 27),
|
|
178
|
+
fit_text(draw, _legend_meta(data, point, collected), meta_font, col_w - 52),
|
|
179
|
+
font=meta_font,
|
|
180
|
+
fill=DIM,
|
|
181
|
+
)
|
|
182
|
+
cursor += rows * row_h
|
|
183
|
+
|
|
184
|
+
# ---- 本区可初次偶遇
|
|
185
|
+
encounters = [e.name for e in sea_map.encounters if e.name]
|
|
186
|
+
if encounters:
|
|
187
|
+
chip_w = chip(
|
|
188
|
+
draw,
|
|
189
|
+
pad,
|
|
190
|
+
cursor + 4,
|
|
191
|
+
"本区可初次偶遇",
|
|
192
|
+
font_set.get(14, True),
|
|
193
|
+
fill=(44, 58, 96),
|
|
194
|
+
ink=CREAM,
|
|
195
|
+
pad_x=12,
|
|
196
|
+
height=26,
|
|
197
|
+
radius=13,
|
|
198
|
+
)
|
|
199
|
+
draw.text(
|
|
200
|
+
(pad + chip_w + 12, cursor + 7),
|
|
201
|
+
fit_text(
|
|
202
|
+
draw,
|
|
203
|
+
" · ".join(encounters),
|
|
204
|
+
font_set.get(16),
|
|
205
|
+
width - pad * 2 - chip_w - 24,
|
|
206
|
+
),
|
|
207
|
+
font=font_set.get(16),
|
|
208
|
+
fill=DIM,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
return finish(
|
|
212
|
+
content,
|
|
213
|
+
width,
|
|
214
|
+
fonts=font_set,
|
|
215
|
+
pad=pad,
|
|
216
|
+
right_text=f"{sea_map.code} · {len(points)} 个点位",
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
# ------------------------------------------------------------------ 点位详情
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def render_point_card(
|
|
224
|
+
data: StarSeaData,
|
|
225
|
+
sea_map: SeaMap,
|
|
226
|
+
point: SeaPoint,
|
|
227
|
+
header_bytes: Optional[bytes],
|
|
228
|
+
icon_bytes: Dict[int, Optional[bytes]],
|
|
229
|
+
*,
|
|
230
|
+
fonts: Optional[FontSet] = None,
|
|
231
|
+
width: int = 1040,
|
|
232
|
+
collected: Optional[Set[int]] = None,
|
|
233
|
+
) -> bytes:
|
|
234
|
+
"""渲染点位详情:头图 + 标题 + 按大类分组的图标墙。"""
|
|
235
|
+
require_pillow()
|
|
236
|
+
font_set = resolve_fontset(fonts)
|
|
237
|
+
|
|
238
|
+
from PIL import Image, ImageDraw
|
|
239
|
+
|
|
240
|
+
pad = 36
|
|
241
|
+
banner_h = 200
|
|
242
|
+
groups = _point_groups(data, point)
|
|
243
|
+
columns = 6
|
|
244
|
+
tile_w = (width - pad * 2) // columns
|
|
245
|
+
tile_h = 138
|
|
246
|
+
section_gap = 26
|
|
247
|
+
target_w = width - pad * 2
|
|
248
|
+
|
|
249
|
+
banner = open_image(header_bytes, "点位头图")
|
|
250
|
+
if banner is not None and banner.width and banner.height:
|
|
251
|
+
banner_h = max(150, min(300, round(target_w * banner.height / banner.width)))
|
|
252
|
+
|
|
253
|
+
total_tiles = sum(max(1, math.ceil(len(lst) / columns)) for _, lst, _ in groups)
|
|
254
|
+
estimate = pad + banner_h + 120 + total_tiles * tile_h + len(groups) * 100 + 260
|
|
255
|
+
content = Image.new("RGBA", (width, estimate), (0, 0, 0, 0))
|
|
256
|
+
draw = ImageDraw.Draw(content)
|
|
257
|
+
|
|
258
|
+
# ---- 头图
|
|
259
|
+
if banner is not None:
|
|
260
|
+
crop_ratio = target_w / banner_h
|
|
261
|
+
if banner.width / banner.height > crop_ratio:
|
|
262
|
+
new_w = max(1, int(banner.height * crop_ratio))
|
|
263
|
+
left = (banner.width - new_w) // 2
|
|
264
|
+
banner = banner.crop((left, 0, left + new_w, banner.height))
|
|
265
|
+
else:
|
|
266
|
+
new_h = max(1, int(banner.width / crop_ratio))
|
|
267
|
+
top = (banner.height - new_h) // 2
|
|
268
|
+
banner = banner.crop((0, top, banner.width, top + new_h))
|
|
269
|
+
content.alpha_composite(resize(rounded(banner, 16), (target_w, banner_h)), (pad, pad))
|
|
270
|
+
draw.rounded_rectangle(
|
|
271
|
+
[pad, pad, pad + target_w - 1, pad + banner_h - 1], 16, outline=LINE, width=2
|
|
272
|
+
)
|
|
273
|
+
else:
|
|
274
|
+
draw.rounded_rectangle(
|
|
275
|
+
[pad, pad, width - pad - 1, pad + banner_h - 1],
|
|
276
|
+
16,
|
|
277
|
+
fill=TILE_BG,
|
|
278
|
+
outline=LINE,
|
|
279
|
+
width=2,
|
|
280
|
+
)
|
|
281
|
+
draw.text(
|
|
282
|
+
(width / 2, pad + banner_h / 2),
|
|
283
|
+
point.type_name or "点位",
|
|
284
|
+
font=font_set.get(30, True),
|
|
285
|
+
fill=DIM,
|
|
286
|
+
anchor="mm",
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
# ---- 标题
|
|
290
|
+
cursor = pad + banner_h + 18
|
|
291
|
+
title_font = font_set.get(38, True)
|
|
292
|
+
title = sea_map.display_name if point.is_station else point.name
|
|
293
|
+
title = fit_text(draw, title, title_font, target_w - 170)
|
|
294
|
+
bold_text(draw, (pad, cursor), title, title_font, font_set)
|
|
295
|
+
if point.type_name:
|
|
296
|
+
chip(draw, pad + text_width(draw, title, title_font) + 16, cursor + 8, point.type_name, font_set.get(17, True))
|
|
297
|
+
|
|
298
|
+
cursor += 56
|
|
299
|
+
species_total = sum(len(lst) for _, lst, _ in groups)
|
|
300
|
+
if species_total:
|
|
301
|
+
meta = f"{species_total} 种可采集物 · {len(groups)} 个大类 · {sea_map.display_name}"
|
|
302
|
+
if collected:
|
|
303
|
+
done = sum(1 for sp in data.species_of(point) if sp.id in collected)
|
|
304
|
+
meta += f" · 已收集 {done}/{species_total}"
|
|
305
|
+
elif point.is_station and sea_map.encounters:
|
|
306
|
+
meta = f"{point.type_name or '传送点'} · 本区可初次偶遇 {len(sea_map.encounters)} 位友邻"
|
|
307
|
+
else:
|
|
308
|
+
meta = f"{sea_map.display_name} · {point.type_name or '特殊点位'}"
|
|
309
|
+
draw.text((pad, cursor), fit_text(draw, meta, font_set.get(18), target_w), font=font_set.get(18), fill=DIM)
|
|
310
|
+
cursor += 40
|
|
311
|
+
|
|
312
|
+
# ---- 内容
|
|
313
|
+
note = point.note.strip()
|
|
314
|
+
note_drawn = False
|
|
315
|
+
if groups:
|
|
316
|
+
for kind_name, species_list, section_note in groups:
|
|
317
|
+
kind_font = font_set.get(24, True)
|
|
318
|
+
bold_text(draw, (pad, cursor), kind_name, kind_font, font_set, fill=YELLOW)
|
|
319
|
+
draw.text(
|
|
320
|
+
(pad + text_width(draw, kind_name, kind_font) + 10, cursor + 9),
|
|
321
|
+
str(len(species_list)),
|
|
322
|
+
font=font_set.get(15),
|
|
323
|
+
fill=DIM,
|
|
324
|
+
)
|
|
325
|
+
cursor += 36
|
|
326
|
+
if section_note:
|
|
327
|
+
draw.text(
|
|
328
|
+
(pad, cursor),
|
|
329
|
+
fit_text(draw, section_note.replace("\n", " "), font_set.get(14), target_w),
|
|
330
|
+
font=font_set.get(14),
|
|
331
|
+
fill=FAINT,
|
|
332
|
+
)
|
|
333
|
+
cursor += 24
|
|
334
|
+
cursor += 8
|
|
335
|
+
|
|
336
|
+
flower_states = _flower_states(point, species_list)
|
|
337
|
+
for index, species in enumerate(species_list):
|
|
338
|
+
row, col = divmod(index, columns)
|
|
339
|
+
_draw_species_tile(
|
|
340
|
+
content,
|
|
341
|
+
draw,
|
|
342
|
+
species,
|
|
343
|
+
pad + col * tile_w + tile_w // 2,
|
|
344
|
+
cursor + row * tile_h + 46,
|
|
345
|
+
radius=40,
|
|
346
|
+
icon_bytes=icon_bytes.get(species.id),
|
|
347
|
+
font_set=font_set,
|
|
348
|
+
name_width=tile_w - 12,
|
|
349
|
+
flower_state=flower_states.get(species.id),
|
|
350
|
+
done=bool(collected and species.id in collected),
|
|
351
|
+
)
|
|
352
|
+
cursor += math.ceil(len(species_list) / columns) * tile_h + section_gap
|
|
353
|
+
elif point.special:
|
|
354
|
+
cursor = _draw_special_block(draw, sea_map, point, pad, cursor, target_w, font_set)
|
|
355
|
+
note_drawn = True
|
|
356
|
+
else:
|
|
357
|
+
cursor = _draw_fallback_tags(draw, point, pad, cursor, target_w, font_set)
|
|
358
|
+
cursor += 16
|
|
359
|
+
|
|
360
|
+
if note and not note_drawn:
|
|
361
|
+
cursor += draw_paragraph(
|
|
362
|
+
draw, note, font_set.get(16), pad, cursor, target_w, line_height=24, max_lines=3
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
return finish(
|
|
366
|
+
content,
|
|
367
|
+
width,
|
|
368
|
+
fonts=font_set,
|
|
369
|
+
pad=pad,
|
|
370
|
+
right_text=f"{sea_map.display_name} · {species_total} 种" if species_total else "",
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def _point_groups(
|
|
375
|
+
data: StarSeaData, point: SeaPoint
|
|
376
|
+
) -> List[Tuple[str, List[Species], str]]:
|
|
377
|
+
"""按大类分组;鲜花补「星屿状态」说明,创想卡补 kindNote。"""
|
|
378
|
+
out: List[Tuple[str, List[Species], str]] = []
|
|
379
|
+
for kind_name, species_list in data.groups_of(point):
|
|
380
|
+
note = ""
|
|
381
|
+
if species_list and species_list[0].kind_note:
|
|
382
|
+
note = species_list[0].kind_note
|
|
383
|
+
if species_list and species_list[0].kind == "鲜花":
|
|
384
|
+
families: Dict[str, int] = {}
|
|
385
|
+
for sp in species_list:
|
|
386
|
+
families[sp.flower_family] = families.get(sp.flower_family, 0) + 1
|
|
387
|
+
species_list = sorted(
|
|
388
|
+
species_list,
|
|
389
|
+
key=lambda sp: (
|
|
390
|
+
9
|
|
391
|
+
if point.hide_flower_state
|
|
392
|
+
else (sp.flower_state if families.get(sp.flower_family, 0) >= 3 else 9),
|
|
393
|
+
sp.sort,
|
|
394
|
+
),
|
|
395
|
+
)
|
|
396
|
+
if not note and species_list[0].flower_state_note:
|
|
397
|
+
note = species_list[0].flower_state_note
|
|
398
|
+
out.append((kind_name, species_list, note))
|
|
399
|
+
return out
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def _flower_states(point: SeaPoint, species_list: Sequence[Species]) -> Dict[int, int]:
|
|
403
|
+
"""鲜花角标:同一品种三色齐全才标状态。"""
|
|
404
|
+
if point.hide_flower_state:
|
|
405
|
+
return {}
|
|
406
|
+
families: Dict[str, int] = {}
|
|
407
|
+
for sp in species_list:
|
|
408
|
+
families[sp.flower_family] = families.get(sp.flower_family, 0) + 1
|
|
409
|
+
states: Dict[int, int] = {}
|
|
410
|
+
for sp in species_list:
|
|
411
|
+
if sp.flower_state is None:
|
|
412
|
+
continue
|
|
413
|
+
if families.get(sp.flower_family, 0) >= 3:
|
|
414
|
+
states[sp.id] = sp.flower_state
|
|
415
|
+
return states
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def _draw_species_tile(
|
|
419
|
+
canvas,
|
|
420
|
+
draw: Draw,
|
|
421
|
+
species: Species,
|
|
422
|
+
cx: float,
|
|
423
|
+
cy: float,
|
|
424
|
+
*,
|
|
425
|
+
radius: int,
|
|
426
|
+
icon_bytes: Optional[bytes],
|
|
427
|
+
font_set: FontSet,
|
|
428
|
+
name_width: float,
|
|
429
|
+
flower_state: Optional[int] = None,
|
|
430
|
+
done: bool = False,
|
|
431
|
+
) -> None:
|
|
432
|
+
color = grade_color(species.grade)
|
|
433
|
+
icon = open_image(icon_bytes, species.label or "物种")
|
|
434
|
+
icon_disc(
|
|
435
|
+
canvas,
|
|
436
|
+
draw,
|
|
437
|
+
icon,
|
|
438
|
+
cx,
|
|
439
|
+
cy,
|
|
440
|
+
radius,
|
|
441
|
+
ring=color,
|
|
442
|
+
fill=TILE_BG,
|
|
443
|
+
placeholder=species.grade or "?",
|
|
444
|
+
font=font_set.get(28, True),
|
|
445
|
+
placeholder_fill=color,
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
# 品质角标
|
|
449
|
+
if species.grade:
|
|
450
|
+
bx, by = cx + radius * 0.62, cy + radius * 0.58
|
|
451
|
+
draw.ellipse([bx - 12, by - 12, bx + 12, by + 12], fill=color, outline=BG_BOTTOM, width=2)
|
|
452
|
+
draw.text(
|
|
453
|
+
(bx, by), species.grade, font=font_set.get(14, True), fill=TYPE_CHIP_INK, anchor="mm"
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
# 星屿特产星标
|
|
457
|
+
if species.islet_specialty:
|
|
458
|
+
sx, sy = cx - radius * 0.66, cy - radius * 0.50
|
|
459
|
+
draw.ellipse(
|
|
460
|
+
[sx - 11, sy - 11, sx + 11, sy + 11], fill=SPECIALTY_BLUE, outline=BG_BOTTOM, width=2
|
|
461
|
+
)
|
|
462
|
+
star(draw, sx, sy, 6.5, (255, 255, 255))
|
|
463
|
+
|
|
464
|
+
# 鲜花星屿状态
|
|
465
|
+
if flower_state is not None:
|
|
466
|
+
sx, sy = cx, cy - radius - 2
|
|
467
|
+
draw.ellipse([sx - 12, sy - 12, sx + 12, sy + 12], fill=CREAM, outline=BG_BOTTOM, width=2)
|
|
468
|
+
draw.text(
|
|
469
|
+
(sx, sy),
|
|
470
|
+
str(flower_state + 1),
|
|
471
|
+
font=font_set.get(14, True),
|
|
472
|
+
fill=TYPE_CHIP_INK,
|
|
473
|
+
anchor="mm",
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
# 已收集:右上角绿勾
|
|
477
|
+
if done:
|
|
478
|
+
check_mark(draw, cx + radius * 0.72, cy - radius * 0.72, 12)
|
|
479
|
+
|
|
480
|
+
# 名字(最多两行)
|
|
481
|
+
name_font = font_set.get(16)
|
|
482
|
+
for i, line in enumerate(wrap_text(draw, species.label, name_font, name_width, max_lines=2)):
|
|
483
|
+
draw.text(
|
|
484
|
+
(cx, cy + radius + 9 + i * 21), line, font=name_font, fill=CREAM, anchor="mt"
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def _draw_special_block(
|
|
489
|
+
draw: Draw,
|
|
490
|
+
sea_map: SeaMap,
|
|
491
|
+
point: SeaPoint,
|
|
492
|
+
x: int,
|
|
493
|
+
y: int,
|
|
494
|
+
max_width: int,
|
|
495
|
+
font_set: FontSet,
|
|
496
|
+
) -> int:
|
|
497
|
+
"""传送点 / 星门:列本区可初次偶遇的友邻,再写一句点位说明。"""
|
|
498
|
+
cursor = y
|
|
499
|
+
if point.is_station and sea_map.encounters:
|
|
500
|
+
bold_text(draw, (x, cursor), "本区可初次偶遇", font_set.get(20, True), font_set, fill=YELLOW)
|
|
501
|
+
cursor += 36
|
|
502
|
+
chip_font = font_set.get(16)
|
|
503
|
+
chip_x = x
|
|
504
|
+
for encounter in sea_map.encounters:
|
|
505
|
+
if not encounter.name:
|
|
506
|
+
continue
|
|
507
|
+
width = int(text_width(draw, encounter.name, chip_font)) + 30
|
|
508
|
+
if chip_x > x and chip_x + width > x + max_width:
|
|
509
|
+
chip_x = x
|
|
510
|
+
cursor += 40
|
|
511
|
+
chip(
|
|
512
|
+
draw,
|
|
513
|
+
chip_x,
|
|
514
|
+
cursor,
|
|
515
|
+
encounter.name,
|
|
516
|
+
chip_font,
|
|
517
|
+
fill=(40, 52, 88),
|
|
518
|
+
ink=CREAM,
|
|
519
|
+
pad_x=15,
|
|
520
|
+
height=32,
|
|
521
|
+
radius=16,
|
|
522
|
+
)
|
|
523
|
+
chip_x += width + 8
|
|
524
|
+
cursor += 46
|
|
525
|
+
|
|
526
|
+
note = point.note.strip()
|
|
527
|
+
if not note:
|
|
528
|
+
note = "这片区域的传送点。" if point.is_station else "特殊点位,不产出采集物。"
|
|
529
|
+
return cursor + draw_paragraph(
|
|
530
|
+
draw, note, font_set.get(16), x, cursor, max_width, line_height=24, max_lines=3
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def _draw_fallback_tags(
|
|
535
|
+
draw: Draw,
|
|
536
|
+
point: SeaPoint,
|
|
537
|
+
x: int,
|
|
538
|
+
y: int,
|
|
539
|
+
max_width: int,
|
|
540
|
+
font_set: FontSet,
|
|
541
|
+
) -> int:
|
|
542
|
+
"""点位还没填物种时,用旧的四列兜底。"""
|
|
543
|
+
rows: List[Tuple[str, List[str]]] = [
|
|
544
|
+
("可能出现的生物类型", point.creatures),
|
|
545
|
+
("树类", point.trees),
|
|
546
|
+
("花卉类型", point.flowers),
|
|
547
|
+
("特产", [point.specialty] if point.specialty else []),
|
|
548
|
+
]
|
|
549
|
+
cursor = y
|
|
550
|
+
chip_font = font_set.get(15)
|
|
551
|
+
for title, values in rows:
|
|
552
|
+
if not values:
|
|
553
|
+
continue
|
|
554
|
+
draw.text((x, cursor), title, font=font_set.get(18, True), fill=YELLOW)
|
|
555
|
+
cursor += 30
|
|
556
|
+
chip_x = x
|
|
557
|
+
for value in values:
|
|
558
|
+
width = int(text_width(draw, value, chip_font)) + 24
|
|
559
|
+
if chip_x > x and chip_x + width > x + max_width:
|
|
560
|
+
chip_x = x
|
|
561
|
+
cursor += 36
|
|
562
|
+
chip(
|
|
563
|
+
draw,
|
|
564
|
+
chip_x,
|
|
565
|
+
cursor,
|
|
566
|
+
value,
|
|
567
|
+
chip_font,
|
|
568
|
+
fill=(40, 52, 88),
|
|
569
|
+
ink=CREAM,
|
|
570
|
+
pad_x=12,
|
|
571
|
+
height=30,
|
|
572
|
+
radius=15,
|
|
573
|
+
)
|
|
574
|
+
chip_x += width + 8
|
|
575
|
+
cursor += 44
|
|
576
|
+
if cursor == y:
|
|
577
|
+
draw.text((x, y), "这个点位还没有填写采集物。", font=font_set.get(16), fill=DIM)
|
|
578
|
+
cursor += 30
|
|
579
|
+
return cursor
|