public void CreateHUDMessage(string message, Sprite icon) { lock (_HUDMessageLock) { if (_HUDMessages.Count == HUD_MESSAGE_MAX_COUNT) { Destroy(_HUDMessages.RemoveFromFront().Self); _lastHUDMessageIndex = HUD_MESSAGE_MAX_COUNT - 1; } } lock (_HUDMessageLock) { if (_HUDMessages.Any()) { GameObject existingMsg = _HUDMessages.First().Self; if (existingMsg.GetComponentInChildren <Text>().text == message) { // Found identical message already existing. Do not duplicate, just identify that upcoming msg is the same existingMsg.GetComponent <Shake>().ShakeIt(); return; } } } GameObject HUDMessage = Instantiate(HUDMessagePrefab, new Vector3(0, 0, 0), Quaternion.identity, Canvas.transform); RectTransform rTransform = HUDMessage.GetComponent <RectTransform>(); HUDMessage.GetComponentInChildren <Text>().text = message; rTransform.position = new Vector3(HUD_MESSAGE_INIT_X, HUD_MESSAGE_INIT_Y, rTransform.position.z); rTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, HUD_MESSAGE_INIT_Y + (_lastHUDMessageIndex * HUD_MESSAGE_SHIFT_Y), 0); Transform HUDMessageType = HUDMessage.transform.Find("HUDMessageType"); HUDMessageType.gameObject.GetComponent <Image>().sprite = icon; lock (_HUDMessageLock) { _HUDMessages.AddToFront(new HUDMessage() { Self = HUDMessage, TimeCreation = DateTime.Now }); } if (_lastHUDMessageIndex + 1 < HUD_MESSAGE_MAX_COUNT) { _lastHUDMessageIndex++; } }
private IEnumerable <Translation> parse_translation_page(string pageContent) { var rows = new Deque <HtmlNode>(get_all_rows(pageContent)); while (rows.Any() && is_separator(rows.RemoveFromFront()) && !is_unknown_separator(rows)) { yield return(ParseTranslation(rows)); } }
private Position GetNextPosition(Deque <Position> unused) { if (unused.Any()) { return(unused.Pop()); } else { return(Position.N); } }
private void Traverse(IRenderingElement newElement) { var stack = new Deque <IRenderingElement>(); stack.Push(newElement); while (stack.Any()) { var element = stack.Poll(); switch (element) { case Bounds e: Add(e); break; case GeneralPath e: Add(e); break; case LineElement lineElem: var vec = lineElem.SecondPoint - lineElem.FirstPoint; var ortho = new WPF::Vector(-vec.Y, vec.X); ortho.Normalize(); vec.Normalize(); ortho *= lineElem.Width / 2; // stroke width vec *= lineElem.Width / 2; // stroke rounded also makes line longer Add(lineElem.FirstPoint - vec + ortho); Add(lineElem.SecondPoint + vec + ortho); Add(lineElem.FirstPoint - vec - ortho); Add(lineElem.SecondPoint + vec - ortho); break; case OvalElement oval: Add(new Point(oval.Coord.X - oval.Radius, oval.Coord.Y)); Add(new Point(oval.Coord.X + oval.Radius, oval.Coord.Y)); Add(new Point(oval.Coord.X, oval.Coord.Y - oval.Radius)); Add(new Point(oval.Coord.X, oval.Coord.Y + oval.Radius)); break; case ElementGroup elementGroup: stack.AddRange(elementGroup); break; case MarkedElement e: stack.Add(e.Element()); break; default: // ignored from bounds calculation, we don't really // care but log we skipped it Trace.TraceWarning($"{element.GetType()} not included in bounds calculation"); break; } } }
private List <Topic> ParseTopics(Deque <HtmlNode> rows) { List <Topic> topics = new List <Topic>(); while (rows.Any()) { var row = rows.RemoveFromFront(); if (is_separator(row)) { rows.AddToFront(row); break; } topics.Add(ParseTopic(row)); } return(topics); }
private static bool IsInSmallRingSize(IAtom atom, int size) { var mol = atom.Container; var distTo = new int[mol.Atoms.Count]; Arrays.Fill(distTo, 1 + distTo.Length); distTo[atom.Index] = 0; var queue = new Deque <IAtom>(); queue.Push(atom); int smallest = 1 + distTo.Length; while (queue.Any()) { var a = queue.Poll(); int dist = 1 + distTo[a.Index]; foreach (var b in a.Bonds) { var nbr = b.GetOther(a); if (dist < distTo[nbr.Index]) { distTo[nbr.Index] = dist; queue.Add(nbr); } else if (dist != 2 + distTo[nbr.Index]) { int tmp = dist + distTo[nbr.Index]; if (tmp < smallest) { smallest = tmp; } } } if (2 * dist > 1 + size) { break; } } return(smallest == size); }