public static string AdviserFilePathAndName(string productName, bool isPlugin = false) { string fileName; Timer checkTimer = new Timer(10000); // give up after 10 seconds try { checkTimer.Reset(); while (ObjectManager.Me.WowClass.ToString() == "None") { Thread.Sleep(10); Application.DoEvents(); if (checkTimer.IsReady) { break; } } fileName = productName + "-" + Others.DelSpecialChar(ObjectManager.Me.Name) + "." + ObjectManager.Me.WowClass + "." + Others.DelSpecialChar(Usefuls.RealmName) + ".xml"; } catch (Exception e) { Logging.WriteError("AdviserFileName(string productName): " + e); fileName = productName + "-null.xml"; } return(Application.StartupPath + "\\Settings" + (isPlugin ? "\\Plugins" : "") + "\\" + fileName); }
public static List <BuildingID> GetBuildingOwnedList() { try { var listOwnedBuildings = new List <BuildingID>(); Lua.LuaDoString( "mygb = \"\"; " + "local buildings = C_Garrison.GetBuildings(LE_GARRISON_TYPE_6_0) " + " for i = 1, #buildings do " + " mygb = mygb.. tostring(buildings[i].buildingID) .. \"|\" end "); foreach (string value in Lua.GetLocalizedText("mygb").Split('|')) { int tValue = Others.ToInt32(value); if (tValue > 0) { listOwnedBuildings.Add((BuildingID)tValue); } } return(listOwnedBuildings); } catch (Exception e) { Logging.WriteError("public static List<BuildingID> GetBuildingOwnedList(): " + e); } return(new List <BuildingID>()); }
public static int GetGarrisonLevel() { string randomString = Others.GetRandomString(Others.Random(4, 10)); Lua.LuaDoString(randomString + " = C_Garrison.GetGarrisonInfo(LE_GARRISON_TYPE_6_0)"); string ret = Lua.GetLocalizedText(randomString); return(Others.ToInt32(ret)); }
public static int GetBuildingRank(BuildingID buildingId) { // buildingID, buildingName, texturePrefix, icon, description, rank = C_Garrison.GetBuildingInfo(buildingID) // try { string result = Others.GetRandomString(Others.Random(4, 10)); Lua.LuaDoString("_, _, _, _, _, " + result + " = C_Garrison.GetBuildingInfo(" + (int)buildingId + ");"); return(Others.ToInt32(Lua.GetLocalizedText(result))); } catch (Exception e) { Logging.WriteError("public int GetBuildingRank(int buildingId): " + e); } return(0); }
public static void NewFile() { try { _log = new List <Log>(); _logFileName = DateTime.Now.ToString("d MMM yyyy HH") + "H" + DateTime.Now.ToString("mm") + ".log.html"; if (File.Exists(Application.StartupPath + "\\Logs\\" + _logFileName)) { _logFileName = DateTime.Now.ToString("d MMM yyyy HH") + "H" + DateTime.Now.ToString("mm") + " - " + Others.GetRandomString(Others.Random(4, 7)) + ".log.html"; } WriteDebug("Log file created: " + _logFileName); Write("Welcome to " + Information.MainTitle + ", if you have any trouble, please upload the FILE of this log from your /Logs/ directory on the community forum."); } catch (Exception exception) { WriteError("NewFile(): " + exception); } }
public void ToForm() { try { // Create Form _mainForm = new Form { BackColor = Color.FromArgb(232, 232, 232), Size = new Size(575, 403), FormBorderStyle = FormBorderStyle.None, Name = "MainForm", ShowIcon = false, StartPosition = FormStartPosition.CenterParent, Text = Others.GetRandomString(Others.Random(4, 10)), Icon = ((Icon)(_resources.GetObject("$this.Icon"))), BackgroundImage = Resources.backgroundCustomSettings, Font = new Font("Segoe UI", 8.25F, FontStyle.Regular, GraphicsUnit.Point, (0)) }; _mainForm.Load += GiveFocusToMainPanel; _mainForm.Click += GiveFocusToMainPanel; if (nManagerSetting.CurrentSetting.ActivateAlwaysOnTopFeature) { _mainForm.TopMost = true; } _mainHeader = new TnbControlMenu { BackgroundImageLayout = ImageLayout.None, Location = new Point(0, 0), Margin = new Padding(0), Name = "MainHeader", Size = new Size(575, 43), TitleFont = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point, 0), TitleForeColor = Color.FromArgb(250, 250, 250), TitleText = _windowName, }; _mainForm.Controls.Add(_mainHeader); _mainPanel = new TnbRibbonManager { Anchor = AnchorStyles.None, AutoScroll = true, AutoScrollMinSize = new Size(0, 361), BackColor = Color.Transparent, ForeColor = Color.FromArgb(52, 52, 52), Location = new Point(-7, 24), TabIndex = 0, Name = "MainPanel", Size = new Size(573, 359), }; _mainForm.Controls.Add(_mainPanel); var listExpandablePanel = new List <TnbExpendablePanel>(); var lastLineY = new Dictionary <string, int>(); foreach (FormSetting f in _listFormSetting) { Label label = null; int indexTab = -1; for (int i = listExpandablePanel.Count - 1; i >= 0; i--) { if (listExpandablePanel[i].TitleText != f.Category) { continue; } indexTab = i; break; } if (indexTab < 0) { var newPanel = new TnbExpendablePanel { BackColor = Color.FromArgb(232, 232, 232), BorderColor = Color.FromArgb(52, 52, 52), BorderStyle = ButtonBorderStyle.Solid, ContentSize = new Size(556, 0), Fold = false, AutoSize = true, HeaderBackColor = Color.FromArgb(250, 250, 250), HeaderSize = new Size(556, 36), Location = new Point(0, 0), Margin = new Padding(0), Padding = new Padding(0, 0, 0, LineSpacing), Size = new Size(556, 36), TitleFont = new Font("Segoe UI", 7.65F, FontStyle.Bold), TitleForeColor = Color.FromArgb(232, 232, 232), TitleText = f.Category, }; newPanel.Click += GiveFocusToMainPanel; listExpandablePanel.Add(newPanel); lastLineY.Add(f.Category, newPanel.HeaderSize.Height + LineSpacing); indexTab = listExpandablePanel.Count - 1; } int posY; lastLineY.TryGetValue(f.Category, out posY); if (f.FieldName == string.Empty) { // It's a description label for a field. label = new Label { Text = f.Description, Location = new Point(LineSpacing, posY), Size = new Size(80, 17), AutoSize = true, BackColor = Color.FromArgb(232, 232, 232), ForeColor = Color.FromArgb(52, 52, 52) }; listExpandablePanel[indexTab].Controls.Add(label); lastLineY.Remove(f.Category); lastLineY.Add(f.Category, posY + LineSpacing); continue; } FieldInfo fieldInfo = GetType().GetField(f.FieldName); if (fieldInfo != null) { // It's a field. NumericUpDown numericUpDown; switch (Type.GetTypeCode(fieldInfo.FieldType)) { case TypeCode.Boolean: var switchButton = new TnbSwitchButton { Value = (bool)fieldInfo.GetValue(this), ForeColor = Color.FromArgb(52, 52, 52), Location = new Point(LineSpacing, posY), Name = f.FieldName, OffText = Translate.Get(Translate.Id.NO), OnText = Translate.Get(Translate.Id.YES), Size = new Size(60, 20), }; label = new Label { Text = f.Description, Location = new Point(LineSpacing + switchButton.Size.Width + LineSpacing, posY + 4), Size = new Size(80, 17), AutoSize = true, BackColor = Color.Transparent, }; listExpandablePanel[indexTab].Controls.Add(label); lastLineY.Remove(f.Category); lastLineY.Add(f.Category, posY + LineSpacing + switchButton.Size.Height); listExpandablePanel[indexTab].Controls.Add(switchButton); break; case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: if (!f.SettingsType.Contains("Percentage") && f.SettingsType != "Percentage") { numericUpDown = new NumericUpDown { Location = new Point(LineSpacing, posY), Maximum = new decimal(new[] { -1592738368, 7, 0, 0 }), Minimum = new decimal(new[] { -1592738368, 7, 0, -2147483648 }), Name = f.FieldName, Size = new Size(120, 20), Value = Convert.ToInt64(fieldInfo.GetValue(this)) }; label = new Label { Text = f.Description, Location = new Point(LineSpacing + numericUpDown.Size.Width + LineSpacing, posY + 2), Size = new Size(80, 17), AutoSize = true, BackColor = Color.Transparent, }; if (f.SettingsType == "Percentage") { numericUpDown.Maximum = new decimal(100); numericUpDown.Minimum = new decimal(0); numericUpDown.Size = new Size(66, 22); label.Location = new Point(LineSpacing + numericUpDown.Size.Width + LineSpacing, posY + 2); } lastLineY.Remove(f.Category); lastLineY.Add(f.Category, posY + LineSpacing + numericUpDown.Size.Height); listExpandablePanel[indexTab].Controls.Add(numericUpDown); listExpandablePanel[indexTab].Controls.Add(label); } else { label = new Label { Text = f.Description, Location = new Point(LineSpacing, posY), Size = new Size(80, 17), AutoSize = true, BackColor = Color.Transparent, }; lastLineY.Remove(f.Category); lastLineY.Add(f.Category, posY + label.Size.Height); listExpandablePanel[indexTab].Controls.Add(label); } break; case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: if (!f.SettingsType.Contains("Percentage") && f.SettingsType != "Percentage") { numericUpDown = new NumericUpDown { Location = new Point(LineSpacing, posY), Maximum = new decimal(new[] { -1592738368, 7, 0, 0 }), Name = f.FieldName, Size = new Size(120, 20), Value = Convert.ToUInt64(fieldInfo.GetValue(this)) }; label = new Label { Text = f.Description, Location = new Point(LineSpacing + numericUpDown.Size.Width + LineSpacing, posY + 2), Size = new Size(80, 17), AutoSize = true, BackColor = Color.Transparent, }; if (f.SettingsType == "Percentage") { numericUpDown.Maximum = new decimal(100); numericUpDown.Minimum = new decimal(0); numericUpDown.Size = new Size(66, 22); label.Location = new Point(LineSpacing + numericUpDown.Size.Width + LineSpacing, posY + 2); } lastLineY.Remove(f.Category); lastLineY.Add(f.Category, posY + LineSpacing + numericUpDown.Size.Height); listExpandablePanel[indexTab].Controls.Add(numericUpDown); listExpandablePanel[indexTab].Controls.Add(label); } else { label = new Label { Text = f.Description, Location = new Point(LineSpacing, posY), Size = new Size(80, 17), AutoSize = true, BackColor = Color.Transparent, }; lastLineY.Remove(f.Category); lastLineY.Add(f.Category, posY + label.Size.Height); listExpandablePanel[indexTab].Controls.Add(label); } break; case TypeCode.Single: case TypeCode.Double: numericUpDown = new NumericUpDown { Location = new Point(LineSpacing, posY), DecimalPlaces = 3, Increment = new decimal(new[] { 1, 0, 0, 65536 }), Maximum = new decimal(new[] { -1592738368, 7, 0, 0 }), Minimum = new decimal(new[] { -1592738368, 7, 0, -2147483648 }), Name = f.FieldName, Size = new Size(120, 20), Value = Convert.ToDecimal(fieldInfo.GetValue(this)) }; label = new Label { Text = f.Description, Location = new Point(LineSpacing + numericUpDown.Size.Width + LineSpacing, posY + 2), Size = new Size(80, 17), AutoSize = true, BackColor = Color.Transparent, }; lastLineY.Remove(f.Category); lastLineY.Add(f.Category, posY + LineSpacing + numericUpDown.Size.Height); listExpandablePanel[indexTab].Controls.Add(numericUpDown); listExpandablePanel[indexTab].Controls.Add(label); break; case TypeCode.String: var textBox = new TextBox { Location = new Point(LineSpacing, posY), Name = f.FieldName, Size = new Size(100, 20), TabIndex = 3, Text = Convert.ToString(fieldInfo.GetValue(this)) }; label = new Label { Text = f.Description, Location = new Point(LineSpacing + textBox.Size.Width + LineSpacing, posY + 2), TextAlign = ContentAlignment.MiddleLeft, Size = new Size(80, 17), AutoSize = true, BackColor = Color.Transparent, }; if (f.SettingsType == "List") { label.Size = new Size(532, 20); label.Location = new Point(LineSpacing, posY + 2); label.TextAlign = ContentAlignment.BottomLeft; textBox.Size = new Size(532, 20); textBox.Location = new Point(LineSpacing, posY + label.Height + LineSpacingLabel); } lastLineY.Remove(f.Category); lastLineY.Add(f.Category, textBox.Location.Y + textBox.Size.Height + LineSpacing); listExpandablePanel[indexTab].Controls.Add(label); listExpandablePanel[indexTab].Controls.Add(textBox); break; } if (f.SettingsType.Contains("Percentage") && f.SettingsType != "Percentage") { int Spacing = 0; if (label != null) { Spacing = label.Size.Width + label.Location.X; } string labelName = ""; FieldInfo percentageField = GetType().GetField(f.FieldName); if (percentageField != null) { string ressource = "this"; if (f.RessourceType != "") { ressource = f.RessourceType; } switch (f.SettingsType) { case "AtPercentage": labelName = "at " + ressource + " percentage:"; // if (UsePowerWordShieldAtPercentage == 10) break; case "BelowPercentage": labelName = "below " + ressource + " percentage:"; // if (UsePowerWordShieldBelowPercentage < 10) break; case "AbovePercentage": labelName = "above " + ressource + " percentage:"; // if (UsePowerWordShieldAbovePercentage > 10) break; } var percentageLabel = new Label { Text = labelName, Location = new Point(Spacing + LineSpacing * 2, posY), Size = new Size(90, 17), AutoSize = true, BackColor = Color.FromArgb(232, 232, 232), ForeColor = Color.FromArgb(52, 52, 52), }; var percentage = new NumericUpDown { Location = new Point(Spacing + LineSpacing * 2 + percentageLabel.Location.X + percentageLabel.Width + LineSpacing * 2, posY - 4), Maximum = new decimal(100), Minimum = new decimal(0), Name = f.FieldName, Size = new Size(38, 22), Value = Convert.ToUInt64(percentageField.GetValue(this)) }; listExpandablePanel[indexTab].Controls.Add(percentageLabel); listExpandablePanel[indexTab].Controls.Add(percentage); } } } } bool isFirst = true; foreach (TnbExpendablePanel tabPage in listExpandablePanel) { if (!isFirst) { tabPage.Fold = true; } isFirst = false; _mainPanel.Controls.Add(tabPage); } _mainPanel.Click += GiveFocusToMainPanel; _mainForm.Shown += GiveFocusToMainPanel; _mainForm.ShowDialog(); ReadForm(_mainForm); } catch (Exception e) { Logging.WriteError("Settings > ToForm(): " + e); } }