示例#1
0
/**
 * @brief Attempts to detect the system language unless cl_lang was already set.
 * Then loads the PO file containing translated strings.
 */
void I18N_Init(void)
{
	FL_Locale                       *locale;
	std::set<tinygettext::Language> languages;
	std::set<tinygettext::Language> languages_mod;

	cl_lang      = Cvar_Get("cl_lang", "en", CVAR_ARCHIVE | CVAR_LATCH);
	cl_langDebug = Cvar_Get("cl_langDebug", "0", CVAR_ARCHIVE);

	tinygettext::Log::set_log_error_callback(&Tinygettext_Error);
	tinygettext::Log::set_log_info_callback(&Tinygettext_Info);
	tinygettext::Log::set_log_warning_callback(&Tinygettext_Warning);

	FL_FindLocale(&locale);

	// Do not change the language if it is already set
	if (!cl_lang->string[0])
	{
		// locale->country is also supported for 'en_US' format
		if (locale->lang && locale->lang[0])
		{
			Cvar_Set("cl_lang", va("%s", locale->lang));
		}
		else
		{
			// Language detection failed. Fallback to English
			Cvar_Set("cl_lang", "en");
		}
	}

	dictionary.set_filesystem(std::auto_ptr<tinygettext::FileSystem>(new QFileSystem));
	dictionary_mod.set_filesystem(std::auto_ptr<tinygettext::FileSystem>(new QFileSystem));

	dictionary.add_directory("locale/client");
	dictionary_mod.add_directory("locale/mod");

	languages = dictionary.get_languages();
	Com_Printf("Available client translations:");
	for (std::set<tinygettext::Language>::iterator p = languages.begin(); p != languages.end(); p++)
	{
		Com_Printf(" %s", p->get_name().c_str());
	}
	Com_Printf("\n");

	languages_mod = dictionary_mod.get_languages();
	Com_Printf("Available mod translations:");
	for (std::set<tinygettext::Language>::iterator p = languages_mod.begin(); p != languages_mod.end(); p++)
	{
		Com_Printf(" %s", p->get_name().c_str());
	}
	Com_Printf("\n");

	I18N_SetLanguage(cl_lang->string);
	FL_FreeLocale(&locale);
}
示例#2
0
void
PingusMain::apply_args()
{
  // FIXME: merge cmd_options with stuff read from config file here
  auto& options = cmd_options;

  // Mode toggles
  if (options.list_languages.is_set() &&
      options.list_languages.get())
  { // language listing only works after the data path has been set
    std::cout << "Available languages are:" << std::endl;
    std::cout << "========================" << std::endl;
    std::set<tinygettext::Language> lst = dictionary_manager.get_languages();
    for (std::set<tinygettext::Language>::iterator i = lst.begin(); i != lst.end(); ++i)
      std::cout << i->get_name() << " (" << i->str() << ")" << std::endl;

    std::cout << "\nLanguages can be used via:\n\n    pingus --language de\n" << std::endl; 

    exit(EXIT_SUCCESS);
  }

  if (options.software_cursor.is_set())
    globals::software_cursor = options.software_cursor.get();

  // Sound
  if (options.disable_music.is_set())
    globals::music_enabled = !options.disable_music.get();

  if (options.disable_sound.is_set())
    globals::sound_enabled = !options.disable_sound.get();

  // Misc
  if (options.language.is_set())
    dictionary_manager.set_language(tinygettext::Language::from_name(options.language.get()));

  if (options.auto_scrolling.is_set())
    globals::auto_scrolling = options.auto_scrolling.get();

  if (options.drag_drop_scrolling.is_set())
    globals::drag_drop_scrolling = options.drag_drop_scrolling.get();
  
  if (options.developer_mode.is_set())
    globals::developer_mode = options.developer_mode.get();

  if (options.speed.is_set())
    globals::game_speed = options.speed.get();

  if (options.desiredfps.is_set())
    globals::desired_fps = options.desiredfps.get();

  if (options.tile_size.is_set())
    globals::tile_size = options.tile_size.get();
}
示例#3
0
OptionMenu::OptionMenu() :
  background(),
  ok_button(),
  x_pos(),
  y_pos(),
  options(),
  fullscreen_box(),
  swcursor_box(),
  autoscroll_box(),
  mousegrab_box(),
  printfps_box(),
  master_volume_box(),
  sound_volume_box(),
  music_volume_box(),
  defaults_label(),
  defaults_box(),
  connections(),
  language(),
  language_map()
{
  background = Sprite("core/menu/optionmenu");
  gui_manager->add(ok_button = new OptionMenuCloseButton(this, 
                                                         Display::get_width()/2 + 225,
                                                         Display::get_height()/2 + 125));

  x_pos = 0;
  y_pos = 0;

  int resolutions[][2] = {
    { 640, 480 },   // 4:3, VGA
    { 768, 576 },   // 4:3, PAL
    { 800, 480 },   // Nokia N770, N800
    { 800, 600 },   // 4:3, SVGA
    { 1024, 768 },  // 4:3, XGA
    { 1152, 864 },  // 4:3
    { 1280, 720 },  // 16:9, HD-TV, 720p
    { 1280, 960 },  // 4:3
    { 1280, 1024 }, // 5:4
    { 1366, 768 },  // ~16:9, Wide XGA
    { 1440, 900, }, // 16:10
    { 1600, 1200 }, // 4:3, UXGA
    { 1680, 1050 }, // 16:10, WSXGA
    { 1920, 1080 }, // 16:9, HD-TV, 1080p
    { 1920, 1200 }, // 16:10
    { -1, -1 }
  };
  int current_choice = -1;
  int n;

  ChoiceBox* resolution_box = new ChoiceBox(Rect());
  for (n = 0; resolutions[n][0] != -1; ++n)
  {
    std::ostringstream ostr;
    ostr << resolutions[n][0] << "x" << resolutions[n][1];
    resolution_box->add_choice(ostr.str());
    if (Display::get_width()  == resolutions[n][0] &&
        Display::get_height() == resolutions[n][1])
    {
      current_choice = n;
    }
  }
  resolution_box->add_choice("Custom");
  if (current_choice == -1)
    current_choice = n;

  resolution_box->set_current_choice(current_choice);

  tinygettext::Language current_language = dictionary_manager.get_language();
  language = current_language;
  n = 0;

  ChoiceBox* language_box = new ChoiceBox(Rect());
  std::set<tinygettext::Language> languages = dictionary_manager.get_languages();

  for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); ++i)
  {
    language_box->add_choice(i->str());
    if (current_language == *i)
      language_box->set_current_choice(current_choice);
  }

  ChoiceBox* scroll_box = new ChoiceBox(Rect());
  scroll_box->add_choice("Drag&Drop");
  scroll_box->add_choice("Rubberband");
  
  swcursor_box      = new CheckBox(Rect());
  fullscreen_box    = new CheckBox(Rect());
  autoscroll_box    = new CheckBox(Rect());
  mousegrab_box     = new CheckBox(Rect());
  printfps_box      = new CheckBox(Rect());

  master_volume_box = new SliderBox(Rect());
  sound_volume_box  = new SliderBox(Rect());
  music_volume_box  = new SliderBox(Rect());

  C(swcursor_box->on_change.connect(std::bind(&OptionMenu::on_swcursor_change, this, std::placeholders::_1)));
  C(fullscreen_box->on_change.connect(std::bind(&OptionMenu::on_fullscreen_change, this, std::placeholders::_1)));
  C(autoscroll_box->on_change.connect(std::bind(&OptionMenu::on_autoscroll_change, this, std::placeholders::_1)));
  C(mousegrab_box->on_change.connect(std::bind(&OptionMenu::on_mousegrab_change, this, std::placeholders::_1)));
  C(printfps_box->on_change.connect(std::bind(&OptionMenu::on_printfps_change, this, std::placeholders::_1)));

  C(master_volume_box->on_change.connect(std::bind(&OptionMenu::on_master_volume_change, this, std::placeholders::_1)));
  C(sound_volume_box->on_change.connect(std::bind(&OptionMenu::on_sound_volume_change, this, std::placeholders::_1)));
  C(music_volume_box->on_change.connect(std::bind(&OptionMenu::on_music_volume_change, this, std::placeholders::_1)));

  C(language_box->on_change.connect(std::bind(&OptionMenu::on_language_change, this, std::placeholders::_1)));
  C(resolution_box->on_change.connect(std::bind(&OptionMenu::on_resolution_change, this, std::placeholders::_1)));

  add_item(_("Language:"),        language_box);
  //  add_item(_("Scroll Mode:"),     scroll_box);
  add_item(_("Resolution:"),      resolution_box);
  add_item(_("Fullscreen:"),      fullscreen_box);
  add_item(_("Master Volume:"),   master_volume_box);
  add_item(_("Sound Volume:"),    sound_volume_box);
  add_item(_("Music Volume:"),    music_volume_box);
  add_item(_("Autoscrolling:"),   autoscroll_box);
  add_item(_("Print FPS:"),       printfps_box);
  add_item(_("Mouse Grab:"),      mousegrab_box);
  add_item(_("Software Cursor:"), swcursor_box);

  // Connect with ConfigManager
  mousegrab_box->set_state(config_manager.get_mouse_grab(), false);
  C(config_manager.on_mouse_grab_change.connect(std::bind(&CheckBox::set_state, mousegrab_box, std::placeholders::_1, false)));

  printfps_box->set_state(config_manager.get_print_fps(), false);
  C(config_manager.on_print_fps_change.connect(std::bind(&CheckBox::set_state, printfps_box, std::placeholders::_1, false)));

  fullscreen_box->set_state(config_manager.get_fullscreen(), false);
  C(config_manager.on_fullscreen_change.connect(std::bind(&CheckBox::set_state, fullscreen_box, std::placeholders::_1, false)));

  swcursor_box->set_state(config_manager.get_swcursor(), false);
  C(config_manager.on_swcursor_change.connect(std::bind(&CheckBox::set_state, swcursor_box, std::placeholders::_1, false)));

  autoscroll_box->set_state(config_manager.get_autoscroll(), false);
  C(config_manager.on_autoscroll_change.connect(std::bind(&CheckBox::set_state, autoscroll_box, std::placeholders::_1, false)));

  defaults_label = new Label(_("Reset to Defaults:"), Rect(Vector2i(Display::get_width()/2 - 100, Display::get_height()/2 + 160), Size(170, 32)));
  gui_manager->add(defaults_label);
  defaults_box = new CheckBox(Rect(Vector2i(Display::get_width()/2 - 100 + 170, Display::get_height()/2 + 160), Size(32, 32)));
  gui_manager->add(defaults_box);
}
示例#4
0
OptionMenu::OptionMenu() :
  m_background("core/menu/wood"),
  m_blackboard("core/menu/blackboard"),
  ok_button(),
  x_pos(),
  y_pos(),
  options(),
  fullscreen_box(),
  software_cursor_box(),
  autoscroll_box(),
  dragdrop_scroll_box(),
  mousegrab_box(),
  printfps_box(),
  master_volume_box(),
  sound_volume_box(),
  music_volume_box(),
  //defaults_label(),
  //defaults_box(),
  connections(),
  m_language(),
  m_language_map()
{
  gui_manager->add(ok_button = new OptionMenuCloseButton(this, 
                                                         Display::get_width()/2 + 245,
                                                         Display::get_height()/2 + 150));

  x_pos = 0;
  y_pos = 0;

  ChoiceBox* resolution_box = new ChoiceBox(Rect());
  {
    std::vector<SDL_DisplayMode> resolutions = Display::get_fullscreen_video_modes();
    Size fullscreen = config_manager.get_fullscreen_resolution();

    int choice = static_cast<int>(resolutions.size()) - 1;
    for (auto it = resolutions.begin(); it != resolutions.end(); ++it)
    {
      // add resolution to the box
      std::ostringstream ostr;
      ostr << it->w << "x" << it->h << "@" << it->refresh_rate;
      resolution_box->add_choice(ostr.str());

      // FIXME: ignoring refresh_rate
      if (fullscreen.width == it->w &&
          fullscreen.height == it->h)
      {
        choice = static_cast<int>(it - resolutions.begin());
      }
    }

    resolution_box->set_current_choice(choice);
  }

  ChoiceBox* renderer_box = new ChoiceBox(Rect());
  renderer_box->add_choice("sdl");
  renderer_box->add_choice("delta");
  renderer_box->add_choice("opengl");

  switch(config_manager.get_renderer())
  {
    case SDL_FRAMEBUFFER:    renderer_box->set_current_choice(0); break;
    case DELTA_FRAMEBUFFER:  renderer_box->set_current_choice(1); break;
    case OPENGL_FRAMEBUFFER: renderer_box->set_current_choice(2); break;
    default: assert(!"unknown renderer type");
  }
  
  m_language = dictionary_manager.get_language();

  ChoiceBox* language_box = new ChoiceBox(Rect());
  {
    std::set<tinygettext::Language> languages = dictionary_manager.get_languages();

    // English is the default language, thus it's not in the list of
    // languages returned by tinygettext and we have to add it manually
    languages.insert(tinygettext::Language::from_name("en"));

    std::vector<tinygettext::Language> langs(languages.begin(), languages.end());
    std::sort(langs.begin(), langs.end(), LanguageSorter());

    for (auto i = langs.begin(); i != langs.end(); ++i)
    {
      m_language_map[i->get_name()] = *i;
      language_box->add_choice(i->get_name());

      if (m_language == *i)
      {
        language_box->set_current_choice(static_cast<int>(i - langs.begin()));
      }
    }
  }

  ChoiceBox* scroll_box = new ChoiceBox(Rect());
  scroll_box->add_choice("Drag&Drop");
  scroll_box->add_choice("Rubberband");

  software_cursor_box = new CheckBox(Rect());
  fullscreen_box      = new CheckBox(Rect());
  autoscroll_box      = new CheckBox(Rect());
  dragdrop_scroll_box = new CheckBox(Rect());
  mousegrab_box       = new CheckBox(Rect());
  printfps_box        = new CheckBox(Rect());

  master_volume_box = new SliderBox(Rect(), 25);
  sound_volume_box  = new SliderBox(Rect(), 25);
  music_volume_box  = new SliderBox(Rect(), 25);

  master_volume_box->set_value(config_manager.get_master_volume());
  sound_volume_box->set_value(config_manager.get_sound_volume());
  music_volume_box->set_value(config_manager.get_music_volume());

  C(software_cursor_box->on_change.connect(std::bind(&OptionMenu::on_software_cursor_change, this, std::placeholders::_1)));
  C(fullscreen_box->on_change.connect(std::bind(&OptionMenu::on_fullscreen_change, this, std::placeholders::_1)));
  C(autoscroll_box->on_change.connect(std::bind(&OptionMenu::on_autoscroll_change, this, std::placeholders::_1)));
  C(dragdrop_scroll_box->on_change.connect(std::bind(&OptionMenu::on_drag_drop_scrolling_change, this, std::placeholders::_1)));
  C(mousegrab_box->on_change.connect(std::bind(&OptionMenu::on_mousegrab_change, this, std::placeholders::_1)));
  C(printfps_box->on_change.connect(std::bind(&OptionMenu::on_printfps_change, this, std::placeholders::_1)));

  C(master_volume_box->on_change.connect(std::bind(&OptionMenu::on_master_volume_change, this, std::placeholders::_1)));
  C(sound_volume_box->on_change.connect(std::bind(&OptionMenu::on_sound_volume_change, this, std::placeholders::_1)));
  C(music_volume_box->on_change.connect(std::bind(&OptionMenu::on_music_volume_change, this, std::placeholders::_1)));

  C(language_box->on_change.connect(std::bind(&OptionMenu::on_language_change, this, std::placeholders::_1)));
  C(resolution_box->on_change.connect(std::bind(&OptionMenu::on_resolution_change, this, std::placeholders::_1)));
  C(renderer_box->on_change.connect(std::bind(&OptionMenu::on_renderer_change, this, std::placeholders::_1)));

  x_pos = 0;
  y_pos = 0;
  add_item(_("Fullscreen"), fullscreen_box);
  add_item(_("Mouse Grab"), mousegrab_box);
  y_pos += 1;
  add_item(_("Software Cursor"), software_cursor_box);
  add_item(_("Autoscrolling"), autoscroll_box);
  add_item(_("Drag&Drop Scrolling"), dragdrop_scroll_box);
  y_pos += 1;
  add_item(_("Print FPS"), printfps_box);

  x_pos = 1;
  y_pos = 0;
  add_item(_("Resolution:"),    resolution_box);
  add_item(_("Renderer:"),      renderer_box);
  y_pos += 1;
  add_item(_("Language:"),        language_box);
  y_pos += 1;
  add_item(_("Master Volume:"),   master_volume_box);
  add_item(_("Sound Volume:"),    sound_volume_box);
  add_item(_("Music Volume:"),    music_volume_box);
  
  // Connect with ConfigManager
  mousegrab_box->set_state(config_manager.get_mouse_grab(), false);
  C(config_manager.on_mouse_grab_change.connect(std::bind(&CheckBox::set_state, mousegrab_box, std::placeholders::_1, false)));

  printfps_box->set_state(config_manager.get_print_fps(), false);
  C(config_manager.on_print_fps_change.connect(std::bind(&CheckBox::set_state, printfps_box, std::placeholders::_1, false)));

  fullscreen_box->set_state(config_manager.get_fullscreen(), false);
  C(config_manager.on_fullscreen_change.connect(std::bind(&CheckBox::set_state, fullscreen_box, std::placeholders::_1, false)));

  software_cursor_box->set_state(config_manager.get_software_cursor(), false);
  C(config_manager.on_software_cursor_change.connect(std::bind(&CheckBox::set_state, software_cursor_box, std::placeholders::_1, false)));

  autoscroll_box->set_state(config_manager.get_auto_scrolling(), false);
  C(config_manager.on_auto_scrolling_change.connect(std::bind(&CheckBox::set_state, autoscroll_box, std::placeholders::_1, false)));

  dragdrop_scroll_box->set_state(config_manager.get_drag_drop_scrolling(), false);
  C(config_manager.on_drag_drop_scrolling_change.connect(std::bind(&CheckBox::set_state, dragdrop_scroll_box, std::placeholders::_1, false)));

  /*
    defaults_label = new Label(_("Reset to Defaults:"), Rect(Vector2i(Display::get_width()/2 - 100, Display::get_height()/2 + 160), Size(170, 32)));
    gui_manager->add(defaults_label);
    defaults_box = new CheckBox(Rect(Vector2i(Display::get_width()/2 - 100 + 170, Display::get_height()/2 + 160), Size(32, 32)));
    gui_manager->add(defaults_box);
  */
}