public void LoadContent(ContentManager contentManager) { _buttonFont = contentManager.Load <SpriteFont>("Fonts/Main"); _hintTitleFont = contentManager.Load <SpriteFont>("Fonts/HintTitle"); _auxFont = contentManager.Load <SpriteFont>("Fonts/UiAux"); _hintBackgorundTexture = contentManager.Load <Texture2D>("Sprites/ui/HintBackground"); _buttonTexture = contentManager.Load <Texture2D>("Sprites/ui/button"); _modalShadowTexture = contentManager.Load <Texture2D>("Sprites/ui/ModalDialogShadow"); _modalTopTextures = new[] { contentManager.Load <Texture2D>("Sprites/ui/ModalDialogBackgroundTop1") }; _modalBottomTextures = new[] { contentManager.Load <Texture2D>("Sprites/ui/ModalDialogBackgroundBottom1") }; _attributeIconsTexture = contentManager.Load <Texture2D>("Sprites/ui/AttributeIcons"); _attributesBackgroundTexture = contentManager.Load <Texture2D>("Sprites/ui/AttributesBackground"); _smallVerticalButtonIconsTexture = contentManager.Load <Texture2D>("Sprites/ui/SmallVerticalButtonIcons"); _smallVerticalButtonBackgroundTexture = contentManager.Load <Texture2D>("Sprites/ui/SmallVerticalButtonBackground"); _bottomPanelBackground = contentManager.Load <Texture2D>("Sprites/ui/BottomPanelBackground"); _selectedButtonMarker = contentManager.Load <Texture2D>("Sprites/ui/SelectedButtonMarker"); _contextualMenuItemFont = contentManager.Load <SpriteFont>("Fonts/ContextualMenu"); _contextualMenuBorderTexture = contentManager.Load <Texture2D>("Sprites/ui/ContextualMenuBorder"); _contextualMenuItemBackgroundTexture = contentManager.Load <Texture2D>("Sprites/ui/ContextualMenuItemBackground"); InitPropIcons(contentManager); InitCombatActIcons(contentManager); InitConditionIconsAndBackgrounds(contentManager); }
protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); _whiteRectangle = new Texture2D(GraphicsDevice, width: 1, height: 1); _whiteRectangle.SetData(new[] { Color.White }); }
public MultilineTextBox(Rectangle bounds, Texture2D?textBoxTexture, Texture2D?caretTexture, SpriteFont font, Color textColor) : base(textBoxTexture, caretTexture, font, textColor) { _bounds = bounds; _text = new StringBuilder(); _glyphs = _font.GetGlyphs(); _caretPosition = new Point(0); _index = 0; _heldDelay = 200.0; _heldTimer = 0.0; _repeatDelay = 40.0; _repeatTimer = 0.0; Rectangle scrollBarBounds = default; scrollBarBounds.X = _bounds.X + _bounds.Width + 48; scrollBarBounds.Y = _bounds.Y + 116; scrollBarBounds.Width = 24; scrollBarBounds.Height = _bounds.Height - 152; Rectangle scrollContentBounds = new Rectangle(_bounds.X, _bounds.Y, _bounds.Width + 8, _bounds.Height); scrollContentBounds = Utility.ConstrainScissorRectToScreen(scrollContentBounds); scrollContentBounds.Height = (scrollContentBounds.Height / _font.LineSpacing) * _font.LineSpacing; scrollComponent = new ScrollComponent(scrollBarBounds, scrollContentBounds, _font.LineSpacing, true); }
private void MovePrevious() { if (_config.MusicPlayerEnabled) { if (_disoPreviewPlayer.CurrentAudioTime > 1f) { _disoPreviewPlayer.CrossfadeTo(_disoPreviewPlayer.DefaultAudioClip, 0f, _disoPreviewPlayer.DefaultAudioClip.length); _disoPlayerPanel.SetTime(0f); return; } if (_playHistory.Count > 0) { if (_currentContainer != null) { _playFuture.Push(_currentContainer.Value); } var record = _playHistory.Pop(); _currentContainer = record; _activeName = record.name; _activeTexture = record.texture; _disoPreviewPlayer.CrossfadeToNewDefault(record.clip); _disoPlayerPanel.SetPlayer(_activeName, _disoPreviewPlayer.DefaultAudioClip.length, _activeTexture, !_paused); } else { MoveNext(); } if (_paused) { _disoPlayerPanel.SetTime(0f); } } }
private async void MoveNext() { if (_config.MusicPlayerEnabled && _initialized) { if (_currentContainer != null) { _playHistory.Push(_currentContainer.Value); } AudioContainer container; if (_playFuture.Count > 0) { container = _playFuture.Pop(); } else { container = await _audioContainerService.GetRandomContainer(); } if (container.name == "^") { _disoPreviewPlayer.NextDoRandom = false; return; } _activeName = container.name; _currentContainer = container; _activeTexture = container.texture; _disoPreviewPlayer.CrossfadeToNewDefault(container.clip); _disoPreviewPlayer.NextDoRandom = false; _disoPlayerPanel.SetPlayer(_activeName, _disoPreviewPlayer.DefaultAudioClip.length, _activeTexture, !_paused); if (_paused) { _disoPlayerPanel.SetTime(0f); } } _disoPreviewPlayer.NextDoRandom = false; }
public TaskParameterTextBox(TaskParameter parameter, Texture2D?textBoxTexture, Texture2D?caretTexture, SpriteFont font, Color textColor, ITranslationHelper translation) : base(textBoxTexture, caretTexture, font, textColor) { TaskParameter = parameter; TaskParser = new TaskParser(translation); Label = string.Empty; }
private void InitConditionIconsAndBackgrounds(ContentManager contentManager) { _survivalStatConditionIcons = new Dictionary <SurvivalStatType, Texture2D> { { SurvivalStatType.Satiety, contentManager.Load <Texture2D>("Sprites/ui/PersonConditions/HungerConditionIcon") }, { SurvivalStatType.Hydration, contentManager.Load <Texture2D>("Sprites/ui/PersonConditions/ThristConditionIcon") }, { SurvivalStatType.Intoxication, contentManager.Load <Texture2D>("Sprites/ui/PersonConditions/IntoxicationConditionIcon") }, { SurvivalStatType.Health, contentManager.Load <Texture2D>("Sprites/ui/PersonConditions/InjureConditionIcon") } }; _conditionIconBackgroundTextures = new[] { contentManager.Load <Texture2D>("Sprites/ui/PersonConditions/ConditionIconLesserBackground"), contentManager.Load <Texture2D>("Sprites/ui/PersonConditions/ConditionIconStrongBackground"), contentManager.Load <Texture2D>("Sprites/ui/PersonConditions/ConditionIconCriticalBackground") }; _conditionDeseaseSymptomIcon = contentManager.Load <Texture2D>("Sprites/ui/PersonConditions/DiseaseSymptomConditionIcon"); _conditionDefaultIcon = contentManager.Load <Texture2D>("Sprites/ui/PersonConditions/DefaultIcon"); }
private bool TryLoad(out Texture2D?texture) { if (tex != null) { texture = tex; return(true); } byte[] data; try { data = File.ReadAllBytes(FullFilename); } catch (Exception e) { Log.Unity($"Couldn't load Aya photo {FullFilename}: {e.Message}", level: Log.Level.WARNING); texture = null; return(false); } try { texture = new Texture2D(PixelWidth, PixelHeight, Format, TextureCreationFlags.None); texture.LoadImage(data); tex = texture; } catch (Exception e) { Log.Unity($"Couldn't read data from Aya photo {FullFilename}: {e.Message}", level: Log.Level.WARNING); texture = null; return(false); } return(true); }
private void Init() { int tWidth = Rect.Width; int sliceWidth = Rect.Width / 8; int mainWidth = tWidth - sliceWidth; int hueWidth = sliceWidth; MainArea = new Rectangle(0, 0, mainWidth, Rect.Height); HueArea = new Rectangle(mainWidth, 0, hueWidth, Rect.Height); colorData = new Color[MainArea.Width * MainArea.Height]; if (mainTexture == null) { int width = MainArea.Width, height = MainArea.Height; GenerateGradient(ref colorData !, width, height, DrawHVArea); mainTexture = CreateGradientTexture(colorData !, MainArea.Width, MainArea.Height); } if (hueTexture == null) { int width = HueArea.Width, height = HueArea.Height; Color[] hueData = new Color[width * height]; GenerateGradient(ref hueData, width, height, DrawHueArea); hueTexture = CreateGradientTexture(hueData, width, height); } }
public void LoadContent(ContentManager contentManager) { this.spriteBatch = new SpriteBatch(this.graphicsDevice); this.gemTexture = contentManager.Load <Texture2D>("gems"); this.cursorTexture = contentManager.Load <Texture2D>("cursor"); this.waveAttackFont = contentManager.Load <SpriteFont>("WaveAttack"); int backgroundWidth = this.config.BoardWidth * this.config.GemWidth; int backgroundHeight = this.config.BoardHeight * this.config.GemHeight; this.backgroundTexture = new Texture2D( this.graphicsDevice, backgroundWidth, backgroundHeight ); Color[] backgroundData = new Color[ backgroundWidth * backgroundHeight ]; Color backgroundColor = new Color(0, 0, 0, 255); for (int i = 0; i < backgroundData.Length; i++) { backgroundData[i] = backgroundColor; } this.backgroundTexture.SetData(backgroundData); }
public void Initialize(IPickerElement pickerElement, Action <string> onClick) { myListElement = pickerElement; myTexture = null; myOnClick = onClick; if (myLabelText == null) { return; } myLabelText.text = pickerElement.Name; myCornerImage.gameObject.SetActive(true); if (!pickerElement.SupportsDesktop && !pickerElement.SupportsQuest) { myCornerImage.gameObject.SetActive(false); } else if (pickerElement.SupportsDesktop) { myCornerImage.sprite = pickerElement.SupportsQuest ? AssetsHandler.IconUni : AssetsHandler.IconPC; } else { myCornerImage.sprite = pickerElement.SupportsQuest ? AssetsHandler.IconQuest : AssetsHandler.IconUni; } myPrivateImage.SetActive(pickerElement.IsPrivate); if (gameObject.activeSelf) { DoDownloadImage(); } }
public DividerNode(LayoutNode parent, Texture2D?source = null, Rectangle?sourceRectVert = null, Rectangle?sourceRectHoriz = null) { Parent = parent; Source = source; SourceRectHoriz = sourceRectHoriz; SourceRectVert = sourceRectVert; }
public SpriteInfo( Texture2D texture, Rectangle baseSource, Color?baseColor = null, float baseScale = 1f, Texture2D?overlayTexture = null, Rectangle?overlaySource = null, Color?overlayColor = null, float overlayScale = 1f, bool isPrismatic = false, int baseFrames = 1, int overlayFrames = 1, int framesPerRow = int.MaxValue, int frameTime = 100, int frameDelay = 0 ) { Texture = texture; BaseSource = baseSource; BaseColor = baseColor; BaseScale = baseScale; OverlayTexture = overlayTexture; OverlaySource = overlaySource; OverlayColor = overlayColor; OverlayScale = overlayScale; IsPrismatic = isPrismatic; BaseFrames = baseFrames; OverlayFrames = overlayFrames; FramesPerRow = framesPerRow; FrameTime = frameTime; FrameDelay = frameDelay; }
public EditorImage(string path, Vector2 pos) { Image = Sprite.LoadTexture(path, out Sprite _, compress: false); ImagePath = path; Position = pos; UpdateRectangle(); }
/// <summary> /// Loads graphics content for this screen. This uses the shared ContentManager /// provided by the Game class, so the content will remain loaded forever. /// Whenever a subsequent MessageBoxScreen tries to load this same content, /// it will just get back another reference to the already loaded data. /// </summary> public override void Activate(bool instancePreserved) { if (!instancePreserved) { GradientTexture = Game.Content.Load <Texture2D>("gradient"); } }
/// <summary>Get the custom spritesheet and source rectangle for an in-game entity.</summary> /// <param name="entity">The in-world entity (e.g. fruit tree).</param> /// <param name="texture">The custom sprite texture.</param> /// <param name="sourceRect">The custom area within the texture containing the spritesheet.</param> /// <param name="currentSpriteOnly">Whether to return a rectangle which only contains the entity's current sprite (e.g. for a crop's current phase of growth), instead of all its sprites.</param> /// <returns>Returns true if the entity has a custom sprite, else false.</returns> /// <remarks>This returns a texture which matches the vanilla layout. For example, for a fruit tree this would return the area containing all the sprites for the tree's growth stages and states in the same layout as the vanilla tilesheet.</remarks> public bool TryGetCustomSpriteSheet(object entity, [NotNullWhen(true)] out Texture2D?texture, out Rectangle sourceRect, bool currentSpriteOnly = false) { this.AssertLoaded(); return(currentSpriteOnly ? this.ModApi.TryGetCustomSprite(entity, out texture, out sourceRect) : this.ModApi.TryGetCustomSpriteSheet(entity, out texture, out sourceRect)); }
public TextureNode(Texture2D?texture, Rectangle?source = null, float scale = 1f, bool shadow = false, Alignment alignment = Alignment.None) { Texture = texture; Source = source ?? texture?.Bounds ?? Rectangle.Empty; Scale = scale; DrawShadow = shadow; Alignment = alignment; }
public static Sprite?LoadSpriteFromTexture(Texture2D?SpriteTexture, float PixelsPerUnit = 100.0f) { if (SpriteTexture != null) { return(Sprite.Create(SpriteTexture, new Rect(0, 0, SpriteTexture.width, SpriteTexture.height), new Vector2(0, 0), PixelsPerUnit)); } return(null); }
private void OnImageDownloaded(Texture2D texture) { myTexture = texture; if (gameObject.activeSelf) { myImage.texture = texture; } }
/// <summary>Try to load the asset for a texture from the assets folder (including seasonal logic if applicable).</summary> /// <param name="spritesheet">The spritesheet name without the path or extension (like 'tractor' or 'garage').</param> /// <param name="texture">The loaded texture, if found.</param> /// <param name="error">A human-readable error to show to the user if texture wasn't found.</param> private bool TryLoadFromFile(string spritesheet, [NotNullWhen(true)] out Texture2D?texture, [NotNullWhen(false)] out string?error) { texture = this.TryGetTextureKey(spritesheet, out string?key, out error) ? this.ContentHelper.Load <Texture2D>(key) : null; return(texture != null); }
internal void Clean() { OnDisable(); if (myListElement != null) { GlobalImageCache.CancelRequest(myListElement.ImageUrl, OnImageDownloaded); } myListElement = null; myOnClick = null; myTexture = null; }
/// <summary>Switch to the previous data map.</summary> public void PrevTexture() { int index = Array.IndexOf(this.TextureNames, this.CurrentName) - 1; if (index < 0) { index = this.TextureNames.Length - 1; } this.CurrentName = this.TextureNames[index]; this.CurrentTexture = this.Content.Load <Texture2D>(this.CurrentName); }
/// <summary>Switch to the next texture.</summary> public void NextTexture() { int index = Array.IndexOf(this.TextureNames, this.CurrentName) + 1; if (index >= this.TextureNames.Length) { index = 0; } this.CurrentName = this.TextureNames[index]; this.CurrentTexture = this.Content.Load <Texture2D>(this.CurrentName); }
} //JSON constructor public AyaPhoto(Texture2D photo, CRect rect) { Filename = $"{DateTime.Now.FileableTime()}-{RNG.RandStringOffFrame()}"; PixelWidth = photo.width; PixelHeight = photo.height; ScreenWidth = rect.halfW * 2; ScreenHeight = rect.halfH * 2; Angle = rect.angle; Format = photo.graphicsFormat; KeepAlive = false; FileUtils.WriteTex(FullFilename, photo); tex = photo; allPhotos.Add(this); }
/********* ** Private methods *********/ /// <summary>Try to load the asset for a texture from the game's content folder so other mods can apply edits.</summary> /// <param name="spritesheet">The spritesheet name without the path or extension (like 'Tractor' or 'Garage').</param> /// <param name="texture">The loaded texture, if found.</param> /// <param name="error">A human-readable error to show to the user if texture wasn't found.</param> private bool TryLoadFromContent(string spritesheet, [NotNullWhen(true)] out Texture2D?texture, [NotNullWhen(false)] out string?error) { try { texture = Game1.content.Load <Texture2D>($"{this.PublicAssetBasePath}/{spritesheet}"); error = null; } catch (Exception ex) { texture = null; error = ex.ToString(); return(false); } return(texture != null); }
private void OnSaveLoaded(object?sender, SaveLoadedEventArgs e) { // Load the icon from the mod folder iconTexture = Helper.GameContent.Load <Texture2D>(assetName); // Check if the loading succeeded if (iconTexture is null) { Monitor.Log("Failed loading the icon " + assetName, LogLevel.Error); } // Refresh the config config = Helper.ReadConfig <ModConfig>(); // Update the cycle type ChangeCycleType(config.cycleType); }
private async Task Init() { _siraLog.Debug("Loading music."); var badMusic = new List <FileInfo>(); var stopwatch = Stopwatch.StartNew(); var loadedCustoms = new List <AudioContainer>(); foreach (var musicPath in _config.EnabledMusicFiles) { if (!musicPath.Exists || musicPath.Extension != ".ogg") { badMusic.Add(musicPath); continue; } try { _siraLog.Debug($"Loading {musicPath.FullName}"); AudioClip audioClip = await _cachedMediaAsyncLoader.LoadAudioClipAsync(musicPath.FullName, _cancellationTokenSource.Token); var name = musicPath.Name.Remove(musicPath.Name.IndexOf(musicPath.Extension)); var maybeImage = musicPath.Directory.EnumerateFiles().FirstOrDefault(ef => ef.Name.Remove(ef.Name.IndexOf(ef.Extension)) == name && (ef.Extension == ".png" || ef.Extension == ".jpg")); Texture2D?texHolder = null; if (maybeImage != null && maybeImage.Exists) { texHolder = (await _cachedMediaAsyncLoader.LoadSpriteAsync(maybeImage !.FullName, _cancellationTokenSource.Token)).texture; } loadedCustoms.Add(new AudioContainer(name, audioClip, texHolder)); } catch (Exception e) { _siraLog.Error(e.Message); badMusic.Add(musicPath); } } foreach (var bad in badMusic) { // If any of the music files failed to load or do not exist, remove them. _config.EnabledMusicFiles.Remove(bad); } stopwatch.Stop(); _siraLog.Debug($"Finished Loading Music in {stopwatch.Elapsed} seconds"); _randomObjectPicker = new RandomObjectPicker <AudioContainer>(loadedCustoms.ToArray(), 0.07f); Loaded?.Invoke(); }
protected override void OnInit(double time) { State.CheckError(); TriangleShaderProgram = ShaderProgram.Create("TriangleShaderProgram"); State.CheckError(); using (var vert = Content.LoadShader("TriangleVertex.vert", GFX.ShaderType.Vertex)) { using (var frag = Content.LoadShader("TriangleVertex.frag", GFX.ShaderType.Fragment)) { TriangleShaderProgram.AttachShaders(vert, frag); TriangleShaderProgram.Link(); TriangleShaderProgram.DetachShaders(vert, frag); } } State.CheckError(); TriangleUniformTextureSampler = TriangleShaderProgram.GetUniformLocation("textureSampler"); State.CheckError(); TriangleVertexBuffer = Buffer <Vector3f> .Create( "TriangleVertexBuffer", 3, BufferStorageFlags.MapReadBit | BufferStorageFlags.MapWriteBit ); State.CheckError(); unsafe { var ptr = (Vector3f *)TriangleVertexBuffer.Map(BufferAccess.WriteOnly); State.CheckError(); ptr[0] = new Vector3f(-1f, 1f, 0f); ptr[1] = new Vector3f(1f, 1f, 0f); ptr[2] = new Vector3f(0f, -1f, 0f); TriangleVertexBuffer.Unmap(); State.CheckError(); } TriangleVertexAttributes = VertexAttributes.Create("TriangleVertexAttributes"); TriangleVertexAttributes.SetVertexAttributeEnabled(0, true); TriangleVertexAttributes.SetVertexAttributeLayout(0, "Position", GFX.AttributeType.Vector3, false, 0, 0, TriangleVertexBuffer); State.CheckError(); TriangleTexture = Content.LoadTexture2D("rainbow.png"); }
protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); _cursorTexture = Content.Load <Texture2D>("Sprites/ui/walk-cursor"); var uiContentStorage = ServiceProvider.GetRequiredService <IUiContentStorage>(); uiContentStorage.LoadContent(Content); var personVisualizationContentStorage = ServiceProvider.GetRequiredService <IPersonVisualizationContentStorage>(); personVisualizationContentStorage.LoadContent(Content); var gameobjectVisualizationContentStorage = ServiceProvider.GetRequiredService <IGameObjectVisualizationContentStorage>(); gameobjectVisualizationContentStorage.LoadContent(Content); var personSoundContentStorage = ServiceProvider.GetRequiredService <IPersonSoundContentStorage>(); personSoundContentStorage.LoadContent(Content); var uiSoundStorage = ServiceProvider.GetRequiredService <IUiSoundStorage>(); uiSoundStorage.LoadContent(Content); UiThemeManager.SoundStorage = uiSoundStorage; var sceneManager = new ScreenManager(this); var titleScene = new TitleScreen(this, _spriteBatch); sceneManager.ActiveScreen = titleScene; Components.Add(sceneManager); #if DEBUG var fpsCounter = new FpsCounter(this, _spriteBatch, Content.Load <SpriteFont>("Fonts/Main")); Components.Add(fpsCounter); var cheatInput = new CheatInput(this, _spriteBatch, Content.Load <SpriteFont>("Fonts/Main")); Components.Add(cheatInput); #endif }
private static async void LaunchRequest(int slot, string url, IStore <ImageLoaderState> store) { Texture2D?texture = null; try { texture = await LoadRemoteTexture(url); } catch (IOException e) { Debug.LogException(e); } catch (Exception e) { Debug.LogException(e); throw; } if (texture is null) { return; } store.Dispatch(new ImageResultAction(slot, texture)); }