public bool Delete(ColorSchemeObj colorScheme) { if (Database.Connect() && colorScheme != null && ColorSchemes.Count > 1) { // Query statement string sql = "DELETE FROM color_scheme WHERE id = @ID"; SqliteCommand cmd = new SqliteCommand(sql, Database.Connection); // Add Parameters to statement cmd.Parameters.Add(new SqliteParameter("ID", colorScheme.ID)); // Result int result = cmd.ExecuteNonQuery(); // Close database connection cmd.Dispose(); Database.Close(); return(result > 0); } // Close database connection Database.Close(); return(false); }
public static bool Exists(ColorSchemeObj colorScheme) { string sql = "SELECT id FROM color_scheme WHERE name = @Name AND viz_id = @Viz_ID AND id != @ID"; SqliteCommand cmd = new SqliteCommand(sql, Database.Connection); // Add Parameters to statement cmd.Parameters.Add(new SqliteParameter("Name", colorScheme.Name)); cmd.Parameters.Add(new SqliteParameter("Viz_ID", colorScheme.Visualization.ID)); cmd.Parameters.Add(new SqliteParameter("ID", colorScheme.ID)); // Exit if color scheme name already exists SqliteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { cmd.Dispose(); reader.Close(); return(true); } // Dispose command cmd.Dispose(); return(false); }
public bool Delete(GameObject gameObject, ColorSchemeObj colorScheme) { if (Delete(colorScheme)) { // Remove from interface DestroyImmediate(gameObject); // Remove from list ColorSchemes.Remove(colorScheme); // Unset active and opened color scheme if (colorScheme.Equals(Settings.Active.ColorScheme)) { Settings.Active.ColorScheme = null; } if (colorScheme.Equals(Settings.Selected.ColorScheme)) { Settings.Selected.ColorScheme = null; } return(true); } return(false); }
public void ToggleColors(ColorSchemeObj colorScheme, bool forceOpen) { // Set color scheme as active color scheme if (!forceOpen) { Settings.Selected.ColorScheme = colorScheme; } // Show or hide colors bool opened = false; foreach (ColorSchemeObj cs in ColorSchemes) { // Get GameObject for current color Transform contents = transform.Find("#" + cs.ID + "/Contents"); GameObject main = contents != null ? contents.gameObject : null; // Get arrow Text arr = transform.Find("#" + cs.ID + "/Main/Arrow").GetComponent <Text>(); // Toggle colors for GameObject if (main != null) { if (cs == colorScheme) { main.SetActive(!forceOpen ? !main.activeSelf : true); opened = main.activeSelf; } else { main.SetActive(false); if (arr.text == IconFont.DROPDOWN_OPENED) { arr.text = IconFont.DROPDOWN_CLOSED; } } } // Change arrows if (!forceOpen && cs != colorScheme) { arr.text = IconFont.DROPDOWN_CLOSED; } } // Change arrow image Text arrow = transform.Find("#" + colorScheme.ID + "/Main/Arrow").GetComponent <Text> (); if (!forceOpen && arrow != null) { arrow.text = opened ? IconFont.DROPDOWN_OPENED : IconFont.DROPDOWN_CLOSED; } // Set opened and selected color scheme Settings.Selected.ColorScheme = opened ? colorScheme : null; // Scroll to top if scrollbar is hidden ScrollToTop(); }
/** * Initializing the scene, creating a field of hexagons shaped like a triangle. **/ void Start() { Vector3 pos = new Vector3(startPos.x, startPos.y, startPos.z); for (int i = 1; i < hexNumber; i++) { if (i > 1) { pos = pos + new Vector3(0, 0, -hexHeight - gap); } for (int j = 0; j < i; j++) { if (j == 0) { pos = new Vector3(startPos.x, pos.y, pos.z); } else { pos = pos + new Vector3(hexwidth + gap, 0, 0); Instantiate(hex, pos, Quaternion.identity, Settings.MenuManager.vizContents); } } } hexes = GameObject.FindGameObjectsWithTag("Hexes"); colorScheme = Settings.Active.ColorScheme; }
/// <summary> /// Determines whether the specified <see cref="System.Object" /> is equal to the current <see cref="ColorSchemeObj" />. /// </summary> /// <param name="obj">The <see cref="System.Object" /> to compare with the current <see cref="ColorSchemeObj" />.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object" /> is equal to the current <see cref="ColorSchemeObj" />; /// otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { ColorSchemeObj rhs = (ColorSchemeObj)obj; return(rhs != null && this.Name == rhs.Name && this.Visualization.Equals(rhs.Visualization)); }
//-- DATABASE METHODS public static void Load(bool defaultOnly) { // Reset color schemes ColorSchemes = new List <ColorSchemeObj> (); // Get color schemes if (Database.Connect() && Settings.Selected.Visualization != null && Settings.Selected.Visualization.ID > 0 && Application.CanStreamedLevelBeLoaded(Settings.Selected.Visualization.BuildNumber)) { // Database command SqliteCommand cmd = new SqliteCommand(Database.Connection); // Query statement string sql = "SELECT id,name,viz_id,colors FROM color_scheme WHERE viz_id = @Viz_ID " + (defaultOnly ? "AND name = @Name " : "") + "ORDER BY name ASC"; cmd.CommandText = sql; // Add Parameters to statement cmd.Parameters.Add(new SqliteParameter("Viz_ID", Settings.Selected.Visualization.ID)); if (defaultOnly) { cmd.Parameters.Add(new SqliteParameter("Name", Settings.Selected.Visualization.Name)); } // Get sql results SqliteDataReader reader = cmd.ExecuteReader(); // Read sql results while (reader.Read()) { // Create color scheme object ColorSchemeObj obj = new ColorSchemeObj(reader.GetString(1)); // Set values obj.ID = reader.GetInt64(0); obj.Visualization = Visualization.GetVisualization(reader.GetInt64(2), false); obj.Colors = GetColors(reader.GetString(3)); // Add color scheme to colorSchemes array ColorSchemes.Add(obj); } // Close reader reader.Close(); cmd.Dispose(); // Close database connection Database.Close(); } }
public void UpdateColor(ColorSchemeObj colorScheme, int id, Color color) { if (colorScheme != null && colorScheme.Colors.Length >= id + 1) { // Set color colorScheme.Colors [id] = color; // Change image GameObject.Find("#" + colorScheme.ID + "." + id).GetComponent <Image> ().color = color; // Edit color scheme in database Edit(colorScheme); } }
public long NewColorScheme(string name) { if (name.Length > 0) { // Create color scheme object ColorSchemeObj colorScheme = new ColorSchemeObj(name, Settings.Selected.Visualization); // Create object in database long id = Create(colorScheme); // Reload playlists if (id > 0) { Load(false); Display(); } return(id); } return((long)Database.Constants.EmptyInputValue); }
public long Edit(ColorSchemeObj colorScheme) { if (Database.Connect() && colorScheme != null && colorScheme.Name.Length > 0) { if (!Exists(colorScheme)) { // Query statement string sql = "UPDATE color_scheme SET name = @Name, viz_id = @Viz_ID, colors = @Colors WHERE id = @ID"; SqliteCommand cmd = new SqliteCommand(sql, Database.Connection); // Add Parameters to statement cmd.Parameters.Add(new SqliteParameter("Name", colorScheme.Name)); cmd.Parameters.Add(new SqliteParameter("Viz_ID", colorScheme.Visualization.ID)); cmd.Parameters.Add(new SqliteParameter("Colors", FormatColors(colorScheme.Colors))); cmd.Parameters.Add(new SqliteParameter("ID", colorScheme.ID)); // Result int result = cmd.ExecuteNonQuery(); // Close database connection cmd.Dispose(); Database.Close(); return((long)(result > 0 ? Database.Constants.Successful : Database.Constants.QueryFailed)); } // Close database connection Database.Close(); return((long)Database.Constants.DuplicateFound); } // Close database connection Database.Close(); return((long)(colorScheme.Name.Length > 0 ? Database.Constants.QueryFailed : Database.Constants.EmptyInputValue)); }
public long Create(ColorSchemeObj colorScheme) { if (Database.Connect() && colorScheme != null && colorScheme.Name.Length > 0) { if (!Exists(colorScheme)) { // Insert color scheme into database string sql = "INSERT INTO color_scheme (name,viz_id,colors) VALUES (@Name, @Viz_ID, @Colors); " + "SELECT last_insert_rowid()"; SqliteCommand cmd = new SqliteCommand(sql, Database.Connection); // Add Parameters to statement cmd.Parameters.Add(new SqliteParameter("Name", colorScheme.Name)); cmd.Parameters.Add(new SqliteParameter("Viz_ID", colorScheme.Visualization.ID)); cmd.Parameters.Add(new SqliteParameter("Colors", FormatColors(colorScheme.Colors))); // Execute insert statement and get ID long id = (long)cmd.ExecuteScalar(); // Close database connection cmd.Dispose(); Database.Close(); return(id); } // Close database connection Database.Close(); return((long)Database.Constants.DuplicateFound); } // Close database connection Database.Close(); return((long)Database.Constants.QueryFailed); }
public void ShowDialog(string type, GameObject obj) { if (Dialog != null) { // Color scheme object ColorSchemeObj colorScheme = FindColorScheme(obj); // Button Button button = Dialog.ButtonOK; Text buttonText = Dialog.GetButtonText(); // Remove listener button.onClick.RemoveAllListeners(); switch (type) { // New color scheme case "CS_ADD": if (Settings.Selected.Visualization != null) { // UI elements Dialog.SetHeading(Settings.MenuManager.LangManager.getString("newColor")); Dialog.SetInputField("", Settings.MenuManager.LangManager.getString("nameColor")); // Events button.onClick.AddListener(delegate { long id = NewColorScheme(Dialog.GetInputText()); switch (id) { // Color scheme name already taken case (long)Database.Constants.DuplicateFound: Dialog.SetInfo(Settings.MenuManager.LangManager.getString("existsColor")); break; // Database query failed case (long)Database.Constants.QueryFailed: Dialog.SetInfo(Settings.MenuManager.LangManager.getString("noColor")); break; // No user input case (long)Database.Constants.EmptyInputValue: Dialog.SetInfo(Settings.MenuManager.LangManager.getString("nameColor")); break; default: Dialog.HideDialog(); break; } }); } else { print(Settings.MenuManager.LangManager); Dialog.ShowDialog( Settings.MenuManager.LangManager.getString("noChosenColor"), Settings.MenuManager.LangManager.getString("chooseColor") ); } break; // Edit color scheme case "CS_EDIT": if (colorScheme != null) { // UI elements Dialog.SetHeading(Settings.MenuManager.LangManager.getString("editColor")); Dialog.SetInputField(colorScheme.Name, colorScheme.Name); // Events button.onClick.AddListener(delegate { // Update color scheme objects if (Settings.Active.ColorScheme != null && Settings.Active.ColorScheme.Equals(colorScheme)) { Settings.Active.ColorScheme.Name = Dialog.GetInputText(); } colorScheme.Name = Dialog.GetInputText(); // Update database long result = Edit(colorScheme); // Handle database result switch (result) { // Color scheme name already taken case (long)Database.Constants.DuplicateFound: Dialog.SetInfo(Settings.MenuManager.LangManager.getString("existsColor")); break; // Database query failed case (long)Database.Constants.QueryFailed: Dialog.SetInfo(Settings.MenuManager.LangManager.getString("noEditColor")); break; // No user input case (long)Database.Constants.EmptyInputValue: Dialog.SetInfo(Settings.MenuManager.LangManager.getString("nameColor")); break; default: Load(false); Display(); Dialog.HideDialog(); break; } }); } else { return; } break; // Delete color scheme case "CS_DEL": if (colorScheme != null) { // UI elements Dialog.SetHeading(Settings.MenuManager.LangManager.getString("deleteColor")); Dialog.SetText(Settings.MenuManager.LangManager.getString("sureDelete")); // Events button.onClick.AddListener(delegate { Delete(obj, colorScheme); Load(false); Display(); Dialog.HideDialog(); }); } else { return; } break; default: return; } // Show dialog Dialog.dialog.SetActive(true); return; } return; }
public void ToggleColors(ColorSchemeObj colorScheme) { ToggleColors(colorScheme, false); }
public void DisplayColor(ColorSchemeObj colorScheme, Color color, int id) { if (colorScheme != null) { // Get Contents GameObject GameObject contents = transform.Find("#" + colorScheme.ID + "/Contents").gameObject; // Create Image GameObject GameObject image = new GameObject("#" + colorScheme.ID + "." + id); image.transform.SetParent(contents.transform); // Add image Image img = image.AddComponent <Image> (); img.color = color; if (colorScheme.Name != Settings.Selected.Visualization.Name) { // Add Event Trigger EventTrigger trigger = image.AddComponent <EventTrigger> (); // Add Click Event EventTrigger.Entry evtClick = new EventTrigger.Entry(); evtClick.eventID = EventTriggerType.PointerClick; trigger.triggers.Add(evtClick); evtClick.callback.AddListener((eventData) => { // Set active color ActiveColor = image; ActiveColorID = id; // Set current color PickerObj.CurrentColor = colorScheme.Colors [id]; // Show color picker ColorPicker.SetActive(true); }); } else { // Create Overlay GameObject GameObject overlay = new GameObject("Overlay"); overlay.transform.SetParent(image.transform); // Add RectTransform RectTransform trans = overlay.AddComponent <RectTransform> (); trans.anchorMin = Vector2.zero; trans.anchorMax = Vector2.one; trans.offsetMin = Vector2.zero; trans.offsetMax = Vector2.zero; // Add Image Image overlayImg = overlay.AddComponent <Image> (); overlayImg.color = new Color(0, 0, 0, 0.5f); // Create Text GameObject GameObject text = new GameObject("Text"); text.transform.SetParent(overlay.transform); // Add RectTransform RectTransform textTrans = text.AddComponent <RectTransform> (); textTrans.anchorMin = Vector2.zero; textTrans.anchorMax = Vector2.one; textTrans.offsetMin = Vector2.zero; textTrans.offsetMax = Vector2.zero; // Add Text TextUnicode textText = text.AddComponent <TextUnicode> (); textText.text = IconFont.LOCK; textText.color = Color.white; textText.font = IconFont.font; textText.fontSize = 24; textText.alignment = TextAnchor.MiddleCenter; } } }
public GameObject DisplayColorScheme(ColorSchemeObj colorScheme) { if (colorScheme != null) { string name = "#" + colorScheme.ID; // Create GameOject GameObject gameObject = new GameObject(name); gameObject.transform.SetParent(transform); // Create main GameObject GameObject main = new GameObject("Main"); main.transform.SetParent(gameObject.transform); // Add Vertical Layout Group VerticalLayoutGroup vlg = gameObject.AddComponent <VerticalLayoutGroup> (); vlg.spacing = 20; vlg.childForceExpandWidth = true; vlg.childForceExpandHeight = false; // Add Layout Element to GameObject LayoutElement mainLayout = main.AddComponent <LayoutElement> (); mainLayout.minHeight = 30; mainLayout.preferredHeight = mainLayout.minHeight; // Add image to GameObject Image mainImg = main.AddComponent <Image> (); mainImg.color = Color.clear; // Set transformations mainImg.rectTransform.pivot = new Vector2(0, 0.5f); // Add Horizontal Layout Group HorizontalLayoutGroup mainHlg = main.AddComponent <HorizontalLayoutGroup> (); mainHlg.spacing = 10; mainHlg.childForceExpandWidth = false; mainHlg.childForceExpandHeight = false; mainHlg.childAlignment = TextAnchor.MiddleLeft; // Set padding right of Horizontal Layout Group mainHlg.padding = new RectOffset(0, 65, 0, 0); // Create arrow text GameObject GameObject mainArrow = new GameObject("Arrow"); mainArrow.transform.SetParent(main.transform); // Add text TextUnicode mainTextArrow = mainArrow.AddComponent <TextUnicode> (); mainTextArrow.text = colorScheme.Equals(Settings.Selected.ColorScheme) ? IconFont.DROPDOWN_OPENED : IconFont.DROPDOWN_CLOSED; // Set text alignment mainTextArrow.alignment = TextAnchor.MiddleLeft; // Font settings mainTextArrow.font = IconFont.font; mainTextArrow.fontSize = 20; // Add Layout Element LayoutElement mainLayoutElementArrow = mainArrow.AddComponent <LayoutElement> (); mainLayoutElementArrow.minWidth = 22; // Create text GameObject GameObject mainText = new GameObject("Text"); mainText.transform.SetParent(main.transform); // Add text Text text = mainText.AddComponent <Text> (); text.text = colorScheme.Name; if (colorScheme.Name == Settings.Selected.Visualization.Name) { text.text += " (Standard)"; } // Set text alignment text.alignment = TextAnchor.MiddleLeft; // Set text color text.color = Color.white; // Font settings text.font = Resources.Load <Font> ("Fonts/FuturaStd-Book"); text.fontSize = 30; // Set transformations text.rectTransform.pivot = new Vector2(0.5f, 0.5f); // Add button Button buttonText = mainText.AddComponent <Button> (); buttonText.transition = Selectable.Transition.Animation; // Add Event to Button buttonText.onClick.AddListener(delegate { ToggleColors(colorScheme); }); // Add animator Animator animatorText = mainText.AddComponent <Animator> (); animatorText.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController> ("Animations/MenuButtons"); // Create active text GameObject GameObject mainActive = new GameObject("Active"); mainActive.transform.SetParent(main.transform); // Add text TextUnicode mainTextActive = mainActive.AddComponent <TextUnicode> (); if (colorScheme.Equals(Settings.Active.ColorScheme)) { mainTextActive.text = IconFont.VISUALIZATION; mainTextActive.fontSize = 30; mainTextActive.color = new Color(0.7f, 0.7f, 0.7f); } // Set text alignment mainTextActive.alignment = TextAnchor.MiddleRight; // Font settings mainTextActive.font = IconFont.font; // Add Layout Element LayoutElement mainLayoutElementListening = mainActive.AddComponent <LayoutElement> (); mainLayoutElementListening.preferredWidth = 40; if (colorScheme.Name != Settings.Selected.Visualization.Name) { // Create edit icons GameObject GameObject editIcons = new GameObject("Images"); editIcons.transform.SetParent(main.transform); // Set transformations RectTransform editIconsTrans = editIcons.AddComponent <RectTransform> (); editIconsTrans.anchoredPosition = Vector2.zero; editIconsTrans.anchorMin = new Vector2(1, 0.5f); editIconsTrans.anchorMax = new Vector2(1, 0.5f); editIconsTrans.pivot = new Vector2(1, 0.5f); // Add Layout Element LayoutElement editIconslayoutElement = editIcons.AddComponent <LayoutElement> (); editIconslayoutElement.ignoreLayout = true; // Add Content Size Fitter ContentSizeFitter editIconsCsf = editIcons.AddComponent <ContentSizeFitter> (); editIconsCsf.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; editIconsCsf.verticalFit = ContentSizeFitter.FitMode.PreferredSize; // Add Layout Group HorizontalLayoutGroup editIconsHlgImg = editIcons.AddComponent <HorizontalLayoutGroup> (); editIconsHlgImg.childAlignment = TextAnchor.MiddleRight; editIconsHlgImg.spacing = 5; editIconsHlgImg.childForceExpandWidth = false; editIconsHlgImg.childForceExpandHeight = false; // Disable edit icons GameObject editIcons.SetActive(false); // Create edit text GameObject GameObject edit = new GameObject("Edit"); edit.transform.SetParent(editIcons.transform); // Add text TextUnicode editText = edit.AddComponent <TextUnicode> (); editText.text = IconFont.EDIT; // Set text alignment editText.alignment = TextAnchor.MiddleRight; // Set transformations editText.rectTransform.sizeDelta = new Vector2(20, 30); // Font settings editText.font = IconFont.font; editText.fontSize = 30; // Add button Button buttonEditEvt = edit.AddComponent <Button> (); buttonEditEvt.transition = Selectable.Transition.Animation; // Add button onclick event buttonEditEvt.onClick.AddListener(delegate { ShowDialog("CS_EDIT", gameObject); }); // Add animator Animator animatorEditEvt = edit.AddComponent <Animator> (); animatorEditEvt.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController> ("Animations/MenuButtons"); // Create delete text GameObject GameObject delete = new GameObject("Delete"); delete.transform.SetParent(editIcons.transform); // Add text Text deleteText = delete.AddComponent <Text> (); deleteText.text = IconFont.TRASH; // Set text alignment deleteText.alignment = TextAnchor.MiddleRight; // Set transformations deleteText.rectTransform.sizeDelta = new Vector2(20, 30); // Font settings deleteText.font = IconFont.font; deleteText.fontSize = 30; // Add button Button buttonDeleteEvt = delete.AddComponent <Button> (); buttonDeleteEvt.transition = Selectable.Transition.Animation; // Add button onclick event buttonDeleteEvt.onClick.AddListener(delegate { ShowDialog("CS_DEL", gameObject); }); // Add animator Animator animatorDeleteEvt = delete.AddComponent <Animator> (); animatorDeleteEvt.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController> ("Animations/MenuButtons"); // Create GameObject Event Triggers EventTrigger evtWrapper = gameObject.AddComponent <EventTrigger> (); // Add Hover Enter Event EventTrigger.Entry evtHover = new EventTrigger.Entry(); evtHover.eventID = EventTriggerType.PointerEnter; evtWrapper.triggers.Add(evtHover); evtHover.callback.AddListener((eventData) => { editIcons.SetActive(true); }); // Add Hover Exit Event EventTrigger.Entry evtExit = new EventTrigger.Entry(); evtExit.eventID = EventTriggerType.PointerExit; evtWrapper.triggers.Add(evtExit); evtExit.callback.AddListener((eventData) => { editIcons.SetActive(false); }); } // Add Event Trigger EventTrigger evtMain = main.AddComponent <EventTrigger> (); // Add Click Event EventTrigger.Entry evtClick = new EventTrigger.Entry(); evtClick.eventID = EventTriggerType.PointerClick; evtMain.triggers.Add(evtClick); evtClick.callback.AddListener((eventData) => { ToggleColors(colorScheme); }); // Add Contents GameObject GameObject contents = new GameObject("Contents"); contents.transform.SetParent(gameObject.transform); // Add Grid Layout Group GridLayoutGroup glg = contents.AddComponent <GridLayoutGroup> (); // Set Grid Layout glg.cellSize = new Vector2(53.5f, 53.5f); glg.spacing = new Vector2(25, 25); glg.constraint = GridLayoutGroup.Constraint.FixedColumnCount; glg.constraintCount = 10; return(gameObject); } return(null); }