void deleteAll_Click(object sender, EventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem != null) { // Retrieve the ContextMenu that contains this MenuItem ContextMenu menu = menuItem.GetContextMenu(); // Get the control that is displaying this context menu Control sourceControl = menu.SourceControl; RSItem item = findItemInValues(sourceControl.Name); DialogResult dialogResult = MessageBox.Show("Are you sure you want to clear the information for this item?", "Rly?", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { item.ownedAmount = 0; foreach (Control c in Controls) { if (c is Label) { if (c.Name == item.imageName) { Label cLabel = c as Label; cLabel.Text = ""; } } else if (c is PictureBox) { if (c.Name == item.imageName) { Image itemIMG = findImageInResources(item.imageName); PictureBox picture = c as PictureBox; picture.Image = SetImageOpacity(itemIMG, 0.3f); } } } if (item.imageName.Contains("_clue")) { int easyClueCount = findItemInValues("Easy_clue").ownedAmount; int medClueCount = findItemInValues("Medium_clue").ownedAmount; int hardClueCount = findItemInValues("Hard_clue").ownedAmount; int eliteClueCount = findItemInValues("Elite_clue").ownedAmount; findItemInValues("Total_clue").ownedAmount = easyClueCount + medClueCount + hardClueCount + eliteClueCount; setItemValue(findItemInValues("Easy_clue")); setItemValue(findItemInValues("Medium_clue")); setItemValue(findItemInValues("Hard_clue")); setItemValue(findItemInValues("Elite_clue")); setItemValue(findItemInValues("Total_clue")); } //SAVE STUFF: ItemContainerSaving.saveAllItemData(this.im); //do something } else if (dialogResult == DialogResult.No) { } } }
/// <summary> /// Sets values of an item into specific pictureboxes and labels. /// </summary> /// <param name="item"></param> public void setItemValue(RSItem item) { foreach (Control c in Controls) { if (c is Label) { if (c.Name == item.imageName) { if (item.ownedAmount == 1 && item.shouldOnlyHaveOne) { c.Text = ""; } else if (item.ownedAmount > 0) { if (item.ownedAmount < 1000) { c.Text = item.ownedAmount.ToString(); } else if (item.ownedAmount >= 1000 && item.ownedAmount < 1000000) { //IS K double kAmount = Convert.ToDouble(item.ownedAmount) / 1000; c.Text = Math.Floor(kAmount) + "K"; } else if (item.ownedAmount < 1000000000) { double MAmount = Convert.ToDouble(item.ownedAmount) / 1000000; c.Text = Math.Floor(MAmount) + "M"; } else { double BAmount = Convert.ToDouble(item.ownedAmount) / 1000000000; c.Text = Math.Floor(BAmount) + "B"; //IS B } } else { c.Text = ""; } } } else if (c is PictureBox) { if (c.Name == item.imageName) { if (item.ownedAmount >= 1) { Image itemIMG = findImageInResources(item.imageName); PictureBox picture = c as PictureBox; picture.Image = itemIMG; } else { Image itemIMG = findImageInResources(item.imageName); PictureBox picture = c as PictureBox; picture.Image = SetImageOpacity(itemIMG, 0.3F); } } } } ItemContainerSaving.saveAllItemData(this.im); }
public TaskBarMenu() { InitializeComponent(); im = new ItemManager(mainMenuItems); ItemContainerSaving.loadAllItems(im); trayMenu = new ContextMenu(); MenuItem toMainProgress = new MenuItem("Main Menu"); MenuItem settingMI = new MenuItem("Settings"); MenuItem aboutMI = new MenuItem("About..."); exitMI = new MenuItem("Exit"); toMainProgress.Click += toMainProgressAction; exitMI.Click += exitApp; settingMI.Click += settingMI_Click; aboutMI.Click += aboutMI_Click; trayMenu.MenuItems.Add(toMainProgress); trayMenu.MenuItems.Add(settingMI); trayMenu.MenuItems.Add(aboutMI); trayMenu.MenuItems.Add(exitMI); // Create a tray icon. In this example we use a // standard system icon for simplicity, but you // can of course use your own custom icon too. trayIcon = new NotifyIcon(); trayIcon.Text = "OSRS Progress Tracker"; trayIcon.Icon = new Icon(Resources.Spellbook_Swap_icon, 40, 40); // Add menu to tray icon and show it. trayIcon.ContextMenu = trayMenu; trayIcon.Visible = true; //LOAD SETTINGS u = new UserSettings(); if (SaveSettings.loadSettings() != null) { u = SaveSettings.loadSettings(); } else { SaveSettings.saveSettings(this.u); } welcomeNotification(); if (u.firstBootup) { DialogResult dialogResult = MessageBox.Show("Hello and welcome to the OSRS Progress Tracker, would you like your username tracked for some extra functionality?", "Welcome!", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { MainSettingForm msf = new MainSettingForm(u, this.im); FormCollection fc = Application.OpenForms; bool already = false; foreach (Form frm in fc) { if (frm is MainSettingForm) { already = true; } } if (!already) { msf.Show(); msf.BringToFront(); } //FirstTimeEntry fte = new FirstTimeEntry(); //fte.Show(); //fte.TopMost = true; //do something } else if (dialogResult == DialogResult.No) { u.firstBootup = false; FormCollection fc = Application.OpenForms; MainMenu mm = new MainMenu(this.im, new Point(300, 300), this.u); bool already = false; foreach (Form frm in fc) { already = true; } if (!already) { mm.fillMenu(); mm.Show(); mm.BringToFront(); } } } else { MainMenu mm = new MainMenu(this.im, new Point(300, 300), this.u); mm.fillMenu(); mm.Show(); mm.BringToFront(); } }