// Return portrait by index and portrait type. May return null.
        private Sprite GetPortrait(Actor actor, int portraitIndex, PortraitType portraitType)
        {
            Sprite portrait = null;

            if (actor != null)
            {
                switch (portraitType)
                {
                case PortraitType.Sprite:
                    portrait = portraitIndex == 1 ?
                               actor.spritePortrait :
                               (portraitIndex - 2 < actor.spritePortraits.Count ?
                                actor.spritePortraits[portraitIndex - 2] :
                                null);
                    break;

                case PortraitType.Texture:
                    portrait = UITools.CreateSprite(portraitIndex == 1 ?
                                                    actor.portrait :
                                                    (portraitIndex - 2 < actor.alternatePortraits.Count ?
                                                     actor.alternatePortraits[portraitIndex - 2] :
                                                     null));
                    break;

                default:
                    Assert.IsTrue(false);
                    break;
                }
            }
            return(portrait);
        }
Ejemplo n.º 2
0
        private void fillComboBox(ComboBox cb, Characteristic characteristic)
        {
            cb.Items.Clear();
            PortraitType portraitType = character.PortraitType;

            if (portraitType == null)
            {
                return;
            }

            int frameCount = loader.ActivePortraitData.GetFrameCount(portraitType, characteristic);

            if (frameCount > 0)
            {
                logger.LogDebug("Item count for {0} {1} : {2}", portraitType, characteristic, frameCount);
                cb.Enabled = true;
                fillComboBox(cb, frameCount);
                if (frameCount == 1)
                {
                    cb.Enabled = false; // Disable if only 1 frame, as there's no selection to do, for instance head (p2)
                }
            }
            else
            {
                logger.LogWarning("Could not find frame count for {0} and {1}, disabling dropdown.", portraitType, characteristic);
                cb.Enabled = false;
            }
        }
Ejemplo n.º 3
0
 public Player(int inPlayerId, PortraitType portraitType)
 {
     playerId = inPlayerId;
     portrait = new Portrait(portraitType);
     points = 0;
     CreateMeeples();
     SetOrientation();
 }
        private void loadPortraitTypes()
        {
            logger.Info("Loading PortraitTypes.");
            object previouslySelectedBasePortrait     = null;
            object previouslySelectedOverridePortrait = null;

            if (cbPortraitTypes.SelectedItem != null)
            {
                previouslySelectedBasePortrait = cbPortraitTypes.Items[cbPortraitTypes.SelectedIndex];
            }
            if (cbCulturePortraitTypes.SelectedItem != null)
            {
                previouslySelectedOverridePortrait = cbCulturePortraitTypes.Items[cbCulturePortraitTypes.SelectedIndex];
            }
            cbPortraitTypes.Items.Clear();
            cbCulturePortraitTypes.Items.Clear();

            loader.LoadPortraits();

            if (loader.GetActivePortraitData().PortraitTypes.Count == 0)
            {
                logger.Fatal("No portrait types found.");
                return;
            }

            cbCulturePortraitTypes.Items.Add("");             // Empty = no override
            foreach (KeyValuePair <string, PortraitType> pair in loader.GetActivePortraitData().PortraitTypes)
            {
                PortraitType portraitType = pair.Value;
                String       portraitName = portraitType.Name.Replace("PORTRAIT_", "");
                if (portraitType.IsBasePortraitType())
                {
                    cbPortraitTypes.Items.Add(portraitName);
                }
                cbCulturePortraitTypes.Items.Add(portraitName);
            }

            if (previouslySelectedBasePortrait != null)
            {
                cbPortraitTypes.SelectedIndex = cbPortraitTypes.Items.IndexOf(previouslySelectedBasePortrait);
            }
            if (previouslySelectedOverridePortrait != null)
            {
                cbCulturePortraitTypes.SelectedIndex = cbCulturePortraitTypes.Items.IndexOf(previouslySelectedOverridePortrait);
            }
            if (cbPortraitTypes.SelectedIndex == -1)
            {
                cbPortraitTypes.SelectedIndex = 0;
            }
            if (cbCulturePortraitTypes.SelectedIndex == -1)
            {
                cbCulturePortraitTypes.SelectedIndex = 0;
            }
            portrait.SetPortraitType(getSelectedPortraitType());
        }
Ejemplo n.º 5
0
    private PortraitType portraitTypeFromLP(int lp)
    {
        PortraitType portraitType = PortraitType.Positive;

        if (lp <= 0)
        {
            portraitType = PortraitType.Negative;
        }

        return(portraitType);
    }
Ejemplo n.º 6
0
        public Portrait(PortraitType inPortraitType)
        {
            portraitType = inPortraitType;

            InitializeComponent();

            Uri uri = new Uri(portraitSourceImages.list[portraitType], UriKind.Relative);
            BitmapImage bitmapImage = new BitmapImage(uri);
            portraitImage.ImageSource = bitmapImage;

            this.MouseLeftButtonUp += new MouseButtonEventHandler(rect_MouseLeftButtonUp);
            this.MouseLeftButtonDown += new MouseButtonEventHandler(rect_MouseLeftButtonDown);
        }
Ejemplo n.º 7
0
        public static PortraitType GetNext(PortraitType pt)
        {
            int portraitTypeAsInt = (int)pt;

            // 'Witch' is the last element
            if (portraitTypeAsInt >= (int)PortraitType.Witch)
            {
                return (PortraitType)1;
            }
            else
            {
                portraitTypeAsInt++;
                return (PortraitType)portraitTypeAsInt;
            }
        }
Ejemplo n.º 8
0
    private void setCharacterId(int characterIdBase, PortraitType portraitType)
    {
        switch (portraitType)
        {
        case PortraitType.Positive:
            currentCharacterId = characterIdBase + (characterPortraits.Length / 3);
            break;

        case PortraitType.Negative:
            currentCharacterId = characterIdBase + (2 * characterPortraits.Length / 3);
            break;

        default:
            currentCharacterId = characterIdBase;
            break;
        }
    }
        private void onChangePortraitType(object sender, EventArgs e)
        {
            if (started)
            {
                started = false;

                PortraitType selectedPortraitType = getSelectedPortraitType();
                portrait.SetPortraitType(selectedPortraitType);

                refreshCustomCharacectiristics();

                fillCharacteristicComboBoxes();
                updateSelectedCharacteristicValues(portrait);

                started = true;

                drawPortrait();
            }
        }
        private PortraitType getSelectedPortraitType()
        {
            PortraitType selectedPortraitType = null;
            object       selectedItem         = cbPortraitTypes.SelectedItem;
            object       selectedItem2        = cbCulturePortraitTypes.SelectedItem;

            if (selectedItem != null)
            {
                if (selectedItem2 != null && !selectedItem2.ToString().Equals(""))
                {
                    return(loader.GetPortraitType("PORTRAIT_" + selectedItem.ToString(), "PORTRAIT_" + selectedItem2.ToString()));
                }
                else
                {
                    return(loader.GetPortraitType("PORTRAIT_" + selectedItem.ToString()));
                }
            }
            return(selectedPortraitType);
        }
Ejemplo n.º 11
0
        public void LoadPortraits()
        {
            MergePortraitData();

            // Apply external offsets
            foreach (KeyValuePair <string, PortraitType> pair in activePortraitData.PortraitTypes)
            {
                PortraitType portraitType = pair.Value;

                foreach (Layer layer in portraitType.Layers)
                {
                    if (activePortraitData.Offsets.ContainsKey(layer.Name))
                    {
                        layer.Offset = activePortraitData.Offsets[layer.Name];
                        logger.Debug(string.Format("Overriding offset of layer {0} to {1}", layer.Name, layer.Offset));
                    }
                }
            }
        }
Ejemplo n.º 12
0
        internal static bool EnsureImageImport(this PortraitData portraitData, PortraitType portraitType, bool force = false)
        {
            EnsureCustomPortraitsImport(portraitData.m_CustomPortraitId, true);
            switch (portraitType)
            {
            case PortraitType.SmallPortrait:
                portraitData.m_PortraitImage = PortraitData.UploadSprite(GetSmallPortraitPathImport(portraitData.CustomId), BlueprintRoot.Instance.CharGen.BasePortraitSmall, force);
                return(portraitData.m_PortraitImage != null);

            case PortraitType.HalfLengthPortrait:
                portraitData.m_HalfLengthImage = PortraitData.UploadSprite(GetMediumPortraitPathImport(portraitData.CustomId), BlueprintRoot.Instance.CharGen.BasePortraitMedium, force);
                return(portraitData.m_HalfLengthImage != null);

            case PortraitType.FullLengthPortrait:
                portraitData.m_FullLengthImage = PortraitData.UploadSprite(GetBigPortraitPathImport(portraitData.CustomId), BlueprintRoot.Instance.CharGen.BasePortraitBig, force);
                return(portraitData.m_FullLengthImage != null);

            default:
                return(false);
            }
        }
Ejemplo n.º 13
0
        private void ParsePortraits(ASTNode node, string filename, PortraitData data)
        {
            IEnumerable <ASTNode> children = node.Children.Where(child => child.Symbol.Name == "groupOption");
            String id;

            foreach (ASTNode child in children)
            {
                id = child.Children[0].Value;

                if (id == "spriteType")
                {
                    try {
                        Sprite sprite = ParseSpriteType(child, filename);
                        if (data.Sprites.ContainsKey(sprite.Name))
                        {
                            logger.Debug("Sprite already exists. Replacing.");
                            data.Sprites.Remove(sprite.Name);
                        }
                        data.Sprites.Add(sprite.Name, sprite);
                    } catch (Exception e) {
                        logger.Error(string.Format("Could not parse spriteType in file {0}", filename), e);
                    }
                }
                else if (id == "portraitType")
                {
                    try {
                        PortraitType portraitType = ParsePortraitType(child, filename);
                        if (data.PortraitTypes.ContainsKey(portraitType.Name))
                        {
                            logger.Debug("Portrait type " + portraitType.Name + "exists. Replacing.");
                            data.PortraitTypes.Remove(portraitType.Name);
                        }
                        data.PortraitTypes.Add(portraitType.Name, portraitType);
                    } catch (Exception e) {
                        logger.Error(string.Format("Could not parse portraitType in file {0}", filename), e);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Returns a new PortraitTytpe, with the clothing layers of basePortraitType overriden by clothingPortraitType
        /// </summary>
        public PortraitType merge(PortraitType basePortraitType, PortraitType clothingPortraitType)
        {
            PortraitType mergedPortraitType = new PortraitType();

            mergedPortraitType.EffectFile            = basePortraitType.EffectFile;
            mergedPortraitType.HairColourIndex       = basePortraitType.HairColourIndex;
            mergedPortraitType.HairColours           = basePortraitType.HairColours;
            mergedPortraitType.HeadgearThatHidesHair = basePortraitType.HeadgearThatHidesHair;
            mergedPortraitType.EyeColours            = basePortraitType.EyeColours;
            mergedPortraitType.EyeColourIndex        = basePortraitType.EyeColourIndex;

            mergedPortraitType.Name = basePortraitType.Name + "/" + clothingPortraitType.Name;

            mergedPortraitType.Layers = new List <Layer>(basePortraitType.Layers.Count);

            foreach (Layer baseLayer in basePortraitType.Layers)
            {
                Layer mergeLayer = baseLayer;
                if (baseLayer.CultureIndex != -1)
                {
                    Layer overrideLayer = clothingPortraitType.GetCultureLayer(baseLayer.CultureIndex);
                    if (overrideLayer != null)
                    {
                        logger.Debug(string.Format("Overriding layer {0} with {1}", baseLayer, overrideLayer));
                        mergeLayer = new Layer();
                        mergeLayer.Characteristic = baseLayer.Characteristic;
                        mergeLayer.CultureIndex   = baseLayer.CultureIndex;
                        mergeLayer.Filename       = overrideLayer.Filename;
                        mergeLayer.IsEye          = baseLayer.IsEye;
                        mergeLayer.IsHair         = baseLayer.IsHair;
                        mergeLayer.Name           = overrideLayer.Name;
                        mergeLayer.Offset         = baseLayer.Offset;
                    }
                }
                mergedPortraitType.Layers.Add(mergeLayer);
            }

            return(mergedPortraitType);
        }
Ejemplo n.º 15
0
        void rect_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Portrait portrait = (Portrait)sender;

            portrait.ReleaseMouseCapture();
            isRectMouseCapture = false;

            portraitType = EnumHelper.GetNext(portraitType);

            Uri uri = new Uri(portraitSourceImages.list[portraitType], UriKind.Relative);
            BitmapImage bitmapImage = new BitmapImage(uri);
            portraitImage.ImageSource = bitmapImage;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Gets the portrait for Character Selection Slots. Can only be used in the Character Selection Scene.
 /// </summary>
 /// <returns>The character selection portrait.</returns>
 /// <param name="gender">Gender.</param>
 /// <param name="raceName">Race name.</param>
 /// <param name="className">Class name.</param>
 /// <param name="portraitType">Portrait type.</param>
 public Sprite GetCharacterSelectionPortrait(string gender, string raceName, string className, PortraitType portraitType)
 {
     if (portraitType == PortraitType.Prefab)
     {
         return(GetRacePortrait(gender, raceName));
     }
     else if (portraitType == PortraitType.Class)
     {
         return(GetClassPortrait(gender, className));
     }
     else if (portraitType == PortraitType.Custom)
     {
         //TODO: Add your code here?
         return(null);
     }
     return(null);
 }
Ejemplo n.º 17
0
        private void DeletePortraitIndexFromActorStates(Actor actor, int portraitIndex, PortraitType portraitType)
        {
            if (!actorsReferencies.ContainsKey(actor.id))
            {
                return;
            }
            var conversationsWithActor = actorsReferencies[actor.id];

            foreach (var keyValue in conversationsWithActor)
            {
                if (keyValue.Value <= 0)
                {
                    continue;
                }
                int conversationId = keyValue.Key;
                var conversation   = database.GetConversation(conversationId);
                if (conversation == null)
                {
                    continue;
                }
                foreach (var dialogueEntry in conversation.dialogueEntries)
                {
                    foreach (var actorState in dialogueEntry.actorsStates)
                    {
                        if (actorState.ActorID == actor.id && actorState.PortraitType == portraitType)
                        {
                            if (actorState.PortraitIndex == portraitIndex)
                            {
                                actorState.PortraitIndex = 1;
                            }
                            else if (actorState.PortraitIndex > portraitIndex)
                            {
                                actorState.PortraitIndex--;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 18
0
        private PortraitType ParsePortraitType(ASTNode node, string filename)
        {
            PortraitType portraitType = new PortraitType();

            portraitType.Filename = filename;

            List <ASTNode> children = node.Children.Where(child => child.Symbol.Name == "Option").ToList();
            string         id, value;
            ASTNode        token;

            foreach (ASTNode child in children)
            {
                token = child.Children[0];

                if (token.Children.Count > 1 == false)
                {
                    continue;
                }

                id    = token.Children[0].Value;
                value = token.Children[1].Value;

                switch (token.Symbol.Name)
                {
                case "stringOption":
                    if (id == "name")
                    {
                        portraitType.Name = value.Replace("\"", "");
                    }
                    if (id == "effectFile")
                    {
                        portraitType.EffectFile = value.Replace("\"", "").Replace(@"\\", @"\");
                    }
                    break;

                case "numberOption":
                    if (id == "hair_color_index")
                    {
                        portraitType.HairColourIndex = parseInt(value);
                    }
                    if (id == "eye_color_index")
                    {
                        portraitType.EyeColourIndex = parseInt(value);
                    }
                    break;
                }
            }

            logger.Debug("Type parsed: ");
            logger.Debug(" --ID: " + portraitType.Name);
            logger.Debug(" --Hair Colour Index: " + portraitType.HairColourIndex);
            logger.Debug(" --Eye Colour Index: " + portraitType.EyeColourIndex);

            // layer = {}
            portraitType.Layers.AddRange(ParseLayers(node.Children.Single(c => c.Symbol.Name == "layerGroup"), filename));

            // headgear_that_hides_hair = {}
            children = node.Children.Where(c => c.Symbol.Name == "cultureGroup").ToList();
            if (children.Count > 0)
            {
                foreach (ASTNode child in children[0].Children)
                {
                    portraitType.HeadgearThatHidesHair.Add(parseInt(child.Value));
                }
            }

            // hair_color = {} / eye_color = {}
            children = node.Children.Where(c => c.Symbol.Name == "groupOption").ToList();

            foreach (ASTNode child in children)
            {
                id = child.Children[0].Value;

                if (id == "hair_color")
                {
                    portraitType.HairColours.AddRange(ParseHairColours(child));
                }
                else if (id == "eye_color")
                {
                    portraitType.EyeColours.AddRange(ParseEyeColours(child));
                }
            }

            return(portraitType);
        }
Ejemplo n.º 19
0
 private void playCurrentStatement(PortraitType portraitType)
 {
     ui.displayStatement(currentStatement, currentCharacterId, gameStateManager.loveIndexOfCharacter(currentCharacterId), portraitType);
     soundManager.playDialogSound(currentStatement.getCurrentSoundFilePath());
 }
Ejemplo n.º 20
0
    // TODO make displayStatement display a given character portrait by currentCharacterId
    public void displayStatement(Statement statement, int characterId, int loveIndex, PortraitType portraitType)
    {
        characterPortraits[currentCharacterId].gameObject.SetActive(false);
        setCharacterId(characterId, portraitType);

        dialogText.text = statement.getCurrentText();
        accidentText.gameObject.SetActive(false);
        informationText.gameObject.SetActive(false);
        dialogText.gameObject.SetActive(true);
        disableOptionBoxes();
        dialogBG.gameObject.SetActive(true);
        characterPortraits[currentCharacterId].gameObject.SetActive(true);

        toggleCurrentHeartIcon(loveIndex);
    }
Ejemplo n.º 21
0
        public static async Task <IActionResult> BuildCharacter(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] PortraitBuilder.Online.Models.Character characterModel)
        {
            var character = new Character();

            character.Import(characterModel.DNA, characterModel.Properties);
            if (Enum.TryParse(characterModel.Government, ignoreCase: true, out GovernmentType government))
            {
                character.Government = government;
            }
            if (Enum.TryParse(characterModel.Rank, ignoreCase: true, out TitleRank rank))
            {
                character.Rank = rank;
            }

            var portrait = await _portraitPack.Value;

            if (!portrait.PortraitTypes.Any())
            {
                return(new StatusCodeResult(500));
            }

            var cultureLookup = await _cultureLookup.Value;

            if (!cultureLookup.Any())
            {
                return(new StatusCodeResult(500));
            }

            string sexSuffix    = characterModel.Female.GetValueOrDefault() ? "female" : "male";
            string periodSuffix = default;

            if (characterModel.Year.HasValue)
            {
                var year = characterModel.Year.Value;
                periodSuffix = year < 950 ? "early" : year > 1250 ? "late" : "";
            }

            string ageSuffix = default;

            if (characterModel.Age.HasValue)
            {
                var age = characterModel.Age.Value;
                //Confusingly, children's portraits are defined
                //with the age suffix before the sex suffix
                ageSuffix         = age <= 30 ? "" : age < 50 ? "1" : "2";
                character.IsChild = age < 16;
            }

            var religiousLookup = await _religiousClothingLookup.Value;

            if (characterModel.Religion != null && religiousLookup.TryGetValue(characterModel.Religion, out (int, int)clothingInfo))
            {
                var religiousClothingHead   = clothingInfo.Item1;
                var religiousClothingPriest = clothingInfo.Item2;

                if (characterModel.ReligiousHead.GetValueOrDefault())
                {
                    character.ReligiousClothingOverride = religiousClothingHead;
                }
                else if (character.Government == GovernmentType.Theocracy)
                {
                    character.ReligiousClothingOverride = religiousClothingPriest;
                }
            }

            PortraitType portraitType = default;
            var          fallbacks    = new List <PortraitType>();

            foreach (var graphicalCulture in cultureLookup[characterModel.Culture])
            {
                bool         omitPeriod = false;
                bool         omitAge    = false;
                PortraitType foundPortraitType;

                while (!portrait.PortraitTypes.TryGetValue(
                           $"PORTRAIT_{graphicalCulture}_{sexSuffix}{(omitPeriod ? "" : periodSuffix)}{(omitAge ? "" : ageSuffix)}",
                           out foundPortraitType))
                {
                    if (omitPeriod && omitAge)
                    {
                        break;
                    }
                    else if (!omitPeriod)
                    {
                        omitPeriod = true;
                    }
                    else if (!omitAge)
                    {
                        omitAge = true;
                    }
                }

                if (foundPortraitType == null)
                {
                    continue;
                }

                portraitType ??= foundPortraitType;
                fallbacks.Add(foundPortraitType);
            }

            if (portraitType == null)
            {
                return(new StatusCodeResult(500));
            }

            character.PortraitType          = portraitType;
            character.FallbackPortraitTypes = fallbacks;

            using var portraitBitmap = await DrawPortraitInternal(character);

            using var portraitPixmap = portraitBitmap.PeekPixels();

            var portraitPng = portraitPixmap.Encode(SKPngEncoderOptions.Default);

            return(new FileStreamResult(portraitPng.AsStream(), "image/png"));
        }