Ejemplo n.º 1
0
        private void ConfigureDependencies()
        {
            _container = new DependencyInjectionContainer();

            _container.Configure(c => c.Export <MailMessageService>().As <IMailMessageService>().Lifestyle.Singleton());
            _container.Configure(c => c.Export <MailContactService>().As <IMailContactService>().Lifestyle.Singleton());

            _container.Configure(c => c.Export <MailAccountOverviewViewModel>().As <MailAccountOverviewViewModel>().Lifestyle.Singleton());
            _container.Configure(c => c.Export <MailAccountViewModel>().As <MailAccountViewModel>().Lifestyle.Singleton());
            _container.Configure(c => c.Export <MailContactOverviewViewModel>().As <MailContactOverviewViewModel>().Lifestyle.Singleton());
            _container.Configure(c => c.Export <MailContactViewModel>().As <MailContactViewModel>().Lifestyle.Singleton());
            _container.Configure(c => c.Export <Views.MailContacts.MailContactOverviewViewModel>().As <Views.MailContacts.MailContactOverviewViewModel>().Lifestyle.Singleton());
            _container.Configure(c => c.Export <MailMessageOverviewView>().As <MailMessageOverviewView>().Lifestyle.Singleton());
            _container.Configure(c => c.Export <MailMessageView>().As <MailMessageView>().Lifestyle.Singleton());

            _container.Configure(c => c.Export <UnitOfWork>().As <IUnitOfWork>().Lifestyle.Singleton());
            _container.Configure(c => c.Export <EventAggregator>().As <IEventAggregator>().Lifestyle.Singleton());
            _container.Configure(c => c.Export <CryptographyService>().As <ICryptographyService>().Lifestyle.Singleton());
            _container.Configure(c => c.ExportFactory <IServiceLocator>(() => new ServiceLocator(_container)).Lifestyle.Singleton());
            _container.Configure(c => c.ExportFactory(() =>
            {
                var optionsBuilder = new DbContextOptionsBuilder <MailieDbContext>();
                optionsBuilder.UseSqlite("Data Source=Mailie.db");
                return(new MailieDbContext(optionsBuilder.Options));
            }).Lifestyle.Singleton());

            StaticServiceLocator.SetCurrent(_container.Locate <IServiceLocator>());
        }
Ejemplo n.º 2
0
        public BattleGameMode(Entity battleWith, EventHandler clickEvent) : base(clickEvent)
        {
            var viewPort = StaticServiceLocator.GetService <BoxingViewportAdapter>();

            Camera = new Camera2D(viewPort)
            {
                Zoom = 1.0f
            };
            _content           = ContentManagerFactory.RequestContentManager();
            _backgroundTexture = _content.Load <Texture2D>($"TopDownRpg/hills");
            var dialogFont = _content.Load <SpriteFont>("dialog");
            var settings   = StaticServiceLocator.GetService <IControllerSettings>();

            DialogBox = new BattleStoryBoxDialog(ScreenSize.Size, dialogFont, settings.GamePadEnabled)
            {
                CompleteEvent = (sender, args) => Complete()
            };
            GuiManager.AddGuiLayer(DialogBox);
            var rectangle    = new Rectangle(new Point(), new Point(16, 16));
            var enemyEntity  = new BattleEntityRenderer(new Rectangle(new Point(600, 300), new Point(160, 160)), rectangle, battleWith, _content);
            var playerEntity = new BattleEntityRenderer(new Rectangle(new Point(50, 300), new Point(160, 160)), rectangle, PlayerEntity.Instance, _content);

            EntityList = new List <BattleEntityRenderer> {
                enemyEntity, playerEntity
            };
            AddInteractionController();
            var boundingRectangle = Camera.BoundingRectangle;
            var size = new Point((int)boundingRectangle.Size.Width, (int)boundingRectangle.Size.Height);

            _destinationRectangle = new Rectangle(boundingRectangle.Location.ToPoint(), size);
        }
Ejemplo n.º 3
0
        public static string ReadStory(string textFile)
        {
            var textReader = StaticServiceLocator.GetService <ISaveAndLoad>();
            var storyText  = textReader.LoadText($"Scripts/{textFile}.json");

            return(storyText);
        }
Ejemplo n.º 4
0
        public void AddAndGetServiceTest()
        {
            StaticServiceLocator.AddService <IButtonAble>(new KeyButton(Keys.A));
            var settings = StaticServiceLocator.GetService <IButtonAble>();

            Assert.IsInstanceOfType(settings, typeof(IButtonAble));
        }
Ejemplo n.º 5
0
        protected override void LoadContent()
        {
            base.LoadContent();
            StaticServiceLocator.AddService(GraphicsDevice);
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, ScreenSize.Width, ScreenSize.Height);

            _rpgScene = new TopDownRpgScene(viewportAdapter, _spriteBatch);
            StaticServiceLocator.AddService(viewportAdapter);
            var screens = new List <Screen>
            {
                new MainMenuScreen(viewportAdapter, Services, this),
                new LoadGameScreen(viewportAdapter, Services),
                new OptionsScreen(viewportAdapter, Services),
                new AudioOptionsScreen(viewportAdapter, Services),
                new VideoOptionsScreen(viewportAdapter, Services),
                new KeyboardOptionsScreen(viewportAdapter, Services),
                new MouseOptionsScreen(viewportAdapter, Services),
                new HelpScreen(viewportAdapter, Services),
                _rpgScene
            };

            foreach (var screen in screens)
            {
                screen.LoadContent();
                _screenComponent.Register(screen);
            }
        }
Ejemplo n.º 6
0
 static void Main()
 {
     StaticServiceLocator.AddService <ISaveAndLoad>(new SaveAndLoad());
     StaticServiceLocator.AddService <IControllerSettings>(new ControllerSettings());
     StaticServiceLocator.AddService <IPossibleMovements>(new FourWayPossibleMovement());
     using (var game = new DemoGame())
         game.Run();
 }
Ejemplo n.º 7
0
        public void ImportStory()
        {
            StaticServiceLocator.AddService <ISaveAndLoad>(new SaveAndLoad());
            var textReader = StaticServiceLocator.GetService <ISaveAndLoad>();
            var storyText  = textReader.LoadText("Scripts/hello.ink.json");

            Debug.WriteLine(storyText);
        }
Ejemplo n.º 8
0
 internal static void RunGame()
 {
     StaticServiceLocator.AddService <ISaveAndLoad>(new SaveAndLoad());
     StaticServiceLocator.AddService <IControllerSettings>(new ControllerSettings());
     StaticServiceLocator.AddService <IPossibleMovements>(new EightWayPossibleMovement(new CrowDistance()));
     game = new DemoGame();
     game.Run();
 }
Ejemplo n.º 9
0
        private void ConfigureDependencies()
        {
            _container = new DependencyInjectionContainer();

            ConfigureApplicationDependencies();
            ConfigureProtocolDependencies();

            StaticServiceLocator.SetCurrent(_container.Locate <IServiceLocator>());
        }
Ejemplo n.º 10
0
        public OptionTextBox(Size screenSize, SpriteFont font, int optionIndex, Choice choice) : base(screenSize, font)
        {
            Text        = choice.text;
            OptionIndex = optionIndex;
            Choice      = choice;
            var graphicsDevice = StaticServiceLocator.GetService <GraphicsDevice>();

            _choosenTexture = new Texture2D(graphicsDevice, 1, 1);
            _choosenTexture.SetData(new[] { new Color(1.0f, 1.0f, 0.55f, 0.5f) });
        }
Ejemplo n.º 11
0
        public GuiManager()
        {
            _guiLayers = new List <IGuiLayer>();
            var graphicsDevice = StaticServiceLocator.GetService <BoxingViewportAdapter>();

            _camera = new Camera2D(graphicsDevice)
            {
                Zoom = 1.0f
            };
        }
Ejemplo n.º 12
0
 public Entity Import(string fileName)
 {
     if (!_loadedEntities.ContainsKey(fileName))
     {
         var textReader = StaticServiceLocator.GetService <ISaveAndLoad>();
         var jsonText   = textReader.LoadText($"Entities/{fileName}.json");
         var entity     = JsonConvert.DeserializeObject <NpcEntity>(jsonText);
         entity.MoveDelegate       = _moveDelegate;
         _loadedEntities[fileName] = entity;
     }
     return(_loadedEntities[fileName]);
 }
Ejemplo n.º 13
0
        public void LoadOpenWorld(string levelName)
        {
            var possibleMovements = StaticServiceLocator.GetService <IPossibleMovements>();

            _possibleMovements = new PossibleMovementWrapper(possibleMovements);
            ClickEvent         = (sender, args) =>
            {
                Action action = Show <MainMenuScreen>;
                action.Invoke();
            };
            OpenWorldGameMode = new OpenWorldGameMode(_viewPort, _possibleMovements, levelName, _entityManager, _storyEngine, ClickEvent);
            var map        = OpenWorldGameMode.Map;
            var player     = PlayerEntity.Instance;
            var grassLayer = map.GetLayer <TiledTileLayer>("Grass-Layer");

            if (grassLayer != null)
            {
                var grassCollisionSystem = new TiledCollisionSystem(_possibleMovements, map, "Grass-Layer");
                PlayerEntity.Instance.OnMoveEvent += (sender, args) =>
                {
                    var point          = player.Position.ToPoint();
                    var grassCollision = grassCollisionSystem.CheckCollision(point);
                    if (grassCollision)
                    {
                        player.SpeedContext.Terrain = new SpeedGrass();
                    }
                    else if (player.SpeedContext.Terrain != null)
                    {
                        player.SpeedContext.Terrain = null;
                    }
                };
            }
            var teleportlayer = map.GetObjectGroup("Teleport-Layer");

            if (teleportlayer != null)
            {
                var tileSize    = new Point(map.TileWidth, map.TileHeight);
                var teleporters = new TiledObjectCollisionSystem(_possibleMovements, map, tileSize, "Teleport-Layer");
                PlayerEntity.Instance.OnMoveEvent += (sender, args) =>
                {
                    var point = player.Position.ToPoint();
                    if (teleporters.CheckCollision(point))
                    {
                        var teleporter = teleporters.GetObjectAt(point);
                        var position   = StringToVector.ConvertString(teleporter.Type);
                        PlayerEntity.Instance = new PlayerEntity(position);
                        GameModeStack.Unload();
                        LoadOpenWorld(teleporter.Name);
                    }
                };
            }
            GameModes.Push(OpenWorldGameMode);
        }
Ejemplo n.º 14
0
        public OpenWorldGameMode(ViewportAdapter viewPort, IPossibleMovements possibleMovements, string worldName, EntityManager entityManager, StoryEngine storyEngine, EventHandler clickEvent) : base(clickEvent)
        {
            _entityManager      = entityManager;
            EntityRenderersDict = new Dictionary <Entity, AbstractEntityRenderer>();
            _possibleMovements  = possibleMovements;
            _content            = ContentManagerFactory.RequestContentManager();
            RenderList          = new List <IRenderable>();
            Map = _content.Load <TiledMap>($"TopDownRpg/{worldName}");
            var graphics = StaticServiceLocator.GetService <GraphicsDevice>();

            _mapRenderer = new FullMapRenderer(graphics);
            _mapRenderer.SwapMap(Map);
            _tileSize     = new Vector2(Map.TileWidth, Map.TileHeight);
            _moverManager = new MoverManager();
            var collisionSystem = new CompositeAbstractCollisionSystem(_possibleMovements);

            _expiringSpatialHash = new ExpiringSpatialHashCollisionSystem <Entity>(_possibleMovements);
            _spatialHashMover    = new SpatialHashMoverManager <Entity>(collisionSystem, _expiringSpatialHash);
            AddPlayer();
            var entityController = EntityControllerFactory.AddEntityController(PlayerEntity.Instance, _possibleMovements, _moverManager);
            var texture          = _content.Load <Texture2D>("TopDownRpg/Path");
            var endTexture       = _content.Load <Texture2D>("TopDownRpg/BluePathEnd");

            collisionSystem.AddCollisionSystem(new TiledCollisionSystem(_possibleMovements, Map, "Collision-Layer"));
            collisionSystem.AddCollisionSystem(_expiringSpatialHash);
            CollisionSystem = collisionSystem;
            AddClickController(PlayerEntity.Instance);
            PathRenderer = new PathRenderer(_moverManager, PlayerEntity.Instance, texture, endTexture, _tileSize.ToPoint(), Map.Width, Map.Height);
            UpdateList.Add(_expiringSpatialHash);
            UpdateList.Add(entityController);
            UpdateList.Add(_spatialHashMover);
            UpdateList.Add(_moverManager);
            CameraTracker = CameraTrackerFactory.CreateTracker(viewPort, EntityRenderersDict[PlayerEntity.Instance], Map);
            UpdateList.Add(CameraTracker);
            LoadEntities();
            var dialogFont = _content.Load <SpriteFont>("dialog");
            var settings   = StaticServiceLocator.GetService <IControllerSettings>();

            DialogBox = new EntityStoryBoxDialog(ScreenSize.Size, dialogFont, settings.GamePadEnabled);
            GuiManager.AddGuiLayer(DialogBox);
            storyEngine.LoadWorld(AddEntity, RemoveEntity, CollisionSystem.CheckMovementCollision, worldName);
            InteractEvent += (sender, args) =>
            {
                var facingDirection = PlayerEntity.Instance.FacingDirection;
                var interactTarget  = (PlayerEntity.Instance.Position + facingDirection).ToPoint();
                Interact(interactTarget);
            };
            AddInteractionController();
            CameraController.AddCameraZoomController(CameraTracker, ClickController);
            CameraController.AddCameraMovementController(CameraTracker, ClickController);
        }
Ejemplo n.º 15
0
        public GamePage()
        {
            InitializeComponent();

            StaticServiceLocator.AddService <ISaveAndLoad>(new SaveAndLoad());
            StaticServiceLocator.AddService <IControllerSettings>(new ControllerSettings());
            StaticServiceLocator.AddService <IPossibleMovements>(new FourWayPossibleMovement());
            // Create the game.
            var launchArguments = string.Empty;
            var bounds          = Window.Current.Bounds;

            ScreenSize.Size = new MonoGame.Extended.Size((int)bounds.Width, (int)bounds.Height);
            _game           = MonoGame.Framework.XamlGame <DemoGame> .Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);
        }
Ejemplo n.º 16
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            StaticServiceLocator.AddService <ISaveAndLoad>(new SaveAndLoad(Assets));
            StaticServiceLocator.AddService <IControllerSettings>(new ControllerSettings());
            StaticServiceLocator.AddService <ITextToSpeech>(new TextToSpeechImplementation());
            StaticServiceLocator.AddService(new List <StoryInterceptor> {
                new TextToSpeechStoryInterceptor()
            });
            StaticServiceLocator.AddService <IPossibleMovements>(new EightWayPossibleMovement(new CrowDistance()));
            var g = new DemoGame();

            SetContentView((View)g.Services.GetService(typeof(View)));
            g.Run();
        }
Ejemplo n.º 17
0
        public void SinglePLayerControllerFactoryTest()
        {
            StaticServiceLocator.AddService <IControllerSettings>(new ControllerSettings());
            var controller = new SinglePlayerControllerFactory();

            controller.CreateEntityController(new BaseMovable(), new EightWayPossibleMovement(new CrowDistance()),
                                              new MoverManager());
            const Buttons buttons = Buttons.A;

            controller.AddGamePadButton(new List <IButtonAble>(), buttons);
            controller.AddKeyBoardButton(new List <IButtonAble>(), Keys.A);

            var button = new KeyButton(Keys.A);


            var smart = new SmartController();

            smart.AddButton(new BaseSmartButton(button));
            smart.Update(new GameTime());
        }
Ejemplo n.º 18
0
        public TextBox(Size screensize, SpriteFont font)
        {
            Font          = font;
            CharacterSize = font.MeasureString(new StringBuilder("W", 1));
            Pages         = new List <string>();
            BorderWidth   = 2;
            DialogColor   = Color.Black;

            BorderColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);

            var graphicsDevice = StaticServiceLocator.GetService <GraphicsDevice>();

            FillTexture = new Texture2D(graphicsDevice, 1, 1);
            FillColor   = new Color(1.0f, 1.0f, 1.0f, 0.5f);

            _borderTexture = new Texture2D(graphicsDevice, 1, 1);
            _borderTexture.SetData(new[] { BorderColor });
            var sizeX = (int)(screensize.Width * 0.5);
            var sizeY = (int)(screensize.Height * 0.2);

            Size = new Vector2(sizeX, sizeY);
        }
        public override void Execute(StoryContext context)
        {
            var textToSpeech = StaticServiceLocator.GetService <ITextToSpeech>();

            textToSpeech.Speak(context.Text);
        }
Ejemplo n.º 20
0
        public void AddAndGetBadServiceTest()
        {
            var settings = StaticServiceLocator.GetService <IControllerSettings>();

            Assert.IsNotInstanceOfType(settings, typeof(IControllerSettings));
        }
Ejemplo n.º 21
0
        public void AddInteractionController()
        {
            var controller     = new SmartController();
            var buttonsCreated = StaticServiceLocator.ContainsService <List <IButtonAble> >();

            if (!buttonsCreated)
            {
                var interactButton = new List <IButtonAble>
                {
                    new KeyButton(Keys.E),
                    new GamePadButton(Buttons.A)
                };
                StaticServiceLocator.AddService(interactButton);
            }
            var buttons     = StaticServiceLocator.GetService <List <IButtonAble> >();
            var smartButton = new CompositeSmartButton(buttons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    if (!DialogBox.Interact())
                    {
                        InteractEvent?.Invoke(this, null);
                    }
                }
            };

            controller.AddButton(smartButton);
            var upButton = new List <IButtonAble> {
                new DirectionGamePadButton(Buttons.DPadUp, PlayerIndex.One, false)
            };
            var smartUpButton = new CompositeSmartButton(upButton)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    DialogBox.Up();
                }
            };

            controller.AddButton(smartUpButton);
            var downButton = new List <IButtonAble> {
                new DirectionGamePadButton(Buttons.DPadDown, PlayerIndex.One, false)
            };
            var smartDownButton = new CompositeSmartButton(downButton)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    DialogBox.Down();
                }
            };

            controller.AddButton(smartDownButton);
            var optionsButtons = new List <IButtonAble>
            {
                new KeyButton(Keys.Escape),
                new GamePadButton(Buttons.Start)
            };
            var optionsAction = new CompositeSmartButton(optionsButtons)
            {
                OnButtonJustPressed = (sender, args) =>
                {
                    _backButtonClickEvent.Invoke(this, null);
                }
            };

            controller.AddButton(optionsAction);
            UpdateList.Add(controller);
        }
 public SinglePlayerControllerFactory()
 {
     ControllerSettings = StaticServiceLocator.GetService <IControllerSettings>();
 }