Пример #1
0
		public void ScrollTo(UIComponent target)
		{
			if (this.Children.Length == 1)
			{
				UIComponent child = this.Children.First();

				Vector2 newPosition = child.Position;

				Vector2 targetPos = target.ScaledSize.Value;
				while (target != child)
				{
					targetPos += target.Position;
					target = target.Parent;
				}

				newPosition.Y = Math.Min(this.Size.Value.Y - targetPos.Y, 0);
				child.Position.Value = newPosition;
			}
		}
Пример #2
0
		public static void Attach(Main main, UIRenderer ui, Property<float> health)
		{
			Sprite damageOverlay = new Sprite();
			damageOverlay.Image.Value = "Images\\damage";
			damageOverlay.AnchorPoint.Value = new Vector2(0.5f);
			ui.Root.Children.Add(damageOverlay);

			// Center the damage overlay and scale it to fit the screen
			damageOverlay.Add(new Binding<Vector2, Point>(damageOverlay.Position, x => new Vector2(x.X * 0.5f, x.Y * 0.5f), main.ScreenSize));
			damageOverlay.Add(new Binding<Vector2>(damageOverlay.Scale, () => new Vector2(main.ScreenSize.Value.X / damageOverlay.Size.Value.X, main.ScreenSize.Value.Y / damageOverlay.Size.Value.Y), main.ScreenSize, damageOverlay.Size));
			damageOverlay.Add(new Binding<float, float>(damageOverlay.Opacity, x => 1.0f - x, health));

			UIComponent targets = new UIComponent();
			ui.Root.Children.Add(targets);
			const string targetOnScreen = "Images\\target";
			const string targetOffScreen = "Images\\target-pointer";
			ui.Add(new ListBinding<UIComponent, Transform>(targets.Children, TargetFactory.Positions, delegate(Transform target)
			{
				Sprite sprite = new Sprite();
				sprite.Image.Value = "Images\\target";
				sprite.Opacity.Value = 0.5f;
				sprite.AnchorPoint.Value = new Vector2(0.5f, 0.5f);
				sprite.Add(new Binding<bool>(sprite.Visible, target.Enabled));
				sprite.Add(new Binding<Vector2>(sprite.Position, delegate()
				{
					Vector3 pos = target.Position.Value;
					Vector4 projectionSpace = Vector4.Transform(new Vector4(pos.X, pos.Y, pos.Z, 1.0f), main.Camera.ViewProjection);
					float originalDepth = projectionSpace.Z;
					projectionSpace /= projectionSpace.W;

					Point screenSize = main.ScreenSize;
					Vector2 screenCenter = new Vector2(screenSize.X * 0.5f, screenSize.Y * 0.5f);

					Vector2 offset = new Vector2(projectionSpace.X * (float)screenSize.X * 0.5f, -projectionSpace.Y * (float)screenSize.Y * 0.5f);

					float radius = Math.Min(screenSize.X, screenSize.Y) * 0.95f * 0.5f;

					float offsetLength = offset.Length();

					Vector2 normalizedOffset = offset / offsetLength;

					bool offscreen = offsetLength > radius;

					bool behind = originalDepth < main.Camera.NearPlaneDistance;

					string img = offscreen || behind ? targetOffScreen : targetOnScreen;

					if (sprite.Image.Value != img)
						sprite.Image.Value = img;

					if (behind)
						normalizedOffset *= -1.0f;

					if (offscreen || behind)
						sprite.Rotation.Value = -(float)Math.Atan2(normalizedOffset.Y, -normalizedOffset.X) - (float)Math.PI * 0.5f;
					else
						sprite.Rotation.Value = 0.0f;

					if (behind || offscreen)
						offset = normalizedOffset * radius;

					return screenCenter + offset;
				}, target.Position, main.Camera.ViewProjection, main.ScreenSize));
				return sprite;
			}));
		}
Пример #3
0
        public override void Awake()
        {
            this.Serialize         = false;
            this.EnabledWhenPaused = false;

#if STEAMWORKS
            this.personaCallback = Callback <PersonaStateChange_t> .Create(this.onPersonaStateChange);
#endif

            {
                Container container = this.main.UIFactory.CreateContainer();
                container.Opacity.Value       = 0.5f;
                container.PaddingBottom.Value = container.PaddingLeft.Value = container.PaddingRight.Value = container.PaddingTop.Value = 16.0f * this.main.FontMultiplier;
                container.AnchorPoint.Value   = new Vector2(1.0f, 0.0f);
                container.Add(new Binding <Vector2, Point>(container.Position, x => new Vector2(x.X * 0.9f, x.Y * 0.1f), this.main.ScreenSize));
                container.Visible.Value = false;
                this.main.UI.Root.Children.Add(container);
                container.Add(new CommandBinding(this.Delete, container.Delete));
                container.Add(new CommandBinding(this.ShowEnd, container.Delete));
                container.Add(new CommandBinding(this.Show, delegate() { container.Visible.Value = true; }));

                ListContainer list = new ListContainer();
                list.Orientation.Value = ListContainer.ListOrientation.Vertical;
                list.Alignment.Value   = ListContainer.ListAlignment.Max;
                container.Children.Add(list);

                TextElement elapsedTime = new TextElement();
                elapsedTime.FontFile.Value = this.main.FontLarge;
                elapsedTime.Add(new Binding <string, float>(elapsedTime.Text, SecondsToTimeString, this.ElapsedTime));
                list.Children.Add(elapsedTime);

                TextElement bestTime = this.main.UIFactory.CreateLabel();
                bestTime.Add(new Binding <string, float>(bestTime.Text, SecondsToTimeString, this.BestTime));
                list.Children.Add(bestTime);
            }

            this.ShowEnd.Action = delegate()
            {
                if (this.shown)
                {
                    return;
                }
                this.shown = true;

                Container container = this.main.UIFactory.CreateContainer();
                container.Opacity.Value       = 0.5f;
                container.PaddingBottom.Value = container.PaddingLeft.Value = container.PaddingRight.Value = container.PaddingTop.Value = 16.0f * this.main.FontMultiplier;
                container.AnchorPoint.Value   = new Vector2(0.5f, 0.5f);
                container.Add(new Binding <Vector2, Point>(container.Position, x => new Vector2(x.X * 0.5f, x.Y * 0.5f), this.main.ScreenSize));
                this.main.UI.Root.Children.Add(container);
                container.Add(new CommandBinding(this.Delete, container.Delete));

                ListContainer list = new ListContainer();
                list.Orientation.Value = ListContainer.ListOrientation.Vertical;
                list.Alignment.Value   = ListContainer.ListAlignment.Middle;
                list.Spacing.Value     = this.spacing;
                container.Children.Add(list);

                TextElement elapsedTime = new TextElement();
                elapsedTime.FontFile.Value = this.main.FontLarge;
                elapsedTime.Add(new Binding <string, float>(elapsedTime.Text, SecondsToTimeString, this.ElapsedTime));
                list.Children.Add(elapsedTime);

                TextElement bestTime = this.main.UIFactory.CreateLabel();
                bestTime.Add(new Binding <string>(bestTime.Text, () => string.Format(main.Strings.Get("best time"), SecondsToTimeString(this.BestTime)), this.BestTime, main.Strings.Language));
                list.Children.Add(bestTime);

#if STEAMWORKS
                Container leaderboard = this.main.UIFactory.CreateContainer();
                this.resizeContainer(leaderboard);
                list.Children.Add(leaderboard);

                ListContainer leaderboardList = new ListContainer();
                leaderboardList.ResizePerpendicular.Value = false;
                leaderboardList.Size.Value        = new Vector2(this.width - 8.0f, 0);
                leaderboardList.Orientation.Value = ListContainer.ListOrientation.Vertical;
                leaderboardList.Alignment.Value   = ListContainer.ListAlignment.Middle;
                leaderboardList.Spacing.Value     = this.spacing;
                leaderboard.Children.Add(leaderboardList);

                this.LeaderboardSync.Action = delegate()
                {
                    leaderboardList.Children.Clear();
                    TextElement leaderboardLabel = this.main.UIFactory.CreateLabel();
                    leaderboardLabel.Text.Value = "\\leaderboard";
                    leaderboardList.Children.Add(leaderboardLabel);
                    TextElement loading = this.main.UIFactory.CreateLabel();
                    loading.Text.Value = "\\loading";
                    leaderboardList.Children.Add(loading);
                };

                this.OnLeaderboardSync.Action = delegate(LeaderboardScoresDownloaded_t globalScores, LeaderboardScoresDownloaded_t friendScores)
                {
                    leaderboardList.Children.Clear();
                    TextElement leaderboardLabel = this.main.UIFactory.CreateLabel();
                    leaderboardLabel.Text.Value = "\\leaderboard";
                    leaderboardList.Children.Add(leaderboardLabel);

                    int[] details = new int[] {};
                    for (int i = 0; i < globalScores.m_cEntryCount; i++)
                    {
                        LeaderboardEntry_t entry;
                        SteamUserStats.GetDownloadedLeaderboardEntry(globalScores.m_hSteamLeaderboardEntries, i, out entry, details, 0);
                        leaderboardList.Children.Add(this.leaderboardEntry(entry));
                    }

                    if (friendScores.m_cEntryCount > 1)
                    {
                        TextElement friendsLabel = this.main.UIFactory.CreateLabel();
                        friendsLabel.Text.Value = "\\friends";
                        leaderboardList.Children.Add(friendsLabel);

                        for (int i = 0; i < friendScores.m_cEntryCount; i++)
                        {
                            LeaderboardEntry_t entry;
                            SteamUserStats.GetDownloadedLeaderboardEntry(friendScores.m_hSteamLeaderboardEntries, i, out entry, details, 0);
                            if (entry.m_steamIDUser != SteamUser.GetSteamID())
                            {
                                leaderboardList.Children.Add(this.leaderboardEntry(entry));
                            }
                        }
                    }
                };

                this.OnLeaderboardError.Action = delegate()
                {
                    leaderboardList.Children.Clear();
                    TextElement error = this.main.UIFactory.CreateLabel();
                    error.Text.Value = "\\leaderboard error";
                    leaderboardList.Children.Add(error);
                };

                this.LeaderboardSync.Execute();
#endif

                Container retry = this.main.UIFactory.CreateButton("\\retry", delegate()
                {
                    this.Retry.Execute();
                });
                this.resizeButton(retry);
                list.Children.Add(retry);

                if (this.main.Settings.GodModeProperty || Path.GetDirectoryName(this.main.MapFile) == this.main.CustomMapDirectory)
                {
                    Container edit = this.main.UIFactory.CreateButton("\\edit mode", delegate()
                    {
                        this.Edit.Execute();
                    });
                    this.resizeButton(edit);
                    list.Children.Add(edit);
                }

                if (!string.IsNullOrEmpty(this.NextMap))
                {
                    Container next = this.main.UIFactory.CreateButton("\\next level", delegate()
                    {
                        this.LoadNextMap.Execute();
                    });
                    this.resizeButton(next);
                    list.Children.Add(next);
                }

                Container mainMenu = this.main.UIFactory.CreateButton("\\main menu", delegate()
                {
                    this.MainMenu.Execute();
                });
                this.resizeButton(mainMenu);
                list.Children.Add(mainMenu);

                this.main.UI.IsMouseVisible.Value = true;

                const float gamepadMoveInterval = 0.1f;
                float       lastGamepadMove     = 0.0f;

                Func <int, int, int> nextButton = delegate(int search, int dir)
                {
                    int i = search;
                    while (true)
                    {
                        i = i + dir;
                        if (i < 0)
                        {
                            i = list.Children.Count - 1;
                        }
                        else if (i >= list.Children.Count)
                        {
                            i = 0;
                        }
                        UIComponent item = list.Children[i];
                        if (item is Container)
                        {
                            return(i);
                        }
                    }
                };

                int selected = nextButton(0, 1);
                if (main.GamePadConnected)
                {
                    list.Children[selected].Highlighted.Value = true;
                }

                PCInput      input         = this.Entity.GetOrCreate <PCInput>();
                Action <int> moveSelection = delegate(int delta)
                {
                    if (this.main.GameTime.TotalGameTime.TotalSeconds - lastGamepadMove > gamepadMoveInterval)
                    {
                        Container button;
                        if (selected < list.Children.Length)
                        {
                            button = (Container)list.Children[selected];
                            button.Highlighted.Value = false;
                        }

                        selected = nextButton(selected, delta);

                        button = (Container)list.Children[selected];
                        button.Highlighted.Value = true;
                        lastGamepadMove          = (float)this.main.GameTime.TotalGameTime.TotalSeconds;
                    }
                };

                input.Add(new CommandBinding(input.GetButtonDown(Buttons.LeftThumbstickUp), delegate()
                {
                    moveSelection(-1);
                }));

                input.Add(new CommandBinding(input.GetButtonDown(Buttons.DPadUp), delegate()
                {
                    moveSelection(-1);
                }));

                input.Add(new CommandBinding(input.GetButtonDown(Buttons.LeftThumbstickDown), delegate()
                {
                    moveSelection(1);
                }));

                input.Add(new CommandBinding(input.GetButtonDown(Buttons.DPadDown), delegate()
                {
                    moveSelection(1);
                }));

                input.Add(new CommandBinding(input.GetButtonDown(Buttons.A), delegate()
                {
                    if (selected < list.Children.Count)
                    {
                        UIComponent selectedItem = list.Children[selected];
                        selectedItem.MouseLeftUp.Execute();
                    }
                }));
            };
        }
Пример #4
0
		public static void Attach(Main main, Entity entity, UIRenderer ui, Property<float> health, Property<float> rotation, Property<bool> noteActive, Property<bool> phoneActive, Property<Vector3> linearVelocity, Property<bool> enableDebugVelocity)
		{
			Sprite damageOverlay = new Sprite();
			damageOverlay.Image.Value = "Images\\damage";
			damageOverlay.AnchorPoint.Value = new Vector2(0.5f);
			ui.Root.Children.Add(damageOverlay);

			// Center the damage overlay and scale it to fit the screen
			damageOverlay.Add(new Binding<Vector2, Point>(damageOverlay.Position, x => new Vector2(x.X * 0.5f, x.Y * 0.5f), main.ScreenSize));
			damageOverlay.Add(new Binding<Vector2>(damageOverlay.Scale, () => new Vector2(main.ScreenSize.Value.X / damageOverlay.Size.Value.X, main.ScreenSize.Value.Y / damageOverlay.Size.Value.Y), main.ScreenSize, damageOverlay.Size));
			damageOverlay.Add(new Binding<float, float>(damageOverlay.Opacity, x => 1.0f - x, health));

			Container debugVelocityContainer = main.UIFactory.CreateContainer();
			debugVelocityContainer.Opacity.Value = UIFactory.Opacity;
			debugVelocityContainer.AnchorPoint.Value = new Vector2(1.0f, 0.0f);
			bool vr = false;
#if VR
			vr = main.VR;
#endif
			debugVelocityContainer.Add(new Binding<Vector2, Point>(debugVelocityContainer.Position, x => new Vector2(x.X * 0.9f, x.Y * (vr ? 0.7f : 0.9f)), main.ScreenSize));
			debugVelocityContainer.Add(new Binding<bool>(debugVelocityContainer.Visible, enableDebugVelocity));
			ui.Root.Children.Add(debugVelocityContainer);

			ListContainer debugVelocityList = new ListContainer();
			debugVelocityList.Orientation.Value = ListContainer.ListOrientation.Vertical;
			debugVelocityContainer.Children.Add(debugVelocityList);

			TextElement debugVelocity = main.UIFactory.CreateLabel();
			debugVelocity.Add(new Binding<string, Vector3>(debugVelocity.Text, x => Math.Abs(x.Y).ToString("00.00"), linearVelocity));
			debugVelocityList.Children.Add(debugVelocity);

			TextElement debugHorizontalVelocity = main.UIFactory.CreateLabel();
			debugHorizontalVelocity.Add(new Binding<string, Vector3>(debugHorizontalVelocity.Text, x =>
			{
				x.Y = 0.0f;
				return x.Length().ToString("00.00");
			}, linearVelocity));
			debugVelocityList.Children.Add(debugHorizontalVelocity);

#if VR
			if (main.VR)
			{
				VirtualReticle reticleController = entity.GetOrCreate<VirtualReticle>();
				reticleController.Add(new Binding<float>(reticleController.Rotation, rotation));

				ModelNonPostProcessed reticle = entity.Create<ModelNonPostProcessed>();
				reticle.Filename.Value = "Models\\plane";
				reticle.EffectFile.Value = "Effects\\VirtualUI";
				reticle.DiffuseTexture.Value = "Images\\reticle";
				reticle.Add(new Binding<Matrix>(reticle.Transform, reticleController.Transform));
				reticle.Add(new Binding<bool>(reticle.Enabled, () => !main.Paused && !phoneActive && !noteActive && main.Settings.EnableReticleVR, main.Paused, phoneActive, noteActive, main.Settings.EnableReticleVR));
			}
			else
#endif
			{
				Sprite reticle = new Sprite();
				reticle.Image.Value = "Images\\reticle";
				reticle.AnchorPoint.Value = new Vector2(0.5f);
				reticle.Opacity.Value = 0.5f;
				ui.Root.Children.Add(reticle);

				reticle.Add(new Binding<bool>(reticle.Visible, main.Settings.EnableReticle));

				// Center the reticle
				reticle.Add(new Binding<Vector2, Point>(reticle.Position, x => new Vector2(x.X * 0.5f, x.Y * 0.5f), main.ScreenSize));
			}

			UIComponent targets = new UIComponent();
			ui.Root.Children.Add(targets);

			TargetUI targetUi = entity.GetOrCreate<TargetUI>();
			targetUi.Add(new ListBinding<UIComponent>(targetUi.Sprites, targets.Children));

			targets.Add(new ListBinding<UIComponent, Transform>(targets.Children, TargetFactory.Positions, delegate(Transform target)
			{
				Sprite sprite = new Sprite();
				sprite.Image.Value = "Images\\target";
				sprite.AnchorPoint.Value = new Vector2(0.5f, 0.5f);
				sprite.UserData.Value = target;
				sprite.Add(new Binding<bool>(sprite.Visible, () => target.Enabled && main.Settings.EnableWaypoints, target.Enabled, main.Settings.EnableWaypoints));
				return sprite;
			}));
		}
Пример #5
0
        public static void Attach(Main main, Entity entity, Player player, AnimatedModel model, FPSInput input, Phone phone, Property <bool> enableWalking, Property <bool> phoneActive, Property <bool> noteActive)
        {
            UIRenderer phoneUi = entity.GetOrCreate <UIRenderer>("PhoneUI");

            model["Phone"].Speed = model["VRPhone"].Speed = model["Note"].Speed = model["VRNote"].Speed = 0.25f;

            const float phoneWidth = 200.0f;

            phoneUi.RenderTargetBackground.Value = Microsoft.Xna.Framework.Color.White;
            phoneUi.RenderTargetSize.Value       = new Point((int)phoneWidth, (int)(phoneWidth * 2.0f));
            phoneUi.Serialize     = false;
            phoneUi.Enabled.Value = false;
#if VR
            if (main.VR)
            {
                phoneUi.Reticle.Tint.Value = new Color(0.0f, 0.0f, 0.0f);
            }
#endif

            Model phoneModel = entity.GetOrCreate <Model>("PhoneModel");
            phoneModel.Filename.Value = "Models\\phone";
            phoneModel.Color.Value    = new Vector3(0.13f, 0.13f, 0.13f);
            phoneModel.Serialize      = false;
            phoneModel.Enabled.Value  = false;

            Property <Matrix> phoneBone = model.GetBoneTransform("Phone");
            phoneModel.Add(new Binding <Matrix>(phoneModel.Transform, () => phoneBone.Value * model.Transform, phoneBone, model.Transform));

            Model screen = entity.GetOrCreate <Model>("Screen");
            screen.Filename.Value = "Models\\plane";
            screen.Add(new Binding <Microsoft.Xna.Framework.Graphics.RenderTarget2D>(screen.GetRenderTarget2DParameter("Diffuse" + Model.SamplerPostfix), phoneUi.RenderTarget));
            screen.Add(new Binding <Matrix>(screen.Transform, x => Matrix.CreateTranslation(0.015f, 0.0f, 0.0f) * x, phoneModel.Transform));
            screen.Serialize     = false;
            screen.Enabled.Value = false;

            PointLight phoneLight = entity.Create <PointLight>();
            phoneLight.Serialize         = false;
            phoneLight.Enabled.Value     = false;
            phoneLight.Attenuation.Value = 0.5f;
            phoneLight.Add(new Binding <Vector3, Matrix>(phoneLight.Position, x => x.Translation, screen.Transform));

            PointLight noteLight = entity.Create <PointLight>();
            noteLight.Serialize         = false;
            noteLight.Enabled.Value     = false;
            noteLight.Attenuation.Value = 1.0f;
            noteLight.Color.Value       = new Vector3(0.3f);
            noteLight.Add(new Binding <Vector3>(noteLight.Position, () => Vector3.Transform(new Vector3(0.25f, 0.0f, 0.0f), phoneBone.Value * model.Transform), phoneBone, model.Transform));

            const float screenScale = 0.0007f;
            screen.Scale.Value = new Vector3(1.0f, (float)phoneUi.RenderTargetSize.Value.Y * screenScale, (float)phoneUi.RenderTargetSize.Value.X * screenScale);

            // Transform screen space mouse position into 3D, then back into the 2D space of the phone UI
            Property <Matrix> screenTransform = new Property <Matrix>();
            screen.Add(new Binding <Matrix>(screenTransform, () => Matrix.CreateScale(screen.Scale) * screen.Transform, screen.Scale, screen.Transform));
            phoneUi.Setup3D(screenTransform);

            // Phone UI

            const float padding      = 8.0f;
            const float messageWidth = phoneWidth - padding * 2.0f;

            Func <Property <Color>, string, float, Container> makeButton = delegate(Property <Color> color, string text, float width)
            {
                Container bg = new Container();
                bg.Tint.Value          = color;
                bg.PaddingBottom.Value = bg.PaddingLeft.Value = bg.PaddingRight.Value = bg.PaddingTop.Value = padding * 0.5f;
                bg.Add(new Binding <Color>(bg.Tint, () => bg.Highlighted ? new Color(color.Value.ToVector4() + new Vector4(0.2f, 0.2f, 0.2f, 0.0f)) : color, bg.Highlighted, color));

                TextElement msg = new TextElement();
                msg.Name.Value      = "Text";
                msg.FontFile.Value  = main.Font;
                msg.Text.Value      = text;
                msg.WrapWidth.Value = width;
                bg.Children.Add(msg);
                return(bg);
            };

            Action <Container, float> centerButton = delegate(Container button, float width)
            {
                TextElement text = (TextElement)button.Children[0];
                text.AnchorPoint.Value = new Vector2(0.5f, 0);
                text.Add(new Binding <Vector2>(text.Position, x => new Vector2(x.X * 0.5f, padding), button.Size));
                button.ResizeHorizontal.Value = false;
                button.ResizeVertical.Value   = false;
                button.Size.Value             = new Vector2(width, 36.0f * main.FontMultiplier);
            };

            Func <UIComponent, bool, Container> makeAlign = delegate(UIComponent component, bool right)
            {
                Container container = new Container();
                container.Opacity.Value          = 0.0f;
                container.PaddingBottom.Value    = container.PaddingLeft.Value = container.PaddingRight.Value = container.PaddingTop.Value = 0.0f;
                container.ResizeHorizontal.Value = false;
                container.Size.Value             = new Vector2(messageWidth, 0.0f);
                component.AnchorPoint.Value      = new Vector2(right ? 1.0f : 0.0f, 0.0f);
                component.Position.Value         = new Vector2(right ? messageWidth : 0.0f, 0.0f);
                container.Children.Add(component);
                return(container);
            };

            Property <Color> incomingColor = new Property <Color> {
                Value = new Color(0.0f, 0.0f, 0.0f, 1.0f)
            };
            Property <Color> outgoingColor = new Property <Color> {
                Value = new Color(0.0f, 0.175f, 0.35f, 1.0f)
            };
            Property <Color> alternateSenderColor = new Property <Color> {
                Value = new Color(0.25f, 0.0f, 0.25f, 1.0f)
            };
            Property <Color> composeColor = new Property <Color> {
                Value = new Color(0.5f, 0.0f, 0.0f, 1.0f)
            };
            Property <Color> disabledColor = new Property <Color> {
                Value = new Color(0.35f, 0.35f, 0.35f, 1.0f)
            };
            Property <Color> topBarColor = new Property <Color> {
                Value = new Color(0.15f, 0.15f, 0.15f, 1.0f)
            };

            Container topBarContainer = new Container();
            topBarContainer.ResizeHorizontal.Value = false;
            topBarContainer.Size.Value             = new Vector2(phoneUi.RenderTargetSize.Value.X, 0.0f);
            topBarContainer.Tint.Value             = topBarColor;
            phoneUi.Root.Children.Add(topBarContainer);

            ListContainer phoneTopBar = new ListContainer();
            phoneTopBar.Orientation.Value = ListContainer.ListOrientation.Horizontal;
            phoneTopBar.Spacing.Value     = padding;
            topBarContainer.Children.Add(phoneTopBar);

            Sprite signalIcon = new Sprite();
            signalIcon.Image.Value = "Images\\signal";
            phoneTopBar.Children.Add(signalIcon);

            TextElement noService = new TextElement();
            noService.FontFile.Value = main.Font;
            noService.Text.Value     = "\\no service";
            phoneTopBar.Children.Add(noService);

            signalIcon.Add(new Binding <bool>(signalIcon.Visible, () => player.SignalTower.Value.Target != null || phone.ActiveAnswers.Length > 0 || phone.Schedules.Length > 0, player.SignalTower, phone.ActiveAnswers.Length, phone.Schedules.Length));
            noService.Add(new Binding <bool>(noService.Visible, x => !x, signalIcon.Visible));

            ListContainer tabs = new ListContainer();
            tabs.Orientation.Value = ListContainer.ListOrientation.Horizontal;
            tabs.Spacing.Value     = 0;
            phoneUi.Root.Children.Add(tabs);

            Property <Color> messageTabColor = new Property <Color> {
                Value = outgoingColor
            };
            phoneUi.Add(new Binding <Color, Phone.Mode>(messageTabColor, x => x == Phone.Mode.Messages ? outgoingColor : topBarColor, phone.CurrentMode));
            Container messageTab = makeButton(messageTabColor, "\\messages", phoneUi.RenderTargetSize.Value.X * 0.5f - padding);
            centerButton(messageTab, phoneUi.RenderTargetSize.Value.X * 0.5f);
            tabs.Children.Add(messageTab);
            messageTab.Add(new CommandBinding(messageTab.MouseLeftUp, delegate()
            {
                phone.CurrentMode.Value = Phone.Mode.Messages;
            }));

            Property <Color> photoTabColor = new Property <Color> {
                Value = topBarColor
            };
            phoneUi.Add(new Binding <Color>(photoTabColor, delegate()
            {
                if (phone.CurrentMode == Phone.Mode.Photos)
                {
                    return(outgoingColor);
                }
                else if (string.IsNullOrEmpty(phone.Photo))
                {
                    return(disabledColor);
                }
                else
                {
                    return(topBarColor);
                }
            }, phone.CurrentMode, phone.Photo));
            Container photoTab = makeButton(photoTabColor, "\\photos", phoneUi.RenderTargetSize.Value.X * 0.5f - padding);
            centerButton(photoTab, phoneUi.RenderTargetSize.Value.X * 0.5f);
            tabs.Children.Add(photoTab);
            photoTab.Add(new CommandBinding(photoTab.MouseLeftUp, delegate()
            {
                if (!string.IsNullOrEmpty(phone.Photo))
                {
                    phone.CurrentMode.Value = Phone.Mode.Photos;
                }
            }));

            tabs.Add(new Binding <Vector2>(tabs.Position, x => new Vector2(0, x.Y), topBarContainer.Size));

            ListContainer messageLayout = new ListContainer();
            messageLayout.Spacing.Value     = padding;
            messageLayout.Orientation.Value = ListContainer.ListOrientation.Vertical;
            messageLayout.Add(new Binding <Vector2>(messageLayout.Position, () => new Vector2(padding, topBarContainer.Size.Value.Y + tabs.Size.Value.Y), topBarContainer.Size, tabs.Size));
            messageLayout.Add(new Binding <Vector2>(messageLayout.Size, () => new Vector2(phoneUi.RenderTargetSize.Value.X - padding * 2.0f, phoneUi.RenderTargetSize.Value.Y - padding - topBarContainer.Size.Value.Y - tabs.Size.Value.Y), phoneUi.RenderTargetSize, topBarContainer.Size, tabs.Size));
            messageLayout.Add(new Binding <bool, Phone.Mode>(messageLayout.Visible, x => x == Phone.Mode.Messages, phone.CurrentMode));
            phoneUi.Root.Children.Add(messageLayout);

            Container photoLayout = new Container();
            photoLayout.Opacity.Value     = 0;
            photoLayout.PaddingLeft.Value = photoLayout.PaddingRight.Value = photoLayout.PaddingTop.Value = photoLayout.PaddingBottom.Value = 0;
            photoLayout.Add(new Binding <Vector2>(photoLayout.Position, () => new Vector2(0, topBarContainer.Size.Value.Y + tabs.Size.Value.Y), topBarContainer.Size, tabs.Size));
            photoLayout.Add(new Binding <Vector2>(photoLayout.Size, () => new Vector2(phoneUi.RenderTargetSize.Value.X, phoneUi.RenderTargetSize.Value.Y - topBarContainer.Size.Value.Y - tabs.Size.Value.Y), phoneUi.RenderTargetSize, topBarContainer.Size, tabs.Size));
            photoLayout.Add(new Binding <bool>(photoLayout.Visible, x => !x, messageLayout.Visible));
            phoneUi.Root.Children.Add(photoLayout);

            Sprite photoImage = new Sprite();
            photoImage.AnchorPoint.Value = new Vector2(0.5f, 0.5f);
            photoImage.Add(new Binding <string>(photoImage.Image, phone.Photo));
            photoImage.Add(new Binding <Vector2>(photoImage.Position, x => x * 0.5f, photoLayout.Size));
            photoLayout.Children.Add(photoImage);

            Container   composeButton = makeButton(composeColor, "\\compose", messageWidth - padding * 2.0f);
            TextElement composeText   = (TextElement)composeButton.GetChildByName("Text");
            composeText.Add(new Binding <string, bool>(composeText.Text, x => x ? "\\compose gamepad" : "\\compose", main.GamePadConnected));
            UIComponent composeAlign = makeAlign(composeButton, true);

            Scroller phoneScroll = new Scroller();
            phoneScroll.ResizeVertical.Value = false;
            phoneScroll.Add(new Binding <Vector2>(phoneScroll.Size, () => new Vector2(messageLayout.Size.Value.X, messageLayout.Size.Value.Y - messageLayout.Spacing.Value - composeAlign.ScaledSize.Value.Y), messageLayout.Size, messageLayout.Spacing, composeAlign.ScaledSize));

            messageLayout.Children.Add(phoneScroll);
            messageLayout.Children.Add(composeAlign);

            ListContainer msgList = new ListContainer();
            msgList.Spacing.Value             = padding * 0.5f;
            msgList.Orientation.Value         = ListContainer.ListOrientation.Vertical;
            msgList.ResizePerpendicular.Value = false;
            msgList.Size.Value = new Vector2(messageWidth, 0.0f);
            phoneScroll.Children.Add(msgList);

            Container answerContainer = new Container();
            answerContainer.PaddingBottom.Value = answerContainer.PaddingLeft.Value = answerContainer.PaddingRight.Value = answerContainer.PaddingTop.Value = padding;
            answerContainer.Tint.Value          = incomingColor;
            answerContainer.AnchorPoint.Value   = new Vector2(1.0f, 1.0f);
            phoneUi.Root.CheckLayout();
            answerContainer.Position.Value = composeAlign.GetAbsolutePosition() + new Vector2(composeAlign.ScaledSize.Value.X, 0);
            phoneUi.Root.Children.Add(answerContainer);
            answerContainer.Visible.Value = false;

            ListContainer answerList = new ListContainer();
            answerList.Orientation.Value = ListContainer.ListOrientation.Vertical;
            answerList.Alignment.Value   = ListContainer.ListAlignment.Max;
            answerContainer.Children.Add(answerList);

            int selectedAnswer = 0;

            composeButton.Add(new CommandBinding(composeButton.MouseLeftUp, delegate()
            {
                answerContainer.Visible.Value = !answerContainer.Visible;
                if (answerContainer.Visible && main.GamePadConnected)
                {
                    selectedAnswer = 0;
                    foreach (UIComponent answer in answerList.Children)
                    {
                        answer.Highlighted.Value = false;
                    }
                    answerList.Children[0].Highlighted.Value = true;
                }
            }));

            tabs.Add(new Binding <bool>(tabs.EnableInput, () => !main.Paused && !answerContainer.Visible, answerContainer.Visible, main.Paused));
            msgList.Add(new Binding <bool>(msgList.EnableInput, () => !main.Paused && !answerContainer.Visible, answerContainer.Visible, main.Paused));
            answerContainer.Add(new Binding <bool>(answerContainer.EnableInput, x => !x, main.Paused));
            composeButton.Add(new Binding <bool>(composeButton.EnableInput, x => !x, main.Paused));

            Action scrollToBottom = delegate()
            {
                // HACK
                Animation scroll = new Animation
                                   (
                    new Animation.Delay(0.01f),
                    new Animation.Execute(delegate()
                {
                    phoneScroll.ScrollToBottom();
                })
                                   );
                entity.Add(scroll);
            };

            // Note

            UIRenderer noteUi = entity.GetOrCreate <UIRenderer>("NoteUI");

            const float noteWidth = 400.0f;

            noteUi.RenderTargetBackground.Value = new Microsoft.Xna.Framework.Color(0.8f, 0.75f, 0.7f);
            noteUi.RenderTargetSize.Value       = new Point((int)noteWidth, (int)(noteWidth * 1.29f));       // 8.5x11 aspect ratio
            noteUi.Serialize     = false;
            noteUi.Enabled.Value = false;

            Model noteModel = entity.GetOrCreate <Model>("Note");
            noteModel.Filename.Value = "Models\\note";
            noteModel.Add(new Binding <Microsoft.Xna.Framework.Graphics.RenderTarget2D>(noteModel.GetRenderTarget2DParameter("Diffuse" + Model.SamplerPostfix), noteUi.RenderTarget));
            noteModel.Add(new Binding <Matrix>(noteModel.Transform, x => Matrix.CreateTranslation(-0.005f, 0.05f, 0.08f) * x, phoneModel.Transform));
            noteModel.Serialize     = false;
            noteModel.Enabled.Value = false;

            Container togglePhoneMessage = null;

            entity.Add(new NotifyBinding(delegate()
            {
                bool hasSignalTower = (player.SignalTower.Value.Target != null && player.SignalTower.Value.Target.Active && !string.IsNullOrEmpty(player.SignalTower.Value.Target.Get <SignalTower>().Initial));
                if (hasSignalTower)
                {
                    phone.Enabled.Value = true;
                }

                bool hasNoteOrSignalTower = (player.Note.Value.Target != null && player.Note.Value.Target.Active) || hasSignalTower;

                if (togglePhoneMessage == null && hasNoteOrSignalTower)
                {
                    togglePhoneMessage = main.Menu.ShowMessage(entity, hasSignalTower ? "\\signal tower prompt" : "\\note prompt");
                }
                else if (togglePhoneMessage != null && !hasNoteOrSignalTower && !phoneActive && !noteActive)
                {
                    main.Menu.HideMessage(null, togglePhoneMessage);
                    togglePhoneMessage = null;
                }
            }, player.Note, player.SignalTower));

            entity.Add(new CommandBinding(entity.Delete, delegate()
            {
                if (togglePhoneMessage != null && togglePhoneMessage.Active)
                {
                    togglePhoneMessage.Delete.Execute();
                }
                if (noteActive)
                {
                    noteActive.Value    = false;
                    player.Note.Value   = null;
                    enableWalking.Value = true;
                }
            }));

            // Note UI

            const float notePadding = 40.0f;

            ListContainer noteLayout = new ListContainer();
            noteLayout.Spacing.Value     = padding;
            noteLayout.Orientation.Value = ListContainer.ListOrientation.Vertical;
            noteLayout.Alignment.Value   = ListContainer.ListAlignment.Min;
            noteLayout.Position.Value    = new Vector2(notePadding, notePadding);
            noteLayout.Add(new Binding <Vector2, Point>(noteLayout.Size, x => new Vector2(x.X - notePadding * 2.0f, x.Y - notePadding * 2.0f), noteUi.RenderTargetSize));
            noteUi.Root.Children.Add(noteLayout);

            Sprite noteUiImage = new Sprite();
            noteLayout.Children.Add(noteUiImage);

            TextElement noteUiText = new TextElement();
            noteUiText.FontFile.Value = main.Font;
            noteUiText.Tint.Value     = new Microsoft.Xna.Framework.Color(0.1f, 0.1f, 0.1f);
            noteUiText.Add(new Binding <float, Vector2>(noteUiText.WrapWidth, x => x.X, noteLayout.Size));
            noteLayout.Children.Add(noteUiText);

            // Toggle note
            Animation noteAnim = null;

            float         startRotationY = 0;
            Action <bool> showNote       = delegate(bool show)
            {
                model.Stop("Phone", "Note", "VRPhone", "VRNote");
                Entity noteEntity = player.Note.Value.Target;
                noteActive.Value = show && noteEntity != null;
                Note note = noteEntity != null?noteEntity.Get <Note>() : null;

                if (noteActive)
                {
                    input.EnableLook.Value  = input.EnableMouse.Value = false;
                    enableWalking.Value     = false;
                    noteModel.Enabled.Value = true;
                    noteUi.Enabled.Value    = true;
                    noteLight.Enabled.Value = true;
                    Session.Recorder.Event(main, "Note", note.Text);
                    noteUiImage.Image.Value = note.Image;
                    noteUiText.Text.Value   = note.Text;
                    string noteAnimation;
#if VR
                    if (main.VR)
                    {
                        noteAnimation = "VRNote";
                    }
                    else
#endif
                    noteAnimation = "Note";

                    model.StartClip(noteAnimation, 6, true, AnimatedModel.DefaultBlendTime * 2.0f);
                    AkSoundEngine.PostEvent(AK.EVENTS.PLAY_NOTE_PICKUP, entity);

                    if (noteAnim != null && noteAnim.Active)
                    {
                        noteAnim.Delete.Execute();
                    }
                    else
                    {
                        startRotationY = input.Mouse.Value.Y;
                    }
                    // Level the player's view
                    noteAnim = new Animation
                               (
                        new Animation.Ease
                        (
                            new Animation.Custom(delegate(float x)
                    {
                        input.Mouse.Value = new Vector2(input.Mouse.Value.X, startRotationY * (1.0f - x));
                    }, 0.5f),
                            Animation.Ease.EaseType.OutQuadratic
                        )
                               );
                    entity.Add(noteAnim);
                }
                else
                {
                    enableWalking.Value = true;
                    if (note != null)
                    {
                        Session.Recorder.Event(main, "NoteEnd");
                    }
                    AkSoundEngine.PostEvent(AK.EVENTS.PLAY_NOTE_DROP, entity);
                    if (note != null && !note.IsCollected)
                    {
                        note.IsCollected.Value = true;
                    }

                    // Return the player's view
                    if (noteAnim != null && noteAnim.Active)
                    {
                        noteAnim.Delete.Execute();
                    }
                    noteAnim = new Animation
                               (
                        new Animation.Ease
                        (
                            new Animation.Custom(delegate(float x)
                    {
                        input.Mouse.Value = new Vector2(input.Mouse.Value.X, startRotationY * x);
                    }, 0.5f),
                            Animation.Ease.EaseType.OutQuadratic
                        ),
                        new Animation.Execute(delegate()
                    {
                        noteModel.Enabled.Value = false;
                        noteUi.Enabled.Value    = false;
                        noteLight.Enabled.Value = false;
                        input.EnableLook.Value  = input.EnableMouse.Value = true;
                    })
                               );
                    entity.Add(noteAnim);
                }
            };

            // Toggle phone

            Animation phoneAnim = null;

            Action <bool> showPhone = delegate(bool show)
            {
                if (togglePhoneMessage != null)
                {
                    main.Menu.HideMessage(null, togglePhoneMessage);
                    togglePhoneMessage = null;
                }

                if (show || (phone.Schedules.Length == 0 && !phone.WaitForAnswer))
                {
                    phoneActive.Value             = show;
                    answerContainer.Visible.Value = false;

                    model.Stop("Phone", "Note", "VRPhone", "VRNote");
                    if (phoneActive)
                    {
                        phoneUi.IsMouseVisible.Value = true;
                        enableWalking.Value          = false;
                        phoneModel.Enabled.Value     = true;
                        screen.Enabled.Value         = true;
                        phoneUi.Enabled.Value        = true;
                        phoneLight.Enabled.Value     = true;
                        input.EnableLook.Value       = input.EnableMouse.Value = false;
                        Session.Recorder.Event(main, "Phone");
                        phoneScroll.CheckLayout();
                        scrollToBottom();

                        string phoneAnimation;
#if VR
                        if (main.VR)
                        {
                            phoneAnimation = "VRPhone";
                        }
                        else
#endif
                        phoneAnimation = "Phone";

                        model.StartClip(phoneAnimation, 6, true, AnimatedModel.DefaultBlendTime * 2.0f);

                        // Level the player's view
                        if (phoneAnim != null && phoneAnim.Active)
                        {
                            phoneAnim.Delete.Execute();
                        }
                        else
                        {
                            startRotationY = input.Mouse.Value.Y;
                        }
                        phoneAnim = new Animation
                                    (
                            new Animation.Ease
                            (
                                new Animation.Custom(delegate(float x)
                        {
                            input.Mouse.Value = new Vector2(input.Mouse.Value.X, startRotationY * (1.0f - x));
                        }, 0.5f),
                                Animation.Ease.EaseType.OutQuadratic
                            )
                                    );
                        entity.Add(phoneAnim);
                    }
                    else
                    {
                        Session.Recorder.Event(main, "PhoneEnd");
                        enableWalking.Value          = true;
                        phoneUi.IsMouseVisible.Value = false;

                        // Return the player's view
                        if (phoneAnim != null && phoneAnim.Active)
                        {
                            phoneAnim.Delete.Execute();
                        }
                        phoneAnim = new Animation
                                    (
                            new Animation.Ease
                            (
                                new Animation.Custom(delegate(float x)
                        {
                            input.Mouse.Value = new Vector2(input.Mouse.Value.X, startRotationY * x);
                        }, 0.5f),
                                Animation.Ease.EaseType.OutQuadratic
                            ),
                            new Animation.Execute(delegate()
                        {
                            phoneModel.Enabled.Value = false;
                            screen.Enabled.Value     = false;
                            phoneUi.Enabled.Value    = false;
                            phoneLight.Enabled.Value = false;
                            input.EnableLook.Value   = input.EnableMouse.Value = true;
                        })
                                    );
                        entity.Add(phoneAnim);
                    }
                }
            };

            input.Bind(main.Settings.TogglePhone, PCInput.InputState.Down, delegate()
            {
                // Special hack to prevent phone toggling when you're trying to open the Steam overlay
                if (main.Settings.TogglePhone.Value.Key == Keys.Tab && input.GetKey(Keys.LeftShift))
                {
                    return;
                }

                if (noteActive || phoneActive || phone.CanReceiveMessages)
                {
                    if (!phoneActive && (noteActive || player.Note.Value.Target != null))
                    {
                        showNote(!noteActive);
                    }
                    else if (phone.Enabled)
                    {
                        showPhone(!phoneActive);
                    }
                }
            });

            phone.Add(new CommandBinding(phone.Show, delegate()
            {
                phone.Enabled.Value = true;
                if (!phoneActive)
                {
                    showPhone(true);
                }
            }));

            // Gamepad code for the phone

            input.Add(new CommandBinding(input.GetButtonUp(Buttons.A), () => phoneActive && composeButton.Visible && phone.CurrentMode.Value == Phone.Mode.Messages, delegate()
            {
                if (answerContainer.Visible)
                {
                    answerList.Children[selectedAnswer].MouseLeftUp.Execute();
                }
                else
                {
                    composeButton.MouseLeftUp.Execute();
                }
            }));

            input.Add(new CommandBinding(input.GetButtonUp(Buttons.B), () => phoneActive && answerContainer.Visible, delegate()
            {
                answerContainer.Visible.Value = false;
            }));

            const float  moveInterval   = 0.1f;
            const float  switchInterval = 0.2f;
            float        lastScroll     = 0;
            float        lastModeSwitch = 0;
            Action <int> scrollPhone    = delegate(int delta)
            {
                if (main.TotalTime - lastScroll > moveInterval &&
                    main.TotalTime - lastModeSwitch > switchInterval)
                {
                    if (answerContainer.Visible)
                    {
                        answerList.Children[selectedAnswer].Highlighted.Value = false;
                        selectedAnswer += delta;
                        while (selectedAnswer < 0)
                        {
                            selectedAnswer += answerList.Children.Length;
                        }
                        while (selectedAnswer > answerList.Children.Length - 1)
                        {
                            selectedAnswer -= answerList.Children.Length;
                        }
                        answerList.Children[selectedAnswer].Highlighted.Value = true;
                    }
                    else
                    {
                        phoneScroll.MouseScrolled.Execute(delta * -4);
                    }
                    lastScroll = main.TotalTime;
                }
            };

            Action switchMode = delegate()
            {
                if (main.TotalTime - lastScroll > switchInterval &&
                    main.TotalTime - lastModeSwitch > moveInterval)
                {
                    Phone.Mode current  = phone.CurrentMode;
                    Phone.Mode nextMode = current == Phone.Mode.Messages ? Phone.Mode.Photos : Phone.Mode.Messages;
                    if (nextMode == Phone.Mode.Photos && string.IsNullOrEmpty(phone.Photo))
                    {
                        nextMode = Phone.Mode.Messages;
                    }
                    phone.CurrentMode.Value = nextMode;
                    lastModeSwitch          = main.TotalTime;
                }
            };
            input.Add(new CommandBinding(input.GetButtonDown(Buttons.LeftThumbstickLeft), () => phoneActive && !answerContainer.Visible, switchMode));
            input.Add(new CommandBinding(input.GetButtonDown(Buttons.LeftThumbstickRight), () => phoneActive && !answerContainer.Visible, switchMode));
            input.Add(new CommandBinding(input.GetButtonDown(Buttons.DPadLeft), () => phoneActive && !answerContainer.Visible, switchMode));
            input.Add(new CommandBinding(input.GetButtonDown(Buttons.DPadRight), () => phoneActive && !answerContainer.Visible, switchMode));

            input.Add(new CommandBinding(input.GetButtonDown(Buttons.LeftThumbstickUp), () => phoneActive, delegate()
            {
                scrollPhone(-1);
            }));

            input.Add(new CommandBinding(input.GetButtonDown(Buttons.DPadUp), () => phoneActive, delegate()
            {
                scrollPhone(-1);
            }));

            input.Add(new CommandBinding(input.GetButtonDown(Buttons.LeftThumbstickDown), () => phoneActive, delegate()
            {
                scrollPhone(1);
            }));

            input.Add(new CommandBinding(input.GetButtonDown(Buttons.DPadDown), () => phoneActive, delegate()
            {
                scrollPhone(1);
            }));

            Func <Phone.Sender, Property <Color> > messageColor = delegate(Phone.Sender sender)
            {
                switch (sender)
                {
                case Phone.Sender.Player:
                    return(outgoingColor);

                case Phone.Sender.A:
                    return(incomingColor);

                default:
                    return(alternateSenderColor);
                }
            };

            msgList.Add(new ListBinding <UIComponent, Phone.Message>
                        (
                            msgList.Children,
                            phone.Messages,
                            delegate(Phone.Message msg)
            {
                return(makeAlign(makeButton(messageColor(msg.Sender), "\\" + msg.Name, messageWidth - padding * 2.0f), msg.Sender == Phone.Sender.Player));
            }
                        ));

            Action <float, Container> animateMessage = delegate(float delay, Container msg)
            {
                msg.CheckLayout();
                Vector2 originalSize = msg.Size;
                msg.Size.Value = new Vector2(0, originalSize.Y);
                entity.Add(new Animation
                           (
                               new Animation.Delay(delay),
                               new Animation.Ease(new Animation.Vector2MoveTo(msg.Size, originalSize, 0.5f), Animation.Ease.EaseType.OutExponential)
                           ));
            };

            Container typingIndicator = null;

            Action showTypingIndicator = delegate()
            {
                typingIndicator = makeAlign(makeButton(incomingColor, "\\...", messageWidth - padding * 2.0f), false);
                msgList.Children.Add(typingIndicator);
                animateMessage(0.2f, typingIndicator);
            };

            if (phone.Schedules.Length > 0)
            {
                showTypingIndicator();
            }

            answerList.Add(new ListBinding <UIComponent, Phone.Ans>
                           (
                               answerList.Children,
                               phone.ActiveAnswers,
                               delegate(Phone.Ans answer)
            {
                UIComponent button = makeButton(outgoingColor, "\\" + answer.Name, messageWidth - padding * 4.0f);
                button.Add(new CommandBinding(button.MouseLeftUp, delegate()
                {
                    if (!phone.WaitForAnswer)                             // If we're not waiting for an answer, the player must be initiating a conversation
                    {
                        // This is the start of a conversation
                        // Disable the signal tower if we're in range
                        Entity s = player.SignalTower.Value.Target;
                        if (s != null)
                        {
                            s.Get <SignalTower>().Initial.Value = null;
                        }
                    }

                    AkSoundEngine.PostEvent(AK.EVENTS.PLAY_PHONE_SEND, entity);
                    phone.Answer(answer);

                    scrollToBottom();
                    if (phone.Schedules.Length == 0)                             // No more messages incoming
                    {
                        if (togglePhoneMessage == null)
                        {
                            togglePhoneMessage = main.Menu.ShowMessage(entity, "\\phone done prompt");
                        }
                    }
                    else
                    {
                        // More messages incoming
                        showTypingIndicator();
                    }
                }));
                return(button);
            }
                           ));

            Action refreshComposeButtonVisibility = delegate()
            {
                bool show = phone.ActiveAnswers.Length > 0 && phone.Schedules.Length == 0;
                answerContainer.Visible.Value &= show;
                composeButton.Visible.Value    = show;
                selectedAnswer = 0;
            };
            composeButton.Add(new ListNotifyBinding <Phone.Ans>(refreshComposeButtonVisibility, phone.ActiveAnswers));
            composeButton.Add(new ListNotifyBinding <Phone.Schedule>(refreshComposeButtonVisibility, phone.Schedules));
            refreshComposeButtonVisibility();

            entity.Add(new CommandBinding(phone.MessageReceived, delegate()
            {
                if (typingIndicator != null)
                {
                    typingIndicator.Delete.Execute();
                    typingIndicator = null;
                }

                if (phone.Schedules.Length > 0)
                {
                    showTypingIndicator();
                }

                float delay;
                if (phoneActive)
                {
                    scrollToBottom();
                    delay = 0;
                }
                else
                {
                    showPhone(true);
                    delay = 0.5f;
                }

                // Animate the new message
                animateMessage(delay, (Container)msgList.Children[msgList.Children.Length - 1].Children[0]);

                AkSoundEngine.PostEvent(AK.EVENTS.PLAY_PHONE_VIBRATE, entity);
                if (togglePhoneMessage == null && phone.Schedules.Length == 0 && phone.ActiveAnswers.Length == 0)                 // No more messages incoming, and no more answers to give
                {
                    togglePhoneMessage = main.Menu.ShowMessage(entity, "[{{TogglePhone}}]");
                }
            }));

            if (noteActive)
            {
                showNote(true);
            }
            else if (phoneActive)
            {
                showPhone(true);
            }
        }
Пример #6
0
        protected override void updateLayout()
        {
            if (this.binding == null)
            {
                this.binding = new NotifyBinding(delegate() { this.layoutDirty = true; }, this.Children.SelectMany(x => new IProperty[] { x.ScaledSize, x.Visible }).ToArray());
                this.Add(this.binding);
            }

            float spacing = this.Spacing;

            Vector2 maxSize = Vector2.Zero;

            if (this.ResizePerpendicular)
            {
                for (int i = 0; i < this.Children.Count; i++)
                {
                    UIComponent child = this.Children[i];
                    if (child.Visible)
                    {
                        Vector2 size = child.ScaledSize;
                        maxSize.X = Math.Max(maxSize.X, size.X);
                        maxSize.Y = Math.Max(maxSize.Y, size.Y);
                    }
                }
            }
            else
            {
                maxSize = this.Size;
            }

            if (this.Orientation.Value == ListOrientation.Horizontal)
            {
                Vector2 anchorPoint;
                switch (this.Alignment.Value)
                {
                case ListAlignment.Min:
                    anchorPoint = Vector2.Zero;
                    break;

                case ListAlignment.Middle:
                    anchorPoint = new Vector2(0, 0.5f);
                    break;

                case ListAlignment.Max:
                    anchorPoint = new Vector2(0, 1);
                    break;

                default:
                    anchorPoint = Vector2.Zero;
                    break;
                }
                Vector2 pos = new Vector2(0, maxSize.Y * anchorPoint.Y);
                foreach (UIComponent child in this.Reversed ? this.Children.Reverse() : this.Children)
                {
                    child.AnchorPoint.Value = anchorPoint;
                    child.Position.Value    = pos;
                    if (child.Visible)
                    {
                        pos.X += child.ScaledSize.Value.X + spacing;
                    }
                }
                this.Size.Value = new Vector2(Math.Max(0, pos.X - spacing), maxSize.Y);
            }
            else
            {
                Vector2 anchorPoint;
                switch (this.Alignment.Value)
                {
                case ListAlignment.Min:
                    anchorPoint = Vector2.Zero;
                    break;

                case ListAlignment.Middle:
                    anchorPoint = new Vector2(0.5f, 0);
                    break;

                case ListAlignment.Max:
                    anchorPoint = new Vector2(1, 0);
                    break;

                default:
                    anchorPoint = Vector2.Zero;
                    break;
                }
                Vector2 pos = new Vector2(maxSize.X * anchorPoint.X, 0);
                foreach (UIComponent child in this.Reversed ? this.Children.Reverse() : this.Children)
                {
                    child.AnchorPoint.Value = anchorPoint;
                    child.Position.Value    = pos;
                    if (child.Visible)
                    {
                        pos.Y += child.ScaledSize.Value.Y + spacing;
                    }
                }
                this.Size.Value = new Vector2(maxSize.X, Math.Max(0, pos.Y - spacing));
            }
        }