v1.6.17.0 (Unto the Breach update)
This commit is contained in:
+105
-62
@@ -674,77 +674,120 @@ namespace Barotrauma.Steam
|
||||
var contextMenuHandler = new GUICustomComponent(new RectTransform(Vector2.Zero, modFrame.RectTransform),
|
||||
onUpdate: (f, component) =>
|
||||
{
|
||||
var parentList = modFrame.Parent?.Parent?.Parent as GUIListBox; //lovely jank :)
|
||||
if (parentList is null) { return; }
|
||||
if (GUI.MouseOn == modFrame && parentList.DraggedElement is null && PlayerInput.SecondaryMouseButtonClicked())
|
||||
if (modFrame.Parent?.Parent?.Parent is not GUIListBox parentList || GUI.MouseOn != modFrame || parentList.DraggedElement is not null || !PlayerInput.SecondaryMouseButtonClicked()) { return; }
|
||||
if (!parentList.AllSelected.Contains(modFrame))
|
||||
{
|
||||
if (!parentList.AllSelected.Contains(modFrame)) { parentList.Select(parentList.Content.GetChildIndex(modFrame)); }
|
||||
static void noop() { }
|
||||
|
||||
List<ContextMenuOption> contextMenuOptions = new List<ContextMenuOption>();
|
||||
if (ContentPackageManager.WorkshopPackages.Contains(mod))
|
||||
parentList.Select(parentList.Content.GetChildIndex(modFrame));
|
||||
}
|
||||
List<ContextMenuOption> contextMenuOptions = new List<ContextMenuOption>();
|
||||
ContentPackage[] selectedMods = parentList.AllSelected.Select(it => it.UserData).OfType<ContentPackage>().ToArray();
|
||||
Identifier swapLabel = ((parentList == enabledRegularModsList, selectedMods.Length > 1) switch
|
||||
{
|
||||
(false, true) => "EnableSelectedWorkshopMods",
|
||||
(false, false) => "EnableWorkshopMod",
|
||||
(true, true) => "DisableSelectedWorkshopMods",
|
||||
(true, false) => "DisableWorkshopMod"
|
||||
}).ToIdentifier();
|
||||
contextMenuOptions.Add(new(swapLabel, isEnabled: true, currentSwapFunc ?? NoOp));
|
||||
if (ContentPackageManager.WorkshopPackages.Contains(mod))
|
||||
{
|
||||
if (selectedMods.Length == 1)
|
||||
{
|
||||
contextMenuOptions.Add(
|
||||
new ContextMenuOption("ViewWorkshopModDetails".ToIdentifier(), isEnabled: true, onSelected: () => PrepareToShowModInfo(mod)));
|
||||
contextMenuOptions.Add(new("ViewWorkshopModDetails".ToIdentifier(), isEnabled: true, () => PrepareToShowModInfo(mod)));
|
||||
contextMenuOptions.Add(new("CopyWorkshopToLocal".ToIdentifier(), isEnabled: true, () => CopyToLocal()));
|
||||
}
|
||||
|
||||
var labelConditions
|
||||
= (parentList == enabledRegularModsList, parentList.AllSelected.Count > 1);
|
||||
Identifier swapLabel = (labelConditions switch
|
||||
if (selectedMods.All(ContentPackageManager.WorkshopPackages.Contains))
|
||||
{
|
||||
(false, true) => "EnableSelectedWorkshopMods",
|
||||
(false, false) => "EnableWorkshopMod",
|
||||
(true, true) => "DisableSelectedWorkshopMods",
|
||||
(true, false) => "DisableWorkshopMod"
|
||||
}).ToIdentifier();
|
||||
|
||||
contextMenuOptions.Add(new ContextMenuOption(swapLabel,
|
||||
isEnabled: true, onSelected: currentSwapFunc ?? noop));
|
||||
|
||||
var selectedMods = parentList.AllSelected.Select(it => it.UserData)
|
||||
.OfType<ContentPackage>().ToArray();
|
||||
if (selectedMods.All(ContentPackageManager.LocalPackages.Contains) && selectedMods.Length > 1)
|
||||
{
|
||||
contextMenuOptions.Add(new ContextMenuOption("MergeSelectedMods".ToIdentifier(), isEnabled: true,
|
||||
onSelected: () => ModMerger.AskMerge(selectedMods)));
|
||||
}
|
||||
|
||||
GUIButton? iconBtn(GUIComponent component) => component.GetChild<GUILayoutGroup>()?.GetAllChildren<GUIButton>().Last();
|
||||
if (selectedMods.All(ContentPackageManager.WorkshopPackages.Contains)
|
||||
&& parentList.AllSelected.All(c => iconBtn(c)?.Style?.Identifier == "WorkshopMenu.DownloadedIcon")
|
||||
&& selectedMods.Length > 0)
|
||||
{
|
||||
contextMenuOptions.Add(new ContextMenuOption(
|
||||
(selectedMods.Length > 1 ? "UnsubscribeFromAllSelected" : "WorkshopItemUnsubscribe").ToIdentifier(),
|
||||
isEnabled: true,
|
||||
onSelected: () =>
|
||||
if (parentList.AllSelected.All(c => c.GetChild<GUILayoutGroup>()?.GetAllChildren<GUIButton>().Last()?.Style?.Identifier == "WorkshopMenu.DownloadedIcon") && selectedMods.Length > 0 && SteamManager.IsInitialized)
|
||||
{
|
||||
contextMenuOptions.Add(new((selectedMods.Length > 1 ? "UnsubscribeFromAllSelected" : "WorkshopItemUnsubscribe").ToIdentifier(), true, () =>
|
||||
{
|
||||
var workshopIds = selectedMods
|
||||
.Select(m => m.UgcId)
|
||||
.NotNone()
|
||||
.OfType<SteamWorkshopId>()
|
||||
.Select(id => id.Value);
|
||||
TaskPool.AddIfNotFound($"UnsubFromSelected", Task.WhenAll(workshopIds.Select(SteamManager.Workshop.GetItem)),
|
||||
t =>
|
||||
TaskPool.AddIfNotFound("UnsubFromSelected", Task.WhenAll(selectedMods.Select(m => m.UgcId).NotNone().OfType<SteamWorkshopId>().Select(id => SteamManager.Workshop.GetItem(id.Value))), t =>
|
||||
{
|
||||
if (!t.TryGetResult(out Option<Steamworks.Ugc.Item>[]? itemOptions)) { return; }
|
||||
itemOptions.ForEach(io =>
|
||||
{
|
||||
if (!t.TryGetResult(out Steamworks.Ugc.Item?[]? items)) { return; }
|
||||
items.ForEach(it =>
|
||||
{
|
||||
if (!(it is { } item)) { return; }
|
||||
|
||||
item.Unsubscribe();
|
||||
SteamManager.Workshop.Uninstall(item);
|
||||
PopulateInstalledModLists();
|
||||
});
|
||||
if (!io.TryUnwrap(out Steamworks.Ugc.Item item) || !item.IsSubscribed) { return; }
|
||||
item.Unsubscribe();
|
||||
SteamManager.Workshop.Uninstall(item);
|
||||
PopulateInstalledModLists();
|
||||
});
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
GUIContextMenu.CreateContextMenu(
|
||||
pos: PlayerInput.MousePosition,
|
||||
header: ToolBox.LimitString(mod.Name, GUIStyle.SubHeadingFont, GUI.IntScale(300f)),
|
||||
headerColor: null,
|
||||
contextMenuOptions.ToArray());
|
||||
}
|
||||
else if (ContentPackageManager.LocalPackages.Contains(mod))
|
||||
{
|
||||
if (selectedMods.Length == 1)
|
||||
{
|
||||
contextMenuOptions.Add(new ContextMenuOption("RenamePackage".ToIdentifier(), isEnabled: true, AskToRenameLocal));
|
||||
}
|
||||
if (selectedMods.All(ContentPackageManager.LocalPackages.Contains))
|
||||
{
|
||||
if (selectedMods.Length > 1)
|
||||
{
|
||||
contextMenuOptions.Add(new("MergeSelectedMods".ToIdentifier(), isEnabled: true, () => ModMerger.AskMerge(selectedMods)));
|
||||
}
|
||||
contextMenuOptions.Add(new("Delete".ToIdentifier(), isEnabled: true, AskToDeleteLocal));
|
||||
}
|
||||
}
|
||||
GUIContextMenu.CreateContextMenu(PlayerInput.MousePosition, ToolBox.LimitString(mod.Name, GUIStyle.SubHeadingFont, GUI.IntScale(300)), null, contextMenuOptions.ToArray());
|
||||
static void NoOp() { }
|
||||
void AskToRenameLocal()
|
||||
{
|
||||
GUIMessageBox msgBox = new(TextManager.Get("RenamePackage"), mod.Name, new LocalizedString[] { TextManager.Get("Confirm"), TextManager.Get("Cancel") }, minSize: new Point(0, GUI.IntScale(195)));
|
||||
GUITextBox textBox = new(new(Vector2.One, msgBox.Content.RectTransform), mod.Name)
|
||||
{
|
||||
OnEnterPressed = (textBox, text) =>
|
||||
{
|
||||
textBox.Text = text.Trim();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
msgBox.Buttons[0].OnClicked += msgBox.Close;
|
||||
msgBox.Buttons[1].OnClicked += (_, _) =>
|
||||
{
|
||||
if (textBox.Text == mod.Name)
|
||||
{
|
||||
msgBox.Close();
|
||||
return true;
|
||||
}
|
||||
if (mod.TryRenameLocal(textBox.Text))
|
||||
{
|
||||
PopulateInstalledModLists();
|
||||
msgBox.Close();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
textBox.Flash();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
void CopyToLocal()
|
||||
{
|
||||
if (mod.TryCreateLocalFromWorkshop())
|
||||
{
|
||||
PopulateInstalledModLists();
|
||||
}
|
||||
}
|
||||
void AskToDeleteLocal()
|
||||
{
|
||||
GUIMessageBox msgBox = new(TextManager.Get("DeleteMods"), TextManager.GetWithVariables("DeleteModsConfirm", ("[amount]", selectedMods.Length.ToString())),
|
||||
new LocalizedString[] { TextManager.Get("Confirm"), TextManager.Get("Cancel")}, textAlignment: Alignment.TopCenter);
|
||||
msgBox.Buttons[0].OnClicked += msgBox.Close;
|
||||
msgBox.Buttons[1].OnClicked += (_, _) =>
|
||||
{
|
||||
foreach (ContentPackage mod in selectedMods)
|
||||
{
|
||||
mod.TryDeleteLocal();
|
||||
PopulateInstalledModLists();
|
||||
}
|
||||
msgBox.Close();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ namespace Barotrauma
|
||||
writePkgElem(CorePackage);
|
||||
RegularPackages.ForEach(writePkgElem);
|
||||
|
||||
if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); }
|
||||
if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath, catchUnauthorizedAccessExceptions: false); }
|
||||
newDoc.SaveSafe(Path.Combine(SavePath, ToolBox.RemoveInvalidFileNameChars($"{Name}.xml")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user