/// <summary>
 /// Saves all important settings for next session.
 /// </summary>
 /// <returns>Settings.</returns>
 public BBPanelSettings getSettings()
 {
     BBPanelSettings settings = new BBPanelSettings();
     settings.x = this.relativePosition.x;
     settings.y = this.relativePosition.y;
     return settings;
 }
Beispiel #2
0
 /// <summary>
 /// Creates extended panel.
 /// </summary>
 /// <param name="data">The settings the panel gets created with.</param>
 /// <param name="isCustom">If the panel got created by the user. Gets deleted if closed by the player.</param>
 public void createExtendedPanel(BBPanelSettings data)
 {
     if (data.isCustom && !data.sticky) // delete closed custom panels (stops panels from summing up into infinity)
         return;
     // create game object
     GameObject go = new GameObject(data.name);
     // attach new extended panel to the gameobject
     UIExtendedBudgetPanel panel = go.AddComponent<UIExtendedBudgetPanel>();
     // attach extended panel to better budget panel/container
     panel.transform.parent = this.transform;
     // set parent to BetterBudget
     panel.Parent = this;
     // insert save data
     panel.load(data);
     // add information panel which opens and closes the extended panel simultaneously/in-sync (optional)
     if (data.informationPanel != null)
     {
         UIPanel informationPanel = view.FindUIComponent<UIPanel>(data.informationPanel);
         if (informationPanel != null)
         {
             informationPanel.eventVisibilityChanged += onVisibilityChangeBetterBudget;
             panel.attachedPanel = informationPanel;
         }
     }
     // adds slider to the extended panel (optional - but panel is useless without them)
     foreach (String sliderName in data.slider)
     {
         UIPanel originalSlider = findUIPanel(sliderName);
         if (originalSlider != null)
         {
             originalSlider.eventIsEnabledChanged += panel.hitMilestone;
             panel.addSlider(originalSlider);
         }
     }
     // finish extended panel by add spacing panel (adds some more space on the bottom of the panel. i am bad at the layout stuff)
     panel.addSpacingPanel();
     panel.setMode(data.mode, false);
     _containerPanels.Add(panel);
 }
Beispiel #3
0
        /// <summary>
        /// Checks if the save file with all settings exists. If not it creates the standard save file.
        /// </summary>
        private void checkForSaveFile()
        {
            if (File.Exists(filePath + fileNameSettings)) // everything is ok, savefile from last session exists
                return;
            System.IO.Directory.CreateDirectory(filePath); // create folder

            // create save file with standard extended panels
            string[] extendedPanelName = {
                                         "ExtendedPanelElectricity",
                                         "ExtendedPanelWater",
                                         "ExtendedPanelGarbage",
                                         "ExtendedPanelHealth",
                                         "ExtendedPanelFireSafety",
                                         "ExtendedPanelCrime",
                                         "ExtendedPanelEducation",
                                         "ExtendedPanelParks",
                                         "ExtendedPanelFreetime",
                                         "ExtendedPanelTransport"
                                };
            string[] informationPanelName = {
                                               "(Library) ElectricityInfoViewPanel",
                                               "(Library) WaterInfoViewPanel",
                                               "(Library) GarbageInfoViewPanel",
                                               "(Library) HealthInfoViewPanel",
                                               "(Library) FireSafetyInfoViewPanel",
                                               "(Library) CrimeInfoViewPanel",
                                               "(Library) EducationInfoViewPanel",
                                               "(Library) HappinessInfoViewPanel",
                                               "(Library) EntertainmentInfoViewPanel",
                                               "(Library) PublicTransportInfoViewPanel"
                                            };
            string[][] sliderPanelTemplate = {
                                               new String[] {"Electricity"},
                                               new String[] {"WaterAndSewage"},
                                               new String[] {"Garbage"},
                                               new String[] {"Healthcare"},
                                               new String[] {"FireDepartment"},
                                               new String[] {"Police"},
                                               new String[] {"Education"},
                                               new String[] {"Beautification"},
                                               new String[] {"Beautification", "Monuments"},
                                               new String[] {"Bus","Metro","Train","Ship","Plane"}
                                           };

            List<BBPanelSettings> settings = new List<BBPanelSettings>();
            for (int i = 0; i < extendedPanelName.Length; i++)
            {
                BBPanelSettings panelSettings = new BBPanelSettings();
                panelSettings.name = extendedPanelName[i];
                panelSettings.slider = sliderPanelTemplate[i];
                panelSettings.informationPanel = informationPanelName[i];

                panelSettings.x = 0;
                panelSettings.y = 0;
                panelSettings.opacity = 1f;
                panelSettings.sticky = false;
                panelSettings.mode = Mode.Default;
                panelSettings.isCustom = false;
                panelSettings.isLeft = false;
                settings.Add(panelSettings);
            }

            BBPanelSettings customPanelSettings = new BBPanelSettings();
            customPanelSettings.x = 80;
            customPanelSettings.y = 80;

            BBSettings BBsettings = new BBSettings();
            BBsettings.panelSettings = settings;
            BBsettings.expenseUpdateActive = true;
            BBsettings.customPanelCreatorSettings = customPanelSettings;

            TextWriter writer = null;
            try
            {
                var serializer = new XmlSerializer(typeof(BBSettings));
                writer = new StreamWriter(filePath + fileNameSettings, false);
                serializer.Serialize(writer, BBsettings);
            }
            finally
            {
                if (writer != null)
                    writer.Close();
            }
        }
        /// <summary>
        /// Creates all objects based on the settings from last session.
        /// </summary>
        /// <param name="settings">All settings for this panel.</param>
        public void load(BBPanelSettings settings)
        {
            _settings = settings;

            // Settings
            canFocus = true;
            isInteractive = true;
            color = new Color32(255, 255, 255, 255);
            sticky = settings.sticky;
            isVisible = settings.sticky;
            opacity = settings.opacity;
            isLeft = settings.isLeft;
            isCustom = settings.isCustom;

            // Layout
            autoLayoutDirection = LayoutDirection.Vertical;
            autoLayoutStart = LayoutStart.TopLeft;
            autoLayoutPadding = new RectOffset(0, 0, 0, 5);
            autoLayout = true;
            autoSize = true;
            autoFitChildrenHorizontally = true;
            autoFitChildrenVertically = true;

            // Titlebar
            _titlebar = AddUIComponent<UIExtendedBudgetTitleBar>();
            _titlebar.Parent = this;
            _titlebar.start();

            // sliderContainer
            _sliderContainer = AddUIComponent<BBSliderContainer>();
            _sliderContainer.Parent = this;
            _sliderContainer.start();

            relativePosition = new Vector3(settings.x, settings.y);
        }
        /// <summary>
        /// Creates all objects based on the given settings. Call this first.
        /// </summary>
        /// <param name="settings">The settings (only uses x and y position).</param>
        public void start(BBPanelSettings settings)
        {
            relativePosition = new Vector3(settings.x, settings.y);
            canFocus = true;
            isInteractive = true;
            isVisible = true;
            backgroundSprite = "MenuPanel2";
            color = new Color32(255, 255, 255, 255);
            size = new Vector2(400,344);
            name = "Better Budget - Custom Panel Creator";

            UILabel label = AddUIComponent<UILabel>();
            label.text = "Custom Panel Creator";
            label.transform.parent = this.transform;
            label.relativePosition = new Vector3((width/2) - ((label.text.Length/2)*8), 12);
            label.name = "Title Label";
            UIDragHandle draghandler = AddUIComponent<UIDragHandle>();
            draghandler.relativePosition = new Vector3(0,0);
            draghandler.transform.parent = this.transform;
            draghandler.target = this;
            draghandler.name = "Drag Handler";
            // icon
            _icon = AddUIComponent<UISprite>();
            _icon.relativePosition = new Vector3(2, 2);
            _icon.spriteName = "MoneyThumb";
            _icon.size = new Vector2(40, 40);
            _icon.eventClick += togglePanel;
            _icon.BringToFront();

            // container Unselected
            _containerUnselected = AddUIComponent<UIPanel>();
            _containerUnselected.name = "Slider Container Unselected";
            _containerUnselected.backgroundSprite = "GenericPanel";
            _containerUnselected.relativePosition = new Vector3(30, 60);
            _containerUnselected.size = new Vector2(145, 145);
            _containerUnselected.autoLayout = true;
            _containerUnselected.autoSize = false;
            _containerUnselected.autoLayoutStart = LayoutStart.TopLeft;
            _containerUnselected.autoLayoutDirection = LayoutDirection.Horizontal;
            _containerUnselected.autoLayoutPadding = new RectOffset(5, 0, 5, 0);
            _containerUnselected.wrapLayout = true;

            // Arrow
            _spriteArrow = AddUIComponent<UISprite>();
            _spriteArrow.name = "Arrow Sprite";
            _spriteArrow.spriteName = "ArrowRight";
            _spriteArrow.relativePosition = new Vector3(163, 100);
            _spriteArrow.size = new Vector3(64, 64);

            // container Selected
            _containerSelected = AddUIComponent<UIPanel>();
            _containerSelected.name = "Slider Container Selected";
            _containerSelected.backgroundSprite = "GenericPanel";
            _containerSelected.relativePosition = new Vector3(225, 60);
            _containerSelected.size = new Vector2(145, 145);
            _containerSelected.autoLayout = true;
            _containerSelected.autoSize = false;
            _containerSelected.autoLayoutStart = LayoutStart.TopLeft;
            _containerSelected.autoLayoutDirection = LayoutDirection.Horizontal;
            _containerSelected.autoLayoutPadding = new RectOffset(5, 0, 5, 0);
            _containerSelected.wrapLayout = true;

            // budget icons
            for(int i = 0; i < spriteIcon.Length; i++)
            {
                UISprite sprite = _containerUnselected.AddUIComponent<UISprite>();
                sprite.name = serviceSlider[i];
                sprite.spriteName = spriteIcon[i];
                sprite.size = new Vector2(30, 30);
                sprite.eventClick += toggleSprite;
                sprite.isInteractive = true;
            }

            // text field
            _textfield = AddUIComponent<UITextField>();
            _textfield.name = "Text Field Name";
            _textfield.size = new Vector2(340,25);
            _textfield.relativePosition = new Vector3(30, 225);
            _textfield.text = "Budget";
            _textfield.enabled = true;
            _textfield.builtinKeyNavigation = true;
            _textfield.isInteractive = true;
            _textfield.readOnly = false;
            _textfield.submitOnFocusLost = true;
            _textfield.horizontalAlignment = UIHorizontalAlignment.Left;
            _textfield.selectionSprite = "EmptySprite";
            _textfield.selectionBackgroundColor = new Color32(0, 171, 234, 255);
            _textfield.normalBgSprite = "TextFieldPanel";
            _textfield.textColor = new Color32(174, 197, 211, 255);
            _textfield.disabledTextColor = new Color32(254, 254, 254, 255);
            _textfield.textScale = 1.3f;
            _textfield.opacity = 1f;
            _textfield.color = new Color32(58, 88, 104, 255);
            _textfield.disabledColor = new Color32(254, 254, 254, 255);

            // is Left toggle button and label
            _checkbox = AddUIComponent<UISprite>();
            _checkbox.name = "Checkbox";
            _checkbox.size = new Vector2(25, 25);
            _checkbox.relativePosition = new Vector3(122, 262);
            _checkbox.spriteName = "AchievementCheckedFalse";
            _checkbox.isInteractive = true;
            _checkbox.eventClick += toggleIsLeft;
            UILabel labelCheckbox = AddUIComponent<UILabel>();
            labelCheckbox.name = "Checkbox Label";
            labelCheckbox.text = "Rightsided";
            labelCheckbox.relativePosition = new Vector3(165, 263);
            labelCheckbox.textScale = 1.3f;

            // create button
            UIButton button = AddUIComponent<UIButton>();
            button.name = "Create Button";
            button.size = new Vector2(340, 30);
            button.relativePosition = new Vector3(30, 300);
            button.normalBgSprite = "ButtonMenu";
            button.focusedBgSprite = "ButtonMenuFocused";
            button.hoveredBgSprite = "ButtonMenuHovered";
            button.pressedBgSprite = "ButtonMenuPressed";
            button.text = "Create Custom Panel";
            button.textScale = 1.3f;
            button.eventClick += createPanel;

            isOpen = false;
            updateState();
        }
        /// <summary>
        /// Creates the custom panel based on the selected sliders.
        /// </summary>
        /// <param name="component">Unused</param>
        /// <param name="eventParam">Unused</param>
        private void createPanel(UIComponent component, UIMouseEventParameter eventParam)
        {
            if (_containerSelected.childCount == 0)
                return;

            BBPanelSettings settings = new BBPanelSettings();
            settings.name = _textfield.text;
            settings.x = 400;
            settings.y = 200;
            settings.opacity = 1f;
            settings.sticky = true;
            settings.mode = Mode.Default;
            settings.isCustom = true;
            if (_checkbox.spriteName.Equals("AchievementCheckedTrue"))
                settings.isLeft = true;
            else
                settings.isLeft = false;
            string[] sliderNames = new string[_containerSelected.childCount];
            for (int i = 0; i < _containerSelected.childCount; i++)
            {
                sliderNames[i] = _containerSelected.components[i].name;
            }
            settings.slider = sliderNames;
            _main.createExtendedPanel(settings);

            foreach (UIComponent sprite in _containerSelected.components.ToArray())
            {
                toggleSprite(sprite, null);
            }
            _checkbox.spriteName = "AchievementCheckedFalse";
            _spriteArrow.spriteName = "ArrowRight";
            _spriteArrow.relativePosition = new Vector3(163, 100);
            _textfield.text = "Budget";
        }