public PatternEditor(Creature creature, List <Creature> females, List <Creature> males, Dictionary <string, string> customReplacings, Action <PatternEditor> reloadCallback) : this() { OnReloadCustomReplacings = reloadCallback; _creature = creature; _females = females; _males = males; _customReplacings = customReplacings; txtboxPattern.Text = Properties.Settings.Default.sequentialUniqueNamePattern; txtboxPattern.SelectionStart = txtboxPattern.Text.Length; // collect creatures of the same species var sameSpecies = (females ?? new List <Creature> { }).Concat((males ?? new List <Creature> { })).ToList(); var creatureNames = sameSpecies.Select(x => x.name).ToList(); var examples = NamePatterns.CreateTokenDictionary(creature, sameSpecies); TableLayoutPanel tlpKeys = new TableLayoutPanel(); tableLayoutPanel1.Controls.Add(tlpKeys); SetControlsToTable(tlpKeys, PatternExplanations(creature.Species.IsGlowSpecies)); TableLayoutPanel tlpFunctions = new TableLayoutPanel(); tableLayoutPanel1.Controls.Add(tlpFunctions); tableLayoutPanel1.SetColumn(tlpFunctions, 1); SetControlsToTable(tlpFunctions, FunctionExplanations(), false, true, 306); void SetControlsToTable(TableLayoutPanel tlp, Dictionary <string, string> nameExamples, bool columns = true, bool useExampleAsInput = false, int buttonWidth = 120) { tlp.Dock = DockStyle.Fill; tlp.AutoScroll = true; tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); int i = 0; foreach (KeyValuePair <string, string> p in nameExamples) { tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); if (!columns) { tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); } Button btn = new Button { Size = new Size(buttonWidth, 23), Text = useExampleAsInput ? p.Key : $"{{{p.Key}}}" }; int substringUntil = p.Value.LastIndexOf("\n"); btn.Tag = useExampleAsInput ? p.Value.Substring(substringUntil + 1) : $"{{{p.Key}}}"; tlp.Controls.Add(btn); tlp.SetCellPosition(btn, new TableLayoutPanelCellPosition(0, i)); if (!columns) { tlp.SetColumnSpan(btn, 2); } btn.Click += Btn_Click; Label lbl = new Label { Dock = DockStyle.Fill, MinimumSize = new Size(50, 30), Text = useExampleAsInput ? p.Value.Substring(0, substringUntil) : p.Value + (examples.ContainsKey(p.Key) ? ". E.g. \"" + examples[p.Key] + "\"" : "") }; lbl.Margin = new Padding(3, 3, 3, 5); tlp.Controls.Add(lbl); tlp.SetCellPosition(lbl, new TableLayoutPanelCellPosition(columns ? 1 : 0, columns ? i : ++i)); if (!columns) { tlp.SetColumnSpan(lbl, 2); } if (!columns && p.Value.Contains("#customreplace")) { // button to open custom replacings file tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); i++; var btCustomReplacings = new Button() { Text = "Open custom replacings file", Width = 150 }; btCustomReplacings.Click += BtCustomReplacings_Click; tlp.Controls.Add(btCustomReplacings); tlp.SetCellPosition(btCustomReplacings, new TableLayoutPanelCellPosition(0, i)); var btCustomReplacingsReload = new Button() { Text = "Reload custom replacings", Width = 150 }; btCustomReplacingsReload.Click += (sender, eventArgs) => OnReloadCustomReplacings?.Invoke(this); tlp.Controls.Add(btCustomReplacingsReload); tlp.SetCellPosition(btCustomReplacingsReload, new TableLayoutPanelCellPosition(1, i)); } // separator if (!columns) { tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); var separator = new Label { BorderStyle = BorderStyle.Fixed3D, Height = 2, Dock = DockStyle.Bottom, Margin = new Padding(0, 0, 0, 5) }; tlp.Controls.Add(separator); tlp.SetRow(separator, ++i); tlp.SetColumnSpan(separator, 2); } i++; } } }
public PatternEditor(Creature creature, List <Creature> females, List <Creature> males) : this() { _creature = creature; _females = females; _males = males; txtboxPattern.Text = Properties.Settings.Default.sequentialUniqueNamePattern; txtboxPattern.SelectionStart = txtboxPattern.Text.Length; // collect creatures of the same species var sameSpecies = (females ?? new List <Creature> { }).Concat((males ?? new List <Creature> { })).ToList(); var creatureNames = sameSpecies.Select(x => x.name).ToList(); var examples = NamePatterns.CreateTokenDictionary(creature, sameSpecies); TableLayoutPanel tlpKeys = new TableLayoutPanel(); tableLayoutPanel1.Controls.Add(tlpKeys); SetControlsToTable(tlpKeys, PatternExplanations(creature.Species.IsGlowSpecies)); TableLayoutPanel tlpFunctions = new TableLayoutPanel(); tableLayoutPanel1.Controls.Add(tlpFunctions); tableLayoutPanel1.SetColumn(tlpFunctions, 1); SetControlsToTable(tlpFunctions, FunctionExplanations(), false, true, 300); void SetControlsToTable(TableLayoutPanel tlp, Dictionary <string, string> nameExamples, bool columns = true, bool useExampleAsInput = false, int buttonWidth = 120) { tlp.Dock = DockStyle.Fill; tlp.AutoScroll = true; tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); if (columns) { tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); } int i = 0; foreach (KeyValuePair <string, string> p in nameExamples) { tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); if (!columns) { tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); } Button btn = new Button { Size = new Size(buttonWidth, 23), Text = useExampleAsInput ? p.Key : $"{{{p.Key}}}" }; int substringUntil = p.Value.LastIndexOf("\n"); btn.Tag = useExampleAsInput ? p.Value.Substring(substringUntil + 1) : $"{{{p.Key}}}"; tlp.Controls.Add(btn); tlp.SetCellPosition(btn, new TableLayoutPanelCellPosition(0, i)); btn.Click += Btn_Click; Label lbl = new Label { Dock = DockStyle.Fill, MinimumSize = new Size(50, 30), Text = useExampleAsInput ? p.Value.Substring(0, substringUntil) : p.Value + (examples.ContainsKey(p.Key) ? ". E.g. \"" + examples[p.Key] + "\"" : "") }; lbl.Margin = new Padding(3, 3, 3, columns ? 5 : 10); tlp.Controls.Add(lbl); tlp.SetCellPosition(lbl, new TableLayoutPanelCellPosition(columns ? 1 : 0, columns ? i : ++i)); i++; } } }
private void Initialization(Creature creature = null, List <Creature> females = null, List <Creature> males = null) { InitializeComponent(); txtboxPattern.Text = Properties.Settings.Default.sequentialUniqueNamePattern; Dictionary <string, string> patternList = new Dictionary <string, string>() { { "species", "species name" }, { "species_short6", "species name shortened to at most 6 letters" }, { "species_short6u", "species name shortened to at most 6 letters in uppercase" }, { "species_short5", "species name shortened to at most 5 letters" }, { "species_short5u", "species name shortened to at most 5 letters in uppercase" }, { "species_short4", "species name shortened to at most 4 letters" }, { "species_short4u", "species name shortened to at most 4 letters in uppercase" }, { "spcs_short4", "species without vowels and shortened to at most 4 characters" }, { "spcs_short4u", "like {spcs_short} and in uppercase" }, { "firstWordOfOldest", "the first word of the name of the first added creature of the species" }, { "sex", "sex (\"Male\", \"Female\", \"Unknown\")" }, { "sex_short", "\"M\", \"F\", \"U\"" }, { "cpr", "{sex_short}{date_short}{hp}{stam}{oxy}{food}{weight}{dmg}{effImp}" }, { "yyyy", "year with 4 digits" }, { "yy", "year with 2 digits" }, { "MM", "month with 2 digits" }, { "dd", "day of the month with 2 digits" }, { "hh", "hours (24 h format)" }, { "mm", "minutes" }, { "ss", "seconds" }, { "date", "yy-MM-dd" }, { "time", "hh:mm:ss" }, { "n", "if the name is not unique, the smallest possible number is appended (only creatues with a given sex are considered)." }, { "hp", "Health" }, { "stam", "Stamina" }, { "oxy", "Oxygen" }, { "food", "Food" }, { "weight", "Weight" }, { "dmg", "Damage" }, { "spd", "Speed" }, { "trp", "Torpor" }, { "baselvl", "Base-level (level without manually added ones), i.e. level right after taming / hatching" }, { "effImp", "Taming-effectiveness or Imprinting (if tamed / bred)" }, { "gen", "Generation" }, { "gena", "Generation in letters" }, { "muta", "Mutations. Numbers larger than 99 will be displayed as 99" }, { "rnd", "6-digit random number in the range 100000 - 999999" }, { "tn", "number of creatures of the current species in the library + 1" }, { "sn", "number of creatures of the current species with the same sex in the library + 1" }, { "dom", "how the creature was domesticated, \"T\" for tamed, \"B\" for bred" } }; // collect creatures of the same species var sameSpecies = (females ?? new List <Creature> { }).Concat((males ?? new List <Creature> { })).ToList(); var creatureNames = sameSpecies.Select(x => x.name).ToList(); var examples = NamePatterns.CreateTokenDictionary(creature, sameSpecies); int i = 0; foreach (KeyValuePair <string, string> p in patternList) { Button btn = new Button { Location = new Point(15, 3 + i * 27), Size = new Size(120, 23), Text = $"{{{p.Key}}}" }; panelButtons.Controls.Add(btn); btn.Click += Btn_Click; Label lbl = new Label(); lbl.Location = new Point(140, 8 + i * 27); lbl.AutoSize = true; lbl.Text = p.Value + (examples.ContainsKey(p.Key) ? ". E.g. \"" + examples[p.Key] + "\"" : ""); panelButtons.Controls.Add(lbl); i++; } }
public PatternEditor(Creature creature, Creature[] creaturesOfSameSpecies, int[] speciesTopLevels, int[] speciesLowestLevels, Dictionary <string, string> customReplacings, int namingPatternIndex, Action <PatternEditor> reloadCallback) : this() { _creature = creature; _creaturesOfSameSpecies = creaturesOfSameSpecies; _speciesTopLevels = speciesTopLevels; _speciesLowestLevels = speciesLowestLevels; _customReplacings = customReplacings; _reloadCallback = reloadCallback; txtboxPattern.Text = Properties.Settings.Default.NamingPatterns?[namingPatternIndex] ?? string.Empty; txtboxPattern.SelectionStart = txtboxPattern.Text.Length; Text = $"Naming Pattern Editor: pattern {(namingPatternIndex + 1)}"; _tokenDictionary = NamePatterns.CreateTokenDictionary(creature, _creaturesOfSameSpecies, _speciesTopLevels, _speciesLowestLevels); TableLayoutPanel tlpKeys = new TableLayoutPanel(); tableLayoutPanel1.Controls.Add(tlpKeys); SetControlsToTable(tlpKeys, PatternExplanations(creature.Species.statNames)); TableLayoutPanel tlpFunctions = new TableLayoutPanel(); tableLayoutPanel1.Controls.Add(tlpFunctions); tableLayoutPanel1.SetColumn(tlpFunctions, 1); SetControlsToTable(tlpFunctions, FunctionExplanations(), false, true, 306); void SetControlsToTable(TableLayoutPanel tlp, Dictionary <string, string> nameExamples, bool columns = true, bool useExampleAsInput = false, int buttonWidth = 120) { tlp.Dock = DockStyle.Fill; // to deactivate the horizontal scrolling but keep the vertical scrolling, // apparently that is the way to go ¯\_(ツ)_/¯ tlp.HorizontalScroll.Maximum = 0; tlp.AutoScroll = false; tlp.VerticalScroll.Visible = false; tlp.AutoScroll = true; tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); tlp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); int i = 0; foreach (KeyValuePair <string, string> p in nameExamples) { tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); if (!columns) { tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); } Button btn = new Button { Size = new Size(buttonWidth, 23), Text = useExampleAsInput ? p.Key : $"{{{p.Key}}}" }; int substringUntil = p.Value.LastIndexOf("\n"); btn.Tag = useExampleAsInput ? p.Value.Substring(substringUntil + 1) : $"{{{p.Key}}}"; tlp.Controls.Add(btn); tlp.SetCellPosition(btn, new TableLayoutPanelCellPosition(0, i)); if (!columns) { tlp.SetColumnSpan(btn, 3); } btn.Click += Btn_Click; Label lbl = new Label { Dock = DockStyle.Fill, MinimumSize = new Size(50, 40), Text = useExampleAsInput ? p.Value.Substring(0, substringUntil) : p.Value + (_tokenDictionary.ContainsKey(p.Key) ? ". E.g. \"" + _tokenDictionary[p.Key] + "\"" : ""), Margin = new Padding(3, 3, 3, 5) }; tlp.Controls.Add(lbl); tlp.SetCellPosition(lbl, new TableLayoutPanelCellPosition(columns ? 1 : 0, columns ? i : ++i)); if (!columns) { tlp.SetColumnSpan(lbl, 3); } if (!columns && p.Value.Contains("#customreplace")) { // button to open custom replacings file tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); i++; const int buttonCustomReplacingWidth = 100; var btCustomReplacings = new Button() { Text = "Open file", Width = buttonCustomReplacingWidth }; btCustomReplacings.Click += BtCustomReplacings_Click; tlp.Controls.Add(btCustomReplacings); tlp.SetCellPosition(btCustomReplacings, new TableLayoutPanelCellPosition(0, i)); var btCustomReplacingsReload = new Button() { Text = "Reload file", Width = buttonCustomReplacingWidth }; btCustomReplacingsReload.Click += (s, e) => _reloadCallback?.Invoke(this); tlp.Controls.Add(btCustomReplacingsReload); tlp.SetCellPosition(btCustomReplacingsReload, new TableLayoutPanelCellPosition(1, i)); var btCustomReplacingsFilePath = new Button() { Text = "Select file", Width = buttonCustomReplacingWidth }; btCustomReplacingsFilePath.Click += ChangeCustomReplacingsFilePath; tlp.Controls.Add(btCustomReplacingsFilePath); tlp.SetCellPosition(btCustomReplacingsFilePath, new TableLayoutPanelCellPosition(2, i)); } // separator if (!columns) { tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize)); var separator = new Label { BorderStyle = BorderStyle.Fixed3D, Height = 2, Dock = DockStyle.Bottom, Margin = new Padding(0, 0, 0, 5) }; tlp.Controls.Add(separator); tlp.SetRow(separator, ++i); tlp.SetColumnSpan(separator, 3); } i++; } } }