public void Refresh() { if (Items.Count == 0) { Populate(); } else { Item selectionItem = Selection.Item; List <Item> combineItems = CombineSelections.Select(x => x.Item).ToList(); Populate(); var newSelection = GetIndex(selectionItem); if (newSelection.HasValue) { Selection = newSelection.Value; } CombineSelections.Clear(); CombineSelections.AddRange(combineItems.Select(x => GetIndex(x)).Where(x => x.HasValue).Select(x => x.Value)); } }
public override void HandleInput(SceneGame scene) { base.HandleInput(scene); if (SubActions.Count > 0) { HandleSubActions(scene); if (SubActions.Count == 0) { Refresh(); } return; } if (Player.InventoryChanged) { Refresh(); } bool up = (scene.InputState.IsKeyPressed(Keys.W, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.LeftThumbstickUp, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.DPadUp, 20, 5)); bool down = (scene.InputState.IsKeyPressed(Keys.S, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.LeftThumbstickDown, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.DPadDown, 20, 5)); bool left = (scene.InputState.IsKeyPressed(Keys.A, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.LeftThumbstickLeft, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.DPadLeft, 20, 5)); bool right = (scene.InputState.IsKeyPressed(Keys.D, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.LeftThumbstickRight, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.DPadRight, 20, 5)); bool confirm = (scene.InputState.IsKeyPressed(Keys.Enter)) || (scene.InputState.IsButtonPressed(Buttons.A)); bool combine = (scene.InputState.IsKeyPressed(Keys.LeftShift, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.Y, 20, 5)); bool cancel = (scene.InputState.IsKeyPressed(Keys.Escape)) || (scene.InputState.IsButtonPressed(Buttons.B)); bool cancelRepeat = (scene.InputState.IsKeyPressed(Keys.Escape, 20, 5)) || (scene.InputState.IsButtonPressed(Buttons.B, 20, 5)); if (up) { Selection.Index--; } else if (down) { Selection.Index++; } else if (left) { Selection.SubIndex--; } else if (right) { Selection.SubIndex++; } else if (Items.Count > 0 && confirm) { var combinedSelections = CombineSelections.Concat(new[] { Selection }).Distinct(); if (combinedSelections.Count() > 1) { SubActions.Add(new ActCombine(Player, combinedSelections)); } else { SubActions.Add(new ActItem(Player, Selection)); } } else if (Items.Count > 0 && combine) { if (!CombineSelections.Contains(Selection)) { CombineSelections.Add(Selection); } else //Otherwise try to add one more item out of the stack { for (int i = 0; i < Selection.Stack.Count; i++) { var selection = new ItemSelection(this, Selection.Index, i); if (!CombineSelections.Contains(selection)) { CombineSelections.Add(selection); break; } } } } else if (cancel && !CombineSelections.Any()) { Result = InputResult.Close; } else if (cancelRepeat && CombineSelections.Any()) { CombineSelections.RemoveAt(CombineSelections.Count - 1); } }
public ItemMenu(Player player) { Player = player; Populate(); Selection = new ItemSelection(this, 0, 0); }
public ActItem(Player player, ItemSelection selection) { Player = player; Selection = selection; Populate(); }