protected override void Calculate(InputState istate)
		{
			if (istate.IsJustDown && innerBoundings.Contains(istate.PointerPosition))
			{
				isMouseDragging = true;
				Cannon.CrosshairSize.SetForce(CROSSHAIR_START_SCALE);
			}
			else if (!istate.IsDown && isMouseDragging)
			{
				isMouseDragging = false;
				Cannon.CrosshairSize.Set(0f);

				//Screen.PushNotification($"Cannon :: target({FloatMath.ToDegree(Cannon.Rotation.TargetValue):000}°)");
			}
			else if (isMouseDragging && istate.IsDown && !innerBoundings.Contains(istate.PointerPosition))
			{
				Cannon.Rotation.Set(FloatMath.PositiveAtan2(istate.PointerPosition.Y - Cannon.Center.Y, istate.PointerPosition.X - Cannon.Center.X));

				var dist = (istate.PointerPosition - Cannon.Center).Length();
				if (dist > 0)
				{
					var crosshairScale = FloatMath.Min(dist / CROSSHAIR_CENTER_DISTANCE, 1f);

					Cannon.CrosshairSize.Set(crosshairScale);
				}
			}
		}
		protected override void OnUpdate(GameTime gameTime, InputState istate)
		{
			if (!IsInViewport) return; // No drawing - no updating (state is frozen)

			internalTime += gameTime.GetElapsedSeconds();

			for (int i = ParticleCount - 1; i >= 0; i--)
			{
				particlePool[i].CurrentLifetime += gameTime.GetElapsedSeconds();
				if (particlePool[i].CurrentLifetime >= particlePool[i].MaxLifetime)
				{
					RemoveParticle(i);
				}
				else
				{
					particlePool[i].Position.X += particlePool[i].Velocity.X * gameTime.GetElapsedSeconds();
					particlePool[i].Position.Y += particlePool[i].Velocity.Y * gameTime.GetElapsedSeconds();
				}
			}

			timeSinceLastSpawn += gameTime.GetElapsedSeconds();
			while (timeSinceLastSpawn >= spawnDelay)
			{
				SpawnParticle();
				timeSinceLastSpawn -= spawnDelay;

				spawnDelay = _config.SpawnDelay;
			}
		}
		protected override void DoUpdate(GameTime gameTime, InputState istate)
		{
			if (IsOpening && FloatMath.IsNotOne(openingProgress))
			{
				bool hasOpened;
				openingProgress = FloatMath.LimitedInc(openingProgress, gameTime.GetElapsedSeconds() * HUDPauseButton.ANIMATION_SPEED, 1f, out hasOpened);
				if (hasOpened)
				{
					IsOpening = false;
				}

				UpdateOpeningPosition();
			}
			else if (IsClosing)
			{
				bool hasClosed;
				openingProgress = FloatMath.LimitedDec(openingProgress, gameTime.GetElapsedSeconds() * HUDPauseButton.ANIMATION_SPEED, 0f, out hasClosed);
				if (hasClosed)
				{
					Remove();
				}

				UpdateClosingPosition();
			}
		}
		public override void Update(GameTime gameTime, InputState istate)
		{
			if (isDragging)
			{
				if (istate.IsDown)
				{
					UpdateDrag(gameTime, istate);
				}
				else
				{
					EndDrag();
				}
			}
			else
			{
				if (istate.IsDown)
				{
					StartDrag(istate);
				}
				else if (!dragSpeed.IsZero() || !outOfBoundsForce.IsZero())
				{
					UpdateRestDrag(gameTime);
				}
			}
		}
示例#5
0
		protected override void OnPointerClick(FPoint relPositionPoint, InputState istate)
		{
			if (!IsEnabled) return;
			if (suppressClick) return;
			if (!IsCursorOnButton(istate)) return;

			lastClickTime = MonoSAMGame.CurrentTime.GetTotalElapsedSeconds();

			if (IsTripleClickMode)
			{
				multiClickCounter++;

				if (multiClickCounter >= 3)
				{
					multiClickCounter = 0;
					OnTriplePress(istate);
				}
			}
			else if (IsDoubleClickMode)
			{
				multiClickCounter++;

				if (multiClickCounter >= 2)
				{
					multiClickCounter = 0;
					OnDoublePress(istate);
				}
			}
			else if (IsSingleClickMode)
			{
				OnPress(istate);
			}
		}
示例#6
0
		private InputState(SAMViewportAdapter adapter, KeyboardState ks, MouseState ms, TouchCollection ts, GamePadState gs, InputState prev)
		{
			Mouse = ms;
			Keyboard = ks;
			TouchPanel = ts;
			GamePad = gs;

			if (Mouse.LeftButton == ButtonState.Pressed)
			{
				IsDown = true;
				PointerPosition = adapter.PointToScreen(Mouse.Position);
			}
			else if (TouchPanel.Count > 0)
			{
				IsDown = true;
				PointerPosition = adapter.PointToScreen(TouchPanel[0].Position.ToPoint());
			}
			else
			{
				IsDown = false;
				PointerPosition = prev.PointerPosition;
			}

			IsJustDown = IsDown && !prev.IsDown;
			IsJustUp = !IsDown && prev.IsDown;

			lastKeyState = prev.currentKeyState;
			currentKeyState = lastKeyState.ToDictionary(p => p.Key, p => ks.IsKeyDown(p.Key));
		}
示例#7
0
		protected override void OnUpdate(GameTime gameTime, InputState istate)
		{
			ShapePosition += velocity * gameTime.GetElapsedSeconds();

			ShapeRotation = FloatMath.IncModulo(ShapeRotation, rotationSpeed * gameTime.GetElapsedSeconds(), FloatMath.TAU);

			if (Lifetime < maxLifetime) ShapeAlpha = 1 - Lifetime / maxLifetime;
			if (Lifetime > maxLifetime) Alive = false;
		}
示例#8
0
		public void Update(GameTime gameTime, InputState istate)
		{
			float sec = gameTime.GetTotalElapsedSeconds();
			if (collCount0 != GC.CollectionCount(0)) { collCount0 = GC.CollectionCount(0); LastGC0 = sec; freq.Inc(sec); }
			if (collCount1 != GC.CollectionCount(1)) { collCount1 = GC.CollectionCount(1); LastGC1 = sec; freq.Inc(sec); }
			if (collCount2 != GC.CollectionCount(2)) { collCount2 = GC.CollectionCount(2); LastGC2 = sec; freq.Inc(sec); }

			TotalMemory = GC.GetTotalMemory(false) / (1024f * 1024f);
		}
示例#9
0
		private void UpdateSwitch(InputState istate)
		{
			if (istate.IsShortcutJustPressed(modifiers, key))
			{
				Active = !Active;

				triggerEvent?.Invoke(this);
			}
		}
示例#10
0
		private void UpdatePush(InputState istate)
		{
			Active = istate.IsShortcutPressed(modifiers, key);

			if (Active)
			{
				triggerEvent?.Invoke(this);
			}
		}
示例#11
0
		public static InputState GetState(SAMViewportAdapter adapter, InputState previous)
		{
			var ks = Microsoft.Xna.Framework.Input.Keyboard.GetState();
			var ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
			var ts = Microsoft.Xna.Framework.Input.Touch.TouchPanel.GetState();
			var gs = Microsoft.Xna.Framework.Input.GamePad.GetState(PlayerIndex.One);

			return new InputState(adapter, ks, ms, ts, gs, previous);
		}
		public void Update(GameTime gameTime, InputState istate)
		{
			timeSinceLastUpdate -= gameTime.GetElapsedSeconds();
			if (timeSinceLastUpdate <= 0)
			{
				timeSinceLastUpdate = updateInterval;

				Calculate(istate);
			}
		}
示例#13
0
		public static void Update(InputState istate)
		{
			foreach (var listener in listeners.ToList())
			{
				if (listener.Value.Owner.Alive)
					listener.Value.Update(istate);
				else
					listeners.Remove(listener.Key);
			}
		}
示例#14
0
		protected override void OnBeforeUpdate(GameTime gameTime, InputState state)
		{
#if DEBUG
			debugView.DebugPanelPosition = new Vector2(55, Owner.VAdapter.RealTotalHeight - 180);
			debugView.PerformancePanelBounds = new Rectangle(450, (int) (Owner.VAdapter.RealTotalHeight - 180), 200, 100);

			debugView.Enabled = DebugSettings.Get("PhysicsDebugView");
#endif

			PhysicsWorld.Step(gameTime.GetElapsedSeconds());
		}
		private void StartDrag(InputState istate)
		{
			mouseStartPos = istate.PointerPosition;
			startOffset = Screen.MapOffset;

			dragSpeed = Vector2.Zero;
			lastMousePos = istate.PointerPosition;
			lastMousePosTimer = 0f;

			isDragging = true;
		}
示例#16
0
		private void UpdateTrigger(InputState istate)
		{
			if (istate.IsShortcutJustPressed(modifiers, key))
			{
				Active = true;

				triggerEvent?.Invoke(this);
			}
			else
			{
				Active = false;
			}
		}
示例#17
0
		public void Update(GameTime gameTime, InputState istate)
		{
			Lifetime += gameTime.GetElapsedSeconds();

			for (int i = ActiveOperations.Count - 1; i >= 0; i--)
			{
				if (!ActiveOperations[i].Update(this, gameTime, istate))
				{
					ActiveOperations[i].OnEnd(this);
					ActiveOperations.RemoveAt(i);
				}
			}

			OnUpdate(gameTime, istate);
		}
示例#18
0
		public void Update(InputState istate)
		{
			switch (type)
			{
				case DebugListenerType.Trigger:
					UpdateTrigger(istate);
					break;
				case DebugListenerType.Switch:
					UpdateSwitch(istate);
					break;
				case DebugListenerType.Push:
					UpdatePush(istate);
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}
		}
示例#19
0
		private void UpdateMultiClick(InputState istate, float delta)
		{
			if (multiClickCounter > 0 && delta > MULTI_CLICK_TIME)
			{
				if (multiClickCounter == 1 && IsSingleClickMode)
				{
					OnPress(istate);
				}

				if (multiClickCounter == 2 && IsDoubleClickMode)
				{
					OnDoublePress(istate);
				}

				multiClickCounter = 0;
			}
		}
示例#20
0
		public void Update(GameTime gameTime, InputState state)
		{
			OnBeforeUpdate(gameTime, state);

			foreach (var entity in entities.ToList())
			{
				entity.Update(gameTime, state);
				if (!entity.Alive)
				{
					entities.Remove(entity);
					entity.OnRemove();

					var pde = entity as ISAMPostDrawable;
					if (pde != null) postDrawEntities.Remove(pde);
				}
			}

			OnAfterUpdate(gameTime, state);
		}
		private void UpdateDrag(GameTime gameTime, InputState istate)
		{
			var delta = istate.PointerPosition - mouseStartPos;

			Screen.MapOffsetX = startOffset.X + delta.X;
			Screen.MapOffsetY = startOffset.Y + delta.Y;

			CalculateOOB();

			lastMousePosTimer += gameTime.GetElapsedSeconds();
			if (lastMousePosTimer > DRAGSPEED_RESOLUTION)
			{
				dragSpeed = (istate.PointerPosition - lastMousePos) / lastMousePosTimer;

				//Debug.WriteLine(dragSpeed);

				lastMousePosTimer = 0f;
				lastMousePos = istate.PointerPosition;
			}
		}
示例#22
0
		protected override bool IsCursorOnButton(InputState istate)
		{
			var ellipseSize = Size;
			if (!OverrideEllipseSize.IsEmpty) ellipseSize = OverrideEllipseSize;


			var relativePoint = BoundingRectangle.Center - istate.PointerPosition;


			if (ellipseSize.IsQuadratic)
			{
				return relativePoint.LengthSquared() <= (ellipseSize.Width / 2) * (ellipseSize.Width / 2);
			}
			else
			{
				// http://math.stackexchange.com/a/76463/126706

				var a = (relativePoint.X * relativePoint.X) / (ellipseSize.Width * ellipseSize.Width);
				var b = (relativePoint.Y * relativePoint.Y) / (ellipseSize.Height * ellipseSize.Height);

				return a + b <= 1;
			}
		}
示例#23
0
		public void Update(GameTime gameTime, InputState istate)
		{
			bool hasFirst = false;
			for (int i = 0; i < lines.Count; i++)
			{
				if (hasFirst)
				{
					lines[i].UpdateDecay(gameTime, false);
				}
				else
				{
					if (lines[i].IsDecaying)
					{
						lines[i].UpdateDecay(gameTime, true);
						hasFirst = true;
					}
					else
					{
						lines[i].UpdateDecay(gameTime, false);
					}
				}

				if (!lines[i].IsAlive) lines.RemoveAt(i);
			}

			for (int i = lines.Count - 1; i >= 0; i--)
			{
				if (!lines[i].IsAlive) lines.RemoveAt(i);
			}

			float posY = TEXT_OFFSET;
			foreach (var line in lines.Where(p => p.Active()))
			{
				line.UpdatePosition(gameTime, font, lines.Count, ref posY);
			}
		}
示例#24
0
		protected override void DoUpdate(GameTime gameTime, InputState istate)
		{
			if (isOpened && FloatMath.IsNotOne(animationProgress))
			{
				animationProgress = FloatMath.LimitedInc(animationProgress, gameTime.GetElapsedSeconds() * ANIMATION_SPEED, 1f);
			}
			else if (!isOpened && FloatMath.IsNotZero(animationProgress))
			{
				animationProgress = FloatMath.LimitedDec(animationProgress, gameTime.GetElapsedSeconds() * ANIMATION_SPEED, 0f);
			}
		}
示例#25
0
		protected override void OnHold(InputState istate, float holdTime)
		{
			this.GDHUD().GDOwner.GDOwner.SetLevelScreen(Levels.LEVEL_DBG);
		}
示例#26
0
		protected override void OnTriplePress(InputState istate)
		{
			// Not Available
		}
示例#27
0
		protected override void OnPress(InputState istate)
		{
			this.GDHUD().GDOwner.PushNotification("Single Press");

			if (!isOpened)
			{
				Open();
			}
			else
			{
				Close();
			}
		}
		protected override void Calculate(InputState istate)
		{
			doBarrelRecharge = CalculateKI(intelligence, false);
		}
		protected override void OnUpdate(GameTime gameTime, InputState istate)
		{

		}
		public InputState GetNewState()
		{
			return stateCache = InputState.GetState(adapter, stateCache);
		}