public void Tick() { DateTime now = DateTime.Now; DateTime alertTime = now.AddMinutes(1); if (updateListView) { listViewBabies.BeginUpdate(); foreach (ListViewItem lvi in listViewBabies.Items) { if ((lvi.Tag.GetType() == typeof(IncubationTimerEntry))) { var t = (IncubationTimerEntry)lvi.Tag; int i = Values.V.speciesNames.IndexOf(t.mother.species); if (i >= 0) { lvi.SubItems[2].Text = Utils.timeLeft(t.incubationEnd); lvi.SubItems[3].Text = Utils.duration((int)(Values.V.species[i].breeding.maturationTimeAdjusted / 10)); lvi.SubItems[4].Text = Utils.duration((int)Values.V.species[i].breeding.maturationTimeAdjusted); double diff = t.incubationEnd.Subtract(alertTime).TotalSeconds; if (diff >= 0 && diff < 1) { timerControl.playSound("Birth", 1); } } } else if ((lvi.Tag.GetType() == typeof(Creature))) { var c = (Creature)lvi.Tag; int i = Values.V.speciesNames.IndexOf(c.species); if (i >= 0 && Values.V.species[i].breeding != null) { DateTime babyUntil = c.growingUntil.AddSeconds(-0.9 * Values.V.species[i].breeding.maturationTimeAdjusted); lvi.SubItems[3].Text = Utils.timeLeft(babyUntil); lvi.SubItems[4].Text = Utils.timeLeft(c.growingUntil); } } } listViewBabies.EndUpdate(); } else { foreach (ListViewItem lvi in listViewBabies.Items) { if ((lvi.Tag.GetType() == typeof(IncubationTimerEntry))) { var t = (IncubationTimerEntry)lvi.Tag; int i = Values.V.speciesNames.IndexOf(t.mother.species); double diff = t.incubationEnd.Subtract(alertTime).TotalSeconds; if (diff >= 0 && diff < 1) { timerControl.playSound("Birth", 1); } } } } }
public void setTimer() { string timerText = ""; foreach (TimerListEntry tle in timers) { timerText += Utils.timeLeft(tle.time) + ":" + tle.name + "\n"; } labelTimer.Text = timerText; }
public void setTimer() { string timerText = ""; foreach (TimerListEntry tle in timers) { int secLeft = (int)tle.time.Subtract(DateTime.Now).TotalSeconds + 1; if (secLeft < 10) { if (secLeft < -10) { timers.Remove(tle); tle.showInOverlay = false; continue; } timerText += "!!! "; } timerText += Utils.timeLeft(tle.time) + ":" + tle.name + "\n"; } labelTimer.Text = timerText; }
private void deleteTimerToolStripMenuItem_Click(object sender, EventArgs e) { if (listViewBabies.SelectedIndices.Count > 0 && listViewBabies.SelectedItems[0].Tag.GetType() == typeof(IncubationTimerEntry)) { IncubationTimerEntry ite = (IncubationTimerEntry)listViewBabies.SelectedItems[0].Tag; if (MessageBox.Show("Delete this timer?\n" + ite.mother.species + ", ending in " + Utils.timeLeft(ite.incubationEnd), "Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { removeIncubationTimer(ite); recreateList(); onChange?.Invoke(); } } }
public void recreateList() { if (cc != null) { updateListView = false; listViewBabies.BeginUpdate(); listViewBabies.Items.Clear(); ListViewGroup g = listViewBabies.Groups[0]; // add eggs / pregnancies foreach (IncubationTimerEntry t in cc.incubationListEntries) { int i = Values.V.speciesNames.IndexOf(t.mother.species); if (i >= 0 && Values.V.species[i].breeding != null) { string kind; if (Values.V.species[i].breeding.gestationTimeAdjusted > 0) { kind = "Gestation"; } else { kind = "Egg"; } string[] cols = new string[] { kind, t.mother.species, Utils.timeLeft(t.incubationEnd), Utils.duration((int)(Values.V.species[i].breeding.maturationTimeAdjusted / 10)), Utils.duration((int)Values.V.species[i].breeding.maturationTimeAdjusted) }; ListViewItem lvi = new ListViewItem(cols, g); lvi.Tag = t; listViewBabies.Items.Add(lvi); } } // add babies / growing DateTime now = DateTime.Now; foreach (Creature c in cc.creatures) { if (c.growingUntil > now) { int i = Values.V.speciesNames.IndexOf(c.species); if (i >= 0 && Values.V.species[i].breeding != null) { DateTime babyUntil = c.growingUntil.AddSeconds(-0.9 * Values.V.species[i].breeding.maturationTimeAdjusted); string[] cols; if (babyUntil > now) { g = listViewBabies.Groups[1]; cols = new string[] { c.name, c.species, "-", Utils.timeLeft(babyUntil), Utils.timeLeft(c.growingUntil) }; } else { g = listViewBabies.Groups[2]; cols = new string[] { c.name, c.species, "-", "-", Utils.timeLeft(c.growingUntil) }; } ListViewItem lvi = new ListViewItem(cols, g); lvi.Tag = c; listViewBabies.Items.Add(lvi); } } } listViewBabies.EndUpdate(); updateListView = true; } }