protected override void Init() { TextureEngine Textures = GetClient().Textures; Tex_None = Textures.GetTexture(tName + "_none"); Tex_Hover = Textures.GetTexture(tName + "_hover"); Tex_Click = Textures.GetTexture(tName + "_click"); }
public UITextLink(Texture ico, string btext, string btexthover, string btextclick, FontSet font, Action clicked, UIAnchor anchor, Func<int> xOff, Func<int> yOff) : base(anchor, () => 0, () => 0, xOff, yOff) { Icon = ico; ClickedTask = clicked; Text = btext; TextHover = btexthover; TextClick = btextclick; TextFont = font; Width = () => font.MeasureFancyText(Text, BColor) + (Icon == null ? 0 : font.font_default.Height); Height = () => TextFont.font_default.Height; }
public TextureLoadedEventArgs(Texture t) { Tex = t; }
/// <summary> /// Loads a texture from file. /// </summary> /// <param name="filename">The name of the file to use.</param> /// <returns>The loaded texture, or null if it does not exist.</returns> public Texture LoadTexture(string filename, int twidth = 0) { try { filename = FileHandler.CleanFileName(filename); if (!TheClient.Files.Exists("textures/" + filename + ".png")) { SysConsole.Output(OutputType.ERROR, "Cannot load texture, file '" + TextStyle.Color_Standout + "textures/" + filename + ".png" + TextStyle.Color_Error + "' does not exist."); return null; } Bitmap bmp = new Bitmap(TheClient.Files.ReadToStream("textures/" + filename + ".png")); if (!AcceptableWidths.Contains(bmp.Width) || !AcceptableWidths.Contains(bmp.Height)) { SysConsole.Output(OutputType.ERROR, "Cannot load texture, file '" + TextStyle.Color_Standout + "textures/" + filename + ".png" + TextStyle.Color_Error + "' is invalid: unreasonable width or height."); return null; } Bitmap bmp2 = twidth <= 0 ? bmp : new Bitmap(bmp, new Size(twidth, twidth)); Texture texture = new Texture(); texture.Engine = this; texture.Name = filename; GL.GenTextures(1, out texture.Original_InternalID); texture.Internal_Texture = texture.Original_InternalID; texture.Bind(); LockBitmapToTexture(bmp2, true); texture.Width = bmp2.Width; texture.Height = bmp2.Height; if (bmp2 != bmp) { bmp2.Dispose(); } bmp.Dispose(); texture.LoadedProperly = true; return texture; } catch (Exception ex) { SysConsole.Output(OutputType.ERROR, "Failed to load texture from filename '" + TextStyle.Color_Standout + "textures/" + filename + ".png" + TextStyle.Color_Error + "': " + ex.ToString()); return null; } }
/// <summary> /// Starts or restarts the texture system. /// </summary> public void InitTextureSystem(Client tclient) { TheClient = tclient; // Create a generic graphics object for later use EmptyBitmap = new Bitmap(1, 1); GenericGraphicsObject = Graphics.FromImage(EmptyBitmap); // Reset texture list LoadedTextures = new List<Texture>(); // Pregenerate a few needed textures White = GenerateForColor(Color.White, "white"); LoadedTextures.Add(White); Black = GenerateForColor(Color.Black, "black"); LoadedTextures.Add(Black); Clear = GenerateForColor(Color.Transparent, "clear"); LoadedTextures.Add(Clear); NormalDef = GetTexture("normal_def"); }
/// <summary> /// Gets the texture object for a specific texture name. /// </summary> /// <param name="texturename">The name of the texture.</param> /// <returns>A valid texture object.</returns> public Texture GetTexture(string texturename, int twidth = 0) { texturename = FileHandler.CleanFileName(texturename); for (int i = 0; i < LoadedTextures.Count; i++) { if (LoadedTextures[i].Name == texturename && (twidth == 0 || LoadedTextures[i].Width == twidth)) { return LoadedTextures[i]; } } Texture Loaded = LoadTexture(texturename, twidth); if (Loaded == null && twidth == 0) { Loaded = new Texture(); Loaded.Engine = this; Loaded.Name = texturename; Loaded.Internal_Texture = White.Original_InternalID; Loaded.Original_InternalID = White.Original_InternalID; Loaded.LoadedProperly = false; } if (Loaded == null) { Loaded = LoadTexture("white", twidth); Loaded.Name = texturename; Loaded.LoadedProperly = false; } LoadedTextures.Add(Loaded); if (OnTextureLoaded != null) { OnTextureLoaded(this, new TextureLoadedEventArgs(Loaded)); } return Loaded; }
/// <summary> /// Creates a Texture object for a specific color. /// </summary> /// <param name="c">The color to use.</param> /// <param name="name">The name of the texture.</param> /// <returns>The generated texture.</returns> public Texture GenerateForColor(Color c, string name) { Texture texture = new Texture(); texture.Engine = this; texture.Name = name; GL.GenTextures(1, out texture.Original_InternalID); texture.Internal_Texture = texture.Original_InternalID; texture.Bind(); texture.Width = 2; texture.Height = 2; Bitmap bmp = new Bitmap(2, 2); bmp.SetPixel(0, 0, c); bmp.SetPixel(0, 1, c); bmp.SetPixel(1, 0, c); bmp.SetPixel(1, 1, c); LockBitmapToTexture(bmp, false); bmp.Dispose(); texture.LoadedProperly = true; return texture; }
/// <summary> /// Called when the window is loading, only to be used by the startup process. /// </summary> void Window_Load(object sender, EventArgs e) { SysConsole.Output(OutputType.INIT, "Window generated!"); DPIScale = Window.Width / CVars.r_width.ValueF; SysConsole.Output(OutputType.INIT, "DPIScale is " + DPIScale + "!"); SysConsole.Output(OutputType.INIT, "Loading base textures..."); PreInitRendering(); Textures = new TextureEngine(); Textures.InitTextureSystem(this); ItemFrame = Textures.GetTexture("ui/hud/item_frame"); SysConsole.Output(OutputType.INIT, "Loading shaders..."); Shaders = new ShaderEngine(); GLVendor = GL.GetString(StringName.Vendor); CVars.s_glvendor.Value = GLVendor; GLVersion = GL.GetString(StringName.Version); CVars.s_glversion.Value = GLVersion; GLRenderer = GL.GetString(StringName.Renderer); CVars.s_glrenderer.Value = GLRenderer; SysConsole.Output(OutputType.INIT, "Vendor: " + GLVendor + ", GLVersion: " + GLVersion + ", Renderer: " + GLRenderer); if (GLVendor.ToLowerFast().Contains("intel")) { SysConsole.Output(OutputType.INIT, "Disabling good graphics (Appears to be Intel: '" + GLVendor + "')"); Shaders.MCM_GOOD_GRAPHICS = false; } Shaders.InitShaderSystem(this); View3D.CheckError("Load - Shaders"); SysConsole.Output(OutputType.INIT, "Loading rendering helper..."); Rendering = new Renderer(Textures, Shaders); Rendering.Init(); SysConsole.Output(OutputType.INIT, "Preparing load screen..."); Texture load_screen = Textures.GetTexture("ui/menus/loadscreen"); load_screen.Bind(); Shaders.ColorMultShader.Bind(); Establish2D(); Rendering.RenderRectangle(0, 0, Window.Width, Window.Height); Window.SwapBuffers(); SysConsole.Output(OutputType.INIT, "Loading block textures..."); TBlock = new TextureBlock(); TBlock.Generate(this, CVars, Textures); View3D.CheckError("Load - Textures"); SysConsole.Output(OutputType.INIT, "Loading fonts..."); Fonts = new GLFontEngine(Shaders); Fonts.Init(this); FontSets = new FontSetEngine(Fonts); FontSets.Init(this); View3D.CheckError("Load - Fonts"); SysConsole.Output(OutputType.INIT, "Loading animation engine..."); Animations = new AnimationEngine(); SysConsole.Output(OutputType.INIT, "Loading model engine..."); Models = new ModelEngine(); Models.Init(Animations, this); SysConsole.Output(OutputType.INIT, "Loading general graphics settings..."); CVars.r_vsync.OnChanged += onVsyncChanged; onVsyncChanged(CVars.r_vsync, null); CVars.r_cloudshadows.OnChanged += onCloudShadowChanged; View3D.CheckError("Load - General Graphics"); SysConsole.Output(OutputType.INIT, "Loading UI engine..."); UIConsole.InitConsole(); // TODO: make this non-static InitChatSystem(); View3D.CheckError("Load - UI"); SysConsole.Output(OutputType.INIT, "Preparing rendering engine..."); InitRendering(); View3D.CheckError("Load - Rendering"); SysConsole.Output(OutputType.INIT, "Loading particle effect engine..."); Particles = new ParticleHelper(this) { Engine = new ParticleEngine(this) }; SysConsole.Output(OutputType.INIT, "Preparing mouse, keyboard, and gamepad handlers..."); KeyHandler.Init(); GamePadHandler.Init(); View3D.CheckError("Load - Keyboard/mouse"); SysConsole.Output(OutputType.INIT, "Building the sound system..."); Sounds = new SoundEngine(); Sounds.Init(this, CVars); View3D.CheckError("Load - Sound"); SysConsole.Output(OutputType.INIT, "Building game world..."); BuildWorld(); View3D.CheckError("Load - World"); SysConsole.Output(OutputType.INIT, "Preparing networking..."); Network = new NetworkBase(this); RegisterDefaultEntityTypes(); View3D.CheckError("Load - Net"); SysConsole.Output(OutputType.INIT, "Playing background music..."); BackgroundMusic(); CVars.a_musicvolume.OnChanged += onMusicVolumeChanged; CVars.a_musicpitch.OnChanged += onMusicPitchChanged; CVars.a_music.OnChanged += onMusicChanged; CVars.a_echovolume.OnChanged += OnEchoVolumeChanged; OnEchoVolumeChanged(null, null); SysConsole.Output(OutputType.INIT, "Setting up screens..."); TheMainMenuScreen = new MainMenuScreen(this); TheGameScreen = new GameScreen(this); TheSingleplayerMenuScreen = new SingleplayerMenuScreen(this); SysConsole.Output(OutputType.INIT, "Preparing inventory..."); InitInventory(); SysConsole.Output(OutputType.INIT, "Showing main menu..."); ShowMainMenu(); SysConsole.Output(OutputType.INIT, "Trying to grab RawGamePad..."); try { RawGamePad = new XInput(); } catch (Exception ex) { SysConsole.Output(OutputType.INIT, "Failed to grab RawGamePad: " + ex.Message); } View3D.CheckError("Load - Final"); SysConsole.Output(OutputType.INIT, "Ready and looping!"); }
public UIImage(Texture image, UIAnchor anchor, Func<float> width, Func<float> height, Func<int> xOff, Func<int> yOff) : base(anchor, width, height, xOff, yOff) { Image = image; }
/// <summary> /// Prepares the console. /// </summary> public static void InitConsole() { ready = true; ConsoleText = Utilities.CopyText("\n", Lines); ConsoleTextLoc = new Location(5, 0, 0); Typing = ""; TypingLoc = new Location(5, 0, 0); ScrollText = "^1" + Utilities.CopyText("/\\ ", 150); ScrollTextLoc = new Location(5, 0, 0); MaxWidth = Client.Central.Window.Width - 10; ConsoleTexture = Client.Central.Textures.GetTexture("ui/hud/console"); WriteLine("Console loaded!"); Write(pre_waiting); }
public void Render(Location pos, Location size) { if (RenderedBlock != null) { return; } if (Tex == null) { if (Name == "block") { Tex = TheClient.Textures.GetTexture("blocks/icons/" + SecondaryName.ToLowerFast()); } else { return; } } Tex.Bind(); TheClient.Rendering.SetColor(TheClient.Rendering.AdaptColor(ClientUtilities.Convert(TheClient.Player.GetPosition()), GetColor())); TheClient.Rendering.RenderRectangle((int)pos.X, (int)pos.Y, (int)(pos.X + size.X), (int)(pos.Y + size.Y)); }
public override void SetTextureName(string name) { if (name == null || name.Length == 0) { Tex = null; } else { if (name.Contains(":") && name.Before(":").ToLowerFast() == "render_block") { string[] blockDataToRender = name.After(":").SplitFast(','); if (blockDataToRender[0] == "self") { BlockInternal bi = BlockInternal.FromItemDatum(Datum); RenderedBlock = new BlockItemEntity(TheClient.TheRegion, bi.Material, bi.BlockData, bi.BlockPaint, bi.Damage); RenderedBlock.GenVBO(); } else { Material mat = MaterialHelpers.FromNameOrNumber(blockDataToRender[0]); byte data = (byte)(blockDataToRender.Length < 2 ? 0 : Utilities.StringToInt(blockDataToRender[1])); byte paint = (byte)(blockDataToRender.Length < 3 ? 0 : Colors.ForName(blockDataToRender[2])); BlockDamage damage = blockDataToRender.Length < 4 ? BlockDamage.NONE : (BlockDamage)Enum.Parse(typeof(BlockDamage), blockDataToRender[3], true); RenderedBlock = new BlockItemEntity(TheClient.TheRegion, mat, data, paint, damage); RenderedBlock.GenVBO(); } Tex = null; } if (name.Contains(":") && name.Before(":").ToLowerFast() == "render_model") { string model = name.After(":"); if (model.ToLowerFast() == "self") { model = GetModelName(); } RenderedModel = new ModelEntity(model, TheClient.TheRegion); RenderedModel.Visible = true; RenderedModel.PreHandleSpawn(); Tex = null; } else { Tex = TheClient.Textures.GetTexture(name); } } }