private TreeNode searchPrev(SearchBox.Option option, TreeNode selected, Module module) { if (option.search_word != null && option.search_word.Length > 0) { // あまりないと思うが、状態によってはオプションが変更される可能性があるので SearchBox.Option new_option = new SearchBox.Option(option); TreeNode current = selected; // あんまり無いと思うが、何も選択されていなかったら頭から // prevの場合はケツからかな? if (current == null) { if (module.tree.Nodes.Count < 1) { return(null); } current = module.tree.Nodes[0]; // 範囲は全検索に変更かな? new_option.range = SearchBox.SearchRange.ByAll; } // 選択されていたらそのノードの前から // ALL TreeNode end = null; // bydlgなのにないがな if (new_option.range == SearchBox.SearchRange.ByDlg) { TreeNode dlg = current; bool find = false; while (dlg != null) { if (( string )dlg.Tag == "dlg") { // それでもnullなら親のrimのnext if (dlg.PrevNode != null) { end = dlg.PrevNode; } else { end = dlg.Parent.PrevNode; } find = true; break; } dlg = dlg.Parent; } // nullなら上位ノードか終端 // 終端なら検索する必要する必要があるが…そうでない場合はrimで指定がおかしいので検索すると最後までいっちゃう // この辺はコンボボックスの中身変えたり事前に正当性チェックしたほうがいいんかねえ //if ( dlg == null ) { //} if (find == false) { return(null); } } // byrimなのにないがな if (new_option.range == SearchBox.SearchRange.ByRim) { TreeNode rim = current; while (rim != null) { if (( string )rim.Tag == "rim") { // それでもnullならこれは終端 end = rim.PrevNode; break; } rim = rim.Parent; } } // bynode if (new_option.range == SearchBox.SearchRange.ByNode) { TreeNode next = current; while (next != null) { if (next.PrevNode != null) { end = next.PrevNode; break; } next = next.Parent; } } ConversationNode cn = current as ConversationNode; if (cn != null) { // 選択ノード以下なのに子ノードがなかた if (current.Nodes.Count < 1) { //if ( new_option.range == SearchBox.SearchRange.ByNode ) { // return null; //} } // selectedは飛ばす current = getPrev(current); } //ConversationNode findnode = findNodePrev( current, new_option ); ConversationNode findnode = findNode(current, end, false, new_option, module); // loop editing if (findnode == null && new_option.loop && selected != null && module.tree.Nodes.Count > 0) { TreeNode start = module.tree.Nodes[module.tree.Nodes.Count - 1]; if (new_option.range == SearchBox.SearchRange.ByDlg) { TreeNode dlg = current; while (dlg != null) { if (( string )dlg.Tag == "dlg") { break; } dlg = dlg.Parent; } // nullなら上位ノードでした // 検索する必要なし? // まあ一応 //if ( dlg == null ) { // return null; //} start = dlg; } if (new_option.range == SearchBox.SearchRange.ByRim) { TreeNode rim = current; while (rim != null) { if (( string )rim.Tag == "rim") { break; } rim = rim.Parent; } //if ( rim == null ) { // return null; //} start = rim; } // これは成立せんよなあ? if (new_option.range == SearchBox.SearchRange.ByNode) { return(null); } findnode = findNode(start, selected, false, new_option, module); } return(findnode); } return(null); }
// remake private ConversationNode findNode(TreeNode begin, TreeNode end, bool forward, SearchBox.Option option, Module module) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // delegate GetNode get_node = null; if (forward) { if (option.expand) { get_node = new GetNode(getNextExpand); } else { get_node = new GetNode(getNext); } } else { if (option.expand) { get_node = new GetNode(getPrevExpand); } else { get_node = new GetNode(getPrev); } } TreeNode current = begin; // ねんのためnullもチェック while (current != end && current != null) { ConversationNode cn = current as ConversationNode; if (cn != null) { if (findWord(cn, option)) { sw.Stop(); System.Console.WriteLine("time: " + sw.ElapsedMilliseconds.ToString() + "ms"); return(cn); } //current = getNext2( current ); } else { switch (( string )current.Tag) { case "dlg": if (current.Nodes.Count == 1 && ( string )current.Nodes[0].Tag == "dummy") { // まだ読んでない current.Nodes.Clear(); //string path = module_directory + "/" + current.Parent.Text + "/" + current.Text + ".txt"; string path = module.directory + "/" + current.FullPath + ".txt"; uint[] start = null; ConversationNode[] nodes = null; loadDlg(path, ref start, ref nodes, module); // error? if (start == null || nodes == null) { continue; } module.tree.SuspendLayout(); createDlgTree(ref start, ref nodes, ref current); module.tree.ResumeLayout(); module.tree.PerformLayout(); } //current = getNext2( current ); break; //case "rim": // preloaded //current = getNext2( current ); //break; default: break; } } current = get_node(current); // delegate } sw.Stop(); System.Console.WriteLine("time: " + sw.ElapsedMilliseconds.ToString() + "ms"); return(null); }
private void loadDlg(string path, ref uint[] start, ref ConversationNode[] nodes, Module module) { // まだカレントディレクトリを考慮してない if (System.IO.File.Exists(path) == false) { return; } string[] data = System.IO.File.ReadAllLines(path); // 変なファイルを検知したいな if (data.Length < 2) { return; } string len_str = data[0]; uint length = getLineToUint(len_str, "Length"); string start_str = data[1]; start = getLineToUintArray(start_str, "StartIndex"); // 一旦チャンクを作成するか nodes = new ConversationNode[length]; for (uint i = 0; i < nodes.Length; ++i) { nodes[i] = new ConversationNode(); nodes[i].index = i; } // 0で大丈夫かな -1だと無い場合オーバーするが元がuintだしちゃんとチェックするしか uint index = 0; for (int i = 2; i < data.Length; ++i) { string line = data[i]; if (line.Length > 0) { string[] splits = line.Split(':'); if (splits.Length == 2) { switch (splits[0]) { case "Index": index = System.Convert.ToUInt32(splits[1]); break; case "ID": uint id = System.Convert.ToUInt32(splits[1]); nodes[index].id = id; nodes[index].conversation = getTlk(id, module.tlk); nodes[index].Text = "[" + id.ToString() + "] "; // nothing conversation if (nodes[index].conversation == null || nodes[index].conversation == "") { nodes[index].ForeColor = System.Drawing.SystemColors.GrayText; } break; case "Speaker": string speaker = splits[1]; if (speaker != null) { if (speaker.Length > 0) { nodes[index].speaker = speaker; nodes[index].Text += "(" + speaker + ")"; } } break; case "Listener": string listener = splits[1]; if (listener != null) { if (listener.Length > 0) { nodes[index].listener = listener; nodes[index].Text += "->(" + listener + ")"; } } break; case "Children": if (splits[1].Length > 0) { string[] array = splits[1].Split(','); if (array.Length > 0) { uint[] children = new uint[array.Length]; for (int c = 0; c < children.Length; ++c) { children[c] = System.Convert.ToUInt32(array[c]); //nodes[ index ].Text += children[ c ]; } nodes[index].children = children; } } // こういう決めうちはあんまりよくないが // まあエクスポートで定型にしたので多分大丈夫 if (nodes[index].conversation != null) { if (nodes[index].conversation.Length > 0) { nodes[index].Text += " " + nodes[index].conversation; } } break; } } } } }