slider bar needs testing and work

This commit is contained in:
2018-08-24 21:55:39 -07:00
parent c0c143ccd8
commit b62a5eb076
3 changed files with 59 additions and 24 deletions

View File

@ -65,7 +65,7 @@ namespace StardustCore.UIUtilities.MenuComponents
/// <summary> /// <summary>
/// Enum dealing with what kind of slider this is. /// Enum dealing with what kind of slider this is.
/// </summary> /// </summary>
SliderStyle sliderStyle; public SliderStyle sliderStyle;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
@ -297,29 +297,66 @@ namespace StardustCore.UIUtilities.MenuComponents
/// <param name="y"></param> /// <param name="y"></param>
public void offset(int x, int y) public void offset(int x, int y)
{ {
int xOffset = x - (this.bounds.X+this.bounds.Width/2);
int yOffset = y - (this.bounds.Y+this.bounds.Height/2); if (x < sliderBar.bounds.X)
{
x = sliderBar.bounds.X;
}
if (y < sliderBar.bounds.Y)
{
y = sliderBar.bounds.Y;
}
if (x > (sliderBar.bounds.X) + (sliderBar.bounds.Width))
{
x = (sliderBar.bounds.X) + (sliderBar.bounds.Width);
}
if (y > (sliderBar.bounds.Y) + (sliderBar.bounds.Height))
{
y = (sliderBar.bounds.Y) + (sliderBar.bounds.Height);
}
//Get offset from button.
int xOffset = (bounds.X - x); //267-300
int yOffset = (bounds.Y - y);
this.sliderInformation.offset(xOffset, yOffset); if (sliderInformation.sliderStyle == SliderStyle.Horizontal || sliderInformation.sliderStyle== SliderStyle.Square)
offsetBounds(); {
this.sliderInformation.xPos = (x - sliderBar.bounds.X) / (int)scale;
this.bounds.X = this.sliderBar.bounds.X + this.sliderInformation.xPos*(int)scale;
if (this.bounds.X > this.sliderBar.bounds.X + this.sliderBar.bounds.Width)
{
this.bounds.X = this.sliderBar.bounds.X + this.sliderBar.bounds.Width;
}
}
if (sliderInformation.sliderStyle == SliderStyle.Vertical || sliderInformation.sliderStyle == SliderStyle.Square)
{
this.sliderInformation.yPos = (y - sliderBar.bounds.Y) / (int)scale;
this.bounds.Y = this.sliderBar.bounds.Y + this.sliderInformation.yPos*(int)scale;
if (this.bounds.Y > this.sliderBar.bounds.Y + this.sliderBar.bounds.Height)
{
this.bounds.Y = this.sliderBar.bounds.Y + this.sliderBar.bounds.Height;
}
}
//this.sliderInformation.offset(xOffset, yOffset);
} }
public void offsetBounds()
{
//EX: 200+(200+(3-200)) = (200)+(200-197)= 200+3 =203;
//EX: 200+(200+(-3-200)) = (200)+(200-203)= 200-3 =197;
this.bounds.X =this.bounds.X+(this.bounds.X + (this.sliderInformation.xPos-bounds.X));
this.bounds.Y =this.bounds.Y+(this.bounds.Y + (this.sliderInformation.yPos-bounds.Y));
}
/// <summary> /// <summary>
/// Sets the initial position for the button at sliderPosition.x=0; /// Sets the initial position for the button at sliderPosition.x=0;
/// </summary> /// </summary>
public void initializeBounds() public void initializeBounds()
{ {
this.bounds.X +=this.sliderInformation.xPos; this.bounds.X +=this.sliderInformation.xPos*(int)scale;
this.bounds.Y +=this.sliderInformation.yPos; this.bounds.Y +=this.sliderInformation.yPos*(int)scale;
} }
/// <summary> /// <summary>
@ -329,8 +366,7 @@ namespace StardustCore.UIUtilities.MenuComponents
/// <param name="y"></param> /// <param name="y"></param>
public void movementOffset(int x, int y) public void movementOffset(int x, int y)
{ {
this.sliderInformation.movementOffset(x, y); offset(x, y);
offsetBounds();
} }
/// <summary> /// <summary>
@ -381,16 +417,14 @@ namespace StardustCore.UIUtilities.MenuComponents
{ {
if (this.containsPoint(x, y)) if (this.containsPoint(x, y))
{ {
int xPos = x - this.sliderBar.bounds.X; this.movementOffset(x, y);
int yPos = y - this.sliderBar.bounds.Y;
this.movementOffset(xPos, yPos);
} }
} }
/// <summary> /// <summary>
/// Draws the slider. /// D raws the slider.
/// </summary> /// </summary>
/// <param name="b"></param> /// <param name="b"></param>
/// <param name="color"></param> /// <param name="color"></param>
@ -428,7 +462,7 @@ namespace StardustCore.UIUtilities.MenuComponents
if (string.IsNullOrEmpty(this.label)) if (string.IsNullOrEmpty(this.label))
return; return;
b.DrawString(Game1.smallFont, this.label+this.sliderInformation.getLabelInformation(this.getLabelXYPos), new Vector2((float)(this.bounds.X + this.bounds.Width+offset.X+this.sliderInformation.xPos), (float)this.bounds.Y + ((float)(this.bounds.Height / 2) - Game1.smallFont.MeasureString(this.label).Y / 2f)+offset.X+this.sliderInformation.yPos), textColor); b.DrawString(Game1.smallFont, this.label+this.sliderInformation.getLabelInformation(this.getLabelXYPos), new Vector2((float)((this.bounds.X + this.bounds.Width+offset.X)*this.scale), (float)this.bounds.Y + ((float)(this.bounds.Height / 2) - Game1.smallFont.MeasureString(this.label).Y / 2f)+offset.X+this.sliderInformation.yPos), textColor);
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 B

After

Width:  |  Height:  |  Size: 168 B

View File

@ -30,10 +30,10 @@ namespace Vocalization.Framework.Menus
public void setUpButtons() public void setUpButtons()
{ {
Texture2DExtended buttonTexture = new Texture2DExtended(Vocalization.ModHelper, Vocalization.Manifest, Path.Combine("Content", "Graphics", "SliderButton.png")); Texture2DExtended buttonTexture = new Texture2DExtended(Vocalization.ModHelper, Vocalization.Manifest, Path.Combine("Content", "Graphics", "SliderButton.png"));
Button bar = new Button(new Rectangle(this.xPositionOnScreen + 100, this.yPositionOnScreen + 220, 100, 20), new Texture2DExtended(Vocalization.ModHelper, Vocalization.Manifest, Path.Combine("Content", "Graphics", "SliderBar.png")),new Rectangle(0,0,100,10),2f); Button bar = new Button(new Rectangle(this.xPositionOnScreen + 100, this.yPositionOnScreen + 220, 200, 40), new Texture2DExtended(Vocalization.ModHelper, Vocalization.Manifest, Path.Combine("Content", "Graphics", "SliderBar.png")),new Rectangle(0,0,100,10),2f);
//Texture2DExtended barTexture = new Texture2DExtended(Vocalization.ModHelper, Vocalization.Manifest, Path.Combine("Content", "Graphics", "SliderBar.png")); //Texture2DExtended barTexture = new Texture2DExtended(Vocalization.ModHelper, Vocalization.Manifest, Path.Combine("Content", "Graphics", "SliderBar.png"));
Rectangle sourceRect = new Rectangle(0, 0, 8, 16); Rectangle sourceRect = new Rectangle(0, 0, 4, 16);
this.sliderButton = new SliderButton("Slider", "Volume", new Rectangle(this.xPositionOnScreen+100, this.yPositionOnScreen+220, 8, 16), buttonTexture, bar, sourceRect, 2f, new SliderInformation(SliderStyle.Horizontal, 100, 1), new StardustCore.Animations.Animation(sourceRect), Color.White, Color.Black, new StardustCore.UIUtilities.MenuComponents.Delegates.Functionality.ButtonFunctionality(null, null, null), false, null, true); this.sliderButton = new SliderButton("Slider", "Volume", new Rectangle(this.xPositionOnScreen+100, this.yPositionOnScreen+220, 4, 16), buttonTexture, bar, sourceRect, 2f, new SliderInformation(SliderStyle.Horizontal, 100, 1), new StardustCore.Animations.Animation(sourceRect), Color.White, Color.Black, new StardustCore.UIUtilities.MenuComponents.Delegates.Functionality.ButtonFunctionality(null, null, null), false, null, true);
} }
@ -57,6 +57,7 @@ namespace Vocalization.Framework.Menus
public override void draw(SpriteBatch b) public override void draw(SpriteBatch b)
{ {
//INCLUDE A COLOR FOR THE MENU!!!!!
this.drawDialogueBoxBackground(this.xPositionOnScreen,this.yPositionOnScreen,this.width,this.height); this.drawDialogueBoxBackground(this.xPositionOnScreen,this.yPositionOnScreen,this.width,this.height);
sliderButton.draw(b,Color.White,Vector2.Zero,0.5f); sliderButton.draw(b,Color.White,Vector2.Zero,0.5f);