Example #1
0
void kPanel::reposition(int l){
  int i,i2,d;

  // brain dead. Don't ask me why I don't use a list, please....

  DesktopEntry tmp;

  /*

    i = 1;
    while ( i < nbuttons ) {

    if ( (orientation == vertical && entries[i-1].button->y() > entries[i].button->y()) ||
    (orientation == horizontal && entries[i-1].button->x() > entries[i].button->x())) {

    tmp = entries[i-1];
    entries[i-1] = entries[i];
    entries[i] = tmp;
    }
    i++;
    }
    */
  bool changed;
  do {
    changed = false;
    for (i = 0; i < (nbuttons - 1); i++) {

      if ( (orientation == vertical && entries[i].button->y() > entries[i+1].button->y()) ||
	   (orientation == horizontal && entries[i].button->x() > entries[i+1].button->x())) {
	tmp = entries[i];
	entries[i] = entries[i+1];
	entries[i+1] = tmp;
	changed = true;
      }
    }
  } while (changed);


  if (orientation == vertical){
    for (i=0; i<nbuttons-1; i++){
      if (entries[i].button->y()<panel_button->y()+panel_button->height())
	entries[i].button->move(entries[i].button->x(),
				panel_button->y()+panel_button->height());
    }
    for (i=0; i<nbuttons-1; i++){
      d = entries[i].button->y() + entries[i].button->height() - entries[i+1].button->y();
      if (d>0){
	for (i2=i+1;
	     i2<nbuttons &&
	       entries[i2].button->y() < entries[i2-1].button->y() +entries[i2-1].button->height();
	     i2++){
	  entries[i2].button->move(entries[i2].button->x(), entries[i2].button->y() + d);
	  if (entries[i2].button->y() > bound_top_left - entries[i2].button->height()&&
	      entries[i2].button->y() < bound_bottom_right
	      && height() - bound_bottom_right > entries[i2].button->height()
	      )
	    entries[i2].button->move(entries[i2].button->x(), bound_bottom_right);
	}
      }
    }

    d = entries[nbuttons-1].button->y() + entries[nbuttons-1].button->height() - height();
    if (entries[nbuttons-1].button->y() < bound_bottom_right &&
	entries[nbuttons-1].button->y() + entries[nbuttons-1].button->height() > bound_top_left)
      d = entries[nbuttons-1].button->y() + entries[nbuttons-1].button->height() - bound_top_left;
    if ( d > 0) {
      entries[nbuttons-1].button->move(entries[nbuttons-1].button->x(),
				entries[nbuttons-1].button->y() - d);
      for (i=nbuttons-2;
	   i>=0 &&
	     entries[i].button->y() + entries[i].button->height() > entries[i+1].button->y();
	   i--){
	entries[i].button->move(entries[i].button->x(), entries[i].button->y() - d);
	if (entries[i].button->y() > bound_top_left - entries[i].button->height()&&
	    entries[i].button->y() < bound_bottom_right)
	  entries[i].button->move(entries[i].button->x(), bound_top_left - entries[i].button->height());
      }
      if (l>nbuttons&&nbuttons>1) {
	if (entries[nbuttons-1].button == kde_button){
	  entries[nbuttons-1].button = entries[nbuttons-2].button;
	  entries[nbuttons-2].button = kde_button;
	  kde_button->setGeometry(entries[nbuttons-1].button->geometry());
	}
	delete_button(entries[nbuttons-1].button);
	l=0;
      }
      reposition(l+1);
    }
  }
  else { // orientation == horizontal

    for (i=0; i<nbuttons-1; i++){
      if (entries[i].button->x()<panel_button->x()+panel_button->width())
	entries[i].button->move(panel_button->x()+panel_button->width(),
				entries[i].button->y());
    }
    for (i=0; i<nbuttons-1; i++){
      d = entries[i].button->x() + entries[i].button->width() - entries[i+1].button->x();
      if (d>0){
	for (i2=i+1;
	     i2<nbuttons &&
	       entries[i2].button->x() < entries[i2-1].button->x() +entries[i2-1].button->width();
	     i2++){
	  entries[i2].button->move(entries[i2].button->x() + d, entries[i2].button->y());
	  if (entries[i2].button->x() > bound_top_left - entries[i2].button->width()&&
	      entries[i2].button->x() < bound_bottom_right
	      && width() - bound_bottom_right > entries[i2].button->width()
	      )
	    entries[i2].button->move(bound_bottom_right, entries[i2].button->y());
	}
      }
    }

    d = entries[nbuttons-1].button->x() + entries[nbuttons-1].button->width() - width();
    if (entries[nbuttons-1].button->x() < bound_bottom_right &&
	entries[nbuttons-1].button->x() + entries[nbuttons-1].button->width() > bound_top_left)
      d = entries[nbuttons-1].button->x() + entries[nbuttons-1].button->width() - bound_top_left;
    if ( d > 0) {
      entries[nbuttons-1].button->move(entries[nbuttons-1].button->x() - d,
				entries[nbuttons-1].button->y());
      for (i=nbuttons-2;
	   i>=0 &&
	     entries[i].button->x() + entries[i].button->width() > entries[i+1].button->x();
	   i--){
	entries[i].button->move(entries[i].button->x() - d, entries[i].button->y());
	if (entries[i].button->x() > bound_top_left - entries[i].button->width()&&
	    entries[i].button->x() < bound_bottom_right)
	  entries[i].button->move(bound_top_left - entries[i].button->width(), entries[i].button->y());
      }
      if (l>nbuttons&&nbuttons>1) {
	if (entries[nbuttons-1].button == kde_button){
	  entries[nbuttons-1].button = entries[nbuttons-2].button;
	  entries[nbuttons-2].button = kde_button;
	  kde_button->setGeometry(entries[nbuttons-1].button->geometry());
	}
	delete_button(entries[nbuttons-1].button);
	l=0;
      }
      reposition(l+1);
    }
  }

}
Example #2
0
std::string load_game_dialog(display& disp, const config& game_config, bool* show_replay, bool* cancel_orders)
{
	std::vector<savegame::save_info> games;
	{
		cursor::setter cur(cursor::WAIT);
		games = savegame::manager::get_saves_list();
	}

	if(games.empty()) {
		gui2::show_transient_message(disp.video(),
		                 _("No Saved Games"),
				 _("There are no saved games to load.\n\n(Games are saved automatically when you complete a scenario)"));
		return "";
	}

	std::vector<config*> summaries;
	std::vector<savegame::save_info>::const_iterator i;
	//FIXME: parent_to_child is not used yet
	std::map<std::string,std::string> parent_to_child;
	for(i = games.begin(); i != games.end(); ++i) {
		config& cfg = savegame::save_index::save_summary(i->name);
		parent_to_child[cfg["parent"]] = i->name;
		summaries.push_back(&cfg);
	}

	const events::event_context context;

	std::vector<std::string> items;
	std::ostringstream heading;
	heading << HEADING_PREFIX << _("Name") << COLUMN_SEPARATOR << _("Date");
	items.push_back(heading.str());

	for(i = games.begin(); i != games.end(); ++i) {
		std::string name = i->name;
		utils::truncate_as_wstring(name, std::min<size_t>(name.size(), 40));

		std::ostringstream str;
		str << name << COLUMN_SEPARATOR << format_time_summary(i->time_modified);

		items.push_back(str.str());
	}

	gamemap map_obj(game_config, "");


	gui::dialog lmenu(disp,
			  _("Load Game"),
			  _("Choose the game to load"), gui::NULL_DIALOG);
	lmenu.set_basic_behavior(gui::OK_CANCEL);

	gui::menu::basic_sorter sorter;
	sorter.set_alpha_sort(0).set_id_sort(1);
	lmenu.set_menu(items, &sorter);

	gui::filter_textbox* filter = new gui::filter_textbox(disp.video(), _("Filter: "), items, items, 1, lmenu);
	lmenu.set_textbox(filter);

	save_preview_pane save_preview(disp.video(),game_config,&map_obj,games,summaries,*filter);
	lmenu.add_pane(&save_preview);
	// create an option for whether the replay should be shown or not
//	if(show_replay != NULL) {
//		lmenu.add_option(_("Show replay"), false,
//			// use smallgui layout as default, otherwise the load screen glitches at low res!
//			//game_config::small_gui ? gui::dialog::BUTTON_CHECKBOX : gui::dialog::BUTTON_STANDARD);
//			gui::dialog::BUTTON_CHECKBOX);
//	}
	if(cancel_orders != NULL) {
		lmenu.add_option(_("Cancel orders"), false,
			// use smallgui layout as default, otherwise the load screen glitches at low res!
			//game_config::small_gui ? gui::dialog::BUTTON_STANDARD : gui::dialog::BUTTON_EXTRA);
			gui::dialog::BUTTON_STANDARD);
	}
	lmenu.add_button(new gui::standard_dialog_button(disp.video(),_("OK"),0,false), gui::dialog::BUTTON_STANDARD);
	lmenu.add_button(new gui::standard_dialog_button(disp.video(),_("Cancel"),1,true), gui::dialog::BUTTON_STANDARD);

	delete_save save_deleter(disp,*filter,games,summaries);
	gui::dialog_button_info delete_button(&save_deleter,_("Delete Save"));

	lmenu.add_button(delete_button,
		// use smallgui layout as default, otherwise the load screen glitches at low res!
		//game_config::small_gui ? gui::dialog::BUTTON_HELP : gui::dialog::BUTTON_EXTRA);
		gui::dialog::BUTTON_HELP);

	int res = lmenu.show();

	savegame::save_index::write_save_index();

	if(res == -1)
		return "";

	res = filter->get_index(res);
	int option_index = 0;
	if(show_replay != NULL) {
	  *show_replay = lmenu.option_checked(option_index++);

		const config& summary = *summaries[res];
		if (summary["replay"].to_bool() && !summary["snapshot"].to_bool(true)) {
			*show_replay = true;
		}
	}
	if (cancel_orders != NULL) {
		*cancel_orders = lmenu.option_checked(option_index++);
	}

	return games[res].name;
}