/// <summary> /// ラベル項目描画時の処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnTechLabelPaint(object sender, PaintEventArgs e) { Label label = sender as Label; TechLabelInfo info = label?.Tag as TechLabelInfo; TechLabel labelItem = info?.Item as TechLabel; string s = labelItem?.ToString(); if (string.IsNullOrEmpty(s)) { return; } // 色指定文字列を解釈する Brush brush; if ((s[0] == '%' || s[0] == 'ァ' || s[0] == '§') && s.Length > 4 && s[1] >= '0' && s[1] <= '9' && s[2] >= '0' && s[2] <= '9' && s[3] >= '0' && s[3] <= '9') { brush = new SolidBrush(Color.FromArgb((s[3] - '0') << 5, (s[2] - '0') << 5, (s[1] - '0') << 5)); s = s.Substring(4); } else { brush = new SolidBrush(Color.White); } e.Graphics.DrawString(s, label.Font, brush, -2, 0); brush.Dispose(); }
/// <summary> /// 技術ツリーに項目ラベルを追加する /// </summary> /// <param name="item">追加対象の項目</param> /// <param name="position">追加対象の位置</param> public void AddItem(ITechItem item, TechPosition position) { TechItem tech = item as TechItem; if (tech != null) { AddTechItem(tech, position); return; } TechLabel label = item as TechLabel; if (label != null) { AddLabelItem(label, position); return; } TechEvent ev = item as TechEvent; if (ev != null) { AddEventItem(ev, position); } }
/// <summary> /// 項目を書き出す /// </summary> /// <param name="item">項目</param> /// <param name="writer">ファイル書き込み用</param> private static void WriteTechItem(ITechItem item, StreamWriter writer) { TechItem techItem = item as TechItem; if (techItem != null) { WriteApplication(techItem, writer); return; } TechLabel labelItem = item as TechLabel; if (labelItem != null) { WriteLabel(labelItem, writer); return; } TechEvent eventItem = item as TechEvent; if (eventItem != null) { WriteEvent(eventItem, writer); } }
/// <summary> /// labelセクションを書き出す /// </summary> /// <param name="item">技術ラベル項目</param> /// <param name="writer">ファイル書き込み用</param> private static void WriteLabel(TechLabel item, StreamWriter writer) { writer.WriteLine(" label ="); writer.WriteLine(" {{ tag = {0}", item.Name); foreach (TechPosition position in item.Positions) { writer.WriteLine(" position = {{ x = {0} y = {1} }}", position.X, position.Y); } writer.WriteLine(" }"); }
/// <summary> /// 重複文字列リストの項目を削除する /// </summary> /// <param name="item">技術項目</param> public static void RemoveDuplicatedListItem(ITechItem item) { TechItem techItem = item as TechItem; if (techItem != null) { DecrementDuplicatedListCount(techItem.Name); DecrementDuplicatedListCount(techItem.ShortName); DecrementDuplicatedListCount(techItem.Desc); foreach (TechComponent component in techItem.Components) { DecrementDuplicatedListCount(component.Name); } return; } TechLabel labelItem = item as TechLabel; if (labelItem != null) { DecrementDuplicatedListCount(labelItem.Name); } }
/// <summary> /// 技術ツリーに技術ラベルを追加する /// </summary> /// <param name="item">追加対象の項目</param> /// <param name="position">追加対象の位置</param> private void AddLabelItem(TechLabel item, TechPosition position) { Label label = new Label { Location = new Point(DeviceCaps.GetScaledWidth(position.X), DeviceCaps.GetScaledHeight(position.Y)), BackColor = Color.Transparent, Tag = new TechLabelInfo { Item = item, Position = position } }; label.Size = Graphics.FromHwnd(label.Handle).MeasureString(item.ToString(), label.Font).ToSize(); label.Click += OnItemLabelClick; label.MouseClick += OnItemLabelMouseClick; label.MouseDown += OnItemLabelMouseDown; label.MouseUp += OnItemLabelMouseUp; label.MouseMove += OnItemLabelMouseMove; label.GiveFeedback += OnItemLabelGiveFeedback; label.Paint += OnTechLabelPaint; _pictureBox.Controls.Add(label); }
/// <summary> /// リンクの切れた一時キーをリストに登録する /// </summary> private static void AddUnlinkedTempKey() { foreach (ITechItem item in Groups.SelectMany(grp => grp.Items)) { if (item is TechItem) { TechItem techItem = item as TechItem; if (Config.IsTempKey(techItem.Name)) { Config.AddTempKey(techItem.Name); } if (Config.IsTempKey(techItem.ShortName)) { Config.AddTempKey(techItem.ShortName); } if (Config.IsTempKey(techItem.Desc)) { Config.AddTempKey(techItem.Desc); } foreach (TechComponent component in techItem.Components) { if (Config.IsTempKey(component.Name)) { Config.AddTempKey(component.Name); } } } else if (item is TechLabel) { TechLabel labelItem = item as TechLabel; if (Config.IsTempKey(labelItem.Name)) { Config.AddTempKey(labelItem.Name); } } } }
/// <summary> /// technologyセクションを構文解析する /// </summary> /// <param name="lexer">字句解析器</param> /// <returns>技術グループデータ</returns> private static TechGroup ParseTechnology(TextLexer lexer) { // = Token token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); return(null); } // { token = lexer.GetToken(); if (token.Type != TokenType.OpenBrace) { Log.InvalidToken(LogCategory, token, lexer); return(null); } TechGroup group = new TechGroup(); while (true) { token = lexer.GetToken(); // ファイルの終端 if (token == null) { break; } // } (セクション終端) if (token.Type == TokenType.CloseBrace) { break; } // 無効なトークン if (token.Type != TokenType.Identifier) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } string keyword = token.Value as string; if (string.IsNullOrEmpty(keyword)) { continue; } keyword = keyword.ToLower(); // id if (keyword.Equals("id")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Number) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 技術グループID group.Id = (int)(double)token.Value; continue; } // category if (keyword.Equals("category")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Identifier) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 無効なカテゴリ文字列 string s = token.Value as string; if (string.IsNullOrEmpty(s)) { continue; } if (!Techs.CategoryMap.ContainsKey(s)) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 技術カテゴリ group.Category = Techs.CategoryMap[s]; continue; } // name if (keyword.Equals("name")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Identifier && token.Type != TokenType.String) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 技術グループ名 group.Name = token.Value as string; continue; } // desc if (keyword.Equals("desc")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Identifier && token.Type != TokenType.String) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 技術グループ説明 group.Desc = token.Value as string; continue; } // label if (keyword.Equals("label")) { TechLabel label = ParseLabel(lexer); if (label == null) { Log.InvalidSection(LogCategory, "label", lexer); continue; } // ラベル group.Items.Add(label); continue; } // event if (keyword.Equals("event")) { TechEvent ev = ParseEvent(lexer); if (ev == null) { Log.InvalidSection(LogCategory, "event", lexer); continue; } // 技術イベント group.Items.Add(ev); continue; } // application if (keyword.Equals("application")) { TechItem application = ParseApplication(lexer); if (application == null) { Log.InvalidSection(LogCategory, "application", lexer); continue; } // 技術 group.Items.Add(application); continue; } // 無効なトークン Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); } return(group); }
/// <summary> /// labelセクションを構文解析する /// </summary> /// <param name="lexer">字句解析器</param> /// <returns>技術ラベルデータ</returns> private static TechLabel ParseLabel(TextLexer lexer) { // = Token token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); return(null); } // { token = lexer.GetToken(); if (token.Type != TokenType.OpenBrace) { Log.InvalidToken(LogCategory, token, lexer); return(null); } TechLabel label = new TechLabel(); while (true) { token = lexer.GetToken(); // ファイルの終端 if (token == null) { break; } // } (セクション終端) if (token.Type == TokenType.CloseBrace) { break; } // 無効なトークン if (token.Type != TokenType.Identifier) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } string keyword = token.Value as string; if (string.IsNullOrEmpty(keyword)) { continue; } keyword = keyword.ToLower(); // tag if (keyword.Equals("tag")) { // = token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // 無効なトークン token = lexer.GetToken(); if (token.Type != TokenType.Identifier && token.Type != TokenType.String) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } // タグ名 label.Name = token.Value as string; continue; } // position if (keyword.Equals("position")) { TechPosition position = ParsePosition(lexer); if (position == null) { Log.InvalidSection(LogCategory, "position", lexer); continue; } // 座標リスト label.Positions.Add(position); continue; } // 無効なトークン Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); } return(label); }