static void PromotionPart(Rect mainRect, float leftColumn, float rightColumn, ModMetaData mod, Page_ModsConfig page) { var mainModID = mod.GetPublishedFileId(); Text.Font = GameFont.Tiny; var headerHeight = 30f; var headerRect = new Rect(leftColumn + 10f, -4f, rightColumn - 20f, headerHeight); Text.Anchor = TextAnchor.UpperCenter; Widgets.Label(headerRect, "Mods of " + mod.Author.Replace("Andreas Pardeike", "Brrainz") + ":".Truncate(headerRect.width, null)); Text.Anchor = TextAnchor.UpperLeft; var outRect = new Rect(leftColumn + 10f, headerHeight - 4f, rightColumn, mainRect.height - (headerHeight - 4f)); var width = outRect.width - 20f; var previewHeight = width * 319f / 588f; var promoMods = CrossPromotion.promotionMods.ToArray().Where(m => m.m_nPublishedFileId != mainModID); var workshopMods = WorkshopItems.AllSubscribedItems.Select(wi => wi.PublishedFileId.m_PublishedFileId).ToList(); var activeMods = ModLister.AllInstalledMods.Where(meta => meta.Active).Select(meta => meta.GetPublishedFileId().m_PublishedFileId).ToList(); var height = 0f; foreach (var promoMod in promoMods) { var myModID = promoMod.m_nPublishedFileId.m_PublishedFileId; var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID && meta.Source == ContentSource.LocalFolder); var isSubbed = workshopMods.Contains(myModID); CrossPromotion.allVoteStati.TryGetValue(myModID, out var voteStatus); if (height > 0) { height += 10f; } var preview = CrossPromotion.PreviewForMod(promoMod.m_nPublishedFileId.m_PublishedFileId); if (preview != null) { height += width * preview.height / preview.width + 2f; if (isLocalFile == false && (isSubbed == false || (voteStatus == false))) { height += 16f; } } } Widgets.BeginScrollView(outRect, ref rightScroll, new Rect(0f, 0f, width, height), true); var firstTime = true; var modRect = new Rect(0f, 0f, width, 0f); foreach (var promoMod in promoMods) { var myModID = promoMod.m_nPublishedFileId.m_PublishedFileId; var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID && meta.Source == ContentSource.LocalFolder); var isSubbed = workshopMods.Contains(myModID); var isActive = activeMods.Contains(myModID); CrossPromotion.allVoteStati.TryGetValue(myModID, out var voteStatus); if (firstTime == false) { modRect.y += 10f; } var preview = CrossPromotion.PreviewForMod(promoMod.m_nPublishedFileId.m_PublishedFileId); if (preview != null) { modRect.height = width * preview.height / preview.width; GUI.DrawTexture(modRect, preview, ScaleMode.ScaleToFit); var checkRect = modRect; checkRect.xMax -= 4f; checkRect.yMax -= 4f; checkRect.xMin = checkRect.xMax - 18f; checkRect.yMin = checkRect.yMax - 18f; var active = isActive; GUI.DrawTexture(checkRect.ContractedBy(-2f), CheckboxBackground); Widgets.Checkbox(checkRect.xMin, checkRect.yMin, ref active, checkRect.width); if (active != isActive) { var clickedMod = ModLister.AllInstalledMods.FirstOrDefault(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID); if (clickedMod != null) { ModsConfig.SetActive(clickedMod, active); ModsConfig.Save(); } } if (Mouse.IsOver(checkRect) == false) { Widgets.DrawHighlightIfMouseover(modRect); if (Widgets.ButtonInvisible(modRect, true)) { var description = promoMod.m_rgchTitle + "\n\n" + promoMod.m_rgchDescription; var actionButton = isSubbed || isLocalFile ? "Select" : "Subscribe"; void actionButtonAction() { if (isSubbed || isLocalFile) { var orderedMods = (IEnumerable <ModMetaData>)AccessTools.Method(typeof(Page_ModsConfig), "ModsInListOrder").Invoke(page, new object[0]); page.selectedMod = orderedMods.FirstOrDefault(meta => meta.GetPublishedFileId().m_PublishedFileId == myModID); var modsBefore = orderedMods.FirstIndexOf(m => m == page.selectedMod); if (modsBefore >= 0) { Traverse.Create(page).Field("modListScrollPosition").SetValue(new Vector2(0f, modsBefore * 26f + 4f)); } } else { new Thread(() => { CrossPromotion.subscribingMods.Add(myModID); SteamUGC.SubscribeItem(new PublishedFileId_t(myModID)); }).Start(); } } var infoWindow = new Dialog_MessageBox(description, "Close".Translate(), null, actionButton, actionButtonAction, null, false, null, null); Find.WindowStack.Add(infoWindow); } } modRect.y += modRect.height + 2f; modRect.height = 0f; if (isLocalFile == false) { if (isSubbed == false) { modRect.height = 16f; if (CrossPromotion.subscribingMods.Contains(myModID)) { Widgets.Label(modRect, WaitingString); } else if (Widgets.ButtonText(modRect, "Subscribe", false, true, true)) { new Thread(() => { CrossPromotion.subscribingMods.Add(myModID); SteamUGC.SubscribeItem(new PublishedFileId_t(myModID)); }).Start(); } } else if (voteStatus != null && voteStatus == false) { modRect.height = 16f; if (Widgets.ButtonText(modRect, "Like", false, true, true)) { new Thread(() => { CrossPromotion.allVoteStati[myModID] = true; SteamUGC.SetUserItemVote(new PublishedFileId_t(myModID), true); }).Start(); } } } modRect.y += modRect.height; } firstTime = false; } Widgets.EndScrollView(); }
static void ContentPart(Rect mainRect, float leftColumn, ModMetaData mod, Page_ModsConfig page) { var workshopMods = WorkshopItems.AllSubscribedItems.Select(wi => wi.PublishedFileId.m_PublishedFileId).ToList(); var mainModID = mod.GetPublishedFileId().m_PublishedFileId; var promoMods = CrossPromotion.promotionMods.ToArray(); var thisMod = promoMods.FirstOrDefault(m => m.m_nPublishedFileId.m_PublishedFileId == mainModID); var isLocalFile = ModLister.AllInstalledMods.Any(meta => meta.GetPublishedFileId().m_PublishedFileId == mainModID && meta.Source == ContentSource.LocalFolder); var isSubbed = workshopMods.Contains(mainModID); if (CrossPromotion.lastPresentedMod != mainModID) { leftScroll = Vector2.zero; rightScroll = Vector2.zero; CrossPromotion.lastPresentedMod = mainModID; new Thread(() => { foreach (var promoMod in promoMods) { CrossPromotion.UpdateVotingStatus(promoMod.m_nPublishedFileId.m_PublishedFileId, (result2, failure2) => { CrossPromotion.allVoteStati[promoMod.m_nPublishedFileId.m_PublishedFileId] = (result2.m_eResult == EResult.k_EResultOK) ? result2.m_bVotedUp : (bool?)null; }); } }).Start(); } var description = thisMod.m_rgchDescription; if (description == null || description.Length == 0) { description = mod.Description; } var outRect = new Rect(0f, 0f, leftColumn, mainRect.height); var width = outRect.width - 20f; var imageRect = new Rect(0f, 0f, width, width * mod.previewImage.height / mod.previewImage.width); var textRect = new Rect(0f, 24f + 10f + imageRect.height, width, Text.CalcHeight(description, width)); var innerRect = new Rect(0f, 0f, width, imageRect.height + 20f + 8f + 10f + textRect.height); Widgets.BeginScrollView(outRect, ref leftScroll, innerRect, true); GUI.DrawTexture(imageRect, mod.previewImage, ScaleMode.ScaleToFit); var widgetRow = new WidgetRow(imageRect.xMax, imageRect.yMax + 8f, UIDirection.LeftThenDown, width, 8f); if (isLocalFile == false) { if (widgetRow.ButtonText("Unsubscribe".Translate(), null, true, true)) { Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmUnsubscribe".Translate(mod.Name), delegate { mod.enabled = false; new Thread(() => { AccessTools.Method(typeof(Workshop), "Unsubscribe").Invoke(null, new object[] { mod }); AccessTools.Method(typeof(Page_ModsConfig), "Notify_SteamItemUnsubscribed").Invoke(page, new object[] { mainModID }); }).Start(); }, true, null)); } } if (isSubbed) { if (widgetRow.ButtonText("WorkshopPage".Translate(), null, true, true)) { SteamUtility.OpenWorkshopPage(new PublishedFileId_t(mainModID)); } } if (Prefs.DevMode && mod.CanToUploadToWorkshop()) { widgetRow = new WidgetRow(imageRect.xMin, imageRect.yMax + 8f, UIDirection.RightThenDown, width, 8f); if (widgetRow.ButtonText("Upload", null, true, true)) { Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmSteamWorkshopUpload".Translate(), delegate { AccessTools.Method(typeof(Workshop), "Upload").Invoke(null, new object[] { mod }); }, true, null)); } } Widgets.Label(textRect, description); Widgets.EndScrollView(); }