public OtherCollectionDataImportTaskHandler() { DisplayName = "Import Another Collection Options"; _sourceOptions = new SourceOptions(Store.Current.Databases); _targetOptions = new TargetOptions(); }
/// <summary> /// Performs the image resize operation by reading from a <see cref="Stream"/> and writing to a <see cref="Stream"/>. /// </summary> /// <param name="source">The stream to read from.</param> /// <param name="sourceOptions">Specifies what should happen with the <paramref name="source"/> stream after processing.</param> /// <param name="destination">The stream to write to.</param> /// <param name="leaveDestinationOpen">Specifies whether the <paramref name="destination"/> stream should be left open after processing.</param> /// <param name="instructions">Specifies how the source bitmap should be resized.</param> /// <remarks> /// Ensure that the first stream you open will be safely closed if the second stream fails to open! This means a <c>using()</c> or <c>try</c>/<c>finally</c> clause. /// </remarks> public static void Build(Stream source, SourceOptions sourceOptions, Stream destination, bool leaveDestinationOpen, Instructions instructions) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } Build( source, sourceOptions, (Bitmap b) => { try { // Encode from temp bitmap to target stream Encode(b, destination, instructions); } finally { // Ensure target stream is disposed if requested if (!leaveDestinationOpen) { destination.Dispose(); } } }, instructions); }
public JsonDataImportTaskHandler(Lazy <IApplicationInteraction> lazyApplicationInteraction) { DisplayName = "Import JSON Options"; _sourceOptions = new SourceOptions(lazyApplicationInteraction); _targetOptions = new TargetOptions(); }
/// <summary> /// Performs the image resize operation by reading from a <see cref="Stream"/> and writing to a file. /// </summary> /// <param name="source">The stream to read from.</param> /// <param name="sourceOptions">Specifies what should happen with the <paramref name="source"/> stream after processing.</param> /// <param name="destinationPath">The path of the file to write to.</param> /// <param name="createDestinationDirectory">Specifies whether to create the output directory or not if it does not exist.</param> /// <param name="instructions">Specifies how the source bitmap should be resized.</param> public static void Build(Stream source, SourceOptions sourceOptions, string destinationPath, bool createDestinationDirectory, Instructions instructions) { if (destinationPath == null) { throw new ArgumentNullException(nameof(destinationPath)); } if (createDestinationDirectory) { string dirName = Path.GetDirectoryName(destinationPath); if (!Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } } Build( source, sourceOptions, (Bitmap b) => { using (var fs = new FileStream(destinationPath, FileMode.Create, FileAccess.Write)) { Encode(b, fs, instructions); } }, instructions); }
public static DataTable ToDataTable(string path, SourceOptions options) { var hasHeader = options.FileContainsHeaders; using (var pck = new OfficeOpenXml.ExcelPackage()) { using (var stream = File.OpenRead(path)) { pck.Load(stream); } var ws = pck.Workbook.Worksheets.First(); DataTable tbl = new DataTable(); foreach (var firstRowCell in ws.Cells[1, 1, 1, ws.Dimension.End.Column]) { tbl.Columns.Add(hasHeader ? firstRowCell.Text : $"Column_{firstRowCell.Start.Column}"); } var startRow = hasHeader ? 2 : 1; for (int rowNum = startRow; rowNum <= ws.Dimension.End.Row; rowNum++) { var wsRow = ws.Cells[rowNum, 1, rowNum, ws.Dimension.End.Column]; DataRow row = tbl.Rows.Add(); foreach (var cell in wsRow) { row[cell.Start.Column - 1] = cell.Text; } } return(tbl); } }
public CsvDataImportTaskHandler(Lazy <IApplicationInteraction> lazyApplicationInteraction) { DisplayName = "Import CSV Options"; _sourceOptions = new SourceOptions(this, lazyApplicationInteraction); _targetOptions = new TargetOptions(); _dataPreviewHolder = new DataPreviewHolder(); }
Generate(SourceOptions options = SourceOptions.None, ClassOptions classOptions = ClassOptions.None) { ClassGenerator classes = new ClassGenerator() { Name = Name }; // Class with many interfaces if (options.HasFlag(SourceOptions.ImplementsInterfaces) && options.HasFlag(SourceOptions.BaseListMany)) { classes.Interface1Name = Interface1Name; classes.Interface2Name = Interface2Name; classes.Interface3Name = Interface3Name; return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >( classes.ClassWithManyInterfaces, classes.ClassWithManyInterfacesAttributes)); } // Class with interface if (options.HasFlag(SourceOptions.ImplementsInterfaces)) { classes.Interface1Name = Interface1Name; return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >( classes.ClassWith1Interface, classes.ClassWith1InterfaceAttributes)); } // Class with base class if (options.HasFlag(SourceOptions.HasInheritance)) { classes.BaseClassName = BaseName; return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >( classes.ClassWithBaseClass, classes.ClassWithBaseClassAttributes)); } // Empty elements if (options.HasFlag(SourceOptions.EmptyElements)) { return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >( classes.VerySimpleClassWithEmptyMethods, classes.VerySimpleClassWithEmptyMethodsAttributes)); } // Namespace if (options.HasFlag(SourceOptions.HasNamespace)) { classes.NamespaceName = NamespaceName; return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >( classes.VerySimpleClassInNamespace, classes.VerySimpleClassInNamespaceAttributes)); } // Simple class if (classOptions.HasFlag(ClassOptions.HasContent)) { return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >( classes.SimpleClass, classes.SimpleClassAttributes)); } return(new KeyValuePair <string, IReadOnlyDictionary <string, string> >( classes.VerySimpleClass, classes.VerySimpleClassAttributes)); }
public void Build_LeavesSourceStreamOpen_WhenAskedTo(SourceOptions sourceOptions) { using (var source = GetBitmapStream(100, 100)) using (var _ = Stream.Null) { var instructions = new Instructions { Width = 50 }; ImageBuilder.Build(source, sourceOptions, _, instructions); Assert.True(source.CanRead); } }
public static DataTable ToDataTable(string path, SourceOptions options) { var configuration = new Configuration { Delimiter = options.Delimiter, }; if (string.IsNullOrEmpty(options.Delimiter) && !string.IsNullOrEmpty(options.OtherDelimiter)) { configuration.Delimiter = options.OtherDelimiter; } var createColumns = !options.FileContainsHeaders; var dt = new DataTable(); using (var reader = new StreamReader(path)) using (var csv = new CsvReader(reader, configuration)) { // Track: https://github.com/JoshClose/CsvHelper/issues/1240 if (createColumns) { while (csv.Read()) { if (createColumns) { for (var i = 0; i < csv.Context.Record.Length; i++) { dt.Columns.Add($"Column_{i}"); } createColumns = false; } var row = dt.NewRow(); for (var i = 0; i < csv.Context.Record.Length; i++) { row[i] = csv.Context.Record[i]; } dt.Rows.Add(row); } } else { // Do any configuration to `CsvReader` before creating CsvDataReader. using (var dr = new CsvDataReader(csv)) { dt.Load(dr); } } } return(dt); }
public void Build_ClosesSourceStream_WhenNotAskedToLeaveItOpen(SourceOptions sourceOptions) { using (var source = GetBitmapStream(100, 100)) using (var _ = Stream.Null) { var instructions = new Instructions { Width = 50 }; ImageBuilder.Build(source, sourceOptions, _, instructions); Assert.False(source.CanRead); } }
/// <summary> /// Convert the specified 'file' into JSON with an OLE DB Connection, and save it to the specified 'outputPath'. /// </summary> /// <param name="options"></param> /// <returns></returns> public async Task ConvertWithOleDbConnectionAsync(SourceOptions options) { var file = new FileInfo(options.File); if (file == null) { throw new ArgumentNullException(nameof(file)); } if (String.IsNullOrWhiteSpace(options.Output)) { throw new ArgumentException("Argument cannot be null, emtpy or whitespace.", nameof(options.Output)); } if (String.IsNullOrWhiteSpace(options.SheetName)) { throw new ConfigurationException("Configuration 'Converter:{Source}:SheetName' cannot be null, emtpy or whitespace."); } _logger.LogInformation($"Reading file '{file}'."); var cs = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={file};Extended Properties=\"Excel 12.0 Xml;HDR=YES\""; using var con = new OleDbConnection(cs); con.Open(); var cmd = con.CreateCommand(); cmd.CommandText = $"SELECT * FROM [{options.SheetName}$]"; using var rdr = cmd.ExecuteReader(); var query = ( from DbDataRecord row in rdr select row).Select(async r => { var columns = new Dictionary <string, object>(); for (var i = 0; i < r.FieldCount; i++) { var name = rdr.GetName(i); var colOptions = options.Columns.ContainsKey(name) ? options.Columns[name] : null; var value = await GetValueAsync(colOptions, r[i], columns); columns.Add(GetName(colOptions, name), value); } return(columns); }); var rows = await Task.WhenAll(query); var json = JsonSerializer.Serialize(rows, _serialzerOptions); ExportJsonFile(json, options.Output); }
public void SetImagePaths(string[] imagePaths, bool isRandom, ITheme theme) { if (imagePaths == null) { throw new ArgumentNullException(nameof(imagePaths)); } if (theme == null) { throw new ArgumentNullException(nameof(theme)); } var list = new List <FilenameIterator>(imagePaths.Length); foreach (var pathInfo in imagePaths) { if (pathInfo == null) { continue; } var path = pathInfo; string optionsString = string.Empty; int index = path.IndexOf('|'); if (index >= 0) { optionsString = path.Substring(0, index); path = path.Substring(index + 1); } path = path.Trim(); var sourceOptions = SourceOptions.Create(optionsString); if (HasAllowedUriScheme(path)) { list.Add(new FileIterator(path, sourceOptions)); } else if (File.Exists(path)) { list.Add(new FileIterator(path, sourceOptions)); } else if (Directory.Exists(path)) { list.Add(new DirectoryIterator(path, sourceOptions)); } } this.isRandom = isRandom; this.theme = theme; cachedAllFilenamesListWeakRef = null; currentEnumeratorInfo?.Dispose(); currentEnumeratorInfo = null; filenameIterators = list.ToArray(); currentFilenameIteratorIndex = 0; NextImageSource(); }
public void Build_DoesNotRewindSourceStream_WhenNotAskedTo(SourceOptions sourceOptions) { using (var source = GetBitmapStream(100, 100)) using (var _ = Stream.Null) { source.Seek(1, SeekOrigin.Begin); var originalPosition = source.Position; var instructions = new Instructions { Width = 50 }; ImageBuilder.Build(source, sourceOptions | LeaveOpen, _, instructions); Assume.That(source.CanSeek); Assert.AreNotEqual(originalPosition, source.Position); } }
public void Build_Succeeds_EvenWhenSourceStreamPositionNotAt0(SourceOptions sourceOptions) { TestDelegate action = () => { using (var source = GetBitmapStream(100, 100)) using (var _ = Stream.Null) { source.Seek(17, SeekOrigin.Begin); var instructions = new Instructions { Width = 50 }; ImageBuilder.Build(source, sourceOptions, _, instructions); } }; Assert.DoesNotThrow(action); }
public static DataTable ToDataTable(string path, SourceOptions options) { var configuration = new Configuration { Delimiter = options.Delimiter, HasHeaderRecord = options.FileContainsHeaders }; using (var reader = new StreamReader(path)) using (var csv = new CsvReader(reader, configuration)) { // Do any configuration to `CsvReader` before creating CsvDataReader. using (var dr = new CsvDataReader(csv)) { var dt = new DataTable(); dt.Load(dr); return(dt); } } }
public Source(SourceOptions options) { Id = options.Id; Transformations = options.Transformations?.Select((it) => TransformationFactory.GetInstance(it)) ?? new List <ITransformation <object> >(); }
public void DoLeftRow(Rect canvas) { Widgets.DrawMenuSection(canvas, false); // filter Rect filterRect = new Rect(10f, canvas.yMin + 5f, canvas.width - 50f, 30f); GUI.SetNextControlName("filterTextfield"); SourceFilter = Widgets.TextField(filterRect, SourceFilter); if (!_postOpenFocus) { GUI.FocusControl("filterTextfield"); _postOpenFocus = true; } if (SourceFilter != "") { Rect clearFilter = new Rect(filterRect.width + 10f, filterRect.yMin, 30f, 30f); if (Widgets.ImageButton(clearFilter, Widgets.CheckboxOffTex)) { SourceFilter = ""; } TooltipHandler.TipRegion(clearFilter, "FMP.ClearFilterDesc".Translate()); } TooltipHandler.TipRegion(filterRect, "FMP.FilterDesc".Translate()); // tabs List<TabRecord> list = new List<TabRecord>(); TabRecord item = new TabRecord("FMP.All".Translate(), delegate { Source = SourceOptions.All; RefreshSourceList(); }, Source == SourceOptions.All); list.Add(item); TabRecord item2 = new TabRecord("FMP.Available".Translate(), delegate { Source = SourceOptions.Available; RefreshSourceList(); }, Source == SourceOptions.Available); list.Add(item2); TabRecord item3 = new TabRecord("FMP.Current".Translate(), delegate { Source = SourceOptions.Current; RefreshSourceList(); }, Source == SourceOptions.Current); list.Add(item3); TabDrawer.DrawTabs(canvas, list); // content Rect scrollCanvas = canvas.ContractedBy(10f); scrollCanvas.yMin = scrollCanvas.yMin + 40f; float height = SourceListHeight + 20f; Rect scrollView = new Rect(0f, 0f, scrollCanvas.width - 16f, height); Widgets.BeginScrollView(scrollCanvas, ref LeftRowScrollPosition, scrollView); Rect scrollContent = scrollView.ContractedBy(10f); GUI.BeginGroup(scrollContent); float y = 0; foreach (ManagerJobProduction current in from job in SourceList where job.Bill.recipe.label.ToUpper().Contains(SourceFilter.ToUpper()) || job.MainProduct.Label.ToUpper().Contains(SourceFilter.ToUpper()) orderby job.Bill.recipe.LabelCap select job) { Rect recipeRow = new Rect(0f, y, scrollContent.width, 25f); string text = current.Bill.recipe.LabelCap + " ("; try { text += String.Join(", ", current.BillGivers.GetBillGiverDefs.Select(ru => ru.LabelCap).ToArray()); } catch { text += "error"; } text += ")"; // resize the row if label grow too big. Rect recipeRowResized = new Rect(recipeRow); recipeRowResized.x += 6f; recipeRowResized.width -= 6f; float calculatedHeight = Text.CalcHeight(text, recipeRowResized.width); if (recipeRowResized.height < calculatedHeight) { recipeRowResized.height = calculatedHeight + 3f; } if (Widgets.TextButton(recipeRowResized, text, false, true)) { SoundDefOf.Click.PlayOneShotOnCamera(); Job = current; } if (Job != null && Job == current) { GUI.DrawTexture(recipeRowResized, TexUI.HighlightTex); } y += recipeRowResized.height; } SourceListHeight = y; GUI.EndGroup(); Widgets.EndScrollView(); }
public DirectoryIterator(string dirPath, SourceOptions sourceOptions) : base(sourceOptions) => this.dirPath = dirPath;
public FileIterator(string filename, SourceOptions sourceOptions) : base(sourceOptions) => this.filename = filename;
protected FilenameIterator(SourceOptions sourceOptions) => SourceOptions = sourceOptions;
public OtherCollectionDataImportTaskHandler() { _sourceOptions = new SourceOptions(Store.Current.Databases); _targetOptions = new TargetOptions(); }
public void DoContent(Rect canvas) { Widgets.DrawMenuSection(canvas); if (Job != null) { // leave some space for bottom buttons. float bottomButtonsHeight = 30f; float bottomButtonsGap = 6f; canvas.height = canvas.height - bottomButtonsHeight - bottomButtonsGap; // bottom buttons Rect bottomButtons = new Rect(canvas.xMin, canvas.height + bottomButtonsGap, canvas.width, bottomButtonsHeight); GUI.BeginGroup(bottomButtons); // add / remove to the stack Rect add = new Rect(bottomButtons.width * .75f, 0f, bottomButtons.width / 4f - 6f, bottomButtons.height); if (Source == SourceOptions.Current) { if (Widgets.TextButton(add, "FM.Delete".Translate())) { Manager.JobStack.Delete(Job); Job = null; RefreshSourceList(); return; // hopefully that'll just skip to the next tick without any further errors? } TooltipHandler.TipRegion(add, "FMP.DeleteBillTooltip".Translate()); } else { if (Job.Trigger.IsValid) { if (Widgets.TextButton(add, "FM.Manage".Translate())) { Manager.JobStack.Add(Job); Source = SourceOptions.Current; RefreshSourceList(); SourceFilter = ""; } TooltipHandler.TipRegion(add, "FMP.ManageBillTooltip".Translate()); } else { TextAnchor oldAnchor = Text.Anchor; Color oldColor = GUI.color; Text.Anchor = TextAnchor.MiddleCenter; GUI.color = new Color(.6f, .6f, .6f); Widgets.DrawBox(add); GUI.Label(add, "FMP.NoThreshold".Translate()); Text.Anchor = oldAnchor; GUI.color = oldColor; TooltipHandler.TipRegion(add, "FMP.NoThresholdTooltip".Translate()); } } GUI.EndGroup(); GUI.BeginGroup(canvas); Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Medium; Rect recta = new Rect(0f, 0f, canvas.width, 50f); Widgets.Label(recta, Job.Bill.LabelCap); Text.Anchor = TextAnchor.UpperLeft; Text.Font = GameFont.Small; Rect rect2 = new Rect(6f, 50f, canvas.width * .3f, canvas.height - 50f); Listing_Standard listingStandard = new Listing_Standard(rect2); if (Job.Bill.suspended) { if (listingStandard.DoTextButton("Suspended".Translate())) { Job.Bill.suspended = false; } } else if (listingStandard.DoTextButton("NotSuspended".Translate())) { Job.Bill.suspended = true; } string billStoreModeLabel = ("BillStoreMode_" + Job.Bill.storeMode).Translate(); if (listingStandard.DoTextButton(billStoreModeLabel)) { List<FloatMenuOption> list = (from BillStoreMode mode in Enum.GetValues(typeof (BillStoreMode)) select new FloatMenuOption(("BillStoreMode_" + mode).Translate(), delegate { Job.Bill.storeMode = mode; })).ToList(); Find.WindowStack.Add(new FloatMenu(list)); } // other stuff listingStandard.DoGap(); listingStandard.DoLabel("IngredientSearchRadius".Translate() + ": " + Job.Bill.ingredientSearchRadius.ToString("#####0")); Job.Bill.ingredientSearchRadius = Mathf.RoundToInt(listingStandard.DoSlider(Job.Bill.ingredientSearchRadius, 0f, 250f)); if (Job.Bill.recipe.workSkill != null) { listingStandard.DoLabel("MinimumSkillLevel".Translate(Job.Bill.recipe.workSkill.label.ToLower()) + ": " + Job.Bill.minSkillLevel.ToString("#####0")); Job.Bill.minSkillLevel = Mathf.RoundToInt(listingStandard.DoSlider(Job.Bill.minSkillLevel, 0f, 20f)); } // draw threshold config Job.Trigger.DrawThresholdConfig(ref listingStandard); Job.BillGivers.DrawBillGiverConfig(ref listingStandard); listingStandard.End(); // ingredient picker Rect rect3 = new Rect(rect2.xMax + 6f, 50f, canvas.width * .4f, canvas.height - 50f); ThingFilterUI.DoThingFilterConfigWindow(rect3, ref BillScrollPosition, Job.Bill.ingredientFilter, Job.Bill.recipe.fixedIngredientFilter, 4); // description Rect rect4 = new Rect(rect3.xMax + 6f, rect3.y + 30f, canvas.width - rect3.xMax - 12f, canvas.height - 50f); StringBuilder stringBuilder = new StringBuilder(); // add mainproduct line stringBuilder.AppendLine("FMP.MainProduct".Translate(Job.MainProduct.Label, Job.MainProduct.Count)); stringBuilder.AppendLine(); if (Job.Bill.recipe.description != null) { stringBuilder.AppendLine(Job.Bill.recipe.description); stringBuilder.AppendLine(); } stringBuilder.AppendLine("WorkAmount".Translate() + ": " + Job.Bill.recipe.WorkAmountTotal(null).ToStringWorkAmount()); stringBuilder.AppendLine(); foreach (IngredientCount ingredientCount in Job.Bill.recipe.ingredients) { if (!ingredientCount.filter.Summary.NullOrEmpty()) { stringBuilder.AppendLine(Job.Bill.recipe.IngredientValueGetter.BillRequirementsDescription(ingredientCount)); } } stringBuilder.AppendLine(); string text4 = Job.Bill.recipe.IngredientValueGetter.ExtraDescriptionLine(); if (text4 != null) { stringBuilder.AppendLine(text4); stringBuilder.AppendLine(); } stringBuilder.AppendLine("MinimumSkills".Translate()); stringBuilder.AppendLine(Job.Bill.recipe.MinSkillString); Text.Font = GameFont.Small; string text5 = stringBuilder.ToString(); if (Text.CalcHeight(text5, rect4.width) > rect4.height) { Text.Font = GameFont.Tiny; } Widgets.Label(rect4, text5); Text.Font = GameFont.Small; if (Job.Bill.recipe.products.Count == 1) { Widgets.InfoCardButton(rect4.x, rect3.y, Job.Bill.recipe.products[0].thingDef); } } GUI.EndGroup(); }
public void DoLeftRow(Rect canvas) { Widgets.DrawMenuSection(canvas, false); // filter var filterRect = new Rect(10f, canvas.yMin + 5f, canvas.width - _leftRowEntryHeight, _entryHeight); GUI.SetNextControlName("filterTextfield"); SourceFilter = Widgets.TextField(filterRect, SourceFilter); if (!_postOpenFocus) { GUI.FocusControl("filterTextfield"); _postOpenFocus = true; } if (SourceFilter != "") { var clearFilter = new Rect(filterRect.width + 10f, filterRect.yMin, _entryHeight, _entryHeight); if (Widgets.ButtonImage(clearFilter, Widgets.CheckboxOffTex)) { SourceFilter = ""; } TooltipHandler.TipRegion(clearFilter, "FMP.ClearFilterDesc".Translate()); } TooltipHandler.TipRegion(filterRect, "FMP.FilterDesc".Translate()); // tabs var list = new List <TabRecord>(); var availableTabRecord = new TabRecord("FMP.Available".Translate(), delegate { Source = SourceOptions.Available; Refresh(); }, Source == SourceOptions.Available); list.Add(availableTabRecord); var currentTabRecord = new TabRecord("FMP.Current".Translate(), delegate { Source = SourceOptions.Current; Refresh(); }, Source == SourceOptions.Current); list.Add(currentTabRecord); TabDrawer.DrawTabs(canvas, list); // content Rect scrollCanvas = canvas; scrollCanvas.yMin = scrollCanvas.yMin + _entryHeight + _margin; float height = SourceListHeight; var scrollView = new Rect(0f, 0f, scrollCanvas.width, height); if (height > scrollCanvas.height) { scrollView.width -= 16f; } Widgets.BeginScrollView(scrollCanvas, ref LeftRowScrollPosition, scrollView); Rect scrollContent = scrollView; GUI.BeginGroup(scrollContent); float y = 0; var i = 0; foreach (ManagerJob_Production current in from job in SourceList where job.Bill.recipe.label.ToUpper() .Contains(SourceFilter.ToUpper()) || job.MainProduct.Label.ToUpper() .Contains(SourceFilter.ToUpper()) select job) { var row = new Rect(0f, y, scrollContent.width, Utilities.LargeListEntryHeight); Widgets.DrawHighlightIfMouseover(row); if (_selected == current) { Widgets.DrawHighlightSelected(row); } if (i++ % 2 == 1) { Widgets.DrawAltRect(row); } Rect jobRect = row; if (Source == SourceOptions.Current) { if (ManagerTab_Overview.DrawOrderButtons( new Rect(row.xMax - _leftRowEntryHeight, row.yMin, _leftRowEntryHeight, _leftRowEntryHeight), manager, current)) { Refresh(); } jobRect.width -= _leftRowEntryHeight; } current.DrawListEntry(jobRect, false, Source == SourceOptions.Current); if (Widgets.ButtonInvisible(jobRect)) { _selected = current; } y += Utilities.LargeListEntryHeight; } SourceListHeight = y; GUI.EndGroup(); Widgets.EndScrollView(); }
public override SourceOptions GetSourceOptions() { return(SourceOptions.CreateFromParameters(false, false)); }
public NamespaceDefinitionsManager(NamespaceDefinitionsClient namespaceDefinitionsClient, SourceOptions sourceOptions, ILogger logger) { this.namespaceDefinitionsClient = namespaceDefinitionsClient; this.sourceOptions = sourceOptions; this.logger = logger; }
public ExcelDataImportTaskHandler(Lazy <IApplicationInteraction> lazyApplicationInteraction) { DisplayName = "Import Excel Options"; _sourceOptions = new SourceOptions(lazyApplicationInteraction); }
public override void DoWindowContents(Rect rect) { base.DoWindowContents(rect); if (IsDirty) { BuildPawnList(); } var position = new Rect(0f, 0f, rect.width, 80f); GUI.BeginGroup(position); var x = 0f; Text.Font = GameFont.Small; // prisoner / colonist / Animal toggle var sourceButton = new Rect(0f, 0f, 200f, 35f); if (Widgets.ButtonText(sourceButton, Source.ToString().Translate())) { List <FloatMenuOption> options = new List <FloatMenuOption>(); if (Source != SourceOptions.Colonists) { options.Add(new FloatMenuOption("Colonists".Translate(), delegate { Source = SourceOptions.Colonists; IsDirty = true; })); } if (Source != SourceOptions.Prisoners) { options.Add(new FloatMenuOption("Prisoners".Translate(), delegate { Source = SourceOptions.Prisoners; IsDirty = true; })); } if (Source != SourceOptions.Animals) { options.Add(new FloatMenuOption("Animals".Translate(), delegate { Source = SourceOptions.Animals; IsDirty = true; })); } Find.WindowStack.Add(new FloatMenu(options)); } // name var nameLabel = new Rect(x, 50f, 165f, 30f); Text.Anchor = TextAnchor.LowerCenter; Widgets.Label(nameLabel, "FluffyMedical.Name".Translate()); if (Widgets.ButtonInvisible(nameLabel)) { if (OrderBy == Order.Name) { Asc = !Asc; } else { OrderBy = Order.Name; Asc = true; } IsDirty = true; } TooltipHandler.TipRegion(nameLabel, "FluffyMedical.ClickToSortBy".Translate("FluffyMedical.Name".Translate())); Widgets.DrawHighlightIfMouseover(nameLabel); x += 165f; // care var careLabel = new Rect(x, 50f, 100f, 30f); Widgets.Label(careLabel, "FluffyMedical.Care".Translate()); if (Widgets.ButtonInvisible(careLabel)) { if (Event.current.shift) { Utility_Medical.MedicalCareSetterAll(pawns); } else { if (OrderBy == Order.Care) { Asc = !Asc; } else { OrderBy = Order.Care; Asc = true; } IsDirty = true; } } TooltipHandler.TipRegion(careLabel, "FluffyMedical.ClickToSortBy".Translate("FluffyMedical.Care".Translate()) + "\n" + "FluffyMedical.ShiftClickTo".Translate("FluffyMedical.SetCare".Translate())); Widgets.DrawHighlightIfMouseover(careLabel); x += 100f; // bloodloss var bloodLabel = new Rect(x, 50f, 50f, 30f); var bloodIcon = new Rect(x + 17f, 60f, 16f, 16f); GUI.DrawTexture(bloodIcon, Utility_Medical.BloodTextureWhite); if (Widgets.ButtonInvisible(bloodLabel)) { if (OrderBy == Order.BleedRate) { Asc = !Asc; } else { OrderBy = Order.BleedRate; Asc = true; } IsDirty = true; } TooltipHandler.TipRegion(bloodLabel, "FluffyMedical.ClickToSortBy".Translate("BleedingRate".Translate())); Widgets.DrawHighlightIfMouseover(bloodLabel); x += 50f; // Operations var opLabel = new Rect(x, 50f, 50f, 30f); var opIcon = new Rect(x + 17f, 60f, 16f, 16f); GUI.DrawTexture(opIcon, Utility_Medical.OpTexture); if (Widgets.ButtonInvisible(opLabel)) { if (OrderBy == Order.Operations) { Asc = !Asc; } else { OrderBy = Order.Operations; Asc = true; } IsDirty = true; } TooltipHandler.TipRegion(opLabel, "FluffyMedical.ClickToSortBy".Translate("FluffyMedical.CurrentOperations".Translate())); Widgets.DrawHighlightIfMouseover(opLabel); x += 50f; // extra 15f offset for... what? makes labels roughly align. var colWidth = (rect.width - x - 15f) / (CapDefs.Count + 1); var offset = true; // Pain var painLabel = new Rect(x - colWidth / 2, 10f + (offset ? 10f : 40f), colWidth * 2, 30f); Widgets.DrawLine(new Vector2(x + colWidth - colWidth / 2, 40f + (offset ? 5f : 35f)), new Vector2(x + colWidth - colWidth / 2, 80f), Color.gray, 1); Widgets.Label(painLabel, "PainLevel".Translate()); if (Widgets.ButtonInvisible(painLabel)) { if (OrderBy == Order.Pain) { Asc = !Asc; } else { OrderBy = Order.Pain; Asc = true; } IsDirty = true; } TooltipHandler.TipRegion(painLabel, "FluffyMedical.ClickToSortBy".Translate("PainLevel".Translate())); Widgets.DrawHighlightIfMouseover(painLabel); offset = !offset; x += colWidth; // Efficiency foreach (PawnCapacityDef capDef in CapDefs) { var defLabel = new Rect(x - colWidth / 2, 10f + (offset ? 10f : 40f), colWidth * 2, 30f); Widgets.DrawLine(new Vector2(x + colWidth - colWidth / 2, 40f + (offset ? 5f : 35f)), new Vector2(x + colWidth - colWidth / 2, 80f), Color.gray, 1); Widgets.Label(defLabel, capDef.LabelCap); if (Widgets.ButtonInvisible(defLabel)) { if (OrderBy == Order.Efficiency && OrderByCapDef == capDef) { Asc = !Asc; } else { OrderBy = Order.Efficiency; OrderByCapDef = capDef; Asc = true; } IsDirty = true; } TooltipHandler.TipRegion(defLabel, "FluffyMedical.ClickToSortBy".Translate(capDef.LabelCap)); Widgets.DrawHighlightIfMouseover(defLabel); offset = !offset; x += colWidth; } GUI.EndGroup(); var content = new Rect(0f, position.yMax, rect.width, rect.height - position.yMax); GUI.BeginGroup(content); DrawRows(new Rect(0f, 0f, content.width, content.height)); GUI.EndGroup(); }
public TargetOptions(SourceOptions sourceOptions) { _sourceOptions = sourceOptions; }
public CsvDataImportTaskHandler(Lazy <IApplicationInteraction> lazyApplicationInteraction) { _sourceSourceOptions = new SourceOptions(lazyApplicationInteraction); _targetOptions = new TargetOptions(); }
public void DoLeftRow( Rect canvas ) { Widgets.DrawMenuSection( canvas, false ); // filter Rect filterRect = new Rect( 10f, canvas.yMin + 5f, canvas.width - _leftRowEntryHeight, _entryHeight ); GUI.SetNextControlName( "filterTextfield" ); SourceFilter = Widgets.TextField( filterRect, SourceFilter ); if ( !_postOpenFocus ) { GUI.FocusControl( "filterTextfield" ); _postOpenFocus = true; } if ( SourceFilter != "" ) { Rect clearFilter = new Rect( filterRect.width + 10f, filterRect.yMin, _entryHeight, _entryHeight ); if ( Widgets.ImageButton( clearFilter, Widgets.CheckboxOffTex ) ) { SourceFilter = ""; } TooltipHandler.TipRegion( clearFilter, "FMP.ClearFilterDesc".Translate() ); } TooltipHandler.TipRegion( filterRect, "FMP.FilterDesc".Translate() ); // tabs List<TabRecord> list = new List<TabRecord>(); TabRecord availableTabRecord = new TabRecord( "FMP.Available".Translate(), delegate { Source = SourceOptions.Available; Refresh(); }, Source == SourceOptions.Available ); list.Add( availableTabRecord ); TabRecord currentTabRecord = new TabRecord( "FMP.Current".Translate(), delegate { Source = SourceOptions.Current; Refresh(); }, Source == SourceOptions.Current ); list.Add( currentTabRecord ); TabDrawer.DrawTabs( canvas, list ); // content Rect scrollCanvas = canvas; scrollCanvas.yMin = scrollCanvas.yMin + _entryHeight + _margin; float height = SourceListHeight; Rect scrollView = new Rect( 0f, 0f, scrollCanvas.width, height ); if ( height > scrollCanvas.height ) { scrollView.width -= 16f; } Widgets.BeginScrollView( scrollCanvas, ref LeftRowScrollPosition, scrollView ); Rect scrollContent = scrollView; GUI.BeginGroup( scrollContent ); float y = 0; int i = 0; foreach ( ManagerJob_Production current in from job in SourceList where job.Bill.recipe.label.ToUpper() .Contains( SourceFilter.ToUpper() ) || job.MainProduct.Label.ToUpper() .Contains( SourceFilter.ToUpper() ) select job ) { Rect row = new Rect( 0f, y, scrollContent.width, Utilities.LargeListEntryHeight ); Widgets.DrawHighlightIfMouseover( row ); if ( _selected == current ) { Widgets.DrawHighlightSelected( row ); } if ( i++ % 2 == 1 ) { Widgets.DrawAltRect( row ); } Rect jobRect = row; if ( Source == SourceOptions.Current ) { if ( ManagerTab_Overview.DrawOrderButtons( new Rect( row.xMax - _leftRowEntryHeight, row.yMin, _leftRowEntryHeight, _leftRowEntryHeight ), current ) ) { Refresh(); } jobRect.width -= _leftRowEntryHeight; } current.DrawListEntry( jobRect, false, Source == SourceOptions.Current ); if ( Widgets.InvisibleButton( jobRect ) ) { _selected = current; } y += Utilities.LargeListEntryHeight; } SourceListHeight = y; GUI.EndGroup(); Widgets.EndScrollView(); }
public void DoContent( Rect canvas ) { Widgets.DrawMenuSection( canvas ); GUI.BeginGroup( canvas ); canvas = canvas.AtZero(); if ( _selected != null ) { // bottom buttons Rect buttonRect = new Rect( canvas.xMax - _button.x, canvas.yMax - _button.y, _button.x - _margin, _button.y - _margin ); Rect ingredientCheck = new Rect( buttonRect.xMin - 300f - _margin, buttonRect.yMin, 300f, buttonRect.height ); // add / remove to the stack if ( Source == SourceOptions.Current ) { if ( Widgets.TextButton( buttonRect, "FM.Delete".Translate() ) ) { _selected.Delete(); _selected = null; Refresh(); return; // just skip to the next tick to avoid null reference errors. } TooltipHandler.TipRegion( buttonRect, "FMP.DeleteBillTooltip".Translate() ); } else { if ( _selected.Trigger.IsValid ) { Widgets.LabelCheckbox(ingredientCheck, "FMP.IngredientDialogTitle".Translate(), ref _selected._createIngredientBills, !_selected._hasMeaningfulIngredientChoices); if ( Widgets.TextButton( buttonRect, "FM.Manage".Translate() ) ) { _selected.Managed = true; Manager.Get.JobStack.Add( _selected ); // refresh source list so that the next added job is not an exact copy. Refresh(); if ( _selected._hasMeaningfulIngredientChoices && _selected._createIngredientBills ) { Find.WindowStack.Add( new Dialog_CreateJobsForIngredients( _selected.Bill.recipe, _selected.Trigger.Count ) ); } Source = SourceOptions.Current; Refresh(); SourceFilter = ""; } TooltipHandler.TipRegion( buttonRect, "FMP.ManageBillTooltip".Translate() ); } else { GUI.color = new Color( .6f, .6f, .6f ); Widgets.DrawBox( buttonRect ); Utilities.Label( buttonRect, "FMP.NoThreshold".Translate(), "FMP.NoThresholdTooltip".Translate(), TextAnchor.MiddleCenter ); GUI.color = Color.white; } } // options Rect optionsColumnRect = new Rect( _margin / 2, _topAreaHeight, canvas.width / 2 - _margin, canvas.height - _topAreaHeight - _margin - _button.y ); Rect recipeColumnRect = new Rect( optionsColumnRect.xMax + _margin, _topAreaHeight, canvas.width / 2 - _margin, canvas.height - _topAreaHeight - _margin - _button.y ); Rect optionsColumnTitle = new Rect( optionsColumnRect.xMin, 0f, optionsColumnRect.width, _topAreaHeight ); Rect recipeColumnTitle = new Rect( recipeColumnRect.xMin, 0f, recipeColumnRect.width, _topAreaHeight ); // backgrounds GUI.DrawTexture( optionsColumnRect, Resources.SlightlyDarkBackground ); GUI.DrawTexture( recipeColumnRect, Resources.SlightlyDarkBackground ); // titles Utilities.Label( optionsColumnTitle, "FMP.Options".Translate(), anchor: TextAnchor.LowerLeft, lrMargin: _margin * 2, font: GameFont.Tiny ); Utilities.Label( recipeColumnTitle, "FMP.Recipe".Translate(), anchor: TextAnchor.LowerLeft, lrMargin: _margin * 2, font: GameFont.Tiny ); // options GUI.BeginGroup( optionsColumnRect ); Vector2 cur = Vector2.zero; float width = optionsColumnRect.width; // keep track of optionIndex for shading purposes (lazy way to avoid having to redo this all the damn time). int optionindex = 0; // suspended Rect suspendedRect = new Rect( cur.x, cur.y, width, _entryHeight ); if (optionindex++ % 2 == 0) Widgets.DrawAltRect( suspendedRect ); Utilities.DrawToggle( suspendedRect, "Suspended".Translate(), _selected.Suspended, delegate { _selected.Suspended = !_selected.Suspended; } ); cur.y += _entryHeight; // store mode Rect takeToStockRect = new Rect( cur.x, cur.y, width, _entryHeight ); if( optionindex++ % 2 == 0 ) Widgets.DrawAltRect( takeToStockRect ); Utilities.DrawToggle( takeToStockRect, "BillStoreMode_BestStockpile".Translate(), _selected.Bill.storeMode == BillStoreMode.BestStockpile, delegate { _selected.Bill.storeMode = BillStoreMode.BestStockpile; }, delegate { _selected.Bill.storeMode = BillStoreMode.DropOnFloor; } ); cur.y += _entryHeight; // ingredient search radius (3) Rect searchRadiusLabelRect = new Rect( cur.x, cur.y, width, _entryHeight ); if( optionindex % 2 == 0 ) Widgets.DrawAltRect( searchRadiusLabelRect ); Utilities.Label( searchRadiusLabelRect, "IngredientSearchRadius".Translate() + ": " + _selected.Bill.ingredientSearchRadius.ToString( " #####0" ), anchor: TextAnchor.MiddleLeft, lrMargin: _margin ); cur.y += _entryHeight; Rect searchRadiusRect = new Rect( cur.x, cur.y, width, Utilities.SliderHeight ); if( optionindex++ % 2 == 0 ) Widgets.DrawAltRect( searchRadiusRect ); _selected.Bill.ingredientSearchRadius = (int)GUI.HorizontalSlider( searchRadiusRect, _selected.Bill.ingredientSearchRadius, 0f, 250f ); cur.y += Utilities.SliderHeight; // prioritize over manually set jobs (4) Rect prioritizeRect = new Rect( cur.x, cur.y, width, _entryHeight ); if( optionindex++ % 2 == 0 ) Widgets.DrawAltRect( prioritizeRect ); Utilities.DrawToggle(prioritizeRect, "FMP.PrioritizeManual".Translate(), ref ManagerJob_Production.prioritizeManual); cur.y += _entryHeight; // min skill (5) if ( _selected.Bill.recipe.workSkill != null ) { Rect skillLabelRect = new Rect( cur.x, cur.y, width, _entryHeight ); if( optionindex % 2 == 0 ) Widgets.DrawAltRect( skillLabelRect ); Utilities.Label( skillLabelRect, "MinimumSkillLevel".Translate( _selected.Bill.recipe.workSkill.label.ToLower() ) + ": " + _selected.Bill.minSkillLevel.ToString( "#####0" ), anchor: TextAnchor.MiddleLeft, lrMargin: 6f ); cur.y += _entryHeight; Rect skillRect = new Rect( cur.x, cur.y, width, Utilities.SliderHeight ); if( optionindex % 2 == 0 ) Widgets.DrawAltRect( skillRect ); _selected.Bill.minSkillLevel = (int)GUI.HorizontalSlider( skillRect, _selected.Bill.minSkillLevel, 0f, 20f ); cur.y += Utilities.SliderHeight; Rect snapToHighestRect = new Rect( cur.x, cur.y, width, _entryHeight ); if( optionindex++ % 2 == 0 ) Widgets.DrawAltRect( snapToHighestRect ); Utilities.DrawToggle( snapToHighestRect, "FMP.SnapToHighestSkill".Translate(), ref _selected.maxSkil ); cur.y += _entryHeight; } // draw threshold and billgiver config (6, 7) _selected.Trigger.DrawTriggerConfig( ref cur, optionsColumnRect.width, _entryHeight, optionindex++ % 2 == 0 ); _selected.BillGivers.DrawBillGiverConfig( ref cur, optionsColumnRect.width, _entryHeight, optionindex++ % 2 == 0 ); // add a better recipe available notification with corresponding float menu if other recipe options are available. if( _selected.Managed && _selected.OtherRecipeAvailable() ) { Rect otherRecipeAvailableRect = new Rect(cur.x, cur.y, width, _entryHeight); Utilities.Label( otherRecipeAvailableRect, "FMP.OtherRecipeAvailable".Translate(), "FMP.OtherRecipeAvailableTooltip".Translate() ); Widgets.DrawHighlightIfMouseover( otherRecipeAvailableRect ); if ( optionindex++ % 2 == 0 ) Widgets.DrawAltRect(otherRecipeAvailableRect); // add a little icon to mark interactivity Rect searchIconRect = new Rect( otherRecipeAvailableRect.xMax - Utilities.Margin - _entryHeight, cur.y, _entryHeight, _entryHeight ); if( searchIconRect.height > Utilities.SmallIconSize ) { // center it. searchIconRect = searchIconRect.ContractedBy( ( searchIconRect.height - Utilities.SmallIconSize ) / 2 ); } GUI.DrawTexture( searchIconRect, Resources.Search ); // draw a floatmenu on click if( Widgets.InvisibleButton( otherRecipeAvailableRect ) ) { List<FloatMenuOption> options = new List<FloatMenuOption>(); string curLabel = "Current: " + _selected.Label + " (<i>" + string.Join( ", ", _selected.Targets ) + "</i>)"; options.Add(new FloatMenuOption( curLabel, null)); foreach( RecipeDef recipe in _selected.OtherRecipeDefs ) { string label = recipe.LabelCap + " (<i>" + string.Join( ", ", recipe.GetRecipeUsers().Select( td => td.LabelCap ).ToArray()) + "</i>)"; Action action = delegate { _selected.SetNewRecipe( recipe ); _selected.ForceRecacheOtherRecipe(); }; options.Add( new FloatMenuOption( label, action ) ); } Find.WindowStack.Add( new FloatMenu( options ) ); } cur.y += _entryHeight; } GUI.EndGroup(); // options // bill GUI.BeginGroup( recipeColumnRect ); cur = Vector2.zero; width = recipeColumnRect.width; // bill information Rect infoRect = new Rect( cur.x, cur.y, width, ( recipeColumnRect.height - cur.y ) / 2 ); string text = GetInfoText(); float actualHeight = Text.CalcHeight( text, infoRect.width ); // if required height is small, cull info area if ( infoRect.height > actualHeight ) { infoRect.height = actualHeight; } // set up scrolling region Rect infoViewRect = infoRect; if ( actualHeight > infoRect.height ) { infoViewRect.width -= 16f; // scrollbar infoViewRect.height = Text.CalcHeight( text, infoViewRect.width ); } Widgets.BeginScrollView( infoRect, ref _infoScrollPosition, infoViewRect ); Utilities.Label( infoRect, text, anchor: TextAnchor.UpperLeft, lrMargin: _margin ); Widgets.EndScrollView(); // if there is one or more products known to us (so not smelting, ugh!) display an infocard button if ( _selected.Bill.recipe.products.Count > 0 ) { Widgets.InfoCardButton( infoRect.xMax - Widgets.InfoCardButtonSize - _margin, infoRect.yMin + _margin, _selected.Bill.recipe.products[0].thingDef ); } cur.y += infoRect.height; // ingredients label Rect ingredientsLabelRect = new Rect( cur.x, cur.y, width, _entryHeight ); Utilities.Label( ingredientsLabelRect, "FMP.AllowedIngredients".Translate(), anchor: TextAnchor.MiddleLeft, lrMargin: _margin ); cur.y += _entryHeight; // ingredients picker, fill available space Rect ingredientsRect = new Rect( cur.x, cur.y, width, recipeColumnRect.height - cur.y ); filterUI.DoThingFilterConfigWindow( ingredientsRect, ref IngredientsScrollPosition, _selected.Bill.ingredientFilter, _selected.Bill.recipe.fixedIngredientFilter, 4 ); GUI.EndGroup(); // bill } GUI.EndGroup(); // window }
public void BeginEdit() { plugin.settingsView.UpdateTextBlock.Visibility = System.Windows.Visibility.Collapsed; plugin.UpdateAvailable().ContinueWith((task) => { var updateAvailable = task.Result.Available; var url = task.Result.Url; var latestVersion = task.Result.LatestVersion; plugin.settingsView.Dispatcher.Invoke(() => { if (updateAvailable) { plugin.settingsView.UpdateTextBlock.Visibility = System.Windows.Visibility.Visible; plugin.settingsView.UpdateLabel.Text = $"New version {latestVersion} available at:\n"; plugin.settingsView.URL.NavigateUri = new Uri(url); plugin.settingsView.URLLabel.Text = url; } }); }); var bt = plugin.settingsView.SelectFolderButton; bt.Click += Bt_Click; // Get all available source names foreach (var src in plugin.PlayniteApi.Database.Sources) { // Add new sources and disable them by default if (!SourceOptions.ContainsKey(src.Name)) { SourceOptions.Add(src.Name, false); } if (!EnabledPlayActions.ContainsKey(src.Name)) { EnabledPlayActions.Add(src.Name, false); } } if (!SourceOptions.ContainsKey(Constants.UNDEFINEDSOURCE)) { SourceOptions.Add(Constants.UNDEFINEDSOURCE, false); } if (!EnabledPlayActions.ContainsKey(Constants.UNDEFINEDSOURCE)) { EnabledPlayActions.Add(Constants.UNDEFINEDSOURCE, false); } // Set up view var container = plugin.settingsView.SourceNamesStack; container.Children.Clear(); foreach (var srcOpt in SourceOptions) { // Add label and set some properties var label = new Label(); label.Content = srcOpt.Key; label.MinWidth = 50; label.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; label.Margin = new System.Windows.Thickness { Bottom = 2, Left = 5, Right = 5, Top = 2 }; label.Height = 20; label.Tag = srcOpt.Key; container.Children.Add(label); } container = plugin.settingsView.SourceSettingsStack; container.Children.Clear(); foreach (var srcOpt in SourceOptions) { // Add checkboxes and set some properties var checkBox = new CheckBox(); checkBox.Content = null; checkBox.IsChecked = srcOpt.Value; checkBox.MinWidth = 50; checkBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; checkBox.Margin = new System.Windows.Thickness { Bottom = 2, Left = 5, Right = 5, Top = 2 }; checkBox.Height = 20; checkBox.Tag = srcOpt.Key; checkBox.ToolTip = $"If enabled, shortcuts to games from {srcOpt.Key} are created and maintained on update."; container.Children.Add(checkBox); } plugin.settingsView.PlayActionSettingsStack.Children.Clear(); foreach (var playActionOpt in EnabledPlayActions) { // Add checkboxes and set some properties var checkBox = new CheckBox(); checkBox.Content = null; checkBox.IsChecked = playActionOpt.Value; checkBox.MinWidth = 50; checkBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; checkBox.Margin = new System.Windows.Thickness { Bottom = 2, Left = 5, Right = 5, Top = 2 }; checkBox.Height = 20; checkBox.Tag = playActionOpt.Key; checkBox.ToolTip = $"If enabled, shortuts try to start games from {playActionOpt.Key} with their native launcher or without any launcher (bypassing Playnite), depending on the existing PlayAction of that game."; plugin.settingsView.PlayActionSettingsStack.Children.Add(checkBox); } plugin.settingsView.ManuallyCreatedShortcutListBox.Items.Clear(); foreach (var id in ManuallyCreatedShortcuts) { var item = new ListBoxItem(); item.Tag = id; item.ContextMenu = new ContextMenu(); var menuItem = new MenuItem { Header = "Remove Entry", Tag = id }; menuItem.Click += RemoveManual_Click; item.ContextMenu.Items.Add(menuItem); var game = plugin.PlayniteApi.Database.Games.Get(id); item.Content = game == null? "Game not found: " + id.ToString() : $"{game.Name} ({ShortcutSync.GetSourceName(game)})"; item.ToolTip = item.Content; plugin.settingsView.ManuallyCreatedShortcutListBox.Items.Add(item); } plugin.settingsView.ExcludedGamesListBox.Items.Clear(); foreach (var id in ExcludedGames) { var item = new ListBoxItem(); item.Tag = id; item.ContextMenu = new ContextMenu(); var menuItem = new MenuItem { Header = "Remove Entry", Tag = id }; menuItem.Click += RemoveExcluded_Click; item.ContextMenu.Items.Add(menuItem); var game = plugin.PlayniteApi.Database.Games.Get(id); item.Content = game == null ? "Game not found: " + id.ToString() : $"{game.Name} ({ShortcutSync.GetSourceName(game)})"; item.ToolTip = item.Content; plugin.settingsView.ExcludedGamesListBox.Items.Add(item); } }
/// <summary> /// Convert the specified 'file' into JSON with the Excel DataReader, and save it to the specified 'outputPath'. /// </summary> /// <param name="options"></param> public async Task ConvertWithDataReaderAsync(SourceOptions options) { var file = new FileInfo(options.File); if (file == null) { throw new ArgumentNullException(nameof(file)); } if (String.IsNullOrWhiteSpace(options.Output)) { throw new ArgumentException("Argument cannot be null, emtpy or whitespace.", nameof(options.Output)); } if (String.IsNullOrWhiteSpace(options.SheetName)) { throw new ConfigurationException("Configuration 'Converter:{Source}:SheetName' cannot be null, emtpy or whitespace."); } _logger.LogInformation($"Reading file '{file}'."); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var excelOptions = new ExcelReaderConfiguration() { FallbackEncoding = Encoding.GetEncoding(1252) }; using var reader = ExcelReaderFactory.CreateReader(file.Open(FileMode.Open, FileAccess.Read), excelOptions); var worksheets = reader.AsDataSet(); var worksheet = worksheets.Tables[options.SheetName]; // Get column names. var columns = new string[worksheet.Columns.Count]; var firstRowIsHeader = options.FirstRowIsHeaders; var rows = new List <Dictionary <string, object> >(); try { foreach (var wrow in worksheet.Rows) { var drow = wrow as DataRow; if (firstRowIsHeader) { columns = drow.ItemArray.Select(i => $"{i}").NotNullOrWhiteSpace().ToArray(); for (var i = 0; i < columns.Length; i++) { columns[i] = $"{drow.ItemArray[i]}"; } firstRowIsHeader = false; } else { var row = new Dictionary <string, object>(); for (var i = 0; i < columns.Length; i++) { var item = drow.ItemArray[i]; var type = item.GetType(); var colOptions = options.Columns.ContainsKey(columns[i]) ? options.Columns[columns[i]] : null; var name = GetName(colOptions, columns[i]); var value = await GetValueAsync(colOptions, item, row); if (colOptions?.Skip != SkipOption.Never) { if (colOptions?.Skip == SkipOption.Always) { continue; } if (colOptions?.Skip == SkipOption.AlreadySet && row.ContainsKey(name)) { continue; } if (colOptions?.Skip == SkipOption.Null && (item.GetType().IsDbNull() || item == null)) { continue; } if (colOptions?.Skip == SkipOption.NullOrEmpty && String.IsNullOrEmpty($"{item}")) { continue; } if (colOptions?.Skip == SkipOption.NullOrWhitespace && String.IsNullOrWhiteSpace($"{item}")) { continue; } } if (colOptions?.OutputTo?.Any() ?? false) { for (var oi = 0; oi < colOptions.OutputTo.Length; oi++) { var outputCol = colOptions.OutputTo[oi]; if (row.ContainsKey(outputCol)) { row[outputCol] = SetValue(value, oi); } else { row.Add(outputCol, SetValue(value, oi)); } } } else { row.Add(name, value); } } // Post actions can further transform data after a row has been created. // This is useful when one row's data relies on others. if (options.Row?.PostActions?.Any() ?? false) { foreach (var action in options.Row.PostActions) { if (!row.ContainsKey(action.Column)) { throw new ConfigurationException($"Row action configuration column '{action.Column}' does not exist."); } try { row[action.Column] = await ConvertAsync(row[action.Column], row, action.Converter, action.ConverterArgs); } catch (Exception ex) { _logger.LogError(ex, $"Unable to perform post action '{action.Column}'."); throw; } } } rows.Add(row); } } } catch (Exception ex) { _logger.LogError(ex, "Fatal error ended converter"); } var json = JsonSerializer.Serialize(rows, _serialzerOptions); ExportJsonFile(json, options.Output); }
public override void DoWindowContents( Rect rect ) { base.DoWindowContents( rect ); if ( IsDirty ) { BuildPawnList( ); } var position = new Rect( 0f, 0f, rect.width, 80f ); GUI.BeginGroup( position ); var x = 0f; Text.Font = GameFont.Small; // prisoner / colonist / Animal toggle var sourceButton = new Rect( 0f, 0f, 200f, 35f ); if ( Widgets.ButtonText( sourceButton, Source.ToString().Translate( ) ) ) { List<FloatMenuOption> options = new List<FloatMenuOption>(); if (Source != SourceOptions.Colonists) options.Add( new FloatMenuOption( "Colonists".Translate(), delegate { Source = SourceOptions.Colonists; IsDirty = true; })); if (Source != SourceOptions.Prisoners) options.Add( new FloatMenuOption( "Prisoners".Translate(), delegate { Source = SourceOptions.Prisoners; IsDirty = true; })); if (Source != SourceOptions.Animals) options.Add( new FloatMenuOption( "Animals".Translate(), delegate { Source = SourceOptions.Animals; IsDirty = true; })); Find.WindowStack.Add(new FloatMenu(options)); } // name var nameLabel = new Rect( x, 50f, 175f, 30f ); Text.Anchor = TextAnchor.LowerCenter; Widgets.Label( nameLabel, "FluffyMedical.Name".Translate( ) ); if ( Widgets.ButtonInvisible( nameLabel ) ) { if ( OrderBy == Order.Name ) { Asc = !Asc; } else { OrderBy = Order.Name; Asc = true; } IsDirty = true; } TooltipHandler.TipRegion( nameLabel, "FluffyMedical.ClickToSortBy".Translate( "FluffyMedical.Name".Translate( ) ) ); Widgets.DrawHighlightIfMouseover( nameLabel ); x += 175f; // care var careLabel = new Rect( x, 50f, 100f, 30f ); Widgets.Label( careLabel, "FluffyMedical.Care".Translate( ) ); if ( Widgets.ButtonInvisible( careLabel ) ) { if ( Event.current.shift ) { Utility_Medical.MedicalCareSetterAll( pawns ); } else { if ( OrderBy == Order.Care ) { Asc = !Asc; } else { OrderBy = Order.Care; Asc = true; } IsDirty = true; } } TooltipHandler.TipRegion( careLabel, "FluffyMedical.ClickToSortBy".Translate( "FluffyMedical.Care".Translate( ) ) + "\n" + "FluffyMedical.ShiftClickTo".Translate( "FluffyMedical.SetCare".Translate( ) ) ); Widgets.DrawHighlightIfMouseover( careLabel ); x += 100f; // bloodloss var bloodLabel = new Rect( x, 50f, 50f, 30f ); var bloodIcon = new Rect( x + 17f, 60f, 16f, 16f ); GUI.DrawTexture( bloodIcon, Utility_Medical.BloodTextureWhite ); if ( Widgets.ButtonInvisible( bloodLabel ) ) { if ( OrderBy == Order.BleedRate ) { Asc = !Asc; } else { OrderBy = Order.BleedRate; Asc = true; } IsDirty = true; } TooltipHandler.TipRegion( bloodLabel, "FluffyMedical.ClickToSortBy".Translate( "BleedingRate".Translate( ) ) ); Widgets.DrawHighlightIfMouseover( bloodLabel ); x += 50f; // Operations var opLabel = new Rect( x, 50f, 50f, 30f ); var opIcon = new Rect( x + 17f, 60f, 16f, 16f ); GUI.DrawTexture( opIcon, Utility_Medical.OpTexture ); if ( Widgets.ButtonInvisible( opLabel ) ) { if ( OrderBy == Order.Operations ) { Asc = !Asc; } else { OrderBy = Order.Operations; Asc = true; } IsDirty = true; } TooltipHandler.TipRegion( opLabel, "FluffyMedical.ClickToSortBy".Translate( "FluffyMedical.CurrentOperations".Translate( ) ) ); Widgets.DrawHighlightIfMouseover( opLabel ); x += 50f; var offset = true; // extra 15f offset for... what? makes labels roughly align. var colWidth = ( rect.width - x - 15f ) / CapDefs.Count; for ( var i = 0; i < CapDefs.Count; i++ ) { var defLabel = new Rect( x + colWidth * i - colWidth / 2, 10f + ( offset ? 10f : 40f ), colWidth * 2, 30f ); Widgets.DrawLine( new Vector2( x + colWidth * ( i + 1 ) - colWidth / 2, 40f + ( offset ? 5f : 35f ) ), new Vector2( x + colWidth * ( i + 1 ) - colWidth / 2, 80f ), Color.gray, 1 ); Widgets.Label( defLabel, CapDefs[i].LabelCap ); if ( Widgets.ButtonInvisible( defLabel ) ) { if ( OrderBy == Order.Efficiency && OrderByCapDef == CapDefs[i] ) { Asc = !Asc; } else { OrderBy = Order.Efficiency; OrderByCapDef = CapDefs[i]; Asc = true; } IsDirty = true; } TooltipHandler.TipRegion( defLabel, "FluffyMedical.ClickToSortBy".Translate( CapDefs[i].LabelCap ) ); Widgets.DrawHighlightIfMouseover( defLabel ); offset = !offset; } GUI.EndGroup( ); var content = new Rect( 0f, position.yMax, rect.width, rect.height - position.yMax ); GUI.BeginGroup( content ); DrawRows( new Rect( 0f, 0f, content.width, content.height ) ); GUI.EndGroup( ); }
/// <summary> /// Generates the appropriate class given some options. /// </summary> /// <param name="options">The options.</param> /// <param name="classOptions">The options for classes.</param> /// <returns> /// A <see cref="KeyValuePair"/> where the first element is the source /// string and the second element is the set of attributes. /// </returns> /// /// TODO: Abstract with a wrapper type wrapping around KeyValuePair. public static KeyValuePair<string, IReadOnlyDictionary<string, string>> Generate(SourceOptions options = SourceOptions.None, ClassOptions classOptions = ClassOptions.None) { ClassGenerator classes = new ClassGenerator() { Name = Name }; // Class with many interfaces if (options.HasFlag(SourceOptions.ImplementsInterfaces) && options.HasFlag(SourceOptions.BaseListMany)) { classes.Interface1Name = Interface1Name; classes.Interface2Name = Interface2Name; classes.Interface3Name = Interface3Name; return new KeyValuePair<string, IReadOnlyDictionary<string, string>>( classes.ClassWithManyInterfaces, classes.ClassWithManyInterfacesAttributes); } // Class with interface if (options.HasFlag(SourceOptions.ImplementsInterfaces)) { classes.Interface1Name = Interface1Name; return new KeyValuePair<string, IReadOnlyDictionary<string, string>>( classes.ClassWith1Interface, classes.ClassWith1InterfaceAttributes); } // Class with base class if (options.HasFlag(SourceOptions.HasInheritance)) { classes.BaseClassName = BaseName; return new KeyValuePair<string, IReadOnlyDictionary<string, string>>( classes.ClassWithBaseClass, classes.ClassWithBaseClassAttributes); } // Empty elements if (options.HasFlag(SourceOptions.EmptyElements)) { return new KeyValuePair<string, IReadOnlyDictionary<string, string>>( classes.VerySimpleClassWithEmptyMethods, classes.VerySimpleClassWithEmptyMethodsAttributes); } // Namespace if (options.HasFlag(SourceOptions.HasNamespace)) { classes.NamespaceName = NamespaceName; return new KeyValuePair<string, IReadOnlyDictionary<string, string>>( classes.VerySimpleClassInNamespace, classes.VerySimpleClassInNamespaceAttributes); } // Simple class if (classOptions.HasFlag(ClassOptions.HasContent)) { return new KeyValuePair<string, IReadOnlyDictionary<string, string>>( classes.SimpleClass, classes.SimpleClassAttributes); } return new KeyValuePair<string, IReadOnlyDictionary<string, string>>( classes.VerySimpleClass, classes.VerySimpleClassAttributes); }
public void DoContent(Rect canvas) { Widgets.DrawMenuSection(canvas); GUI.BeginGroup(canvas); canvas = canvas.AtZero(); if (_selected != null) { // bottom buttons var buttonRect = new Rect(canvas.xMax - _button.x, canvas.yMax - _button.y, _button.x - _margin, _button.y - _margin); var ingredientCheck = new Rect(buttonRect.xMin - 300f - _margin, buttonRect.yMin, 300f, buttonRect.height); // add / remove to the stack if (Source == SourceOptions.Current) { if (Widgets.ButtonText(buttonRect, "FM.Delete".Translate())) { _selected.Delete(); _selected = null; Refresh(); return; // just skip to the next tick to avoid null reference errors. } TooltipHandler.TipRegion(buttonRect, "FMP.DeleteBillTooltip".Translate()); } else { if (_selected.Trigger.IsValid) { Widgets.CheckboxLabeled(ingredientCheck, "FMP.IngredientDialogTitle".Translate(), ref _selected._createIngredientBills, !_selected._hasMeaningfulIngredientChoices); if (Widgets.ButtonText(buttonRect, "FM.Manage".Translate())) { _selected.Managed = true; manager.JobStack.Add(_selected); // refresh source list so that the next added job is not an exact copy. Refresh(); if (_selected._hasMeaningfulIngredientChoices && _selected._createIngredientBills) { Find.WindowStack.Add(new Dialog_CreateJobsForIngredients(manager, _selected.Bill.recipe, _selected.Trigger.Count)); } Source = SourceOptions.Current; Refresh(); SourceFilter = ""; } TooltipHandler.TipRegion(buttonRect, "FMP.ManageBillTooltip".Translate()); } else { GUI.color = new Color(.6f, .6f, .6f); Widgets.DrawBox(buttonRect); Utilities.Label(buttonRect, "FMP.NoThreshold".Translate(), "FMP.NoThresholdTooltip".Translate(), TextAnchor.MiddleCenter); GUI.color = Color.white; } } // options var optionsColumnRect = new Rect(_margin / 2, _topAreaHeight, canvas.width / 2 - _margin, canvas.height - _topAreaHeight - _margin - _button.y); var recipeColumnRect = new Rect(optionsColumnRect.xMax + _margin, _topAreaHeight, canvas.width / 2 - _margin, canvas.height - _topAreaHeight - _margin - _button.y); var optionsColumnTitle = new Rect(optionsColumnRect.xMin, 0f, optionsColumnRect.width, _topAreaHeight); var recipeColumnTitle = new Rect(recipeColumnRect.xMin, 0f, recipeColumnRect.width, _topAreaHeight); // backgrounds GUI.DrawTexture(optionsColumnRect, Resources.SlightlyDarkBackground); GUI.DrawTexture(recipeColumnRect, Resources.SlightlyDarkBackground); // titles Utilities.Label(optionsColumnTitle, "FMP.Options".Translate(), anchor: TextAnchor.LowerLeft, lrMargin: _margin * 2, font: GameFont.Tiny); Utilities.Label(recipeColumnTitle, "FMP.Recipe".Translate(), anchor: TextAnchor.LowerLeft, lrMargin: _margin * 2, font: GameFont.Tiny); // options GUI.BeginGroup(optionsColumnRect); Vector2 cur = Vector2.zero; float width = optionsColumnRect.width; // keep track of optionIndex for shading purposes (lazy way to avoid having to redo this all the damn time). var optionindex = 0; // suspended var suspendedRect = new Rect(cur.x, cur.y, width, _entryHeight); if (optionindex++ % 2 == 0) { Widgets.DrawAltRect(suspendedRect); } Utilities.DrawToggle(suspendedRect, "Suspended".Translate(), _selected.Suspended, delegate { _selected.Suspended = !_selected.Suspended; }); cur.y += _entryHeight; // store mode var takeToStockRect = new Rect(cur.x, cur.y, width, _entryHeight); if (optionindex++ % 2 == 0) { Widgets.DrawAltRect(takeToStockRect); } Utilities.DrawToggle(takeToStockRect, "BillStoreMode_BestStockpile".Translate(), _selected.Bill.storeMode == BillStoreMode.BestStockpile, delegate { _selected.Bill.storeMode = BillStoreMode.BestStockpile; }, delegate { _selected.Bill.storeMode = BillStoreMode.DropOnFloor; }); cur.y += _entryHeight; // ingredient search radius (3) var searchRadiusLabelRect = new Rect(cur.x, cur.y, width, _entryHeight); if (optionindex % 2 == 0) { Widgets.DrawAltRect(searchRadiusLabelRect); } Utilities.Label(searchRadiusLabelRect, "IngredientSearchRadius".Translate() + ": " + _selected.Bill.ingredientSearchRadius.ToString(" #####0"), anchor: TextAnchor.MiddleLeft, lrMargin: _margin); cur.y += _entryHeight; var searchRadiusRect = new Rect(cur.x, cur.y, width, Utilities.SliderHeight); if (optionindex++ % 2 == 0) { Widgets.DrawAltRect(searchRadiusRect); } _selected.Bill.ingredientSearchRadius = (int)GUI.HorizontalSlider(searchRadiusRect, _selected.Bill.ingredientSearchRadius, 0f, 250f); cur.y += Utilities.SliderHeight; // prioritize over manually set jobs (4) var prioritizeRect = new Rect(cur.x, cur.y, width, _entryHeight); if (optionindex++ % 2 == 0) { Widgets.DrawAltRect(prioritizeRect); } Utilities.DrawToggle(prioritizeRect, "FMP.PrioritizeManual".Translate(), ref ManagerJob_Production.prioritizeManual); cur.y += _entryHeight; // skill range (5) if (_selected.Bill.recipe.workSkill != null) { var skillLabelRect = new Rect(cur.x, cur.y, width, _entryHeight); if (optionindex % 2 == 0) { Widgets.DrawAltRect(skillLabelRect); } Utilities.Label(skillLabelRect, "FMP.AllowedSkillRange".Translate() + ": " + _selected.Bill.allowedSkillRange); cur.y += _entryHeight; var skillRect = new Rect(cur.x, cur.y, width, Utilities.SliderHeight); if (optionindex % 2 == 0) { Widgets.DrawAltRect(skillRect); } Widgets.IntRange(skillRect, 2134112311, ref _selected.Bill.allowedSkillRange, 0, 20); cur.y += Utilities.SliderHeight; var snapToHighestRect = new Rect(cur.x, cur.y, width, _entryHeight); if (optionindex++ % 2 == 0) { Widgets.DrawAltRect(snapToHighestRect); } Utilities.DrawToggle(snapToHighestRect, "FMP.SnapToHighestSkill".Translate(), ref _selected.restrictToMaxSkill); cur.y += _entryHeight; } // draw threshold and billgiver config (6, 7) _selected.Trigger.DrawTriggerConfig(ref cur, optionsColumnRect.width, _entryHeight, optionindex++ % 2 == 0); _selected.BillGivers.DrawBillGiverConfig(ref cur, optionsColumnRect.width, _entryHeight, optionindex++ % 2 == 0); // add a better recipe available notification with corresponding float menu if other recipe options are available. if (_selected.Managed && _selected.OtherRecipeAvailable()) { var otherRecipeAvailableRect = new Rect(cur.x, cur.y, width, _entryHeight); Utilities.Label(otherRecipeAvailableRect, "FMP.OtherRecipeAvailable".Translate(), "FMP.OtherRecipeAvailableTooltip".Translate()); Widgets.DrawHighlightIfMouseover(otherRecipeAvailableRect); if (optionindex++ % 2 == 0) { Widgets.DrawAltRect(otherRecipeAvailableRect); } // add a little icon to mark interactivity var searchIconRect = new Rect(otherRecipeAvailableRect.xMax - Utilities.Margin - _entryHeight, cur.y, _entryHeight, _entryHeight); if (searchIconRect.height > Utilities.SmallIconSize) { // center it. searchIconRect = searchIconRect.ContractedBy((searchIconRect.height - Utilities.SmallIconSize) / 2); } GUI.DrawTexture(searchIconRect, Resources.Search); // draw a floatmenu on click if (Widgets.ButtonInvisible(otherRecipeAvailableRect)) { var options = new List <FloatMenuOption>(); string curLabel = "Current: " + _selected.Label + " (<i>" + string.Join(", ", _selected.Targets) + "</i>)"; options.Add(new FloatMenuOption(curLabel, null)); foreach (RecipeDef recipe in _selected.OtherRecipeDefs) { string label = recipe.LabelCap + " (<i>" + string.Join(", ", recipe.GetRecipeUsers().Select(td => td.LabelCap).ToArray()) + "</i>)"; Action action = delegate { _selected.SetNewRecipe(recipe); _selected.ForceRecacheOtherRecipe(); }; options.Add(new FloatMenuOption(label, action)); } Find.WindowStack.Add(new FloatMenu(options)); } cur.y += _entryHeight; } GUI.EndGroup(); // options // bill GUI.BeginGroup(recipeColumnRect); cur = Vector2.zero; width = recipeColumnRect.width; // bill information var infoRect = new Rect(cur.x, cur.y, width, (recipeColumnRect.height - cur.y) / 2); string text = GetInfoText(); float actualHeight = Text.CalcHeight(text, infoRect.width); // if required height is small, cull info area if (infoRect.height > actualHeight) { infoRect.height = actualHeight; } // set up scrolling region Rect infoViewRect = infoRect; if (actualHeight > infoRect.height) { infoViewRect.width -= 16f; // scrollbar infoViewRect.height = Text.CalcHeight(text, infoViewRect.width); } Widgets.BeginScrollView(infoRect, ref _infoScrollPosition, infoViewRect); Utilities.Label(infoRect, text, anchor: TextAnchor.UpperLeft, lrMargin: _margin); Widgets.EndScrollView(); // if there is one or more products known to us (so not smelting, ugh!) display an infocard button if (_selected.Bill.recipe.products.Count > 0) { Widgets.InfoCardButton(infoRect.xMax - Widgets.InfoCardButtonSize - _margin, infoRect.yMin + _margin, _selected.Bill.recipe.products[0].thingDef); } cur.y += infoRect.height; // ingredients label var ingredientsLabelRect = new Rect(cur.x, cur.y, width, _entryHeight); Utilities.Label(ingredientsLabelRect, "FMP.AllowedIngredients".Translate(), anchor: TextAnchor.MiddleLeft, lrMargin: _margin); cur.y += _entryHeight; // ingredients picker, fill available space var ingredientsRect = new Rect(cur.x, cur.y, width, recipeColumnRect.height - cur.y); filterUI.DoThingFilterConfigWindow(ingredientsRect, ref IngredientsScrollPosition, _selected.Bill.ingredientFilter, _selected.Bill.recipe.fixedIngredientFilter, 4); GUI.EndGroup(); // bill } GUI.EndGroup(); // window }