void CommandSelected(Command c) { // Save for later use if there are more than one target _com = c; if (_com.CmdWith) { // Display WorksWith list to user targets = _com.TargetObjects; if (targets.Count == 0) { // We don't have any target, so display empty text AlertDialog.Builder builder = new AlertDialog.Builder(ctrl); builder.SetTitle(c.Text); builder.SetMessage(_com.EmptyTargetListText); builder.SetNeutralButton(Resource.String.ok, (sender, e) => {}); builder.Show(); } else { // We have a list of commands, so show this to the user string[] targetNames = new string[targets.Count]; for(int i = 0; i < targets.Count; i++) targetNames[i] = targets[i].Name; AlertDialog.Builder builder = new AlertDialog.Builder(ctrl); builder.SetTitle(c.Text); builder.SetItems(targetNames, OnTargetListClicked); builder.SetNeutralButton(Resource.String.cancel, (sender, e) => {}); builder.Show(); } } else { // Execute command _com.Execute (); } }
public void Refresh(string what = "") { float maxWidth = this.View.Bounds.Width - 2 * frame; float maxHeight = this.View.Bounds.Height; if ((activeObject is Zone || (activeObject is Thing && ctrl.Engine.VisibleObjects.Contains ((Thing)activeObject))) && activeObject.ObjectLocation != null) NavigationItem.SetRightBarButtonItem (new UIBarButtonItem (Catalog.GetString("Map"), UIBarButtonItemStyle.Plain, (sender, args) => { ctrl.ShowScreen(ScreenType.Map, activeObject); }), false); scrollView.Frame = new RectangleF (0, 0, this.View.Bounds.Width, maxHeight); if (what.Equals ("") || what.Equals ("Name")) { string name = activeObject.Name == null ? "" : activeObject.Name; if (activeObject is Task) this.NavigationItem.Title = (((Task)activeObject).Complete ? (((Task)activeObject).CorrectState == TaskCorrectness.NotCorrect ? Strings.TaskNotCorrect : Strings.TaskCorrect) + " " : "") + name; else this.NavigationItem.Title = name; } if (what.Equals ("") || what.Equals ("Media")) { if (activeObject.Image != null) { image.Image = UIImage.LoadFromData (NSData.FromArray (activeObject.Image.Data)); image.Hidden = false; if (image.Image.Size.Width > maxWidth) image.Bounds = new RectangleF (0, 0, maxWidth, image.Image.Size.Height * maxWidth / image.Image.Size.Width); else image.Bounds = new RectangleF (0, 0, maxWidth, image.Image.Size.Height); } else { image.Image = null; image.Hidden = true; } } if (what.Equals ("") || what.Equals ("Description")) { if (!String.IsNullOrWhiteSpace (activeObject.Description)) { text.Text = activeObject.Description; SizeF size = text.SizeThatFits (new SizeF (maxWidth, 999999)); text.Bounds = new RectangleF (0, 0, maxWidth, size.Height); text.Hidden = false; } else { text.Hidden = true; } } // Check, if commands changed if (what.Equals ("Commands")) { // If commds have changed, than abort target selection actionCommand = null; actionCommandEmpty = null; } if (commands != null && ((what.Equals ("") && actionCommand == null) || what.Equals ("Commands"))) { // Set size buttonView.Bounds = new RectangleF (0, 0, maxWidth, 45 * commands.Count); // Make all buttons we need MakeButtons (commands.Count); // Set text for buttons for (int i = 0; i < commands.Count; i++) buttons [i].SetTitle ((commands [i].Text == null ? "" : commands[i].Text), UIControlState.Normal); buttonView.Hidden = commands.Count == 0; } if (actionCommand != null) { actionText.Text = String.IsNullOrEmpty (actionCommandEmpty) ? (actionCommand.Text == null ? "" : actionCommand.Text) : actionCommandEmpty; actionText.Hidden = false; SizeF size = actionText.SizeThatFits (new SizeF (maxWidth, 999999)); actionText.Bounds = new RectangleF (0, 0, maxWidth, size.Height); // Now create buttons for targets int num = String.IsNullOrEmpty (actionCommandEmpty) ? targets.Count : 1; // Make all buttons we need MakeButtons (num); if (String.IsNullOrEmpty (actionCommandEmpty)) { // Show targets for (int i = 0; i < targets.Count; i++) { buttons [i].SetTitle ((targets [i].Name == null ? "" : targets[i].Name), UIControlState.Normal); buttons [i].Tag = i; } } else // Show empty text buttons[0].SetTitle (Catalog.GetString("Ok"), UIControlState.Normal); buttonView.Hidden = num == 0; } else { actionText.Hidden = true; } // Calc new size float height = frame; if (!image.Hidden) { image.Frame = new RectangleF (frame, height, image.Bounds.Width, image.Bounds.Height); height += image.Bounds.Height + frame; } if (!text.Hidden) { text.Frame = new RectangleF (frame, height, text.Bounds.Width, text.Bounds.Height); height += text.Bounds.Height + frame; } if (!actionText.Hidden) { actionText.Frame = new RectangleF (frame, height, actionText.Bounds.Width, actionText.Bounds.Height); height += actionText.Bounds.Height + frame; } if (!buttonView.Hidden) { if (height + buttonView.Bounds.Height < maxHeight) height = maxHeight - buttonView.Bounds.Height; buttonView.Frame = new RectangleF (frame, height, buttonView.Bounds.Width, buttonView.Bounds.Height); height += buttonView.Bounds.Height; } scrollView.ContentSize = new SizeF(scrollView.Frame.Width,height); }
public void OnButtonClicked(object sender, EventArgs e) { int tag = (int)((Button)sender).Tag; Command c = commands [tag]; if (c.CmdWith) { layoutButtons.Visibility = ViewStates.Gone; layoutWorksWith.Visibility = ViewStates.Visible; com = c; targets = com.TargetObjects; Refresh (); } else { c.Execute (); } }
private void OnTouchUpInside (object sender, EventArgs e) { // Play sound and vibrate, if set in the settings ctrl.ButtonPressed ((UIButton)sender); if (actionCommand == null) { Command command = commands[((UIButton)sender).Tag]; if (command.CmdWith) { // This command did have a list of things, with which it works, so show this list targets = command.TargetObjects; // If things has no entry, than there are no targets for this command if (targets.Count == 0) { actionCommandEmpty = Catalog.GetString(command.EmptyTargetListText); } actionCommand = command; Refresh (); } else { // This command didn't have a list of things, with which it works, so call the method command.Execute (); } } else { // Player select if (String.IsNullOrEmpty(actionCommandEmpty)) { actionCommand.Execute(targets[((UIButton)sender).Tag]); } actionCommand = null; actionCommandEmpty = null; commands = null; targets = null; if (!(activeObject is Task)) { commands = ((Thing)activeObject).ActiveCommands; } Refresh (); } }
/// <summary> /// Raised when the fragment is destroyed, so free references to other UI elements. /// </summary> public override void OnDestroyView() { base.OnDestroyView(); imageView = null; layoutButtons = null; layoutWorksWith = null; textDescription = null; textWorksWith = null; menuMap = null; activeObject = null; com = null; commands = null; targets = null; ctrl = null; }