//The menu item should just perform an action, like an attack or item. public void AddMenuItemToAction(RPGMenuItemWrapper menuItemWrapper) { if (menuItemWrapper.MPCost > 0) { GameObject gO = Instantiate <GameObject>(RPGMenuItemMagicPrefab, MenuItemBackgroundHolder.transform, false); RPGMenuItemMagic magicMenuItem = gO.GetComponent <RPGMenuItemMagic>(); magicMenuItem.MPCost = menuItemWrapper.MPCost; magicMenuItem.Text = menuItemWrapper.Text; magicMenuItem.MenuOfThisItem = this; magicMenuItem.ActionToPerform = menuItemWrapper.ActionToPerform; magicMenuItem.HelpText = menuItemWrapper.HelpText; magicMenuItem.InteractType = RPGMenuItemInteractType.MenuItemAction; this.MenuItems.Add(magicMenuItem); magicMenuItem.transform.GetChild(0).GetComponent <Text>().text = menuItemWrapper.Text; magicMenuItem.transform.GetChild(2).GetComponent <Text>().text = menuItemWrapper.MPCost.ToString(); } else { GameObject gO = Instantiate <GameObject>(RPGMenuItemPrefab, MenuItemBackgroundHolder.transform, false); RPGMenuItem item = gO.GetComponent <RPGMenuItem>(); item.Text = menuItemWrapper.Text; item.MenuOfThisItem = this; item.ActionToPerform = menuItemWrapper.ActionToPerform; item.HelpText = menuItemWrapper.HelpText; item.InteractType = RPGMenuItemInteractType.MenuItemAction; this.MenuItems.Add(item); item.transform.GetChild(0).GetComponent <Text>().text = menuItemWrapper.Text; } }
public static RPGMenuItem RPMLocateByPosition(RPGMenu menu, int i) { //{ Locate the i'th element of the item list, then return its address.} //{ Error check, first off.} if (i > menu.numItem) { Crt.Write("ERROR: RPMLocateByPosition asked to find a message that doesnt exist.\n"); do { rpgtext.RPGKey(); } while (true); } RPGMenuItem a = menu.firstItem; int t = 1; if (i > 1) { for (t = 2; t <= i; ++t) { a = a.next; } } return(a); }
private void handleInput() { dbgCurrentInputMenu = this.gameObject.name; if (Input.GetKeyDown(KeyCode.Backspace)) { if (MenuSections.Count > 1) { GoBackOneSectionInCurrentWindow(); } else if (GlobalMenuListNavigation.Count > 0) //We are closing an additional dialog { CloseCurrentAndAdditionalOpenedWindows(); } } if (menuItemsGO.Count == 0) { return; } int currentIndex = selectedIndex; if (!IsHorizontalKeyboardControl) { handleUpDownControlInput(); } else { handleLeftRightControlInput(); } if (Input.GetKeyDown(KeyCode.Return)) { menuItemsGO[selectedIndex].Invoke(); } selectedIndex = Mathf.Clamp(selectedIndex, 0, menuItemsGO.Count - 1); if (selectedIndex != currentIndex) { if (selectedIndex > currentIndex) { isDownMotion = true; } else { isDownMotion = false; } updateSelected(); if (MenuType == RPGMenuType.TabMenu && ChangeTabsOnMove) { RPGMenuItem item = GetMenuItem(selectedIndex); OpenNewSection(item.MenuItemData.DynamicMenuObject); } } }
/*********** PUBLIC METHODS RELATED TO CONTENT AND DATA ************/ public void AddMenuItem(RPGMenuItemData itemData) { GameObject gO = Instantiate <GameObject>(RPGMenuItemPrefab, HostWindowCommandMenuContent.transform, false); gO.name = itemData.Text; RPGMenuItem item = gO.GetComponent <RPGMenuItem>(); item.ParentMenu = this; item.MenuItemData = itemData; //item.MenuToOpen = menuToOpen; this.menuItemsGO.Add(item); item.transform.GetChild(0).GetComponent <Text>().text = itemData.Text; //Set the text, can be safer }
//The menu item will make premade content appear in a different window. public void AddMenuItemLinkToNewWindow(string name, RPGMenu menuToOpen, string helpText = "") { GameObject gO = Instantiate <GameObject>(RPGMenuItemPrefab, MenuItemBackgroundHolder.transform, false); RPGMenuItem item = gO.GetComponent <RPGMenuItem>(); item.Text = name; item.MenuOfThisItem = this; item.MenuToOpen = menuToOpen; item.HelpText = helpText; item.InteractType = RPGMenuItemInteractType.MenuItemShowNewWindow; this.MenuItems.Add(item); item.transform.GetChild(0).GetComponent <Text>().text = name; }
public void AddMenuItemGOOnly() { //GameObject gO = PrefabUtility.InstantiatePrefab(RPGMenuItemPrefab) as GameObject; //gO.transform.SetParent(HostWindowCommandMenuContent.transform, false); GameObject gO = Instantiate <GameObject>(RPGMenuItemPrefab, HostWindowCommandMenuContent.transform, false); gO.name = "New item"; RPGMenuItem item = gO.GetComponent <RPGMenuItem>(); item.ParentMenu = this; item.MenuItemData = new RPGMenuItemData("New item", "Help text for this item"); this.menuItemsGO.Add(item); item.transform.GetChild(0).GetComponent <Text>().text = "New item"; //Set the text, can be safer }
//Content of the menu item should be renewed, in the same window. public void AddMenuItemLinkToNewContent(string name, RPGMenuWrapper menuToShowInstead, string helpText = "") { GameObject gO = Instantiate <GameObject>(RPGMenuItemPrefab, MenuItemBackgroundHolder.transform, false); RPGMenuItem item = gO.GetComponent <RPGMenuItem>(); item.Text = name; item.MenuOfThisItem = this; item.MenuToShowInstead = menuToShowInstead; item.HelpText = helpText; item.InteractType = RPGMenuItemInteractType.MenuItemRenewContent; this.MenuItems.Add(item); item.transform.GetChild(0).GetComponent <Text>().text = name; }
public static void AddRPGMenuItem(RPGMenu menu, string msg, int value, string desc) { //{Allocate memory for it.} RPGMenuItem item = new RPGMenuItem(msg, value, desc); RPGMenuItem lastItem = LastMenuItem(menu.firstItem); if (lastItem != null) { lastItem.next = item; } else { menu.firstItem = item; } //{Increment the NumItem field.} menu.numItem++; }
static RPGMenuItem LastMenuItem(RPGMenuItem item) { //{ This procedure will find the last item in the linked list.} if (item == null) { return(null); } //{ While the menu item is pointing to a next menu item, it's not the last. duh.} //{ So, move through the list until we hit a null.} while (item.next != null) { //{Check the next one.} item = item.next; } //{ We've found a MI.next = Nil. Yay! Return it.} return(item); }
public void OpenNewSection(GameObject dynamicMenu) { if (MenuType == RPGMenuType.TabMenu) { //We simply show the menu if (this.HostWindowTabControlContent != null) { this.HostWindowTabControlContent.SetActive(false); } this.HostWindowTabControlContent = dynamicMenu; this.HostWindowTabControlContent.SetActive(true); return; } //Else: we are a regular RPG menu, clear the current menu and add this new section removeMenuItems(); //Add to current stack MenuSections if (MenuSections == null) { MenuSections = new Stack <RPGMenuData>(); } //The dynamicMenu parameter is a GameObject with RPGMenuSection component residing in the scene, which we need to copy over into the current menu RPGMenuData menuData = new RPGMenuData(dynamicMenu.name); //Todo use RPGMenuSection data for (int i = 0; i < dynamicMenu.transform.childCount; i++) { GameObject child = dynamicMenu.transform.GetChild(i).gameObject; RPGMenuItem item = child.GetComponent <RPGMenuItem>(); if (item) { menuData.MenuItems.Add(item.MenuItemData); } } MenuSections.Push(menuData); //Add new menu items to current window drawCurrentMenuSection(); }
public List <string> GetMenuItemNames() { if (menuItemsGO.Count == 0) { return(new List <string>()); } List <string> itemNames = new List <string>(); menuItemsGO.ForEach(item => { if (item == null) { return; } RPGMenuItem menuItem = item.GetComponent <RPGMenuItem>(); itemNames.Add(menuItem.MenuItemData.Text); }); return(itemNames); }
/********* Other **********/ //Fill in MenuItems and the first section from what's already on the UI in the editor private void pickupUIElements() { string menuTitle = "Nameless menu"; if (MenuTitle != null) { menuTitle = MenuTitle.text; } RPGMenuData currentMenu = new RPGMenuData(menuTitle); foreach (Transform trans in HostWindowCommandMenuContent.transform) { RPGMenuItem item = trans.GetComponent <RPGMenuItem>(); if (item != null) { item.ParentMenu = this; menuItemsGO.Add(item); currentMenu.AddItem(item.MenuItemData); } } if (currentMenu.MenuItems.Count > 0) { //Add to current stack MenuSections if (MenuSections == null) { MenuSections = new Stack <RPGMenuData>(); } MenuSections.Push(currentMenu); Debug.Log("Picking up UI: " + this.gameObject.name + " and creating new section"); } else { Debug.LogError("Failed to pick up any menu items already in the menu (HostWindowCommandMenuContent). The data inside this menu might not have any RPGMenuItemData component attached?"); } }
public override void OnInspectorGUI() { serializedObject.Update(); GameObject selectedGO = Selection.activeGameObject; RPGMenuItem menuItem = selectedGO.GetComponent <RPGMenuItem>(); EditorGUILayout.LabelField("Currently editing menu item: " + selectedGO.name.ToString()); var nameString = selectedGO.GetComponent <RPGMenuItem>().MenuItemData.Text; //Update scene objects with the data selectedGO.name = nameString; if (selectedGO.transform.childCount > 0) { Text textComp = selectedGO.transform.GetChild(0).GetComponent <Text>(); if (textComp) { textComp.text = nameString; } } EditorGUILayout.PropertyField(MenuItemData); if (menuItem.MenuItemData.ItemType == MenuItemActionType.NewMenuSection && menuItem.MenuItemData.DynamicMenuObject == null) { if (GUILayout.Button("Add section")) { GameObject gO = new GameObject("New section"); gO.transform.parent = menuItem.gameObject.transform; gO.AddComponent <RPGMenuSection>(); menuItem.MenuItemData.DynamicMenuObject = gO; } } serializedObject.ApplyModifiedProperties(); }
public static void RPMSortAlpha(RPGMenu menu) { //{Given a menu, RPM, sort its items based on the alphabetical} //{order of their msg fields.} //{I should mention here that I haven't written a sorting} //{algorithm in years, and only once on a linked list (CS assignment).} //{I think this is an insertion sort... I checked on internet for} //{examples of sorting techniques, found a bunch of contradictory} //{information, and decided to just write the easiest thing that} //{would work. Since we're dealing with a relatively small number} //{of items here, speed shouldn't be that big a concern.} //{Initialize A and Sorted.} RPGMenuItem a = menu.firstItem; RPGMenuItem sorted = null; while (a != null) { RPGMenuItem b = a; //{ b is to be added to sorted} a = a.next; //{ increase A to the next item in the menu} //{ Give b's Next field a value of null.} b.next = null; //{Locate the correct position in Sorted to store b} if (sorted == null) { //{This is the trivial case- Sorted is empty.} sorted = b; } else if (string.Compare(b.msg, sorted.msg, true) < 0) { //{b should be the first element in the list.} RPGMenuItem c = sorted; sorted = b; sorted.next = c; } else { //{c and d will be used to move through Sorted.} RPGMenuItem c = sorted; RPGMenuItem d; //{Locate the last item lower than b} bool youshouldstop = false; do { d = c; c = c.next; if (c == null) { youshouldstop = true; } else if (string.Compare(b.msg, c.msg, true) < 0) { youshouldstop = true; } }while (!youshouldstop); b.next = c; d.next = b; } } menu.firstItem = sorted; }
public static void DisplayMenu(RPGMenu menu) { //{ Display the menu on the screen.} //{ Error check- make sure the menu has items in it.} if (menu.firstItem == null) { return; } //{ Check to see if the user wants a border. If so, draw it.} if (menu.borderColor != Crt.Color.Black) { //{ Draw a LovelyBox first for the menu.} rpgtext.LovelyBox(menu.borderColor, menu.x1, menu.y1, menu.x2, menu.y2); } //{ Next draw a LovelyBox for the item description, if applicable.} if (menu.dx1 > 0) { rpgtext.LovelyBox(menu.dBorColor, menu.dx1, menu.dy1, menu.dx2, menu.dy2); } //{ Display each menu item.} //{ Open an appropriately sized window and clear that area.} Crt.Window(menu.x1 + 1, menu.y1 + 1, menu.x2 - 1, menu.y2 - 1); Crt.ClrScr(); //{ Calculate the width and the height of the menu.} int width = menu.x2 - menu.x1 - 1; int height = menu.y2 - menu.y1 - 1; //{ Locate the top of the menu.} RPGMenuItem a = RPMLocateByPosition(menu, menu.topItem); for (int t = 1; t <= height; ++t) { //{ If we're at the currently selected item, highlight it.} if (((t + menu.topItem - 1) == menu.selectItem) && menu.active) { Crt.TextColor(menu.selColor); } else { Crt.TextColor(menu.itemColor); } Crt.GotoXY(1, t); Crt.Write(a.msg.Substring(0, Math.Min(width, a.msg.Length))); a = a.next; //{Check to see if we've prematurely encountered the end of the list.} if (a == null) { break; } } //{Restore the window to its regular size.} Crt.Window(1, 1, WDM.Book_WIDTH, WDM.CON_HEIGHT); //{If there's an associated Desc field, display it now.} RPMRefreshDesc(menu); }