public void beforeEach() { ctxHelper = new CtxHelper(); ctx = ctxHelper.sharedCtx; userDao = new UserDAO(ctxHelper.sharedCtx); ctxHelper.seed(getDefaultSeed()).Wait(); }
/// <summary> /// Sets the disabled state for the specified menu item. /// </summary> /// <param name='id'> /// The menu item id number. /// </param> /// <param name='isDisabled'> /// The desired disable state. /// </param> public void SetDisabled(int id, bool isDisabled) { CtxHelper.SetDisabled(menuItems, id, isDisabled); if (contextMenu != null) { contextMenu.UpdateVisibleState(); } }
public void OnShowMenu(CtxObject obj) { if (menuItems == null) { int cnt = (int)MenuItemID.Count; menuItems = new CtxMenu.Item[cnt]; for (int i = 0; i < cnt; i++) { MenuItemID itemID = (MenuItemID)i; menuItems[i] = new CtxMenu.Item(); menuItems[i].text = ItemText(itemID); if (menuItems[i].text.StartsWith("Separator")) { menuItems[i].isSeparator = true; } else { menuItems[i].id = i; } } menuItems[(int)MenuItemID.Small].isCheckable = true; menuItems[(int)MenuItemID.Medium].isCheckable = true; menuItems[(int)MenuItemID.Large].isCheckable = true; menuItems[(int)MenuItemID.Small].mutexGroup = 0; menuItems[(int)MenuItemID.Medium].mutexGroup = 0; menuItems[(int)MenuItemID.Large].mutexGroup = 0; menuItems[(int)MenuItemID.Stealth].isCheckable = true; menuItems[(int)MenuItemID.Shield].isCheckable = true; } if (transform.localScale.x == 1f) { CtxHelper.SetChecked(menuItems, (int)MenuItemID.Small, true); } else if (transform.localScale.x == 2f) { CtxHelper.SetChecked(menuItems, (int)MenuItemID.Medium, true); } else { CtxHelper.SetChecked(menuItems, (int)MenuItemID.Large, true); } menuItems[(int)MenuItemID.Stealth].isChecked = stealthOn; menuItems[(int)MenuItemID.Shield].isChecked = shieldOn; obj.menuItems = menuItems; }
void OnPress(bool isPressed) { // Filter for touches or selected mouse button. if (UICamera.currentTouchID >= 0 || UICamera.currentTouchID == (-1 - mouseButton)) { // We show the menu on the up-press not the down-press. Otherwise NGUI would steal // the selection state from the context menu on the up-press, causing the menu to // close immediately. if (!isPressed) { current = this; EventDelegate.Execute(onShow); Vector3 menuPosition = placeAtTouchPosition ? new Vector3(UICamera.currentTouch.pos.x, UICamera.currentTouch.pos.y, 0f) : CtxHelper.ComputeMenuPosition(contextMenu, gameObject); CtxMenu.Item[] items = MenuItems; if (items != null || contextMenu.onShow.Count > 0) { EventDelegate.Add(contextMenu.onSelection, OnMenuSelection); EventDelegate.Add(contextMenu.onHide, OnHide, true); if (menuItems != null && menuItems.Length > 0) { contextMenu.Show(menuPosition, menuItems); } else { contextMenu.Show(menuPosition); } } } } }
void OnPress(bool isPressed) { if (isPressed) { // We compute the menu position on the down-press. Why? Because // UIButtonScale and UIButtonOffset will distort the button's transform // and throw off our calculations if we do it on the up-press. We don't // want to not support those NGUI features, so... menuPosition = CtxHelper.ComputeMenuPosition(contextMenu, gameObject); } else if (enabled && contextMenu != null) { current = this; if (onShow != null) { EventDelegate.Execute(onShow); } CtxMenu.Item[] items = MenuItems; if (items != null || contextMenu.onShow != null) { EventDelegate.Add(contextMenu.onSelection, OnMenuSelection); EventDelegate.Add(contextMenu.onHide, OnHide, true); if (menuItems != null && menuItems.Length > 0) { contextMenu.Show(menuPosition, menuItems); } else { contextMenu.Show(menuPosition); } } } }
public void afterEach() { ctxHelper.Dispose(); ctxHelper = null; }
/// <summary> /// Retrieve the menu item descriptor with the specified id. If this menu has /// submenus, the search will recurse into the child menus after searching all /// of the items in the current menu. /// </summary> /// <returns> /// The menu item descriptor instance. /// </returns> /// <param name='id'> /// The menu item id number. /// </param> public CtxMenu.Item FindItemRecursively(int id) { return(CtxHelper.FindItemRecursively(menuItems, id)); }
/// <summary> /// Retrieve the menu item descriptor with the specified id. /// </summary> /// <returns> /// The menu item descriptor instance. /// </returns> /// <param name='id'> /// The menu item id number. /// </param> public CtxMenu.Item FindItem(int id) { return(CtxHelper.FindItem(menuItems, id)); }
/// <summary> /// Retrieve the name of the icon sprite displayed by this menu item. /// </summary> /// <returns> /// The icon sprite name. /// </returns> /// <param name='id'> /// The menu item id number. /// </param> public string GetIcon(int id) { return(CtxHelper.GetIcon(menuItems, id)); }
/// <summary> /// Assign a new icon sprite to this menu item. /// </summary> /// <param name='id'> /// The menu item id number. /// </param> /// <param name='icon'> /// The name of the sprite to assign. Note that the sprite must be in the atlas /// used by this context menu. Refer to the NGUI documentation for more information. /// </param> public void SetIcon(int id, string icon) { CtxHelper.SetIcon(menuItems, id, icon); }
/// <summary> /// Retrieves the text string displayed by this menu item. /// </summary> /// <returns> /// The text. /// </returns> /// <param name='id'> /// The menu item id number. /// </param> public string GetText(int id) { return(CtxHelper.GetText(menuItems, id)); }
/// <summary> /// Assigns a new text string to the specified menu item. If this is a localized /// menu, you should only assign key strings and allow the localization /// logic to update the visible text. /// </summary> /// <param name='id'> /// The menu item id number. /// </param> /// <param name='text'> /// The text that will be displayed for this menu item. /// </param> public void SetText(int id, string text) { CtxHelper.SetText(menuItems, id, text); }
/// <summary> /// Determines whether the specified menu item is disabled. /// </summary> /// <returns> /// <c>true</c> if the specified menu item is disabled; otherwise, <c>false</c>. /// </returns> /// <param name='id'> /// The menu item id number. /// </param> public bool IsDisabled(int id) { return(CtxHelper.IsDisabled(menuItems, id)); }
/// <summary> /// Determines whether the item with the specified id number is checked. /// </summary> /// <returns> /// <c>true</c> if the item with the specified id number is checked; otherwise, <c>false</c>. /// </returns> /// <param name='id'> /// The menu item id number. /// </param> public bool IsChecked(int id) { return(CtxHelper.IsChecked(menuItems, id)); }
public override void OnInspectorGUI() { contextMenu = target as CtxMenu; EditorGUIUtility.labelWidth = 80f; ComponentSelector.Draw <UIAtlas>(contextMenu.atlas, OnSelectAtlas, false, GUILayout.Width(140f)); //if (NGUIEditorTools.DrawPrefixButton("Atlas")) // ComponentSelector.Show<UIAtlas>(OnSelectAtlas); EditorGUILayout.BeginHorizontal(); CtxMenu.Style style = (CtxMenu.Style)EditorGUILayout.EnumPopup("Style", contextMenu.style, GUILayout.Width(180f)); if (contextMenu.style != style) { RegisterUndo(); contextMenu.style = style; if (style == CtxMenu.Style.Pie) { if (contextMenu.menuBar) { contextMenu.menuBar = false; CtxHelper.DestroyAllChildren(contextMenu.transform); UIPanel panel = NGUITools.FindInParents <UIPanel>(contextMenu.gameObject); if (panel != null) { panel.Refresh(); } refresh = false; } } } if (contextMenu.style != CtxMenu.Style.Pie) { GUILayout.Space(32f); bool menuBar = EditorGUILayout.Toggle("Menu Bar", contextMenu.menuBar); if (contextMenu.menuBar != menuBar) { RegisterUndo(); contextMenu.menuBar = menuBar; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (contextMenu.style != CtxMenu.Style.Pie) { UIWidget.Pivot pivot = (UIWidget.Pivot)EditorGUILayout.EnumPopup("Pivot", contextMenu.pivot, GUILayout.Width(180f)); if (contextMenu.pivot != pivot) { RegisterUndo(); contextMenu.pivot = pivot; } GUILayout.Space(32f); } bool isLocalized = EditorGUILayout.Toggle("Localized", contextMenu.isLocalized); if (contextMenu.isLocalized != isLocalized) { RegisterUndo(); contextMenu.isLocalized = isLocalized; } EditorGUILayout.EndHorizontal(); Vector2 padding = CompactVector2Field("Padding", contextMenu.padding); //EditorGUILayout.Vector2Field("Padding", contextMenu.padding); if (contextMenu.padding != padding) { RegisterUndo(); contextMenu.padding = padding; } EditorGUIUtility.labelWidth = 100f; NGUIEditorTools.DrawEvents("On Selection", contextMenu, contextMenu.onSelection); NGUIEditorTools.DrawEvents("On Show", contextMenu, contextMenu.onShow); NGUIEditorTools.DrawEvents("On Hide", contextMenu, contextMenu.onHide); EditorGUILayout.Space(); EditorGUIUtility.labelWidth = 80f; Rect box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditBackground, "Background Options:")) { contextMenu.backgroundSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.backgroundSprite, OnBackground); Color backgroundColor = EditorGUILayout.ColorField("Normal", contextMenu.backgroundColor); if (contextMenu.backgroundColor != backgroundColor) { RegisterUndo(); contextMenu.backgroundColor = backgroundColor; } Color highlightedColor, disabledColor; if (contextMenu.style == CtxMenu.Style.Pie) { highlightedColor = EditorGUILayout.ColorField("Highlighted", contextMenu.backgroundColorSelected); if (contextMenu.backgroundColorSelected != highlightedColor) { RegisterUndo(); contextMenu.backgroundColorSelected = highlightedColor; } disabledColor = EditorGUILayout.ColorField("Disabled", contextMenu.backgroundColorDisabled); if (contextMenu.backgroundColorDisabled != disabledColor) { RegisterUndo(); contextMenu.backgroundColorDisabled = disabledColor; } } GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); if (contextMenu.style == CtxMenu.Style.Pie) { EditorGUIUtility.labelWidth = 100f; box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditPie, "Pie Menu Options:")) { GUILayout.Space(4f); float pieRadius = EditorGUILayout.FloatField("Radius", contextMenu.pieRadius); if (contextMenu.pieRadius != pieRadius) { RegisterUndo(); contextMenu.pieRadius = pieRadius; } float pieStartingAngle = EditorGUILayout.FloatField("Starting Angle", contextMenu.pieStartingAngle); if (contextMenu.pieStartingAngle != pieStartingAngle) { RegisterUndo(); contextMenu.pieStartingAngle = pieStartingAngle; } float pieArc = EditorGUILayout.FloatField("Placement Arc", contextMenu.pieArc); if (contextMenu.pieArc != pieArc) { RegisterUndo(); contextMenu.pieArc = pieArc; } bool pieCenterItem = EditorGUILayout.Toggle("Center Items", contextMenu.pieCenterItem); if (contextMenu.pieCenterItem != pieCenterItem) { RegisterUndo(); contextMenu.pieCenterItem = pieCenterItem; } GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUIUtility.labelWidth = 80f; } else { box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditHighlight, "Highlight Options:")) { GUILayout.Space(4f); contextMenu.highlightSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.highlightSprite, OnHighlight); Color highlightColor = EditorGUILayout.ColorField("Color", contextMenu.highlightColor); if (contextMenu.highlightColor != highlightColor) { RegisterUndo(); contextMenu.highlightColor = highlightColor; } GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditText, "Text Options:")) { GUILayout.Space(4f); ComponentSelector.Draw <UIFont>(contextMenu.font, OnSelectFont, false, GUILayout.Width(140f)); if (contextMenu.font == null) { EditorGUILayout.HelpBox("Warning: please select a valid font if you want this menu to behave correctly.", MessageType.Warning); } float labelScale = EditorGUILayout.FloatField("Scale", contextMenu.labelScale); if (contextMenu.labelScale != labelScale) { RegisterUndo(); contextMenu.labelScale = labelScale; } Color normalColor = EditorGUILayout.ColorField("Normal", contextMenu.labelColorNormal); if (contextMenu.labelColorNormal != normalColor) { RegisterUndo(); contextMenu.labelColorNormal = normalColor; } Color highlightedColor = EditorGUILayout.ColorField("Highlighted", contextMenu.labelColorSelected); if (contextMenu.labelColorSelected != highlightedColor) { RegisterUndo(); contextMenu.labelColorSelected = highlightedColor; } Color disabledColor = EditorGUILayout.ColorField("Disabled", contextMenu.labelColorDisabled); if (contextMenu.labelColorDisabled != disabledColor) { RegisterUndo(); contextMenu.labelColorDisabled = disabledColor; } GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditCheckmark, "Checkmark Options:")) { GUILayout.Space(4f); contextMenu.checkmarkSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.checkmarkSprite, OnCheckmark); Color checkmarkColor = EditorGUILayout.ColorField("Color", contextMenu.checkmarkColor); if (contextMenu.checkmarkColor != checkmarkColor) { RegisterUndo(); contextMenu.checkmarkColor = checkmarkColor; } GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditSubmenu, "Submenu Options:")) { GUILayout.Space(4f); contextMenu.submenuIndicatorSprite = EditSprite(contextMenu.atlas, "Indicator", contextMenu.submenuIndicatorSprite, OnSubmenuIndicator); Color submenuIndColor = EditorGUILayout.ColorField("Color", contextMenu.submenuIndicatorColor); if (contextMenu.submenuIndicatorColor != submenuIndColor) { RegisterUndo(); contextMenu.submenuIndicatorColor = submenuIndColor; } GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); if (contextMenu.style != CtxMenu.Style.Pie) { box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditSeparator, "Separator Options:")) { GUILayout.Space(4f); contextMenu.separatorSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.separatorSprite, OnSeparator); Color separatorColor = EditorGUILayout.ColorField("Color", contextMenu.separatorColor); if (contextMenu.separatorColor != separatorColor) { RegisterUndo(); contextMenu.separatorColor = separatorColor; } GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } if (!contextMenu.menuBar) { box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditAnimation, "Animation Options:")) { bool isAnimated = EditorGUILayout.Toggle("Animated", contextMenu.isAnimated); if (contextMenu.isAnimated != isAnimated) { RegisterUndo(); contextMenu.isAnimated = isAnimated; } float animationDuration = EditorGUILayout.FloatField("Duration", contextMenu.animationDuration); if (contextMenu.animationDuration != animationDuration) { RegisterUndo(); contextMenu.animationDuration = animationDuration; } EditorGUIUtility.labelWidth = 100f; CtxMenu.GrowDirection growDirection = (CtxMenu.GrowDirection)EditorGUILayout.EnumPopup("Grow Direction", contextMenu.growDirection, GUILayout.Width(192f)); if (contextMenu.growDirection != growDirection) { RegisterUndo(); contextMenu.growDirection = growDirection; } GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditShadow, "Shadow Options:")) { contextMenu.shadowSprite = EditSprite(contextMenu.atlas, "Sprite", contextMenu.shadowSprite, OnShadow); Color shadowColor = EditorGUILayout.ColorField("Color", contextMenu.shadowColor); if (contextMenu.shadowColor != shadowColor) { RegisterUndo(); contextMenu.shadowColor = shadowColor; } Vector2 shadowOffset = CompactVector2Field("Offset", contextMenu.shadowOffset); if (shadowOffset != contextMenu.shadowOffset) { RegisterUndo(); contextMenu.shadowOffset = shadowOffset; } Vector2 shadowSizeDelta = CompactVector2Field("Size +/-", contextMenu.shadowSizeDelta); if (shadowSizeDelta != contextMenu.shadowSizeDelta) { RegisterUndo(); contextMenu.shadowSizeDelta = shadowSizeDelta; } GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); box = EditorGUILayout.BeginVertical(); GUI.Box(box, ""); if (EditorFoldout(Flags.EditAudio, "Audio Options:")) { GUILayout.Space(4f); EditorGUIUtility.labelWidth = 70f; EditorGUILayout.BeginHorizontal(); AudioClip showSound = EditorGUILayout.ObjectField("Show", contextMenu.showSound, typeof(AudioClip), false) as AudioClip; if (contextMenu.showSound != showSound) { RegisterUndo(); contextMenu.showSound = showSound; } GUILayout.Space(20f); AudioClip hideSound = EditorGUILayout.ObjectField("Hide", contextMenu.hideSound, typeof(AudioClip), false) as AudioClip; if (contextMenu.hideSound != hideSound) { RegisterUndo(); contextMenu.hideSound = hideSound; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); AudioClip highlightSound = EditorGUILayout.ObjectField("Highlight", contextMenu.highlightSound, typeof(AudioClip), false) as AudioClip; if (contextMenu.highlightSound != highlightSound) { RegisterUndo(); contextMenu.highlightSound = highlightSound; } GUILayout.Space(20f); AudioClip selectSound = EditorGUILayout.ObjectField("Select", contextMenu.selectSound, typeof(AudioClip), false) as AudioClip; if (contextMenu.selectSound != selectSound) { RegisterUndo(); contextMenu.selectSound = selectSound; } EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = 100f; GUILayout.Space(4f); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); bool isEditingItems = IsEditing(Flags.EditItems); EditMenuItemList(ref contextMenu.items, contextMenu.atlas, true, ref isEditingItems); SetEditing(Flags.EditItems, isEditingItems); if (refresh) { if (contextMenu.menuBar) { contextMenu.Refresh(); } refresh = false; } // How to tell if undo or redo have been hit: else if (contextMenu.menuBar && Event.current.type == EventType.ValidateCommand && (Event.current.commandName == "UndoRedoPerformed")) { contextMenu.Refresh(); } }