Ejemplo n.º 1
0
HBoxContainer* EditorAddonLibrary::_make_pages(int p_page,int p_max_page,int p_page_len,int p_total_items,int p_current_items) {

	HBoxContainer * hbc = memnew( HBoxContainer );

	//do the mario
	int from = p_page-5;
	if (from<0)
		from=0;
	int to = from+10;
	if (to>p_max_page)
		to=p_max_page;

	Color gray = Color(0.65,0.65,0.65);

	hbc->add_spacer();
	hbc->add_constant_override("separation",10);

	LinkButton *first = memnew( LinkButton );
	first->set_text("first");
	first->add_color_override("font_color", gray );
	first->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
	first->connect("pressed",this,"_search",varray(0));
	hbc->add_child(first);

	if (p_page>0) {
		LinkButton *prev = memnew( LinkButton );
		prev->set_text("prev");
		prev->add_color_override("font_color", gray );
		prev->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
		prev->connect("pressed",this,"_search",varray(p_page-1));
		hbc->add_child(prev);
	}

	for(int i=from;i<=to;i++) {

		if (i==p_page) {

			Label *current = memnew(Label);
			current->set_text(itos(i));
			hbc->add_child(current);
		} else {

			LinkButton *current = memnew( LinkButton );
			current->add_color_override("font_color", gray );
			current->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
			current->set_text(itos(i));
			current->connect("pressed",this,"_search",varray(i));

			hbc->add_child(current);

		}
	}

	if (p_page<p_max_page) {
		LinkButton *next = memnew( LinkButton );
		next->set_text("next");
		next->add_color_override("font_color", gray );
		next->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
		next->connect("pressed",this,"_search",varray(p_page+1));

		hbc->add_child(next);
	}
	LinkButton *last = memnew( LinkButton );
	last->set_text("last");
	last->add_color_override("font_color", gray );
	last->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
	hbc->add_child(last);
	last->connect("pressed",this,"_search",varray(p_max_page));

	Label *totals = memnew( Label );
	totals->set_text("( "+itos(from*p_page_len)+" - "+itos(from*p_page_len+p_current_items-1)+" / "+itos(p_total_items)+" )");
	hbc->add_child(totals);

	hbc->add_spacer();

	return hbc;
}