Beispiel #1
0
// Init the gump, call after construction
void AskGump::InitGump(Gump* newparent, bool take_focus)
{
	// OK, this is a bit of a hack, but it's how it has to be
	int	fontnum;
	if (owner == 1) fontnum = 6;
	else if (owner > 256) fontnum = 8;
	else switch (owner%3) {
		case 1:
			fontnum = 5;
			break;
			
		case 2:
			fontnum = 7;
			break;

		default:
			fontnum = 0;
			break;
	}

	int px = 0, py = 0;

	// This is a hack. We init the gump twice...
	ItemRelativeGump::InitGump(newparent, take_focus);

	for (unsigned int i = 0; i < answers->getSize(); ++i) {
		std::string str_answer = "@ ";
		str_answer += UCMachine::get_instance()->getString(answers->getStringIndex(i));

		ButtonWidget *child = new ButtonWidget(px, py, str_answer,
											   true, fontnum);
		child->InitGump(this);
		child->SetIndex(i);

		Pentagram::Rect cd;
		child->GetDims(cd);
		if (i+1 < answers->getSize())
			cd.h += child->getVlead();

		if (px+cd.w > 160 && px != 0) 
		{
			py = dims.h;
			px = 0;
			child->Move(px,py);
		}

		if (cd.w+px > dims.w) dims.w = cd.w+px;
		if (cd.h+py > dims.h) dims.h = cd.h+py;

		px += cd.w+4;
	}

	// Wait with ItemRelativeGump initialization until we calculated our size.
	ItemRelativeGump::InitGump(newparent, take_focus);
}
Beispiel #2
0
bool AskGump::loadData(IDataSource* ids, uint32 version)
{
	if (!ItemRelativeGump::loadData(ids, version)) return false;

	answers = new UCList(2);
	answers->load(ids, version);

	// HACK ALERT
	int px = 0, py = 0;

	dims.w = 0;
	dims.h = 0;


	for (unsigned int i = 0; i < answers->getSize(); ++i) {

		ButtonWidget *child = 0;

		std::list<Gump*>::iterator it;
		for (it = children.begin(); it != children.end(); ++it) {
			if ((*it)->GetIndex() != (int)i) continue;
			child = p_dynamic_cast<ButtonWidget*>(*it);
			if (!child) continue;
		}

		if (!child) return false;

		Pentagram::Rect cd;
		child->GetDims(cd);

		if (px+cd.w > 160 && px != 0) 
		{
			py = dims.h;
			px = 0;
		}
		child->Move(px,py);

		if (cd.w+px > dims.w) dims.w = cd.w+px;
		if (cd.h+py > dims.h) dims.h = cd.h+py;

		px += cd.w+4;
	}

	return true;
}