Ejemplo n.º 1
0
        private void Move(PartContent aPart, int qty, KASModuleContainer destContainer)
        {
            if (destContainer.MaxSizeReached(aPart.grabModule, qty))
            {
                fxSndBipWrong.audio.Play();
                ScreenMessages.PostScreenMessage("Max size of the destination container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            PartContent dest = PartContent.Get(destContainer.contents, aPart.name);

            if (aPart.pristine_count > 0)
            {
                int delta = Math.Min(aPart.pristine_count, qty);
                aPart.pristine_count -= delta;
                dest.pristine_count  += delta;
                qty -= delta;
            }
            while (qty > 0 && aPart.instances.Count > 0)
            {
                dest.Load(aPart.PopInstance());
                qty--;
            }
            RefreshTotalSize();
            destContainer.RefreshTotalSize();
        }
Ejemplo n.º 2
0
        public void Update()
        {
            EditorLogic editor = EditorLogic.fetch;

            if (editor == null)
            {
                return;
            }
            if (editor.editorScreen != EditorLogic.EditorScreen.Parts)
            {
                return;
            }

            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                Part p = KAS_Shared.GetPartUnderCursor();
                if (p)
                {
                    KASModuleContainer containerModule = p.GetComponent <KASModuleContainer>();
                    if (containerModule)
                    {
                        containerModule.EditContents();
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private void CloseGUI()
 {
     showGUI           = guiMode.None;
     exchangeContainer = null;
     availableContents = null;
     if (HighLogic.LoadedSceneIsEditor)
     {
         EditorLogic.fetch.Unlock("KAS DisableEditorClickthrough");
     }
 }
Ejemplo n.º 4
0
 public void ExchangeContents(KASModuleContainer moduleContainer)
 {
     if (showGUI != guiMode.None)
     {
         CloseGUI();
         fxSndClose.audio.Play();
     }
     else
     {
         CloseAllGUI();
         exchangeContainer = moduleContainer;
         guiMainWindowPos  = new Rect(Screen.width / 2, Screen.height / 2, 10, 10);
         showGUI           = guiMode.Exchange;
         fxSndOpen.audio.Play();
     }
 }
Ejemplo n.º 5
0
        private void Move(AvailablePart aPart, int qty, KASModuleContainer destContainer)
        {
            KASModuleGrab moduleGrab = aPart.partPrefab.GetComponent <KASModuleGrab>();

            if (!moduleGrab)
            {
                fxSndBipWrong.audio.Play();
                KAS_Shared.DebugError("Cannot grab the part taken, no grab module found !");
                return;
            }
            if (destContainer.MaxSizeReached(aPart, 1))
            {
                fxSndBipWrong.audio.Play();
                ScreenMessages.PostScreenMessage("Max size of the destination container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            Remove(aPart, qty);
            destContainer.Add(aPart, qty);
        }
Ejemplo n.º 6
0
        private Vector2 GuiContentList(Dictionary <string, PartContent> contentsList, ShowButton showButton, KASModuleContainer actionContainer, Vector2 scrollPos, bool showTotal = true, KASModuleContainer destContainer = null, float scrollHeight = 300f)
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos, guiDataboxStyle, GUILayout.Width(600f), GUILayout.Height(scrollHeight));

            foreach (PartContent item in contentsList.Values)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("  " + item.part.title, "Name"), guiCenterStyle, GUILayout.Width(300f));
                GUILayout.Label(new GUIContent("  " + item.storedSize.ToString("0.0"), "Size"), guiCenterStyle, GUILayout.Width(50f));
                GUILayout.Label(new GUIContent("  " + item.averageMass.ToString("0.000"), "Mass"), guiCenterStyle, GUILayout.Width(50f));
                GUILayout.Label(new GUIContent("  " + item.totalCount, "Quantity"), guiCenterStyle, GUILayout.Width(50f));
                if (showButton == ShowButton.Add)
                {
                    if (GUILayout.Button(new GUIContent("Add", "Add part to container"), guiButtonStyle, GUILayout.Width(50f)))
                    {
                        if (actionContainer.MaxSizeReached(item.grabModule, 1))
                        {
                            fxSndBipWrong.audio.Play();
                            ScreenMessages.PostScreenMessage("Max size of the container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
                            return(scrollPos);
                        }
                        else
                        {
                            actionContainer.Add(item.part, 1);
                        }
                    }
                }
                if (showButton == ShowButton.Remove)
                {
                    if (GUILayout.Button(new GUIContent("Remove", "Remove part from container"), guiButtonStyle, GUILayout.Width(60f)))
                    {
                        actionContainer.Remove(item.part, 1);
                    }
                }
                if (showButton == ShowButton.Take)
                {
                    if (GUILayout.Button(new GUIContent("Take", "Take part from container"), guiButtonStyle, GUILayout.Width(60f)))
                    {
                        actionContainer.Take(item);
                    }

                    /*
                     * if (GUILayout.Button(new GUIContent("Attach", "Attach part"), guiButtonStyle, GUILayout.Width(60f)))
                     * {
                     *  KASModuleGrab moduleGrab = ct.Key.partPrefab.GetComponent<KASModuleGrab>();
                     *  KASAddonPointer.StartPointer(ct.Key.partPrefab, KASAddonPointer.PointerMode.CopyAndAttach, true, true, true, 2, this.part.transform, false);
                     * }*/
                }
                if (showButton == ShowButton.Move)
                {
                    if (GUILayout.Button(new GUIContent("Move", "Move part to the destination container"), guiButtonStyle, GUILayout.Width(60f)))
                    {
                        actionContainer.Move(item, 1, destContainer);
                    }
                }
                GUILayout.EndHorizontal();
            }
            if (showTotal)
            {
                GUILayout.Space(5);
                GUILayout.BeginVertical(guiCenterStyle);
                GUILayout.BeginHorizontal();

                GUIStyle guiLeftWhiteStyle = new GUIStyle(GUI.skin.label);
                guiLeftWhiteStyle.wordWrap         = false;
                guiLeftWhiteStyle.normal.textColor = Color.white;
                guiLeftWhiteStyle.alignment        = TextAnchor.MiddleLeft;

                GUIStyle guiRightWhiteStyle = new GUIStyle(GUI.skin.label);
                guiRightWhiteStyle.wordWrap         = false;
                guiRightWhiteStyle.normal.textColor = Color.white;
                guiRightWhiteStyle.alignment        = TextAnchor.MiddleRight;

                GUILayout.Label(new GUIContent("Weight : " + actionContainer.part.mass.ToString("0.000"), "Total weight of the container with contents"), guiRightWhiteStyle);
                GUILayout.Label(new GUIContent(" | Space : " + actionContainer.totalSize.ToString("0.0") + " / " + actionContainer.maxSize.ToString("0.0"), "Space used / Max space"), guiRightWhiteStyle);
                GUILayout.Label(new GUIContent(" | Cost : √" + actionContainer.GetModuleCost().ToString("0.00"), "Total cost of the container's contents"), guiRightWhiteStyle);
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
            }
            GUILayout.EndScrollView();
            return(scrollPos);
        }
Ejemplo n.º 7
0
 private void Move(AvailablePart aPart, int qty, KASModuleContainer destContainer)
 {
     KASModuleGrab moduleGrab = aPart.partPrefab.GetComponent<KASModuleGrab>();
     if (!moduleGrab)
     {
         fxSndBipWrong.audio.Play();
         KAS_Shared.DebugError("Cannot grab the part taken, no grab module found !");
         return;
     }
     if (destContainer.MaxSizeReached(aPart, 1))
     {
         fxSndBipWrong.audio.Play();
         ScreenMessages.PostScreenMessage("Max size of the destination container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
         return;
     }
     Remove(aPart, qty);
     destContainer.Add(aPart, qty);
 }
Ejemplo n.º 8
0
        private Vector2 GuiContentList(Dictionary<AvailablePart, int> contentsList, ShowButton showButton, KASModuleContainer actionContainer, Vector2 scrollPos, bool showTotal = true, KASModuleContainer destContainer = null, float scrollHeight = 300f)
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos, guiDataboxStyle, GUILayout.Width(600f), GUILayout.Height(scrollHeight));

            foreach (KeyValuePair<AvailablePart, int> ct in contentsList)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("  " + ct.Key.title, "Name"), guiCenterStyle, GUILayout.Width(300f));
                GUILayout.Label(new GUIContent("  " + GetPartSize(ct.Key).ToString("0.0"), "Size"), guiCenterStyle, GUILayout.Width(50f));
                GUILayout.Label(new GUIContent("  " + ct.Key.partPrefab.mass.ToString("0.000"), "Mass"), guiCenterStyle, GUILayout.Width(50f));
                GUILayout.Label(new GUIContent("  " + ct.Value, "Quantity"), guiCenterStyle, GUILayout.Width(50f));
                if (showButton == ShowButton.Add)
                {
                    if (GUILayout.Button(new GUIContent("Add", "Add part to container"), guiButtonStyle, GUILayout.Width(50f)))
                    {
                        if (actionContainer.MaxSizeReached(ct.Key, 1))
                        {
                            fxSndBipWrong.audio.Play();
                            ScreenMessages.PostScreenMessage("Max size of the container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
                            return scrollPos;
                        }
                        else
                        {
                            actionContainer.Add(ct.Key, 1);
                        }
                    }
                }
                if (showButton == ShowButton.Remove)
                {
                    if (GUILayout.Button(new GUIContent("Remove", "Remove part from container"), guiButtonStyle, GUILayout.Width(60f)))
                    {
                        actionContainer.Remove(ct.Key, 1);
                    }
                }
                if (showButton == ShowButton.Take)
                {
                    if (GUILayout.Button(new GUIContent("Take", "Take part from container"), guiButtonStyle, GUILayout.Width(60f)))
                    {
                        actionContainer.Take(ct.Key);
                    }
                    /*
                    if (GUILayout.Button(new GUIContent("Attach", "Attach part"), guiButtonStyle, GUILayout.Width(60f)))
                    {
                        KASModuleGrab moduleGrab = ct.Key.partPrefab.GetComponent<KASModuleGrab>();
                        KASAddonPointer.StartPointer(ct.Key.partPrefab, KASAddonPointer.PointerMode.CopyAndAttach, true, true, true, 2, this.part.transform, false);
                    }*/
                }
                if (showButton == ShowButton.Move)
                {
                    if (GUILayout.Button(new GUIContent("Move", "Move part to the destination container"), guiButtonStyle, GUILayout.Width(60f)))
                    {
                        actionContainer.Move(ct.Key, 1, destContainer);
                    }
                }
                GUILayout.EndHorizontal();

            }
            if (showTotal)
            {
                GUILayout.Space(5);
                GUILayout.BeginVertical(guiCenterStyle);
                GUILayout.BeginHorizontal();

                GUIStyle guiLeftWhiteStyle = new GUIStyle(GUI.skin.label);
                guiLeftWhiteStyle.wordWrap = false;
                guiLeftWhiteStyle.normal.textColor = Color.white;
                guiLeftWhiteStyle.alignment = TextAnchor.MiddleLeft;

                GUIStyle guiRightWhiteStyle = new GUIStyle(GUI.skin.label);
                guiRightWhiteStyle.wordWrap = false;
                guiRightWhiteStyle.normal.textColor = Color.white;
                guiRightWhiteStyle.alignment = TextAnchor.MiddleRight;

                GUILayout.Label(new GUIContent("Weight : " + actionContainer.part.mass.ToString("0.000"), "Total weight of the container with contents"), guiRightWhiteStyle);
                GUILayout.Label(new GUIContent(" | Space : " + actionContainer.totalSize.ToString("0.0") + " / " + actionContainer.maxSize.ToString("0.0"), "Space used / Max space"), guiRightWhiteStyle);
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
            }
            GUILayout.EndScrollView();
            return scrollPos;
        }
Ejemplo n.º 9
0
 private void CloseGUI()
 {
     showGUI = guiMode.None;
     exchangeContainer = null;
     availableContents = null;
     if (HighLogic.LoadedSceneIsEditor) EditorLogic.fetch.Unlock();
 }
Ejemplo n.º 10
0
 public void ExchangeContents(KASModuleContainer moduleContainer)
 {
     if (showGUI != guiMode.None)
     {
         CloseGUI();
         fxSndClose.audio.Play();
     }
     else
     {
         CloseAllGUI();
         exchangeContainer = moduleContainer;
         guiMainWindowPos = new Rect(Screen.width / 2, Screen.height / 2, 10, 10);
         showGUI = guiMode.Exchange;
         fxSndOpen.audio.Play();
     }
 }
Ejemplo n.º 11
0
 private void Move(PartContent aPart, int qty, KASModuleContainer destContainer)
 {
     if (destContainer.MaxSizeReached(aPart.grabModule, qty))
     {
         fxSndBipWrong.audio.Play();
         ScreenMessages.PostScreenMessage("Max size of the destination container reached !", 5, ScreenMessageStyle.UPPER_CENTER);
         return;
     }
     PartContent dest = PartContent.Get(destContainer.contents, aPart.name);
     if (aPart.pristine_count > 0)
     {
         int delta = Math.Min(aPart.pristine_count, qty);
         aPart.pristine_count -= delta;
         dest.pristine_count += delta;
         qty -= delta;
     }
     while (qty > 0 && aPart.instances.Count > 0)
     {
         dest.Load(aPart.PopInstance());
         qty--;
     }
     RefreshTotalSize();
     destContainer.RefreshTotalSize();
 }