public TextBox(Texture2D staticTexture, Texture2D overTexture, Texture2D activeTexture, SpriteFont font, Vector2 position, Vector2 scale) { texture = this.staticTexture = staticTexture; this.overTexture = overTexture; this.activeTexture = activeTexture; this.position = position; this.scale = scale; Vector2 contentPosition = new Vector2(X + 15, Y + (Height/2) - 12); this.content = new GameString(font, "", contentPosition, Color.Azure); finalHeight = position.Y + texture.Height * scale.Y; finalWidth = position.X + texture.Width * scale.X; lastString = ""; IsVisible = true; }
public Button(Texture2D staticTexture, Texture2D overTexture, Texture2D pressTexture, Vector2 position, Vector2 scale, SoundEffect click = null, GameString gs = null) { this.texture = this.staticTexture = staticTexture; this.overTexture = overTexture; this.pressTexture = pressTexture; this.position = position; this.scale = scale; finalWidth = position.X + texture.Width*scale.X; finalHeight = position.Y + texture.Height*scale.Y; this.click = click; //sound = new Thread(() => { click.Play(); }); str = gs; Vector2 measure = gs.Font.MeasureString(gs.Str); gs.Position = new Vector2(position.X + (Width/2) - (measure.X / 2), position.Y + (Height/2) - (measure.Y/2)); }
/// <summary> /// Создает няшнную кнопочку. Тащемта метод себя изживший, но пригождается пока еще. /// </summary> /// <param name="staticTexture">Текстура статичной кнопки.</param> /// <param name="overTexture">Текстура кнопки при наведении на нее курсора мыши.</param> /// <param name="x">Координата по горизонтали.</param> /// <param name="y">Координата по вертикали.</param> /// <param name="scale">Масштаб.</param> /// <param name="str">Строка, если требуется. По дефолту пустая.</param> /// <returns>Возвращает кнопку епта.</returns> private Button CreateButton(string staticTexture, string overTexture, float x, float y, float scale, string str = "") { //TODO Выяснить, что за пиздец со звуком. И с песней тоже. //todo test SoundEffect click; try { click = Content.Load<SoundEffect>("Sound/Click"); SoundEffect.MasterVolume = 0.1f; } catch (NoAudioHardwareException ex) { click = null; } GameString gs = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), str, Vector2.Zero, Color.Azure); return new Button(Content.Load<Texture2D>("UI/Buttons/"+staticTexture), Content.Load<Texture2D>("UI/Buttons/"+overTexture), Content.Load<Texture2D>("UI/Buttons/"+overTexture), Shift(x, y), Resize(scale), click, gs); }
//------------------------------------------------------------ //BLACKHOLE SYSTEM CREATE //------------------------------------------------------------ private void CreateBlackHoleSystem(BlackHoleSystem bhs) { if (!screens.ContainsKey("BlackHoleSystem")) { Screen BlackHoleSystemScreen = new Screen(); BackGround BlackHoleSystemBack = CreateBackground("Temp/SolarBackTest", Scales.None, 255f, false); BlackHoleSystemScreen.Objects.Add("Back", BlackHoleSystemBack); //info popup BackGround infoPopupBack = CreateBackground("UI/SoftPopup", Scales.Quarter, 255f); Popup infoPopup = CreatePopup(infoPopupBack, Scales.None, 400, 400); GameString infoString = CreateGameString("SpriteFont1", "", 30, 20, Color.Azure); infoPopup.Objects.Add("InfoString", infoString); //end info popup //more info popup TextBox nameTextBox = CreateTextBox("Square", "SpriteFont1", 332, 40, Scales.ThreeWithHalfTenth); Popup moreInfoPopup = CreateInfoPopup(); //for buttons position BackGround moreInfoPopupBack = (BackGround)moreInfoPopup.Objects["Back"]; GameString name = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Name", Shift(30, 20), Color.Azure); ((GameString)nameTextBox.ContentSource).Position = new Vector2(moreInfoPopup.Position.X + nameTextBox.Position.X + 10, moreInfoPopup.Position.Y + nameTextBox.Position.Y + 5); GameString PlanetSizeString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Size", Shift(30, 50), Color.Azure); GameString MinTemperatureString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Minimum Temperature", Shift(30, 80), Color.Azure); GameString MaxTemperatureString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Maximum Temperature", Shift(30, 110), Color.Azure); GameString IsAborigensString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Life", Shift(30, 140), Color.Azure); GameString MassString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Mass", Shift(30, 170), Color.Azure); GameString OwnerString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Owner", Shift(30, 200), Color.Azure); GameString RaceString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Race", Shift(30, 230), Color.Azure); GameString GravityString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Gravity", Shift(30, 260), Color.Azure); GameString ClimatString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Climat", Shift(30, 290), Color.Azure); GameString StabilityString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Stability", Shift(30, 320), Color.Azure); GameString FertilityString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Fertility", Shift(30, 350), Color.Azure); GameString RadioactivityString = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Radioactivity", Shift(30, 380), Color.Azure); moreInfoPopup.Objects.Add("NameString", name); moreInfoPopup.Objects.Add("PlanetSizeString", PlanetSizeString); moreInfoPopup.Objects.Add("MinTemperatureString", MinTemperatureString); moreInfoPopup.Objects.Add("MaxTemperatureString", MaxTemperatureString); moreInfoPopup.Objects.Add("IsAborigensString", IsAborigensString); moreInfoPopup.Objects.Add("MassString", MassString); moreInfoPopup.Objects.Add("OwnerString", OwnerString); moreInfoPopup.Objects.Add("RaceString", RaceString); moreInfoPopup.Objects.Add("GravityString", GravityString); moreInfoPopup.Objects.Add("ClimatString", ClimatString); moreInfoPopup.Objects.Add("StabilityString", StabilityString); moreInfoPopup.Objects.Add("FertilityString", FertilityString); moreInfoPopup.Objects.Add("RadioactivityString", RadioactivityString); moreInfoPopup.Objects.Add("NameTextBox", nameTextBox); //end more info popup BlackHoleSystemScreen.Objects.Add("BlackHoleSystem", bhs); BlackHoleSystemScreen.Objects.Add("InfoPopup", infoPopup); BlackHoleSystemScreen.Objects.Add("MoreInfoPopup", moreInfoPopup); BlackHoleSystemScreen.Objects.Add("EscPopup", CreateEscMenu()); CreateHUD(BlackHoleSystemScreen); screens.Add("BlackHoleSystem", BlackHoleSystemScreen); } else { screens["BlackHoleSystem"].Objects["BlackHoleSystem"] = bhs; } }
//------------------------------------------------------------ //SOLAR SYSTEM CREATE //------------------------------------------------------------ private void SolarSystem(SolarSystem ss) { if (!screens.ContainsKey("SolarSystem")) { Screen SolarSystemScreen = new Screen(); BackGround solarSystemBack = CreateBackground("Temp/SolarBackTest", Scales.None, 255f, false); SolarSystemScreen.Objects.Add("Back", solarSystemBack); //info popup BackGround infoPopupBack = CreateBackground("UI/SoftPopup", Scales.Quarter, 255f); Popup infoPopup = CreatePopup(infoPopupBack, Scales.None, 600, 500); GameString infoString = CreateGameString("SpriteFont1", "", 30, 20, Color.Azure); infoPopup.Objects.Add("InfoString", infoString); //end info popup TextBox nameTextBox = CreateTextBox("Square", "SpriteFont1", 332, 40, Scales.ThreeWithHalfTenth); Popup moreInfoPopup = CreateInfoPopup(); //for buttons position BackGround moreInfoPopupBack = (BackGround)moreInfoPopup.Objects["Back"]; GameString name = new GameString(Content.Load<SpriteFont>("Fonts/SpriteFont1"), "Name", Shift(262, 40), Color.Azure); ((GameString)nameTextBox.ContentSource).Position = Shift(new Vector2(moreInfoPopup.Position.X + nameTextBox.Position.X + 10, moreInfoPopup.Position.Y + nameTextBox.Position.Y + 5)); BackGround PlanetStateFrame = CreateIcon("PlanetState/Frame", Scales.SevenTenth, 255f, new Vector2(100, 80)); Button colonize = CreateStrButton("blue", 654, 487, Scales.SevenTenth, locals.Strings["Colonize"]); Button terraform = CreateStrButton("blue", 400, 487, Scales.SevenTenth, locals.Strings["Terraform"]); Button stationBuilder = CreateStrButton("blue", 400, 487, Scales.SevenTenth, locals.Strings["StationBuilder"]); Button createShip = CreateStrButton("blue", 654, 487, Scales.SevenTenth, locals.Strings["CreateShip"]); ProgressBar progress = CreateProgressBar("FillingBar", 262, 380, Scales.TwoTenth);//new ProgressBar(Content.Load<Texture2D>("UI/FillingBar"), /*HERE*/Shift(262, 380), /*HERE*/Resize(/*0.2f*/Scales.TwoTenth.Value)); moreInfoPopup.Objects.Add("Progress", progress); moreInfoPopup.Objects.Add("NameString", name); moreInfoPopup.Objects.Add("PlanetStateFrame", PlanetStateFrame); moreInfoPopup.Objects.Add("NameTextBox", nameTextBox); moreInfoPopup.Objects.Add("ColonizeBtn", colonize); moreInfoPopup.Objects.Add("TerraformBtn", terraform); moreInfoPopup.Objects.Add("CreateShipBtn", createShip); moreInfoPopup.Objects.Add("StationBuilderBtn", stationBuilder); //end more info popup SolarSystemScreen.Objects.Add("SolarSystem", ss); SolarSystemScreen.Objects.Add("InfoPopup", infoPopup); CreateHUD(SolarSystemScreen); SolarSystemScreen.Objects.Add("MoreInfoPopup", moreInfoPopup); SolarSystemScreen.Objects.Add("EscPopup", CreateEscMenu()); CreateDebugInfoWindow(SolarSystemScreen); screens.Add("SolarSystem", SolarSystemScreen); } else { screens["SolarSystem"].Objects["SolarSystem"] = ss; } }