public void AddRecord(ResourceBlock block, ResourceForm form) { ResourceRecord newRecord = new ResourceRecord(); newRecord.Id = m_iIdCounter++; newRecord.ResourceBlock = block; newRecord.ResourceForm = form; m_aRecords.Add(newRecord); }
public ResourceBlock GetResourceBlock(ResourceForm form) { for (int i = 0; i < m_aRecords.Count; i++) { if (m_aRecords[i].ResourceForm == form) { return(m_aRecords[i].ResourceBlock); } } return(null); }
public void RemoveRecord(ResourceForm form) { int iIndex = -1; for (int i = 0; i < m_aRecords.Count; i++) { if (m_aRecords[i].ResourceForm == form) { iIndex = i; break; } } if (iIndex >= 0) { m_aRecords.RemoveAt(iIndex); } }
private void OnResourceFormClosed(ResourceForm form) { ResourceBlock block = tmSingleton <ResourceBlockManager> .Instance.GetResourceBlock(form); if (block == null) { return; } string sConsoleString = block.GetFullDescription(); tmSingleton <ResourceBlockManager> .Instance.RemoveRecord(form); ConsoleLog(String.Format("Removed resource block: {0}", sConsoleString)); UpdateResourcesList(); }
private void button_add_Click(object sender, EventArgs e) { // Collect data int iSizeMB = 0; try { iSizeMB = Convert.ToInt32(textBox_add.Text); } catch { MessageBox.Show("Invalid value for resource size"); return; } ResourceBlock newBlock = null; ResourceForm newForm = null; switch (tabControl_add.SelectedIndex) { case 0: // Text newBlock = new TextResourceBlock(iSizeMB, textBox_text.Text); TextResourceForm textForm = new TextResourceForm(); textForm.ResourceBlock = newBlock; textForm.OnClose = OnResourceFormClosed; newForm = textForm; break; case 1: // Color colorDialog.ShowDialog(); newBlock = new ColorResourceBlock(iSizeMB, colorDialog.Color.ToArgb()); ColorResourceForm colorForm = new ColorResourceForm(); colorForm.ResourceBlock = newBlock; colorForm.OnClose = OnResourceFormClosed; newForm = colorForm; break; case 2: // Random newBlock = new RandomResourceBlock(iSizeMB); RandomResourceForm randomForm = new RandomResourceForm(); randomForm.ResourceBlock = newBlock; randomForm.OnClose = OnResourceFormClosed; newForm = randomForm; break; default: MessageBox.Show("Invalid tab selected"); return; } // Cleanup textBox_add.Clear(); // Add tmSingleton <ResourceBlockManager> .Instance.AddRecord(newBlock, newForm); newForm.Show(); ConsoleLog(String.Format("Added new resource block: {0}", newBlock.GetFullDescription())); UpdateResourcesList(); }