Exemple #1
0
StdStrBuf C4ObjectList::GetNameList(C4DefList &rDefs) const
{
	int cpos,idcount;
	C4ID c_id;
	C4Def *cdef;
	StdStrBuf Buf;
	for (cpos=0; (c_id=GetListID(C4D_All,cpos)); cpos++)
		if ((cdef=rDefs.ID2Def(c_id)))
		{
			idcount=ObjectCount(c_id);
			if (cpos>0) Buf.Append(", ");
			Buf.AppendFormat("%dx %s",idcount,cdef->GetName());
		}
	return Buf;
}
Exemple #2
0
bool C4MainMenu::ActivateGoals(int32_t iPlayer, bool fDoActivate)
{
	C4FacetSurface fctSymbol;
	C4Facet fctGF; // goal fulfilled facet

	if (fDoActivate)
	{
		// Menu symbol/init
		InitRefSym(GfxR->fctMenu.GetPhase(4),LoadResStr("IDS_MENU_CPGOALS"),iPlayer);
		SetAlignment(C4MN_Align_Left | C4MN_Align_Bottom);
		SetPermanent(false);
		fctGF.Set(NULL, C4SymbolSize-::GraphicsResource.fctCaptain.Wdt-2, 2, ::GraphicsResource.fctCaptain.Wdt, ::GraphicsResource.fctCaptain.Hgt);
	}
	// determine if the goals are fulfilled - do the calls even if the menu is not to be opened to ensure synchronization
	C4IDList GoalList, FulfilledGoalList;
	C4RoundResults::EvaluateGoals(GoalList, FulfilledGoalList, iPlayer);
	// Add Items
	if (fDoActivate)
	{
		int32_t iNumGoals = GoalList.GetNumberOfIDs(), cnt;
		C4ID idGoal; C4Def *pDef;
		for (int32_t i=0; i<iNumGoals; ++i)
			if ((idGoal = GoalList.GetID(i, &cnt)))
				if ((pDef = C4Id2Def(idGoal)))
				{
					fctSymbol.Create(C4SymbolSize,C4SymbolSize);
					// 2do: If an object instance is known, draw the object instead?
					// this would allow us to do dynamic pictures and overlays; e.g. draw the actual, required settlement score
					// for settlement score goals
					// Same for pDef->GetName(), pDef->GetDesc()
					pDef->Draw(fctSymbol);
					if (FulfilledGoalList.GetIDCount(idGoal))
					{
						fctGF.Surface=fctSymbol.Surface;
						::GraphicsResource.fctCaptain.Draw(fctGF);
					}
					StdStrBuf Command; Command.Format("Player:Goal:%s", idGoal.ToString());
					Add(pDef->GetName(),fctSymbol,Command.getData(),C4MN_Item_NoCount,NULL,"");
				}
		// Go back to options menu on close
		SetCloseCommand("ActivateMenu:Main");
	}
	// Done
	return true;
}
Exemple #3
0
C4GoalDisplay::GoalPicture::GoalPicture(const C4Rect &rcBounds, C4ID idGoal, bool fFulfilled)
 : idGoal(idGoal), fFulfilled(fFulfilled), C4GUI::Window()
	{
	// bounds
	SetBounds(rcBounds);
	// can't get specialized desc from object at the moment because of potential script callbacks!
	StdStrBuf strGoalName, strGoalDesc;
	/*C4Object *pGoalObj = Game.Objects.FindInternal(idGoal);
	if (pGoalObj)
		{
		pGoalObj->GetInfoString().getData(); 
		}
	else*/
		{
		// just get desc from def
		C4Def *pGoalDef = Game.Defs.ID2Def(idGoal);
		if (pGoalDef)
			{
			strGoalName.Copy(pGoalDef->GetName());
			strGoalDesc.Copy(pGoalDef->GetDesc());
			}
		}
	// get tooltip
	StdStrBuf sToolTip;
	if (fFulfilled)
		sToolTip.Format(LoadResStr("IDS_DESC_GOALFULFILLED"), strGoalName.getData(), strGoalDesc.getData());
	else
		sToolTip.Format(LoadResStr("IDS_DESC_GOALNOTFULFILLED"), strGoalName.getData(), strGoalDesc.getData());
	SetToolTip(sToolTip.getData());
	// create buffered picture of goal definition
	C4Def *pDrawDef = Game.Defs.ID2Def(idGoal);
	if (pDrawDef)
		{
		Picture.Create(C4PictureSize, C4PictureSize);
		// get an object instance to draw (optional; may be zero)
		C4Object *pGoalObj = Game.Objects.FindInternal(idGoal);
		// draw goal def!
		pDrawDef->Draw(Picture, false, 0, pGoalObj);
		}
	// unfulfilled goal: grey out picture
	if (!fFulfilled)
		Picture.Grayscale(30);
	}
Exemple #4
0
bool C4MainMenu::ActivateRules(int32_t iPlayer)
{
	// Menu symbol/init
	char Command[256];
	C4FacetSurface fctSymbol;
	InitRefSym(GfxR->fctMenu.GetPhase(5),LoadResStr("IDS_MENU_CPRULES"),iPlayer);
	SetAlignment(C4MN_Align_Left | C4MN_Align_Bottom);
	SetPermanent(false);
	// Items
	int32_t cnt; C4ID idGoal; C4Def *pDef;
	for (cnt=0; (idGoal=::Objects.GetListID(C4D_Rule,cnt)); cnt++)
		if ((pDef=C4Id2Def(idGoal)))
		{
			fctSymbol.Create(C4SymbolSize,C4SymbolSize); pDef->Draw(fctSymbol);
			sprintf(Command, "Player:Rule:%s", idGoal.ToString());
			Add(pDef->GetName(),fctSymbol,Command,C4MN_Item_NoCount,NULL,"");
		}
	// Go back to options menu on close
	SetCloseCommand("ActivateMenu:Main");
	// Done
	return true;
}
void C4DefGraphicsAdapt::CompileFunc(StdCompiler *pComp)
{
	bool fCompiler = pComp->isCompiler();
	// nothing?
	if (!fCompiler && !pDefGraphics) return;
	// definition
	C4ID id; if (!fCompiler) id = pDefGraphics->pDef->id;
	pComp->Value(id);
	// go over two separators ("::"). Expect them if an id was found.
	if (!pComp->Separator(StdCompiler::SEP_PART2) || !pComp->Separator(StdCompiler::SEP_PART2))
		pComp->excCorrupt("DefGraphics: expected \"::\"");
	// compile name
	StdStrBuf Name; if (!fCompiler) Name = pDefGraphics->GetName();
	pComp->Value(mkDefaultAdapt(mkParAdapt(Name, StdCompiler::RCT_Idtf), ""));
	// reading: search def-graphics
	if (fCompiler)
	{
		// search definition, throw expection if not found
		C4Def *pDef = ::Definitions.ID2Def(id);
		// search def-graphics
		if (!pDef || !( pDefGraphics = pDef->Graphics.Get(Name.getData()) ))
			pComp->excCorrupt("DefGraphics: could not find graphics \"%s\" in %s(%s)!", Name.getData(), id.ToString(), pDef ? pDef->GetName() : "def not found");
	}
}
void C4ConsoleQtDefinitionListModel::ReInit()
{
	// Re-fill definition model with all loaded definitions matching condition
	// (TODO: Add conditional lists)
	root = std::make_unique<C4ConsoleQtDefinitionListModel::DefListNode>();
	int32_t index = 0; C4Def *def;
	while ((def = ::Definitions.GetDef(index++)))
	{
		// Ignore hidden defs
		if (def->HideInCreator) continue;
		// Build path leading to this definition
		DefListNode *node_parent = root.get();
		StdCopyStrBuf fn(def->Filename), fn2;
		StdCopyStrBuf fn_full;
		fn.ReplaceChar(AltDirectorySeparator, DirectorySeparator);
		for (;;)
		{
			bool is_parent_folder = fn.SplitAtChar(DirectorySeparator, &fn2);
			if (fn_full.getLength())
			{
				fn_full.AppendChar(DirectorySeparator);
			}
			fn_full.Append(fn);
			if (!is_parent_folder || WildcardMatch(C4CFN_DefFiles, fn.getData())) // ignore non-.ocd-folders (except for final definition)
			{
				// Find if path is already there
				RemoveExtension(&fn);
				DefListNode *node_child = nullptr;
				for (auto &test_node_child : node_parent->items)
					if (test_node_child->filename == fn)
					{
						node_child = &*test_node_child;
						break;
					}
				// If not, create it
				if (!node_child)
				{
					node_parent->items.emplace_back((node_child = new DefListNode()));
					node_child->idx = node_parent->items.size() - 1;
					node_child->parent = node_parent;
					const char *localized_name = ::Definitions.GetLocalizedGroupFolderName(fn_full.getData());
					node_child->name.Copy(localized_name ? localized_name : fn.getData());
					node_child->filename.Copy(fn);
				}
				// And fill in node if this is not a parent folder
				if (!is_parent_folder)
				{
					node_child->def = def;
					const char *def_name = def->GetName();
					if (def_name && *def_name) node_child->name.Copy(def_name);
					break;
				}
				else
				{
					// Parent folder: Next path segment
					node_parent = node_child;
				}
			}
			fn = fn2;
		}
	}
	// Descend into singleton root classes. I.e. if all elements are children of Objects/Items, move the root in there.
	DefListNode *new_root = root.get();
	while (new_root->items.size() == 1 && !new_root->items[0]->def)
	{
		std::unique_ptr<DefListNode> tmp(new_root->items[0].release());
		root.reset(tmp.release());
		new_root = root.get();
	}
	root->parent = nullptr;
	// Copy group path names into definitions for later lookup by script
	QStringList group_names;
	DefListNode *node = root.get();
	while (node)
	{
		if (node->def)
		{
			node->def->ConsoleGroupPath.Copy(group_names.join('/').toUtf8());
		}
		// Walk over tree. Remember groups in group_names string list.
		if (!node->items.empty())
		{
			if (node != root.get()) group_names.append(node->name.getData());
			node = node->items[0].get();
		}
		else
		{
			int32_t idx = node->idx + 1;
			while ((node = node->parent))
			{
				if (node->items.size() > idx)
				{
					node = node->items[idx].get();
					break;
				}
				if (group_names.size()) group_names.pop_back();
				idx = node->idx + 1;
			}
		}
	}
	// Sort everything by display name (recursively)
	root->SortByName();
	// Model reset to invalidate all indexes
	beginResetModel();
	endResetModel();
}