private void SwapResource(Int32 indexFirst, Int32 indexSecond) { List <ResourceSettings> lstTemp = settings.Resources.Values.ToList(); ResourceSettings tempItem = lstTemp[indexFirst]; lstTemp[indexFirst] = lstTemp[indexSecond]; lstTemp[indexSecond] = tempItem; settings.Resources = lstTemp.ToDictionary(x => x.id); }
internal override void DrawWindow(int id) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Configure Resources", Styles.styleTextYellowBold); GUILayout.FlexibleSpace(); if (GUILayout.Button("Close")) { this.Visible = false; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(2); GUILayout.Label("Icon", Styles.styleStageTextHead, GUILayout.Width(32)); GUILayout.Label("Name", Styles.styleStageTextHead, GUILayout.Width(120)); GUILayout.Label("Position", Styles.styleStageTextHead, GUILayout.Width(56)); GUILayout.Space(6); GUILayout.Label("Visibility", Styles.styleStageTextHead, GUILayout.Width(80)); GUILayout.Label("Monitor", Styles.styleStageTextHead, GUILayout.Width(60)); GUILayout.EndHorizontal(); Int32 SepToDelete = 0; Int32 NameWidth = 120; Styles.styleResourceSettingsArea.fixedWidth = ScrollAreaWidth - 23; ScrollPosition = GUILayout.BeginScrollView(ScrollPosition, new GUIStyle(), GUILayout.Width(ScrollAreaWidth)); //wrapper for preventing horiz scroll GUILayout.BeginVertical(GUILayout.Width(ScrollAreaWidth - 23)); //foreach (PartResourceDefinition item in PartResourceLibrary.Instance.resourceDefinitions) if (Event.current.type == EventType.Repaint) { lstResPositions = new List <ResourcePosition>(); } for (int i = 0; i < settings.Resources.Count; i++) { ResourceSettings item = settings.Resources.Values.ElementAt(i); if (ResourceToShowAlarm == item.id) { GUILayout.Space(4); GUILayout.BeginVertical(Styles.styleResourceSettingsArea); NameWidth = 119; } GUILayout.BeginHorizontal(); if (!item.IsSeparator) { GUILayout.BeginVertical(); GUILayout.Space(6); Drawing.DrawResourceIcon(item.name); Rect IconRect; if (Event.current.type == EventType.Repaint) { IconRect = GUILayoutUtility.GetLastRect(); //float intOffset = 0; //if (lstResPositions.Count != 0) // intOffset = lstResPositions.Last().resourceRect.y + 22; //Rect resResourcePos = new Rect(mbARP.windowDebug.intTest1, mbARP.windowDebug.intTest2 + intOffset, 0, 0); lstResPositions.Add(new ResourcePosition(item.id, item.name, IconRect, ScrollAreaWidth - 20, (ResourceToShowAlarm == item.id))); } GUILayout.EndVertical(); //GUILayout.Label(item.name, GUILayout.Width(NameWidth)); if (GUILayout.Button(item.name, SkinsLibrary.CurrentSkin.label, GUILayout.Width(NameWidth))) { if (ResourceToShowAlarmChanger == item.id) { ResourceToShowAlarmChanger = 0; } else { ResourceToShowAlarmChanger = item.id; ddlMonType.SelectedIndex = (Int32)settings.Resources[ResourceToShowAlarmChanger].MonitorDirection; ddlDisplayValueAs.SelectedIndex = (Int32)settings.Resources[ResourceToShowAlarmChanger].DisplayValueAs; } ResourceToShowAlarmChangeNeeded = true; } } else { GUILayout.BeginVertical(); GUILayout.Space(13); GUILayout.Label("", Styles.styleSeparatorH, GUILayout.Width(120 + 36)); GUILayout.Space(7); GUILayout.EndVertical(); if (Event.current.type == EventType.Repaint) { Rect IconRect = new Rect(lstResPositions.Last().iconRect) { y = lstResPositions.Last().iconRect.y + 22, width = 120 + 36 }; lstResPositions.Add(new ResourcePosition(item.id, "Separator", IconRect, ScrollAreaWidth - 20, (ResourceToShowAlarm == item.id))); } } if (GUILayout.Button(new GUIContent("S", "Add Separator"), GUILayout.Width(21))) { AddSeparatorAtEnd(); MoveResource(settings.Resources.Count - 1, i + 1); } //Move up and down if (i > 0) { if (GUILayout.Button(new GUIContent("↑", "Move Up"), GUILayout.Width(21))) { SwapResource(i - 1, i); } } else { GUILayout.Space(21 + 4); } if (i < settings.Resources.Count - 1) { if (GUILayout.Button("↓", GUILayout.Width(21))) { SwapResource(i, i + 1); } } else { GUILayout.Space(21 + 4); } //Move top and Bottom if (i > 0) { if (GUILayout.Button(new GUIContent("↑↑", "Move to Top"), GUILayout.Width(27))) { MoveResource(i, 0); } } else { GUILayout.Space(27 + 4); } if (i < settings.Resources.Count - 1) { if (GUILayout.Button(new GUIContent("↓↓", "Move to Bottom"), GUILayout.Width(27))) { MoveResource(i, settings.Resources.Count); } } else { GUILayout.Space(27 + 4); } // Visibility level and alarm values/Delete if (!item.IsSeparator) { if (GUILayout.Button(settings.Resources[item.id].Visibility.ToString(), GUILayout.Width(75))) { settings.Resources[item.id].Visibility = settings.Resources[item.id].Visibility.Next(); } if (GUILayout.Button(string.Format("{0}/{1}", settings.Resources[item.id].MonitorWarningLevel, settings.Resources[item.id].MonitorAlertLevel), GUILayout.Width(58))) { if (ResourceToShowAlarmChanger == item.id) { ResourceToShowAlarmChanger = 0; } else { ResourceToShowAlarmChanger = item.id; ddlMonType.SelectedIndex = (Int32)settings.Resources[ResourceToShowAlarmChanger].MonitorDirection; ddlDisplayValueAs.SelectedIndex = (Int32)settings.Resources[ResourceToShowAlarmChanger].DisplayValueAs; } ResourceToShowAlarmChangeNeeded = true; } } else { if (GUILayout.Button("Delete", GUILayout.Width(75 + 58 + 4))) { SepToDelete = item.id; } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (ResourceToShowAlarm == item.id) { GUILayout.BeginVertical(GUILayout.Height(40), GUILayout.Width(ScrollAreaWidth - 20)); GUILayout.Space(8);//4 GUILayout.BeginHorizontal(); GUILayout.Label("Display As:", Styles.styleStageTextHead, GUILayout.Width(151)); //GUILayout.Label("Monitoring Type:", GUILayout.Width(mbARP.windowDebug.intTest1)); ddlDisplayValueAs.SetListBoxOffset(vectMonTypeOffset - ScrollPosition); ddlDisplayValueAs.DrawButton(); GUILayout.Space(4); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Monitoring Levels:", Styles.styleStageTextHead, GUILayout.Width(151)); //GUILayout.Label("Monitoring Type:", GUILayout.Width(mbARP.windowDebug.intTest1)); ddlMonType.SetListBoxOffset(vectMonTypeOffset - ScrollPosition); ddlMonType.DrawButton(); GUILayout.Space(4); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Warning Level:", GUILayout.Width(90)); settings.Resources[item.id].MonitorWarningLevel = (Int32)Math.Round(GUILayout.HorizontalSlider(settings.Resources[item.id].MonitorWarningLevel, 0, 100, GUILayout.Width(220))); GUILayout.Label(settings.Resources[item.id].MonitorWarningLevel.ToString() + "%", GUILayout.Width(35)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Alert Level:", GUILayout.Width(90)); settings.Resources[item.id].MonitorAlertLevel = (Int32)Math.Round(GUILayout.HorizontalSlider(settings.Resources[item.id].MonitorAlertLevel, 0, 100, GUILayout.Width(220))); GUILayout.Label(settings.Resources[item.id].MonitorAlertLevel.ToString() + "%", GUILayout.Width(35)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); if (settings.Resources[item.id].MonitorDirection == ResourceSettings.MonitorDirections.Low) { settings.Resources[item.id].MonitorWarningLevel = Mathf.Clamp(settings.Resources[item.id].MonitorWarningLevel, settings.Resources[item.id].MonitorAlertLevel, 100); } else { settings.Resources[item.id].MonitorWarningLevel = Mathf.Clamp(settings.Resources[item.id].MonitorWarningLevel, 0, settings.Resources[item.id].MonitorAlertLevel); } GUIStyle temp = new GUIStyle(Styles.styleStageTextHead); temp.padding.top = 0; GUILayout.BeginHorizontal(); GUILayout.Label("Alarms for this:", temp, GUILayout.Width(120)); DrawToggle(ref settings.Resources[item.id].AlarmEnabled, "Alarm Enabled", Styles.styleToggle); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Empty Behaviour:", temp, GUILayout.Width(120)); DrawToggle(ref settings.Resources[item.id].HideWhenEmpty, "Hide When Empty", Styles.styleToggle); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Full Behaviour:", temp, GUILayout.Width(120)); DrawToggle(ref settings.Resources[item.id].HideWhenFull, "Hide When Full", Styles.styleToggle); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Stage Bars:", temp, GUILayout.Width(120)); DrawToggle(ref settings.Resources[item.id].SplitLastStage, "Split Enabled", Styles.styleToggle); GUILayout.EndHorizontal(); if (settings.Resources[item.id].SplitLastStage && ( PartResourceLibrary.Instance.resourceDefinitions[item.id].resourceFlowMode == ResourceFlowMode.ALL_VESSEL || PartResourceLibrary.Instance.resourceDefinitions[item.id].resourceFlowMode == ResourceFlowMode.STAGE_PRIORITY_FLOW) ) { GUILayout.BeginHorizontal(); GUILayout.Label("Split Behaviour:", temp, GUILayout.Width(120)); DrawToggle(ref settings.Resources[item.id].ShowReserveLevels, new GUIContent("Show Reserve Levels", "instead of Whole Vessel/Last Stage split"), Styles.styleToggle); GUILayout.EndHorizontal(); } GUILayout.Space(3); GUILayout.EndVertical(); } } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.EndVertical(); if (SepToDelete != 0) { settings.Resources.Remove(SepToDelete); List <ResourceSettings> lstTemp = settings.Resources.Values.ToList(); settings.Resources = lstTemp.ToDictionary(x => x.id); } GUILayout.BeginHorizontal(); if (DrawButton("Add Separator")) { AddSeparatorAtEnd(); } if (DrawButton("Sort Groups")) { SortGroups(); } if (DrawButton("Save")) { settings.Save(); } GUILayout.EndHorizontal(); if (ResourceToShowAlarmChangeNeeded) { ResourceToShowAlarmChangeNeeded = false; ResourceToShowAlarm = ResourceToShowAlarmChanger; } // Draw the Yellow insertion strip if (DraggingResource && DropWillReorderList && resourceOver != null) { Single rectResMoveY; if (resourceInsertIndex < lstResPositions.Count) { rectResMoveY = lstResPositions[resourceInsertIndex].resourceRect.y; } else { rectResMoveY = lstResPositions[lstResPositions.Count - 1].resourceRect.y + lstResPositions[lstResPositions.Count - 1].resourceRect.height; } Rect rectResMove = new Rect(4, rectResMoveY + 49 - ScrollPosition.y, 380, 9); GUI.Box(rectResMove, "", Styles.styleDragInsert); } //Do the mouse checks IconMouseEvents(); //Disable the Window from dragging if we are dragging a resource DragEnabled = !DraggingResource; }
internal ARPResource(PartResourceDefinition ResourceDefinition, ResourceSettings ResourceConfig) { this.ResourceDef = ResourceDefinition; this.ResourceConfig = ResourceConfig; }