public void Execute()
        {
            string fileName = Path.GetFileName(args.FilePath);

            if (File.Exists(Path.Combine(locationModel.LocalDirectoryBackgrounds, fileName)))
            {
                fileName = GetUnusedName(locationModel.LocalDirectoryBackgrounds, fileName);
            }

            string destinationFileName = $"{Path.GetFileNameWithoutExtension(fileName)}.jpg";
            string destinationPath     = Path.Combine(locationModel.LocalDirectoryBackgrounds, destinationFileName);

            BitmapImage originalBitmap = new BitmapImage(new Uri(args.FilePath));

            if (!args.CropArea.IsEmpty)
            {
                SaveJpeg(CropBitmap(originalBitmap, args.CropArea), destinationPath);
            }
            else
            {
                SaveJpeg(originalBitmap, destinationPath);
            }

            BackgroundModel background = BackgroundFactory.NewBackgroundModel(args.Name, destinationFileName, BaseDirectoryType.BACKGROUNDS_DIRECTORY, false, args.Layout);

            database.AddBackground(background);
            collection.Add(background);
            screenModel.SetBackground(background);

            Injector.ExecuteCommand <ValidatePlaceholderCollectionCommand>(new CollectionEventArgs <PlaceholderModel>(0, placeholderCollection, placeholderCollection.Items.ToArray()));
        }
Пример #2
0
        /// <summary>
        /// Creates an instance of <see cref="BackgroundListItemViewModel"/>
        /// </summary>
        public BackgroundListItemViewModel(BackgroundModel backgroundModel, StringService stringService)
        {
            _backgroundModel = backgroundModel;
            _stringService   = stringService;

            Initialize();
        }
        /// <summary>
        /// Creates an instance of <see cref="BackgroundViewModel"/>
        /// </summary>
        public BackgroundViewModel(BackgroundModel backgroundModel)
        {
            _backgroundModel = backgroundModel;

            _skills = "None";

            if (_backgroundModel.Skills.Count > 0)
            {
                _skills = String.Join(", ", _backgroundModel.Skills.Select(x => _stringService.GetString(x)));
            }
            else if (_backgroundModel.SkillsTraitIndex > -1 &&
                     _backgroundModel.SkillsTraitIndex < _backgroundModel.Traits.Count)
            {
                TraitModel trait = _backgroundModel.Traits[_backgroundModel.SkillsTraitIndex];
                _skills = trait.TextCollection[0].Trim();
            }
            else if (_backgroundModel.StartingTraitIndex > -1 &&
                     _backgroundModel.StartingTraitIndex < _backgroundModel.Traits.Count)
            {
                foreach (string text in _backgroundModel.Traits[_backgroundModel.StartingTraitIndex].TextCollection)
                {
                    if (text.Contains("Skills: "))
                    {
                        _skills = text.Replace("Skills: ", "").Trim();
                        break;
                    }
                }
            }

            foreach (TraitModel trait in _backgroundModel.Traits)
            {
                _traits.Add(new TraitViewModel(trait));
            }
        }
Пример #4
0
 /// <summary>
 /// Returns true if the search input applies to the model
 /// </summary>
 public bool SearchInputApplies(BackgroundSearchInput searchInput, BackgroundModel backgroundModel)
 {
     return(HasSearchText(backgroundModel, searchInput.SearchText) &&
            HasSkill(backgroundModel, searchInput.Skill.Key) &&
            HasTool(backgroundModel, searchInput.Tool.Key) &&
            HasLanguage(backgroundModel, searchInput.Language.Key));
 }
        public void Execute()
        {
            BackgroundModel background = backgroundCollection.Get(args.Value);

            string parentProfileNames = GetParentProfileNames(background);

            if (parentProfileNames != null)
            {
                MessageBoxView.Show("Can't delete this background", $"This background is used by one or more profiles ({parentProfileNames}), you can't delete it.");
                return;
            }

            backgroundCollection.Remove(background);

            if (screenModel.Background == background)
            {
                // Default background can't be deleted so there's always at least 1 item in the list.
                screenModel.SetBackground(backgroundCollection.Items[0]);
            }

            database.DeleteBackground(background);

            string dirPath = locationModel.GetGraphicBasePath(background.DirectoryType);

            File.Delete(Path.Combine(dirPath, background.FileName));
        }
Пример #6
0
 private void ImportBackgrounds()
 {
     foreach (BackgroundModel backgroundModel in _backgrounds)
     {
         if (_addAllEntries)
         {
             _compendium.AddBackground(backgroundModel);
         }
         else if (_skipDuplicateEntries)
         {
             if (!_compendium.Backgrounds.Any(x => x.Name.Equals(backgroundModel.Name, StringComparison.CurrentCultureIgnoreCase)))
             {
                 _compendium.Backgrounds.Add(backgroundModel);
             }
         }
         else if (_replaceExistingEntries)
         {
             BackgroundModel existing = _compendium.Backgrounds.FirstOrDefault(x => x.Name.Equals(backgroundModel.Name, StringComparison.CurrentCultureIgnoreCase));
             if (existing == null)
             {
                 _compendium.AddBackground(backgroundModel);
             }
             else
             {
                 backgroundModel.Id = existing.Id;
                 _compendium.UpdateBackground(backgroundModel);
             }
         }
     }
 }
Пример #7
0
 /// <summary>
 /// Adds a background model
 /// </summary>
 public void AddBackground(BackgroundModel backgroundModel)
 {
     if (backgroundModel != null &&
         !_backgrounds.Any(x => x.Id == backgroundModel.Id))
     {
         _backgrounds.Add(backgroundModel);
     }
 }
Пример #8
0
        /// <summary>
        /// Updates the model
        /// </summary>
        public void UpdateModel(BackgroundModel backgroundModel)
        {
            _backgroundModel = backgroundModel;

            Initialize();

            OnPropertyChanged("");
        }
    public void CreateSingleColourBackgroundTest()
    {
        var bg = new BackgroundModel(columns: 1, rows: 1, colours: new Colour[] { Colour.Red });

        Colour colour;
        var    tryGet = bg.TryGet(0, 0, out colour);

        Assert.IsTrue(tryGet == true && colour == Colour.Red);
    }
Пример #10
0
 public void init(int x, int y, GameManager gm)
 {
     this.gm          = gm;
     this.modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
     modelObject.name = "BG Model";
     this.bg_model    = modelObject.AddComponent <BackgroundModel>();
     this.bg_model.init(this);
     bgMat = bg_model.GetComponent <Renderer> ().material;
 }
Пример #11
0
        public void SetBackground(BackgroundModel background)
        {
            Background = background;

            string dirPath = locationModel.GetGraphicBasePath(background.DirectoryType);

            bitmap = assetsFactory.GetNoCache(Path.Combine(dirPath, Background.FileName));

            DispatchEvent(new ScreenModelEventArgs(EVENT_BACKGROUND_CHANGED, this));
        }
Пример #12
0
 void SetBackground(BGType background)
 {
     // when there's changes in type
     if (_TmpCurrentType != CurrentType)
     {
         CurrentBackgroundModel = FindBackground(background);
         CurrentBackgroundModel.BGSprite.Init();
         _TmpCurrentType = CurrentType;
     }
 }
Пример #13
0
        /// <summary>
        /// Gets formatted xml of object
        /// </summary>
        public string GetXML(BackgroundModel model)
        {
            string xml = String.Empty;

            if (model != null)
            {
                xml = $"<background><id>{model.Id}</id>{model.XML}</background>";
            }

            return(xml);
        }
Пример #14
0
        protected override MenuItem ModelToItem(ProfileModel model)
        {
            var             item       = base.ModelToItem(model);
            BackgroundModel background = backgroundCollection.Get(model.BackgroundId);

            item.Icon = new Image()
            {
                Source = assetsFactory.GetLayoutIcon(background.Layout)
            };
            return(item);
        }
Пример #15
0
 public PlayerCharacterModel()
 {
     PlayerClass   = new ClassModel();
     Archetype     = new ArchetypeModel();
     Background    = new BackgroundModel();
     Race          = new RaceModel();
     Alignment     = new AlignmentModel();
     AbilityScores = new List <PcAbilityScoreModel>();
     SavingThrows  = new List <int>();
     PlayerSkills  = new List <int>();
 }
Пример #16
0
        internal void DeleteBackground(BackgroundModel background)
        {
            using (SQLiteConnection db = new SQLiteConnection(dbArgs))
            {
                db.Open();

                NoQuery($"DELETE FROM backgrounds WHERE id = {background.Id}"
                        , db);

                db.Close();
            }
        }
Пример #17
0
        public void AddBackground(BackgroundModel background)
        {
            using (SQLiteConnection db = new SQLiteConnection(dbArgs))
            {
                db.Open();

                NoQuery("INSERT INTO backgrounds (id, name, fileName, directoryType, isBuiltIn, layoutType) VALUES " +
                        $"({background.Id}, '{StringUtils.ToDatabaseUserString(background.Name)}', '{background.FileName}', {(int)background.DirectoryType}, {Convert.ToInt32(background.IsBuiltInt)}, {(int)background.Layout})"
                        , db);

                db.Close();
            }
        }
Пример #18
0
        public ActionResult Background()
        {
            BackgroundModel bgModel = new BackgroundModel();

            HttpResponseMessage response = Client.GetAsync("api/CreateCharacter/GetAllBackgrounds").Result;

            if (response.IsSuccessStatusCode)
            {
                IEnumerable <Background> backgrounds = response.Content.ReadAsAsync <IEnumerable <Background> >().Result;

                bgModel.TheBackgrounds = backgrounds.ToList <Background>();
            }

            return(View(bgModel));
        }
Пример #19
0
 internal void UpdateProfile(ProfileModel profile)
 {
     // TODO Add update management to abstract class?
     foreach (MenuItem item in ContextMenu.Items)
     {
         if ((int)item.Tag == profile.Id)
         {
             BackgroundModel background = backgroundCollection.Get(profile.BackgroundId);
             item.Icon = new Image()
             {
                 Source = assetsFactory.GetLayoutIcon(background.Layout)
             };
             break;
         }
     }
 }
Пример #20
0
 public List<BackgroundModel> GetBackgroundList()
 {
     List<BackgroundModel> backgroundList = new List<BackgroundModel>();
     IEnumerable<BackgroundTable> backgroundTableList = DatabaseManager.Current.FetchBackgroundItems();
     if (backgroundTableList.Count() == 0)
     {
         Init();
         backgroundTableList = DatabaseManager.Current.FetchBackgroundItems();
     }
     foreach (BackgroundTable item in backgroundTableList)
     {
         BackgroundModel backgroundItem = new BackgroundModel(item);
         backgroundList.Add(backgroundItem);
     }
     return backgroundList;
 }
Пример #21
0
        public void Execute()
        {
            List <BackgroundModel> backgrounds = database.GetAllBackgrounds();

            if (backgrounds.Count == 0)
            {
                BackgroundModel defaultBackground = BackgroundFactory.NewBackgroundModel("Default", "background.png", BaseDirectoryType.GRAPHICAL_ASSETS, true, ScreenLayoutType.SINGLE);
                backgroundCollection.AddRange(new List <BackgroundModel>(new BackgroundModel[] { defaultBackground }));
                database.AddBackground(defaultBackground);
                screenModel.SetBackground(defaultBackground);
            }
            else
            {
                backgroundCollection.AddRange(backgrounds);
                screenModel.SetBackground(backgrounds[0]);
            }
        }
        private string GetParentProfileNames(BackgroundModel background)
        {
            string names = "";

            foreach (var profile in profileCollection.Items)
            {
                if (profile.BackgroundId == background.Id)
                {
                    names += $"{profile.Name}, ";
                }
            }

            if (names.Length > 0)
            {
                return(names.Substring(0, names.Length - 2));
            }
            return(null);
        }
Пример #23
0
 public PlayerCharacterModel()
 {
     AbilityScores = new List <PcAbilityScoreModel>();
     Alignment     = new AlignmentModel();
     Archetype     = new ArchetypeModel();
     Background    = new BackgroundModel();
     PlayerClass   = new ClassModel();
     Equipment     = new List <PcEquipmentModel>();
     Features      = new List <FeatureModel>();
     Player        = new PlayerModel();
     Race          = new RaceModel();
     SavingThrows  = new List <int>();
     PlayerSkills  = new List <int>();
     Spells        = new List <PcSpellModel>();
     SpellLevels   = new List <PcSpellLevelModel>();
     Traits        = new List <TraitModel>();
     Treasure      = new List <PcTreasureModel>();
 }
Пример #24
0
        public void Execute()
        {
            ScreenLayoutType currentLayout = screenModel.Layout;
            BackgroundModel  background    = backgroundCollection.Get(args.ItemId);

            screenModel.SetBackground(background);

            bool layoutFixed = false;

            if (currentLayout == ScreenLayoutType.TRIPLE && background.Layout == ScreenLayoutType.SINGLE)
            {
                layoutFixed = ScreenUtils.PromptUserIfOutsideOfCenterScreenPlaceholders(placeholderCollection, preferences, database);
            }

            if (!layoutFixed)
            {
                Injector.ExecuteCommand <ValidatePlaceholderCollectionCommand>(new CollectionEventArgs <PlaceholderModel>(0, placeholderCollection, placeholderCollection.Items.ToArray()));
            }
        }
Пример #25
0
        public void Execute()
        {
            if (profileSelection.Selection == null)
            {
                return;
            }

            ProfileModel    profile    = profileSelection.Selection;
            string          filePath   = Path.Combine(location.LocalDirectoryProfiles, profile.FileName);
            BackgroundModel background = screen.Background;

            profile.BackgroundId = background.Id;
            profile.MotecId      = assetFactory.SelectedMotec.Id;
            database.UpdateProfile(profile);
            layoutIO.WriteProfileLayout(profile, placeholderCollection.Items);
            layoutIO.DispatchSaveStatus();

            DispatchEvent(new ProfileEventArgs(EVENT_PROFILE_CHANGES_SAVED, profile));
        }
        public void Execute()
        {
            string fileName = ToFileName(args.Value);
            string filePath = Path.Combine(location.LocalDirectoryProfiles, fileName); // TODO tester les noms de fichier

            File.Copy(location.HudTemplateFile, filePath);

            BackgroundModel background = screen.Background;

            ProfileModel newProfile = ProfileFactory.NewProfileModel(args.Value, background.Id, fileName, assetsFactory.SelectedMotec.Id);

            layoutIO.WriteProfileLayout(newProfile, placeholderCollection.Items);

            database.AddProfile(newProfile);
            profileCollection.Add(newProfile);

            selectedProfile.SelectProfile(newProfile);
            layoutIO.DispatchSaveStatus();
        }
        public void Execute()
        {
            ProfileModel            profile      = profileCollection.Get(args.ItemId);
            List <PlaceholderModel> placeholders = layoutIO.LoadProfileLayout(profile);

            if (placeholders == null)
            {
                return;
            }
            // TODO gestion des erreurs, chargemetn de fichiers, bitmaps...
            BackgroundModel background = backgroundCollection.Get(profile.BackgroundId);

            selectionModel.Unselect();
            screen.SetBackground(background);
            placeholderCollection.Clear();
            placeholderCollection.AddRange(placeholders);
            assetFactory.SetMotec(motecCollection.Get(profile.MotecId));
            selectedProfile.SelectProfile(profile);
            layoutIO.DispatchSaveStatus();
        }
Пример #28
0
    BackgroundModel FindBackground(BGType type)
    {
        BackgroundModel currentBGModel = null;
        BackgroundModel foundedModel   = null;

        for (int i = 0; i < Backgrounds.Length; i++)
        {
            currentBGModel = Backgrounds [i];
            if (currentBGModel.BackgroundType == type)
            {
                currentBGModel.BGSprite.gameObject.SetActive(true);
                foundedModel = currentBGModel;
            }
            else
            {
                currentBGModel.BGSprite.gameObject.SetActive(false);
            }
        }

        return(foundedModel);
    }
Пример #29
0
        private bool HasLanguage(BackgroundModel backgroundModel, LanguageModel languageModel)
        {
            bool hasLanguage = languageModel == null;

            if (languageModel != null)
            {
                if (backgroundModel.LanguagesTraitIndex > -1 &&
                    backgroundModel.LanguagesTraitIndex < backgroundModel.Traits.Count)
                {
                    TraitModel trait = backgroundModel.Traits[backgroundModel.LanguagesTraitIndex];
                    hasLanguage = trait.Text.ToLower().Contains(languageModel.Name.ToLower());
                }
                else if (backgroundModel.StartingTraitIndex > -1 &&
                         backgroundModel.StartingTraitIndex < backgroundModel.Traits.Count)
                {
                    TraitModel trait = backgroundModel.Traits[backgroundModel.StartingTraitIndex];
                    hasLanguage = trait.Text.ToLower().Contains(languageModel.Name.ToLower());
                }
            }

            return(hasLanguage);
        }
        public static void Initialize()
        {
            FightSoundPlayed = false;

            DeadFighter = false;

            rng = new Random();

            BgModel = new BackgroundModel(PickRandomBackground());

            FirstFighter  = new FighterModel("Clark");
            SecondFighter = new FighterModel("Yuri");

            FirstFighterHealth  = new HealthView(new Vector2(20, 20));
            SecondFighterHealth = new HealthView(new Vector2(PlazaSmashGame.WindowWidth - 100, 20));

            BgView = new BackgroundView(BgModel.Name);

            FirstFighterActions = new Dictionary <string, ViewObject>();
            FirstFighterActions.Add("Stand", new StandView(FirstFighter.Name));
            FirstFighterActions.Add("Move", new MoveView(FirstFighter.Name));
            FirstFighterActions.Add("ReversedMove", new ReversedMoveView(FirstFighter.Name));
            FirstFighterActions.Add("Punch", new PunchView(FirstFighter.Name));
            FirstFighterActions.Add("Kick", new KickView(FirstFighter.Name));
            FirstFighterActions.Add("Block", new BlockView(FirstFighter.Name)); // IMPLEMENT
            FirstFighterActions.Add("Hit", new HitView(FirstFighter.Name));
            FirstFighterActions.Add("Die", new DieView(FirstFighter.Name));

            SecondFighterActions = new Dictionary <string, ViewObject>();
            SecondFighterActions.Add("Stand", new StandView(SecondFighter.Name));
            SecondFighterActions.Add("Move", new MoveView(SecondFighter.Name));
            SecondFighterActions.Add("ReversedMove", new ReversedMoveView(SecondFighter.Name));
            SecondFighterActions.Add("Punch", new PunchView(SecondFighter.Name));
            SecondFighterActions.Add("Kick", new KickView(SecondFighter.Name));
            SecondFighterActions.Add("Block", new BlockView(SecondFighter.Name)); // IMPLEMENT
            SecondFighterActions.Add("Hit", new HitView(SecondFighter.Name));
            SecondFighterActions.Add("Die", new DieView(SecondFighter.Name));
        }
Пример #31
0
        /// <summary>
        /// Updates the compendium background with id matching the parameter's id
        /// </summary>
        public void UpdateBackground(BackgroundModel model)
        {
            BackgroundModel currentModel = _backgrounds.FirstOrDefault(x => x.Id == model.Id);

            if (currentModel != null)
            {
                _backgrounds[_backgrounds.IndexOf(currentModel)] = model;

                List <Guid> characterIDs = new List <Guid>();
                foreach (CharacterModel character in _characters)
                {
                    if (character.Background.Id == model.Id)
                    {
                        character.Background = model;
                        characterIDs.Add(character.Id);
                    }
                }
                if (characterIDs.Any())
                {
                    CharacterChanged?.Invoke(this, new CompendiumChangeEventArgs(characterIDs.Distinct()));
                }
            }
        }
Пример #32
0
 public BackgroundModel GetSelected()
 {
     BackgroundTable table = DatabaseManager.Current.LookupSelectedBackground();
     BackgroundModel backgroundItem = new BackgroundModel(table);
     return backgroundItem;
 }