/// <summary> /// Get OOFormArray from json string. /// </summary> /// <param name="jsonString"></param> /// <returns></returns> public static OOFormArray GetFormByJsonString(string jsonString) { OOFormArray form_array = new OOFormArray(); List <Hashtable> table_list = OOLitJson.JsonMapper.ToObject <List <Hashtable> >(jsonString); form_array.InsertRow(0); form_array.InsertColumn(0); //int row = 0; foreach (Hashtable table in table_list) { form_array.InsertRow(form_array.mRowCount); foreach (string key_str in table.Keys) { if (form_array.GetColumn(key_str) == -1) { if (form_array.mColumnDic.Count <= 1) { form_array.SetString(key_str, 0, 0); form_array.AddColumnName(key_str, 0); } else { form_array.InsertColumn(form_array.mColumnCount); form_array.SetString(key_str, form_array.mColumnCount - 1, 0); form_array.AddColumnName(key_str, form_array.mColumnCount - 1); } } form_array.SetString(table[key_str].ToString(), form_array.GetColumn(key_str), form_array.mRowCount - 1); } } return(form_array); }
private static OOFormArray InitForm(DataTable dt) { OOFormArray form; int colNum = dt.Columns.Count; int rowNum = dt.Rows.Count; form = new OOFormArray(); colNum = dt.Columns.Count; rowNum = dt.Rows.Count; // init form for (int i = 0; i < colNum; i++) { form.InsertColumn(i); } for (int i = 0; i < rowNum + 1; i++) { form.InsertRow(i); } // set column key for (int c = 0; c < colNum; c++) { string cName = dt.Columns[c].ColumnName; form.SetString(cName, c, 0); } return(form); }
/// <summary> /// Get OOFormArray from xml string; /// </summary> /// <param name="xmlString"></param> /// <returns></returns> public static OOFormArray GetFormByXMLString(string xmlString) { //if string with BOM,remove it. if ((int)xmlString[0] == 65279) { xmlString = xmlString.Substring(1); } OOFormArray form_array = new OOFormArray(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlString); form_array.InsertRow(0); form_array.InsertColumn(0); XmlNode node = xmlDoc.FirstChild; XmlNodeList component_list = node.ChildNodes; foreach (XmlNode row_node in component_list) { form_array.InsertRow(form_array.mRowCount); foreach (XmlAttribute attr in row_node.Attributes) { if (form_array.GetColumn(attr.Name) == -1) { if (form_array.mColumnDic.Count <= 1) { form_array.SetString(attr.Name, 0, 0); form_array.AddColumnName(attr.Name, 0); } else { form_array.InsertColumn(form_array.mColumnCount); form_array.SetString(attr.Name, form_array.mColumnCount - 1, 0); form_array.AddColumnName(attr.Name, form_array.mColumnCount - 1); } } form_array.SetString(attr.Value.ToString(), form_array.GetColumn(attr.Name), form_array.mRowCount - 1); } } return(form_array); }
/// <summary> /// Convert text to a OOFormArray /// </summary> /// <param name="formString"></param> /// <returns></returns> public static OOFormArray GetForm(string formString) { OOFormArray form_array = new OOFormArray(); string[] string_rows = formString.Split('\n'); int column_count = 0; int row_count = string_rows.Length; if (row_count > 0) { string[] string_firstRow = string_rows[0].Split('\t'); column_count = string_firstRow.Length; form_array.InsertRow(0); for (int i = 0; i < column_count; i++) { form_array.InsertColumn(i); form_array.mData[i][0] = string_firstRow[i].Replace("\r", ""); } for (int j = 1; j < row_count; j++) { string[] string_oneRow = string_rows[j].Split('\t'); int nod_count = Mathf.Min(column_count, string_oneRow.Length); form_array.InsertRow(j); for (int i = 0; i < nod_count; i++) { form_array.mData[i][j] = string_oneRow[i].Replace("\r", ""); } } } return(form_array); }
void DrawFormData() { if (mSelectionTable == null) { return; } string tmp_string = ""; Color tmp_color; //+ - buttons GUILayout.BeginHorizontal(); //3A+ tmp_color = GUI.backgroundColor; if (mIsModify) { GUI.backgroundColor = Color.blue; } if (GUILayout.Button("Save", GUILayout.Width(50))) { SaveSelectTable(); GUI.FocusControl("ForFouce"); } GUI.backgroundColor = tmp_color; for (int i = 0; i < mSelectionTable.mColumnCount; i++) { if (i < (mCurrentColumnPage - 1) * mPageColumnCount || i > mCurrentColumnPage * mPageColumnCount - 1) { if (i != 0) { continue; } } if (GUILayout.Button("<--")) { mSelectionTable.MoveColumnLeft(i); mIsModify = true; GUI.FocusControl("ForFouce"); break; } if (GUILayout.Button("-->")) { mSelectionTable.MoveColumnRight(i); mIsModify = true; GUI.FocusControl("ForFouce"); break; } } if (GUILayout.Button(" ", GUILayout.Width(30))) { } GUILayout.EndHorizontal(); //3A- //+ - buttons GUILayout.BeginHorizontal(); //3A+ tmp_color = GUI.backgroundColor; if (mIsModify) { GUI.backgroundColor = Color.yellow; } if (GUILayout.Button("Revert", GUILayout.Width(50))) { //ShowTableData(mSelectionIndex); SetAsset(mSelectionAsset); mIsModify = false; GUI.FocusControl("ForFouce"); } GUI.backgroundColor = tmp_color; for (int i = 0; i < mSelectionTable.mColumnCount; i++) { if (i < (mCurrentColumnPage - 1) * mPageColumnCount || i > mCurrentColumnPage * mPageColumnCount - 1) { if (i != 0) { continue; } } if (GUILayout.Button("+ " + i.ToString())) { mSelectionTable.InsertColumn(i); GUI.FocusControl("ForFouce"); mIsModify = true; break; } if (GUILayout.Button("-")) { mSelectionTable.DeleteColumn(i); GUI.FocusControl("ForFouce"); mIsModify = true; break; } } if (GUILayout.Button("+", GUILayout.Width(30))) { mSelectionTable.InsertColumn(mSelectionTable.mColumnCount); GUI.FocusControl("ForFouce"); mIsModify = true; } GUILayout.EndHorizontal(); //3A- //first line tmp_color = GUI.backgroundColor; GUI.backgroundColor = mFormHeadColor; GUILayout.BeginHorizontal(); //3B+ if (GUILayout.Button("", GUILayout.Width(50))) { } for (int i = 0; i < mSelectionTable.mColumnCount; i++) { if (i < (mCurrentColumnPage - 1) * mPageColumnCount || i > mCurrentColumnPage * mPageColumnCount - 1) { if (i != 0) { continue; } } tmp_string = mSelectionTable.mData[i][0]; mSelectionTable.mData[i][0] = EditorGUILayout.TextField(mSelectionTable.mData[i][0]); if (tmp_string != mSelectionTable.mData[i][0]) { mIsModify = true; } } if (GUILayout.Button("", GUILayout.Width(30))) { } GUILayout.EndHorizontal(); //3B- GUI.backgroundColor = tmp_color; //all mFormDataScroll = GUILayout.BeginScrollView(mFormDataScroll, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));//3C+ for (int j = 0; j < mSelectionTable.mRowCount; j++) { if (j < (mCurrentRowPage - 1) * mPageRowCount || j > mCurrentRowPage * mPageRowCount - 1) { if (j != 0) { continue; } } if (j % 2 == 0) { GUI.backgroundColor = mFormColor1; } else { GUI.backgroundColor = mFormColor2; } if (j == 0) { GUI.backgroundColor = mFormFirstRow; } GUILayout.BeginHorizontal(); //3D+ if (GUILayout.Button(j.ToString(), GUILayout.Width(50), GUILayout.Height(20))) { mSelectionTable.InsertRow(j); mIsModify = true; } for (int i = 0; i < mSelectionTable.mColumnCount; i++) { if (i < (mCurrentColumnPage - 1) * mPageColumnCount || i > mCurrentColumnPage * mPageColumnCount - 1) { if (i != 0) { continue; } } tmp_string = mSelectionTable.mData[i][j]; Color tmp_color_2 = GUI.backgroundColor; if (tmp_string.Contains(mSearchString) && mSearchString != "") { GUI.backgroundColor = mSearchColor; } mSelectionTable.mData[i][j] = EditorGUILayout.TextField(mSelectionTable.mData[i][j], GetTextField(), GUILayout.Height(20)); if (tmp_string != mSelectionTable.mData[i][j]) { mIsModify = true; } GUI.backgroundColor = tmp_color_2; } if (GUILayout.Button("-", GUILayout.Width(30), GUILayout.Height(20))) { mSelectionTable.DeleteRow(j); GUI.FocusControl("ForFouce"); mIsModify = true; } GUILayout.EndHorizontal(); //3D- GUI.backgroundColor = tmp_color; } if (GUILayout.Button("+", GUILayout.Width(50), GUILayout.Height(20))) { mSelectionTable.InsertRow(mSelectionTable.mRowCount); GUI.FocusControl("ForFouce"); mIsModify = true; } GUILayout.EndScrollView();//3C- }