//separate out parameter value information from configuration string //note: link level parameters are not supported in this implementation public void ParseConfig(ConvergeManager manager) { this.manager = manager; this.seriesParams = new Dictionary <string, ConvergeParam>(); string remainder = config; int nodeCnt = 0; int nodeId; int start, end, nodeIdx; int paramCnt; float value, valNotNeeded; string name; string paramId; //sequence is nodeCnt,[node0],biomass0,perunitbiomass0,paramCnt0,(if any)paramID0,value0,paramID1,value1,... //[node1],biomass1,perunitbiomass1,paramCnt1,...,[nodeN],biomassN,... if (remainder != null) { //"nodeCnt," nodeCnt = int.Parse(remainder.Substring(0, remainder.IndexOf(","))); } for (int i = 0; i < nodeCnt; i++) { //"[node_Id(i)],biomass(i)," start = remainder.IndexOf("["); end = remainder.IndexOf("],"); nodeId = int.Parse(remainder.Substring(start + 1, end - start - 1)); nodeIdx = manager.seriesNodes.IndexOf(nodeId); name = manager.seriesLabels[nodeIdx]; remainder = remainder.Substring(end + 2); //"]," end = remainder.IndexOf(","); valNotNeeded = float.Parse(remainder.Substring(0, end)); //biomass remainder = remainder.Substring(end + 1); end = remainder.IndexOf(","); valNotNeeded = float.Parse(remainder.Substring(0, end)); //per-unit-biomass remainder = remainder.Substring(end + 1); end = remainder.IndexOf(","); //get counts of node parameters for current node paramCnt = int.Parse(remainder.Substring(0, end)); remainder = remainder.Substring(end + 1); //get node parameters for (int j = 0; j < paramCnt; j++) { //"paramID(j)=value(j)," start = remainder.IndexOf("="); paramId = remainder.Substring(0, start).ToUpper(); end = remainder.IndexOf(","); value = float.Parse(remainder.Substring(start + 1, end - start - 1)); remainder = remainder.Substring(end + 1); ConvergeParam param = new ConvergeParam(name, nodeId, paramId, value); seriesParams.Add(param.nodeIdParamId, param); } //get link parameters end = remainder.IndexOf(","); if (end == Constants.ID_NOT_SET) { end = remainder.Length; } paramCnt = int.Parse(remainder.Substring(0, end)); if (paramCnt != 0) { Debug.LogError("Error in ConvergeAttempt::ParseConfig() - link parameters found but not supported."); } } }
public void UpdateConfig() { string oldConfig = config; string newConfig = ""; int nodeCnt, paramCnt; int offset, start, end, nextStart; int nodeId; string paramId; string nodeData; float newValue; //loop through nodes nodeCnt = int.Parse(oldConfig.Substring(0, oldConfig.IndexOf(","))); for (int i = 0; i < nodeCnt; i++) { start = oldConfig.IndexOf("["); end = oldConfig.IndexOf("],"); if (end <= start) { Debug.LogError("In ConvergeAttempt::UpdateConfig - invalid configuration string"); break; } nodeId = int.Parse(oldConfig.Substring(start + 1, end - start - 1)); newConfig = newConfig + oldConfig.Substring(0, end + 2); //"]," nextStart = oldConfig.IndexOf("[", end + 2); if (nextStart == Constants.ID_NOT_SET) { nextStart = oldConfig.Length; } nodeData = oldConfig.Substring(end + 2, nextStart - end - 2); if (nextStart < oldConfig.Length) { oldConfig = oldConfig.Substring(nextStart); } else { oldConfig = ""; } //loop through node params int skip = nodeData.IndexOf(","); //biomass skip = nodeData.IndexOf(",", skip + 1); //per-unit-biomass paramCnt = int.Parse(nodeData.Substring(skip + 1, nodeData.IndexOf(",", skip + 1) - skip - 1)); if (paramCnt == 0) { newConfig = newConfig + nodeData.Substring(0, nodeData.IndexOf(",", skip + 1)); //param-cnt->0 } offset = 0; for (int j = 0; j < paramCnt; j++) { start = nodeData.IndexOfAny(new char[] { 'K', 'R', 'X' }, offset); end = nodeData.IndexOf('=', start); paramId = nodeData.Substring(start, end - start); ConvergeParam param = seriesParams [ConvergeParam.NodeIdParamId(nodeId, paramId)]; newValue = param.value; newConfig = newConfig + nodeData.Substring(offset, end + 1 - offset); //i.e. through "=" int thousands = Mathf.CeilToInt(newValue * 1000f); newConfig = newConfig + string.Format("{0:0.000}", (float)thousands / 1000f); offset = nodeData.IndexOf(",", end + 1); } //holding place for (unsupported) link params newConfig = newConfig + ",0" + (i == nodeCnt - 1 ? "" : ","); } this.config = newConfig; }
private void DrawParameterFields(GUIStyle style) { style.alignment = TextAnchor.UpperRight; style.font = font; style.fontSize = 14; Color savedColor = GUI.color; Color savedBkgdColor = GUI.backgroundColor; if (currAttempt != null && currAttempt.seriesParams.Count > 0) { int paramCnt = currAttempt.seriesParams.Count; int row = 0; int col = 0; float entryHeight = height - heightGraph - 30 * 3 - bufferBorder * 2; GUI.BeginGroup(new Rect(bufferBorder, topGraph + heightGraph + bufferBorder, width, entryHeight)); //use seriesNodes to force order foreach (int nodeId in manager.seriesNodes) { //look for all possible parameter types for each node foreach (char paramId in new char[] { 'K', 'R', 'X' }) { string strId = paramId.ToString(); ConvergeParam param; string nodeIdParamId = ConvergeParam.NodeIdParamId(nodeId, strId); if (currAttempt.seriesParams.ContainsKey(nodeIdParamId)) { param = currAttempt.seriesParams [nodeIdParamId]; } else { continue; } float min = 0f; float max = 1f; switch (paramId) { case 'K': min = 1000f; max = 15000f; break; case 'R': min = 0f; max = 3f; break; default: break; } Rect labelRect; //draw name, paramId labelRect = new Rect(col * (350 + bufferBorder), row * 35, 250, 30); if (labelRect.Contains(Event.current.mousePosition)) { manager.mouseOverLabels.Add(param.name); manager.selected = param.name; manager.lastSeriesToDraw = param.name; } GUI.color = (param.name.Equals(manager.selected)) ? manager.seriesColors [param.name] : Color.white; GUI.Label(labelRect, param.name + " - " + param.paramId, style); //if player clicks on species, set as selected and activate foodWeb if (GUI.Button(labelRect, "", GUIStyle.none)) { foodWeb.selected = SpeciesTable.GetSpeciesName(param.name); foodWeb.SetActive(true, foodWeb.selected); } //draw slider with underlying colored bar showing original value Rect sliderRect = new Rect(labelRect.x + 250 + bufferBorder, labelRect.y + 5, 100, 20); if (sliderRect.Contains(Event.current.mousePosition)) { manager.mouseOverLabels.Add(param.name); manager.selected = param.name; manager.lastSeriesToDraw = param.name; } GUI.color = manager.seriesColors [param.name]; float origValWidth = ConvergeParam.NormParam(param.origVal, min, max, sliderRect.width); //float origValWidth = (param.origVal / (max - min)) * sliderRect.width; Color slTexture = new Color(0.85f, 0.85f, 0.85f); GUI.DrawTexture(new Rect(sliderRect.x, sliderRect.y, origValWidth, 10), //sliderRect.height), Functions.CreateTexture2D(slTexture)); // GUI.color = savedColor; //draw slider for parameter value manipulation GUI.backgroundColor = manager.seriesColors [param.name]; param.value = GUI.HorizontalSlider( sliderRect, param.value, min, max ); //show normalized value for parameter if (param.name.Equals(manager.selected)) { string valLabel = String.Format( "{0}", ConvergeParam.NormParam(param.value, min, max)); if (param.value != param.origVal) { valLabel = valLabel + String.Format( " [{0}]", ConvergeParam.NormParam(param.origVal, min, max)); } style.alignment = TextAnchor.UpperLeft; float xPosn = sliderRect.x + (param.value / (max - min)) * sliderRect.width + bufferBorder; Rect valRect = new Rect(xPosn, labelRect.y, 70, labelRect.height - 5); GUI.Box(valRect, valLabel); style.alignment = TextAnchor.UpperRight; } if ((row + 1) * 35 + 30 > entryHeight) { col++; row = 0; } else { row++; } GUI.color = savedColor; GUI.backgroundColor = savedBkgdColor; } } GUI.EndGroup(); } style.alignment = TextAnchor.UpperLeft; style.font = font; style.fontSize = 16; }
private void DrawParameterFields(GUIStyle style) { style.alignment = TextAnchor.UpperRight; style.font = font; style.fontSize = 14; Color temp = GUI.color; if (currAttempt != null && currAttempt.seriesParams.Count > 0) { int paramCnt = currAttempt.seriesParams.Count; int row = 0; int col = 0; float entryHeight = height - heightGraph - 30 * 3 - bufferBorder * 2; GUI.BeginGroup(new Rect(bufferBorder, topGraph + heightGraph + bufferBorder, width, entryHeight)); //use seriesNodes to force order foreach (int nodeId in manager.seriesNodes) { //look for all possible parameter types for each node foreach (char paramId in new char[] { 'K', 'R', 'X' }) { string strId = paramId.ToString(); ConvergeParam param; string nodeIdParamId = ConvergeParam.NodeIdParamId(nodeId, strId); if (currAttempt.seriesParams.ContainsKey(nodeIdParamId)) { param = currAttempt.seriesParams [nodeIdParamId]; } else { continue; } float min = 0f; float max = 1f; switch (paramId) { case 'K': min = 1000f; max = 15000f; break; case 'R': min = 0f; max = 3f; break; default: break; } Rect itemRect; //draw name, paramId itemRect = new Rect(col * (350 + bufferBorder), row * 35, 250, 30); if (itemRect.Contains(Event.current.mousePosition)) { manager.mouseOverLabels.Add(param.name); manager.selected = param.name; manager.lastSeriesToDraw = param.name; } style.normal.textColor = (param.name == manager.selected) ? manager.seriesColors [param.name] : Color.white; GUI.Label(itemRect, param.name + " - " + param.paramId, style); //if player clicks on species, set as selected and activate foodWeb if (GUI.Button(itemRect, "", GUIStyle.none)) { foodWeb.selected = SpeciesTable.GetSpeciesName(param.name); foodWeb.SetActive(true, foodWeb.selected); } //draw colored bar showing original value itemRect = new Rect(col * (350 + bufferBorder) + 250 + bufferBorder, row * 35 + 5, 100, 10); if (itemRect.Contains(Event.current.mousePosition)) { manager.mouseOverLabels.Add(param.name); manager.selected = param.name; manager.lastSeriesToDraw = param.name; } GUI.color = manager.seriesColors [param.name]; float origValWidth = (param.origVal / (max - min)) * itemRect.width; GUI.DrawTexture(new Rect(itemRect.x, itemRect.y, origValWidth, itemRect.height), Functions.CreateTexture2D(new Color(0.85f, 0.85f, 0.85f))); GUI.color = temp; //draw slider for parameter value manipulation GUI.backgroundColor = manager.seriesColors [param.name]; param.value = GUI.HorizontalSlider( itemRect, param.value, min, max ); GUI.backgroundColor = temp; if ((row + 1) * 35 + 30 > entryHeight) { col++; row = 0; } else { row++; } } } GUI.EndGroup(); } style.alignment = TextAnchor.UpperLeft; style.font = font; style.fontSize = 16; style.normal.textColor = temp; GUI.color = temp; }
//separate out parameter value information from configuration string //note: link level parameters are not supported in this implementation public void ParseConfig(ConvergeManager manager) { //this.manager = manager; this.seriesParams = new Dictionary<string, ConvergeParam>(); string remainder = config; int nodeCnt = 0; int nodeId; int start, end, nodeIdx; int paramCnt; float value, valNotNeeded; string name; string paramId; //sequence is nodeCnt,[node0],biomass0,perunitbiomass0,paramCnt0,(if any)paramID0,value0,paramID1,value1,... //[node1],biomass1,perunitbiomass1,paramCnt1,...,[nodeN],biomassN,... if (remainder != null) { //"nodeCnt," nodeCnt = int.Parse(remainder.Substring(0, remainder.IndexOf(","))); } for (int i = 0; i < nodeCnt; i++) { //"[node_Id(i)],biomass(i)," start = remainder.IndexOf("["); end = remainder.IndexOf("],"); nodeId = int.Parse(remainder.Substring(start + 1, end - start - 1)); nodeIdx = manager.seriesNodes.IndexOf (nodeId); name = manager.seriesLabels[nodeIdx]; remainder = remainder.Substring(end + 2); //"]," end = remainder.IndexOf(","); valNotNeeded = float.Parse(remainder.Substring(0, end)); //biomass remainder = remainder.Substring(end + 1); end = remainder.IndexOf(","); valNotNeeded = float.Parse(remainder.Substring(0, end)); //per-unit-biomass remainder = remainder.Substring(end + 1); end = remainder.IndexOf(","); //get counts of node parameters for current node paramCnt = int.Parse(remainder.Substring(0, end)); remainder = remainder.Substring(end + 1); //get node parameters for (int j = 0; j < paramCnt; j++) { //"paramID(j)=value(j)," start = remainder.IndexOf("="); paramId = remainder.Substring(0, start).ToUpper(); end = remainder.IndexOf(","); value = float.Parse(remainder.Substring(start + 1, end - start - 1)); remainder = remainder.Substring(end + 1); ConvergeParam param = new ConvergeParam (name, nodeId, paramId, value); seriesParams.Add (param.nodeIdParamId, param); } //get link parameters end = remainder.IndexOf(","); if (end == Constants.ID_NOT_SET) { end = remainder.Length; } paramCnt = int.Parse(remainder.Substring(0, end)); if (paramCnt != 0) { Debug.LogError ("Error in ConvergeAttempt::ParseConfig() - link parameters found but not supported."); } } }