void Clean()
        {
            if (!module)
            {
                return;
            }
            module.block.visible.EnableOutlineGlow(false, cakeslice.Outline.OutlineEnableReason.ScriptHighlight);
            module       = null;
            useGUILayout = false;

            CleanGroup();
            selectedGroup = null;
            GUI.UnfocusWindow();
        }
        private void DoWindow(int id)
        {
            if (selectedGroup != null && changeKey)
            {
                Event current = Event.current;
                if (current.isKey)
                {
                    selectedGroup.keyCode = current.keyCode;
                    changeKey             = false;
                } /*else if (current.isMouse) {
                   * Console.WriteLine(current.button + " " + current.keyCode);
                   * }*/
            }

            GUILayout.BeginVertical();
            scroll = GUILayout.BeginScrollView(scroll);
            {
                //Groups
                for (int i = 0; i < module.groups.Count; i++)
                {
                    var group = module.groups[i];

                    var tempgroup    = selectedGroup;
                    var tempExpanded = expanded;

                    GUILayout.BeginHorizontal(GUI.skin.button, GUILayout.Height(25));
                    {
                        GUILayout.BeginVertical();
                        {
                            GUILayout.FlexibleSpace();
                            GUILayout.BeginHorizontal();
                            {
                                //Renaming
                                if (renaming && group == selectedGroup)
                                {
                                    group.name = GUILayout.TextField(group.name, textField, GUILayout.Width(250), GUILayout.Height(icon_size));
                                }
                                else
                                {
                                    GUILayout.Label(group.name, bigText, GUILayout.Width(250));
                                }

                                GUILayout.FlexibleSpace();

                                //Rename button
                                if (GUILayout.Button(renaming && group == selectedGroup ? icon_cancel : icon_rename, GUILayout.Width(icon_size), GUILayout.Height(icon_size)))
                                {
                                    renaming  = !renaming;
                                    changeKey = false;
                                }

                                //Key button
                                if (GUILayout.Button(changeKey && group == selectedGroup ? "Press a key" : group.keyCode.ToString(), GUILayout.MinWidth(icon_size)))
                                {
                                    changeKey = true;
                                }

                                //Remove button
                                if (GUILayout.Button(icon_remove, GUILayout.Width(icon_size), GUILayout.Height(icon_size)))
                                {
                                    groupToRemove = i;
                                    if (selectedGroup == group)
                                    {
                                        CleanGroup();
                                    }
                                }

                                //Expand button
                                if (GUILayout.Button(selectedGroup == group && expanded ? "V" : ">", GUILayout.Width(icon_size), GUILayout.Height(icon_size)))
                                {
                                    if (group != selectedGroup)
                                    {
                                        CleanGroup();
                                        expanded = true;

                                        selectedGroup = group;

                                        foreach (var w in selectedGroup.weapons)
                                        {
                                            w.block.visible.EnableOutlineGlow(true, cakeslice.Outline.OutlineEnableReason.ScriptHighlight);
                                        }
                                    }
                                    else
                                    {
                                        expanded = !expanded;
                                    }
                                }
                            }
                            GUILayout.EndHorizontal();
                            GUILayout.FlexibleSpace();
                        }
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();


                    if (Event.current.type == EventType.Repaint)
                    {
                        //Scroll to added group
                        var lastrect = GUILayoutUtility.GetLastRect();
                        if (groupAdded && i == module.groups.Count - 1)
                        {
                            groupAdded = false;
                            scroll.y   = lastrect.y + lastrect.height / 2;
                        }
                    }

                    if (tempgroup != null && selectedGroup == tempgroup)
                    {
                        if (group == selectedGroup && tempExpanded)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Space(25f);
                            {
                                GUILayout.BeginVertical();
                                //Group weapons
                                for (int j = 0; j < displayWeapons.Count; j++)
                                {
                                    var weapon = displayWeapons[j];
                                    GUILayout.BeginHorizontal(GUI.skin.button);
                                    {
                                        GUILayout.Label(StringLookup.GetItemName(ObjectTypes.Block, (int)weapon.block.BlockType), middledText, GUILayout.Width(250));

                                        GUILayout.FlexibleSpace();

                                        if (GUILayout.Button(icon_remove, GUILayout.Width(icon_size), GUILayout.Height(icon_size)))
                                        {
                                            weapon.block.visible.EnableOutlineGlow(false, cakeslice.Outline.OutlineEnableReason.ScriptHighlight);
                                            group.weapons.RemoveAt(j);
                                            if (weapon.hammer)
                                            {
                                                ModuleWeaponGroupController.RemoveGroupForHammer(weapon.hammer, group);
                                            }
                                        }
                                    }
                                    GUILayout.EndHorizontal();

                                    if (Event.current.type == EventType.Repaint && weaponSelected && j == displayWeapons.Count - 1)
                                    {
                                        weaponSelected = false;
                                        var rect = GUILayoutUtility.GetLastRect();
                                        scroll.y = rect.y + rect.height / 2;
                                    }
                                }
                                if (GUILayout.Button(selectingWeapon ? "Selecting weapon..." : "Add weapon to group"))
                                {
                                    selectingWeapon = true;
                                }
                                GUILayout.EndVertical();
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                }
            }
            GUILayout.EndScrollView();
            //Add group button
            if (GUILayout.Button("Add group"))
            {
                CleanGroup();
                selectedGroup = new ModuleWeaponGroupController.WeaponGroup();
                module.groups.Add(selectedGroup);
                groupAdded = true;
            }
            GUILayout.EndVertical();

            GUI.DragWindow();
        }