private void CommentReceived(Comment comment) { Utils.DebugLog(comment); try { this.commentViewer.Add(comment); } catch (Exception e) { Utils.DebugLog(e); } }
private void ProcReceiveComment(string commentXml) { if (commentXml.StartsWith("<")) { //Utils.DebugLog(commentXml); //Utils.DebugLog("read"); XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.LoadXml(commentXml); //Utils.DebugLog(xmlDoc.DocumentElement.OuterXml); //long vpos = Utils.GetUnixTimeMS(DateTime.Now)/10 - (long.Parse(this.commentThreadId) * 100); //Utils.DebugLog("vpos=" + vpos.ToString()); switch (xmlDoc.DocumentElement.Name) { case "thread": foreach (XmlAttribute attr in xmlDoc.DocumentElement.Attributes) { switch (attr.Name) { case "last_res": this.commentLastRes = int.Parse(attr.Value); break; case "ticket": this.commentTicket = attr.Value; break; } } break; case "chat": Comment comment = new Comment(xmlDoc.DocumentElement); this.commentLastRes = comment.Number; this.commentReceived(comment); break; case "chat_result": bool status = false; int number = -1; foreach (XmlAttribute attr in xmlDoc.DocumentElement.Attributes) { switch (attr.Name) { case "status": status = (attr.Value == "0"); break; case "no": if (attr.Value != null) { number = int.Parse(attr.Value); } break; } } if (status == true) { // numberだけは補完 if (number == -1) { Utils.DebugLog("warning: can't grab no"); } else { string str = this.lastSentXml; str = str.Replace("\">", String.Format("\" no=\"{0}\">", number)); ProcReceiveComment(str); } } this.CommentSent(status); break; case "view_counter": break; default: Utils.DebugLog("Unknown response: " + xmlDoc.DocumentElement.Name); break; } } catch (Exception e) { // FIXME Utils.DebugLog(e.ToString()); return; } } }
/// <summary> /// コメントを表示リストに追加 /// </summary> /// <param name="comment"></param> public void Add(Comment comment) { if (comment.Text == null) { return; } CommentElement c = new CommentElement(); c.Comment = comment; c.Y = posY; c.Color = CommentViewer.commentColors["white"]; c.Font = CommentViewer.commentFonts["medium"]; c.Lane = -1; foreach (var cmd in comment.Commands) { if (CommentViewer.commentColors.ContainsKey(cmd)) { Utils.DebugLog("color=" + cmd); c.Color = CommentViewer.commentColors[cmd]; continue; } if (CommentViewer.commentFonts.ContainsKey(cmd)) { Utils.DebugLog("size=" + cmd); c.Font = CommentViewer.commentFonts[cmd]; continue; } if (c.Lane == -1) { if (cmd == "ue") { c.Lane = SetUeShitaLane(c, 10); } else if (cmd == "shita") { c.Lane = SetUeShitaLane(c, 20); } } } // レーン決定前にPixelsPerFrameを決めておく必要がある c.Render(); c.CalcPPF(this.Width, this.fps); if (c.Lane == -1) { c.Lane = SetNakaLane(c); } lock (lockObject) { this.comments.Add(c); } Invalidate(); posY = (posY + c.Height) % (this.Height - c.Height); }