protected void SetIndent(MCListItem mcListItem, int indent) { // Don't bother messing around if there is no indent if (indent == 0) { return; } // Re-order the hierarchy to add spacers for indented items GameObject go = new GameObject("GroupContainer"); go.transform.parent = mcListItem.transform.parent; go.AddComponent<RectTransform>(); go.AddComponent<CanvasRenderer>(); go.AddComponent<HorizontalLayoutGroup>(); ((Container)mcListItem.container.Data).listItemTransform = go.transform; // Create a spacer sized based on the indent GameObject spacer = new GameObject("Spacer"); spacer.AddComponent<RectTransform>(); LayoutElement spacerLayout = spacer.AddComponent<LayoutElement>(); spacerLayout.minWidth = indent * 12; ContentSizeFitter spacerFitter = spacer.AddComponent<ContentSizeFitter>(); spacerFitter.horizontalFit = ContentSizeFitter.FitMode.MinSize; // Re-parent the spacer and list item spacer.transform.SetParent(go.transform); mcListItem.transform.SetParent(go.transform); // Perform some surgery on the list item to set its preferred width to the correct value LayoutElement le = mcListItem.GetComponent<LayoutElement>(); le.preferredWidth = 316 - indent * 12; le.flexibleWidth = 1; ContentSizeFitter mcListItemFitter = mcListItem.gameObject.AddComponent<ContentSizeFitter>(); mcListItemFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; }
protected void SetContractTitle(MCListItem mcListItem, ContractContainer cc) { // Set up the list item with the contract details string color = cc.contract == null ? "A9A9A9" : cc.contract.ContractState == Contract.State.Active ? "96df41" : "fefa87"; string title = ""; if (cc.contract != null) { title = cc.contract.Title; } else { title = cc.contractType.genericTitle; // Special case for one-off contracts if (cc.contractType.maxCompletions == 1) { foreach (ConfiguredContract c in ConfiguredContract.CompletedContracts) { if (c.contractType != null && c.contractType.name == cc.contractType.name) { title = c.Title; break; } } } } mcListItem.title.text = StringBuilderCache.Format("<color=#{0}>{1}</color>", color, title); if (cc.contract != null && cc.contract.ContractViewed != Contract.Viewed.Read) { mcListItem.title.text = StringBuilderCache.Format("<b>{0}</b>", mcListItem.title.text); } if (displayModeAll) { float preferredHeight = mcListItem.title.GetPreferredValues(mcListItem.title.text, 316 - cc.indent * 12 - 64, TMPro.TMP_Math.FLOAT_MAX).y; bool twoLines = preferredHeight > 14; mcListItem.GetComponent<LayoutElement>().preferredHeight = twoLines ? 38 : 25; if (cc.statusRect != null) { cc.statusRect.anchoredPosition = new Vector2(16.0f, 0f); } } // Setup prestige if (cc.contract != null) { mcListItem.difficulty.SetState((int)cc.contract.Prestige); } else { // Set difficulty Contract.ContractPrestige? prestige = GetPrestige(cc.contractType); if (prestige != null) { cc.mcListItem.difficulty.SetState((int)prestige.Value); } else { cc.mcListItem.difficulty.gameObject.SetActive(false); } } }