| 454 | } |
| 455 | |
| 456 | void Window_Settings::RefreshEngineFont(bool mincho) { |
| 457 | auto fs = Game_Config::GetFontFilesystem(); |
| 458 | |
| 459 | if (!fs) { |
| 460 | Pop(); |
| 461 | } |
| 462 | |
| 463 | fs.ClearCache(); |
| 464 | |
| 465 | auto& cfg = Player::player_config; |
| 466 | |
| 467 | auto& setting = mincho ? cfg.font2 : cfg.font1; |
| 468 | |
| 469 | auto set_help2 = [this]() { |
| 470 | GetFrame().options.back().help2 = ToString(sample_text.GetDescriptions()[static_cast<int>(sample_text.Get())]); |
| 471 | }; |
| 472 | |
| 473 | AddOption(MenuItem("<Built-in Font>", "Use the built-in pixel font", setting.Get().empty() ? "[x]" : ""), [this, &setting, mincho]() { |
| 474 | Font::SetDefault(nullptr, mincho); |
| 475 | setting.Set(""); |
| 476 | Pop(); |
| 477 | }); |
| 478 | set_help2(); |
| 479 | |
| 480 | std::string font_lower = Utils::LowerCase(Font::Default(mincho)->GetName()); |
| 481 | |
| 482 | auto list = fs.ListDirectory(); |
| 483 | assert(list); |
| 484 | for (const auto& item: *list) { |
| 485 | bool is_font = std::any_of(FileFinder::FONTS_TYPES.begin(), FileFinder::FONTS_TYPES.end(), [&item](const auto& ext) { |
| 486 | return EndsWith(item.first, ext); |
| 487 | }); |
| 488 | |
| 489 | if (item.second.type == DirectoryTree::FileType::Regular && is_font) { |
| 490 | AddOption(MenuItem(item.second.name, "Use this font", EndsWith(font_lower, item.first) ? "[x]" : ""), [=, &cfg, &setting]() mutable { |
| 491 | if (Input::IsTriggered(Input::LEFT) || Input::IsRepeated(Input::LEFT)) { |
| 492 | if (font_size.Get() == font_size.GetMin()) { |
| 493 | font_size.Set(font_size.GetMax()); |
| 494 | } else { |
| 495 | font_size.Set(font_size.Get() - 1); |
| 496 | } |
| 497 | return; |
| 498 | } else if (Input::IsTriggered(Input::RIGHT) || Input::IsRepeated(Input::RIGHT)) { |
| 499 | if (font_size.Get() == font_size.GetMax()) { |
| 500 | font_size.Set(font_size.GetMin()); |
| 501 | } else { |
| 502 | font_size.Set(font_size.Get() + 1); |
| 503 | } |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | auto is = fs.OpenInputStream(item.second.name); |
| 508 | if (is) { |
| 509 | auto font = Font::CreateFtFont(std::move(is), font_size.Get(), false, false); |
| 510 | if (font) { |
| 511 | setting.Set(FileFinder::MakePath(fs.GetFullPath(), item.second.name)); |
| 512 | auto& setting_size = mincho ? cfg.font2_size : cfg.font1_size; |
| 513 | setting_size.Set(font->GetCurrentStyle().size); |
nothing calls this directly
no test coverage detected