void RefreshFaces()
        {
            // Clear existing faces
            ClearFaces();

            // Load matching texture for each face
            // Only Redguard and Breton supported for now
            // Generally FACTION.TXT only uses these two races - could expand later
            foreach (FaceDetails face in faces)
            {
                // Get race template
                RaceTemplate raceTemplate;
                switch (face.targetRace)
                {
                case Races.Redguard:
                    raceTemplate = new Redguard();
                    break;

                default:
                case Races.Breton:
                    raceTemplate = new Breton();
                    break;
                }

                // Get image for this face
                Texture2D faceTexture = null;
                if (face.gender == Genders.Male)
                {
                    faceTexture = DaggerfallUI.GetTextureFromCifRci(raceTemplate.PaperDollHeadsMale, face.faceIndex);
                }
                else if (face.gender == Genders.Female)
                {
                    faceTexture = DaggerfallUI.GetTextureFromCifRci(raceTemplate.PaperDollHeadsFemale, face.faceIndex);
                }

                // Must have a texture by now
                if (faceTexture == null)
                {
                    throw new Exception("RefreshFaces() could not load face texture for Person resource.");
                }

                // Add texture to list
                Panel facePanel = new Panel();
                facePanel.Size = new Vector2(faceTexture.width, faceTexture.height);
                facePanel.BackgroundTexture = faceTexture;
                facePanels.Add(facePanel);
                Components.Add(facePanel);
            }
        }
Example #2
0
        void UpdateFaceTextures()
        {
            if (raceTemplate != null)
            {
                for (int i = 0; i < faceCount; i++)
                {
                    if (raceGender == Genders.Male)
                    {
                        faceTextures[i] = DaggerfallUI.GetTextureFromCifRci(raceTemplate.PaperDollHeadsMale, i);
                    }
                    else if (raceGender == Genders.Female)
                    {
                        faceTextures[i] = DaggerfallUI.GetTextureFromCifRci(raceTemplate.PaperDollHeadsFemale, i);
                    }
                }
            }

            SetCurrentFace();
        }
        public Button AddButton(MessageBoxButtons messageBoxButton)
        {
            if (!IsSetup)
            {
                Setup();
            }

            Texture2D background = DaggerfallUI.GetTextureFromCifRci(buttonsFilename, (int)messageBoxButton);
            Button    button     = DaggerfallUI.AddButton(Vector2.zero, new Vector2(background.width, background.height), buttonPanel);

            button.BackgroundTexture       = background;
            button.BackgroundTextureLayout = BackgroundLayout.StretchToFill;
            button.Tag           = messageBoxButton;
            button.OnMouseClick += ButtonClickHandler;
            buttons.Add(button);

            UpdatePanelSizes();

            return(button);
        }
        public Button AddButton(MessageBoxButtons messageBoxButton, bool defaultButton = false)
        {
            if (!IsSetup)
            {
                Setup();
            }

            // If this is to become default button, first unset any other default buttons
            // Only one button in collection can be default
            if (defaultButton)
            {
                foreach (Button b in buttons)
                {
                    b.DefaultButton = false;
                }
            }

            Texture2D background = DaggerfallUI.GetTextureFromCifRci(buttonsFilename, (int)messageBoxButton);
            Button    button     = DaggerfallUI.AddButton(Vector2.zero,
                                                          TextureReplacement.GetSize(background, buttonsFilename, (int)messageBoxButton), buttonPanel);

            button.BackgroundTexture       = background;
            button.BackgroundTextureLayout = BackgroundLayout.StretchToFill;
            button.Tag              = messageBoxButton;
            button.OnMouseClick    += ButtonClickHandler;
            button.DefaultButton    = defaultButton;
            button.Hotkey           = DaggerfallShortcut.GetBinding(ToShortcutButton(messageBoxButton));
            button.OnKeyboardEvent += ButtonKeyboardEvent;
            buttons.Add(button);

            // Once a button has been added the owner is expecting some kind of input from player
            // Don't allow a messagebox with buttons to be cancelled with escape
            AllowCancel = false;

            UpdatePanelSizes();

            return(button);
        }
        public void RefreshFaces()
        {
            const int specialFacePanelWidth  = 48;
            const int specialFacePanelHeight = 48;

            // Clear existing faces
            ClearFaces();

            // Load matching texture for each face
            // Only Redguard and Breton supported for now
            // Generally FACTION.TXT only uses these two races - could expand later
            foreach (FaceDetails face in faces)
            {
                // Get race template
                RaceTemplate raceTemplate;
                switch (face.targetRace)
                {
                case Races.Redguard:
                    raceTemplate = new Redguard();
                    break;

                default:
                case Races.Breton:
                    raceTemplate = new Breton();
                    break;
                }

                // Get image for this face
                Texture2D faceTexture = null;
                Panel     facePanel   = new Panel();
                // Disable until placed
                facePanel.Enabled = false;
                if (face.factionFaceIndex >= 0 && face.factionFaceIndex <= 60)
                {
                    // Use special NPC face set at time face data was added
                    faceTexture    = DaggerfallUI.GetTextureFromCifRci(factionFaceFile, face.factionFaceIndex);
                    facePanel.Size = new Vector2(specialFacePanelWidth, specialFacePanelHeight);
                }
                else if (face.factionFaceIndex > 60 && face.factionFaceIndex <= 502)
                {
                    // Use special NPC face set by a mod at time face data was added
                    faceTexture    = DaggerfallUI.GetTextureFromCifRci(factionExtraFaceFile, face.factionFaceIndex);
                    facePanel.Size = new Vector2(specialFacePanelWidth, specialFacePanelHeight);
                }
                else
                {
                    string fileName;

                    // Use generic NPC face
                    if (!face.isChild)
                    {
                        // Get a racial portrait
                        fileName = face.gender == Genders.Male ? raceTemplate.PaperDollHeadsMale : raceTemplate.PaperDollHeadsFemale;
                    }
                    else
                    {
                        // Get a child portrait
                        fileName = factionChildrenFaceFile;
                    }

                    // Allow individual factions from mods to use normal race faces
                    ImageData imageData = ImageReader.GetImageData(fileName, face.faceIndex, 0, true, true);
                    faceTexture    = imageData.texture;
                    facePanel.Size = new Vector2(imageData.width, imageData.height);
                }

                // Must have a texture by now
                if (faceTexture == null)
                {
                    throw new Exception("RefreshFaces() could not load face texture for Person resource.");
                }

                // Add texture to list
                facePanel.BackgroundTexture = faceTexture;
                facePanels.Add(facePanel);
                Components.Add(facePanel);
            }
        }
        /// <summary>
        /// Updates portrait layout to latest data.
        /// </summary>
        public void Refresh()
        {
            // Update character background
            if (lastBackgroundName != PlayerEntity.Race.PaperDollBackground)
            {
                Texture2D raceBackground = DaggerfallUI.GetTextureFromImg(PlayerEntity.Race.PaperDollBackground, new Rect(8, 7, 110, 184));
                characterBackgroundPanel.BackgroundTexture = raceBackground;
                characterBackgroundPanel.Size = new Vector2(raceBackground.width, raceBackground.height);
                lastBackgroundName            = PlayerEntity.Race.PaperDollBackground;
            }

            // Get character body image name
            string paperDollBodyImageName = string.Empty;

            if (DaggerfallUnity.Settings.NoPlayerNudity)
            {
                if (PlayerEntity.Gender == Genders.Male)
                {
                    paperDollBodyImageName = PlayerEntity.Race.PaperDollBodyMaleClothed;
                }
                else
                {
                    paperDollBodyImageName = PlayerEntity.Race.PaperDollBodyFemaleClothed;
                }
            }
            else
            {
                if (PlayerEntity.Gender == Genders.Male)
                {
                    paperDollBodyImageName = PlayerEntity.Race.PaperDollBodyMaleUnclothed;
                }
                else
                {
                    paperDollBodyImageName = PlayerEntity.Race.PaperDollBodyFemaleUnclothed;
                }
            }

            // Update character body
            DFPosition offset;

            if (lastBodyName != paperDollBodyImageName)
            {
                Texture2D playerBodyTexture = DaggerfallUI.GetTextureFromImg(paperDollBodyImageName, out offset);
                characterBodyPanel.Size              = new Vector2(playerBodyTexture.width, playerBodyTexture.height);
                characterBodyPanel.Position          = new Vector2(offset.X - portraitOrigin.X, offset.Y - portraitOrigin.Y);
                characterBodyPanel.BackgroundTexture = playerBodyTexture;
                lastBodyName = paperDollBodyImageName;
            }

            // Get character head image name
            string paperDollHeadImageName = string.Empty;

            if (PlayerEntity.Gender == Genders.Male)
            {
                paperDollHeadImageName = PlayerEntity.Race.PaperDollHeadsMale;
            }
            else
            {
                paperDollHeadImageName = PlayerEntity.Race.PaperDollHeadsFemale;
            }

            // Update character head
            if (lastHeadName != paperDollHeadImageName)
            {
                Texture2D playerHeadTexture = DaggerfallUI.GetTextureFromCifRci(paperDollHeadImageName, PlayerEntity.FaceIndex, out offset);
                characterHeadPanel.Size              = new Vector2(playerHeadTexture.width, playerHeadTexture.height);
                characterHeadPanel.Position          = new Vector2(offset.X - portraitOrigin.X, offset.Y - portraitOrigin.Y);
                characterHeadPanel.BackgroundTexture = playerHeadTexture;
                lastHeadName = paperDollHeadImageName;
            }
        }
        public void RefreshFaces()
        {
            const int specialFacePanelWidth  = 48;
            const int specialFacePanelHeight = 48;

            // Clear existing faces
            ClearFaces();

            // Load matching texture for each face
            // Only Redguard and Breton supported for now
            // Generally FACTION.TXT only uses these two races - could expand later
            foreach (FaceDetails face in faces)
            {
                // Get race template
                RaceTemplate raceTemplate;
                switch (face.targetRace)
                {
                case Races.Redguard:
                    raceTemplate = new Redguard();
                    break;

                default:
                case Races.Breton:
                    raceTemplate = new Breton();
                    break;
                }

                // Get image for this face
                Texture2D faceTexture = null;
                Panel     facePanel   = new Panel();
                if (face.factionFaceIndex >= 0 && face.factionFaceIndex <= 60)
                {
                    // Use special NPC face set at time face data was added
                    faceTexture    = DaggerfallUI.GetTextureFromCifRci(factionFaceFile, face.factionFaceIndex);
                    facePanel.Size = new Vector2(specialFacePanelWidth, specialFacePanelHeight);
                }
                else
                {
                    // Use generic NPC face
                    if (!face.isChild)
                    {
                        // Get a racial portrait
                        if (face.gender == Genders.Male)
                        {
                            faceTexture = DaggerfallUI.GetTextureFromCifRci(raceTemplate.PaperDollHeadsMale, face.faceIndex);
                        }
                        else if (face.gender == Genders.Female)
                        {
                            faceTexture = DaggerfallUI.GetTextureFromCifRci(raceTemplate.PaperDollHeadsFemale, face.faceIndex);
                        }
                    }
                    else
                    {
                        // Get a child portrait
                        faceTexture = DaggerfallUI.GetTextureFromCifRci(factionChildrenFaceFile, face.faceIndex);
                    }

                    facePanel.Size = new Vector2(faceTexture.width, faceTexture.height);
                }

                // Must have a texture by now
                if (faceTexture == null)
                {
                    throw new Exception("RefreshFaces() could not load face texture for Person resource.");
                }

                // Add texture to list
                facePanel.BackgroundTexture = faceTexture;
                facePanels.Add(facePanel);
                Components.Add(facePanel);
            }
        }