Esempio n. 1
0
        public BattleScene(Battle battle, Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _battle = battle;

            var actionsComponent = new ActionsComponent(game);

            actionsComponent.SetPosition(new Vector2(
                                             0, Resolution.VirtualHeight - actionsComponent.GetHeight()
                                             ));

            var attackerComponent = new ArmyComponent(_battle.GetAttacker(), game);

            attackerComponent.SetPosition(new Vector2(
                                              Resolution.VirtualWidth / 2 - attackerComponent.GetWidth() / 2,
                                              Resolution.VirtualHeight - attackerComponent.GetHeight() - actionsComponent.GetHeight() - 20
                                              ));

            var targetComponent = new ArmyComponent(_battle.GetTarget(), game);

            targetComponent.SetPosition(new Vector2(
                                            Resolution.VirtualWidth / 2 - targetComponent.GetWidth() / 2,
                                            20
                                            ));

            AddComponent(actionsComponent);
            AddComponent(attackerComponent);
            AddComponent(targetComponent);
        }
Esempio n. 2
0
 private void OnMetaFlagRemoval(EntityUid uid, ActionsComponent component, ref MetaFlagRemoveAttemptEvent args)
 {
     if (component.LifeStage == ComponentLifeStage.Running)
     {
         args.Cancelled = true;
     }
 }
Esempio n. 3
0
 private void OnMetaFlagRemoval(EntityUid uid, ActionsComponent component, ref MetaFlagRemoveAttemptEvent args)
 {
     if (component.LifeStage == ComponentLifeStage.Running)
     {
         args.ToRemove &= ~MetaDataFlags.EntitySpecific;
     }
 }
 private void OnCanGetState(EntityUid uid, ActionsComponent component, ref ComponentGetStateAttemptEvent args)
 {
     // Only send action state data to the relevant player.
     if (args.Player.AttachedEntity != uid)
     {
         args.Cancelled = true;
     }
 }
    protected void PerformAction(ActionsComponent component, ActionType action, BaseActionEvent?actionEvent, TimeSpan curTime)
    {
        var handled = false;

        var toggledBefore = action.Toggled;

        if (actionEvent != null)
        {
            // This here is required because of client-side prediction (RaisePredictiveEvent results in event re-use).
            actionEvent.Handled = false;

            if (action.Provider == null)
            {
                RaiseLocalEvent(component.Owner, (object)actionEvent, broadcast: true);
            }
            else
            {
                RaiseLocalEvent(action.Provider.Value, (object)actionEvent, broadcast: true);
            }

            handled = actionEvent.Handled;
        }

        // Execute convenience functionality (pop-ups, sound, speech)
        handled |= PerformBasicActions(component.Owner, action);

        if (!handled)
        {
            return; // no interaction occurred.
        }
        // reduce charges, start cooldown, and mark as dirty (if required).

        var dirty = toggledBefore == action.Toggled;

        if (action.Charges != null)
        {
            dirty = true;
            action.Charges--;
            if (action.Charges == 0)
            {
                action.Enabled = false;
            }
        }

        action.Cooldown = null;
        if (action.UseDelay != null)
        {
            dirty           = true;
            action.Cooldown = (curTime, curTime + action.UseDelay.Value);
        }

        if (dirty)
        {
            Dirty(component);
        }
    }
Esempio n. 6
0
        private IItemStateComponent GetOrAdd <TInput>()
        {
            var key = typeof(TInput).FullName;

            if (!this.parent.TryGetValue(key, out var component))
            {
                component = new ActionsComponent();
                this.parent.Add(key, component);
            }

            return(component as IItemStateComponent);
        }
    private void OnHandEquipped(EntityUid uid, ActionsComponent component, DidEquipHandEvent args)
    {
        var ev = new GetItemActionsEvent();

        RaiseLocalEvent(args.Equipped, ev, false);

        if (ev.Actions.Count == 0)
        {
            return;
        }

        AddActions(args.User, ev.Actions, args.Equipped, component);
    }
    private void OnDidEquip(EntityUid uid, ActionsComponent component, DidEquipEvent args)
    {
        var ev = new GetItemActionsEvent(args.SlotFlags);

        RaiseLocalEvent(args.Equipment, ev, false);

        if (ev.Actions.Count == 0)
        {
            return;
        }

        AddActions(args.Equipee, ev.Actions, args.Equipment, component);
    }
        public void Scenario()
        {
            var player = _world.CreateEntity();

            player.Attach(new PlayerComponent());
            player.Attach(new StatusComponent());
            player.Attach(new PropComponent());

            var playerActions = new ActionsComponent();

            player.Attach(playerActions);


            var enemies = new List <Entity>();

            for (var i = 0; i < 10; ++i)
            {
                var enemy = _world.CreateEntity();
                enemy.Attach(new StatusComponent());
                enemy.Attach(new PropComponent());
                enemy.Attach(new ActionsComponent());

                enemies.Add(enemy);
            }

            var battle = _world.CreateEntity();

            battle.Attach(new BattleComponent(enemies, player));

            // TODO: BattleSystem scenario
            for (var i = 0; i < 20; ++i)
            {
                _world.Update(new GameTime());

                var turn = battle.Get <TurnComponent>();
                if (turn != null && turn.State == Turn.Player)
                {
                    battle.Get <ActionQueueComponent>()
                    .Add(new ActionQueueItem(playerActions.DrinkCoffee, player));
                    battle.Attach(new TurnEndComponent());
                }
            }
        }
 private void GetState(EntityUid uid, ActionsComponent component, ref ComponentGetState args)
 {
     args.State = new ActionsComponentState(component.Actions.ToList());
 }
 private void OnHandUnequipped(EntityUid uid, ActionsComponent component, DidUnequipHandEvent args)
 {
     RemoveProvidedActions(uid, args.Unequipped, component);
 }
 private void OnDidUnequip(EntityUid uid, ActionsComponent component, DidUnequipEvent args)
 {
     RemoveProvidedActions(uid, args.Equipment, component);
 }
 protected virtual void AddActionInternal(ActionsComponent comp, ActionType action)
 {
     comp.Actions.Add(action);
 }
Esempio n. 14
0
 private void OnStartup(EntityUid uid, ActionsComponent component, ComponentStartup args)
 {
     _metaSystem.AddFlag(uid, MetaDataFlags.EntitySpecific);
 }
Esempio n. 15
0
        public ActionsUI(ActionsSystem system, ActionsComponent component)
        {
            SetValue(LayoutContainer.DebugProperty, true);
            System = system;
            Component = component;
            _gameHud = IoCManager.Resolve<IGameHud>();
            _timing = IoCManager.Resolve<IGameTiming>();
            _entMan = IoCManager.Resolve<IEntityManager>();
            _menu = new ActionMenu(this);

            LayoutContainer.SetGrowHorizontal(this, LayoutContainer.GrowDirection.End);
            LayoutContainer.SetGrowVertical(this, LayoutContainer.GrowDirection.Constrain);
            LayoutContainer.SetAnchorTop(this, 0f);
            LayoutContainer.SetAnchorBottom(this, 0.8f);
            LayoutContainer.SetMarginLeft(this, 13);
            LayoutContainer.SetMarginTop(this, 110);

            HorizontalAlignment = HAlignment.Left;
            VerticalExpand = true;

            var resourceCache = IoCManager.Resolve<IResourceCache>();

            // everything needs to go within an inner panel container so the panel resizes to fit the elements.
            // Because ActionsUI is being anchored by layoutcontainer, the hotbar backing would appear too tall
            // if ActionsUI was the panel container

            var panelContainer = new PanelContainer()
            {
                StyleClasses = {StyleNano.StyleClassHotbarPanel},
                HorizontalAlignment = HAlignment.Left,
                VerticalAlignment = VAlignment.Top
            };
            AddChild(panelContainer);

            var hotbarContainer = new BoxContainer
            {
	            Orientation = LayoutOrientation.Vertical,
                SeparationOverride = 3,
                HorizontalAlignment = HAlignment.Left
            };
            panelContainer.AddChild(hotbarContainer);

            var settingsContainer = new BoxContainer
            {
                Orientation = LayoutOrientation.Horizontal,
                HorizontalExpand = true
            };
            hotbarContainer.AddChild(settingsContainer);

            settingsContainer.AddChild(new Control { HorizontalExpand = true, SizeFlagsStretchRatio = 1 });
            _lockTexture = resourceCache.GetTexture("/Textures/Interface/Nano/lock.svg.192dpi.png");
            _unlockTexture = resourceCache.GetTexture("/Textures/Interface/Nano/lock_open.svg.192dpi.png");
            _lockButton = new TextureButton
            {
                TextureNormal = _unlockTexture,
                HorizontalAlignment = HAlignment.Center,
                VerticalAlignment = VAlignment.Center,
                SizeFlagsStretchRatio = 1,
                Scale = (0.5f, 0.5f),
                ToolTip = Loc.GetString("ui-actionsui-function-lock-action-slots"),
                TooltipDelay = CustomTooltipDelay
            };
            settingsContainer.AddChild(_lockButton);
            settingsContainer.AddChild(new Control { HorizontalExpand = true, SizeFlagsStretchRatio = 2 });
            _settingsButton = new TextureButton
            {
                TextureNormal = resourceCache.GetTexture("/Textures/Interface/Nano/gear.svg.192dpi.png"),
                HorizontalAlignment = HAlignment.Center,
                VerticalAlignment = VAlignment.Center,
                SizeFlagsStretchRatio = 1,
                Scale = (0.5f, 0.5f),
                ToolTip = Loc.GetString("ui-actionsui-function-open-abilities-menu"),
                TooltipDelay = CustomTooltipDelay
            };
            settingsContainer.AddChild(_settingsButton);
            settingsContainer.AddChild(new Control { HorizontalExpand = true, SizeFlagsStretchRatio = 1 });

            // this allows a 2 column layout if window gets too small
            _slotContainer = new GridContainer
            {
                MaxGridHeight = CalcMaxHeight()
            };
            hotbarContainer.AddChild(_slotContainer);

            _loadoutContainer = new BoxContainer
            {
                Orientation = LayoutOrientation.Horizontal,
                HorizontalExpand = true,
                MouseFilter = MouseFilterMode.Stop
            };
            hotbarContainer.AddChild(_loadoutContainer);

            _loadoutContainer.AddChild(new Control { HorizontalExpand = true, SizeFlagsStretchRatio = 1 });
            var previousHotbarIcon = new TextureRect()
            {
                Texture = resourceCache.GetTexture("/Textures/Interface/Nano/left_arrow.svg.192dpi.png"),
                HorizontalAlignment = HAlignment.Center,
                VerticalAlignment = VAlignment.Center,
                SizeFlagsStretchRatio = 1,
                TextureScale = (0.5f, 0.5f)
            };
            _loadoutContainer.AddChild(previousHotbarIcon);
            _loadoutContainer.AddChild(new Control { HorizontalExpand = true, SizeFlagsStretchRatio = 2 });
            _loadoutNumber = new Label
            {
                Text = "1",
                SizeFlagsStretchRatio = 1
            };
            _loadoutContainer.AddChild(_loadoutNumber);
            _loadoutContainer.AddChild(new Control { HorizontalExpand = true, SizeFlagsStretchRatio = 2 });
            var nextHotbarIcon = new TextureRect
            {
                Texture = resourceCache.GetTexture("/Textures/Interface/Nano/right_arrow.svg.192dpi.png"),
                HorizontalAlignment = HAlignment.Center,
                VerticalAlignment = VAlignment.Center,
                SizeFlagsStretchRatio = 1,
                TextureScale = (0.5f, 0.5f)
            };
            _loadoutContainer.AddChild(nextHotbarIcon);
            _loadoutContainer.AddChild(new Control { HorizontalExpand = true, SizeFlagsStretchRatio = 1 });

            _slots = new ActionSlot[ActionsSystem.Slots];

            _dragShadow = new TextureRect
            {
                MinSize = (64, 64),
                Stretch = TextureRect.StretchMode.Scale,
                Visible = false,
                SetSize = (64, 64)
            };
            UserInterfaceManager.PopupRoot.AddChild(_dragShadow);

            for (byte i = 0; i < ActionsSystem.Slots; i++)
            {
                var slot = new ActionSlot(this, _menu, i, _timing, _entMan);
                _slotContainer.AddChild(slot);
                _slots[i] = slot;
            }

            DragDropHelper = new DragDropHelper<ActionSlot>(OnBeginActionDrag, OnContinueActionDrag, OnEndActionDrag);
            DragDropHelper.Deadzone = DragDeadZone;

            MinSize = (10, 400);
        }
Esempio n. 16
0
 private void OnPlayerAttached(EntityUid uid, ActionsComponent component, PlayerAttachedEvent args)
 {
     // need to send state to new player.
     component.Dirty();
 }
Esempio n. 17
0
 private void OnShutdown(EntityUid uid, ActionsComponent component, ComponentShutdown args)
 {
     _metaSystem.RemoveFlag(uid, MetaDataFlags.EntitySpecific);
 }