public MultiOptionSelector(AssetManager assets, string themeName, Vector2 position, Anchor anchor, List<Option> options, MultiOptionArrangement arrangement, Cursor cursor, int initialValue) : base(themeName, position, initialValue) { //process arrangement if (arrangement == MultiOptionArrangement.ListX) arrangement = new MultiOptionArrangement(options.Count, 1); if (arrangement == MultiOptionArrangement.ListY) arrangement = new MultiOptionArrangement(1, options.Count); this.arrangement = arrangement; TextDictionary assetDictionary = new TextDictionary(assets.GetText("selector")); //load themes string cursorTheme = assetDictionary.LookupString(themeName, "cursorTheme"); string optionTheme = assetDictionary.LookupString(themeName, "optionTheme"); Anchor justify = Anchor.Center; bool justifySuccess = assetDictionary.CheckPropertyExists(themeName, "justify"); if (justifySuccess) { string justifyString = assetDictionary.LookupString(themeName, "justify"); if (justifyString == "Left") justify = Anchor.CenterLeft; else if (justifyString == "Right") justify = Anchor.CenterRight; } //position components cursor.Initialize(options, assets, cursorTheme); Vector2 individualSize = Vector2.Zero; for (int i = 0; i < options.Count; i++) { options[i].Initialize(assets, optionTheme); if (options[i].Dimensions.X > individualSize.X) individualSize.X = options[i].Dimensions.X; if (options[i].Dimensions.Y > individualSize.Y) individualSize.Y = options[i].Dimensions.Y; } for (int i = 0; i < options.Count; i++) options[i].Position = (individualSize + cursor.Spacing * Vector2.One) * arrangement.GetPosition(i); Vector2 overallSize = new Vector2(arrangement.Columns * (individualSize.X + cursor.Spacing) - cursor.Spacing, arrangement.Rows * (individualSize.Y + cursor.Spacing) - cursor.Spacing); for (int i = 0; i < options.Count; i++) { Vector2 p = options[i].Position; if (justify == Anchor.TopCenter || justify == Anchor.Center || justify == Anchor.BottomCenter) p.X += (individualSize.X - options[i].Dimensions.X) / 2; else if (justify == Anchor.TopRight || justify == Anchor.CenterRight || justify == Anchor.BottomRight) p.X += individualSize.X - options[i].Dimensions.X; if (justify == Anchor.CenterLeft || justify == Anchor.Center || justify == Anchor.CenterRight) p.Y += (individualSize.Y - options[i].Dimensions.Y) / 2; else if (justify == Anchor.BottomLeft || justify == Anchor.BottomCenter || justify == Anchor.BottomRight) p.Y += individualSize.Y - options[i].Dimensions.Y; options[i].Position = p; } this.Position -= GraphicsHelper.ComputeAnchorOrigin(anchor, overallSize / GraphicsConstants.VIEWPORT_DIMENSIONS); this.options = options; this.cursor = cursor; //initialize position Vector2 initialPosition = arrangement.GetPosition(IntValue); x = (int)initialPosition.X; y = (int)initialPosition.Y; cursor.Update(IntValue); }
public override void Initialize(AssetManager assets, string themeName) { TextDictionary assetDictionary = new TextDictionary(assets.GetText("option")); fontFace = assets.GetFont(assetDictionary.LookupString(themeName, "fontFace")); try { fontColor = new Color(assetDictionary.LookupVector4(themeName, "fontColor")); } catch { fontColor = new Color(assetDictionary.LookupVector3(themeName, "fontColor")); } dimensions = fontFace.MeasureString(text) + new Vector2(0, -5); }
public static MultiOptionSelector BuildMultiOptionSelector(AssetManager assets, string theme, string selectorName, List<Option> options, MultiOptionArrangement arrangement, Cursor cursor, int initialValue = 0) { TextDictionary assetDictionary = new TextDictionary(assets.GetText("selector")); string selectorTheme = assetDictionary.LookupString(theme, selectorName + "SelectorTheme"); Vector2 selectorPosition = assetDictionary.LookupVector2(theme, selectorName + "SelectorPosition"); Anchor selectorAnchor = Anchor.Center; if (assetDictionary.CheckPropertyExists(theme, selectorName + "SelectorAnchor")) Enum.TryParse<Anchor>(assetDictionary.LookupString(theme, selectorName + "SelectorAnchor"), out selectorAnchor); return new MultiOptionSelector(assets, selectorTheme, selectorPosition, selectorAnchor, options, arrangement, cursor, initialValue); }
public virtual void Initialize(List<Option> options, AssetManager assets, string themeName) { TextDictionary assetDictionary = new TextDictionary(assets.GetText("cursor")); this.options = options; try { cycleDelay = assetDictionary.LookupInt32(themeName, "cycleDelay"); } catch { cycleDelay = 1; } try { cycleInterval = assetDictionary.LookupInt32(themeName, "cycleInterval"); } catch { cycleInterval = 1; } spacing = assetDictionary.LookupSingle(themeName, "spacing"); if (assetDictionary.CheckPropertyExists(themeName, "cycleSound")) cycleSound = new SoundObject(assets.GetSFX(assetDictionary.LookupString(themeName, "cycleSound"))); if (assetDictionary.CheckPropertyExists(themeName, "selectSound")) selectSound = new SoundObject(assets.GetSFX(assetDictionary.LookupString(themeName, "selectSound"))); selected = false; }
public SingularSelector(AssetManager assets, string themeName, Vector2 position, Anchor anchor, Option option) : base(themeName, position, 0) { TextDictionary assetDictionary = new TextDictionary(assets.GetText("selector")); string optionTheme = assetDictionary.LookupString(themeName, "optionTheme"); blinkRate = assetDictionary.LookupInt32(themeName, "blinkRate"); if (assetDictionary.CheckPropertyExists(themeName, "sound")) sound = new SoundObject(assets.GetSFX(assetDictionary.LookupString(themeName, "sound"))); option.Initialize(assets, optionTheme); //this.position *= GraphicsConstants.VIEWPORT_DIMENSIONS / GraphicsConstants.DEFAULT_DIMENSIONS; this.Position -= GraphicsHelper.ComputeAnchorOrigin(anchor, option.Dimensions / GraphicsConstants.VIEWPORT_DIMENSIONS); this.option = option; IntValue = 0; timer = 0; selected = false; }
public BackgroundParticleSettings(AssetManager assets, int actNumber) { TextDictionary td = new TextDictionary(assets.GetText("particles")); string act = "act" + actNumber; numParticles = td.LookupInt32(act, "numParticles"); if (numParticles > 0) { rotationRateRange = td.LookupVector2(act, "rotationRateRange"); scaleRange = td.LookupVector2(act, "scaleRange"); colorLow = td.LookupColor(act, "colorLow"); colorHigh = td.LookupColor(act, "colorHigh"); texture = assets.GetTexture(td.LookupString(act, "texture")); distance = td.LookupSingle(act, "dist"); } }
public override void Initialize(List<Option> options, AssetManager assets, string themeName) { TextDictionary assetDictionary = new TextDictionary(assets.GetText("cursor")); base.Initialize(options, assets, themeName); graphic = assets.GetTexture(assetDictionary.LookupString(themeName, "graphic")); try { color = new Color(assetDictionary.LookupVector4(themeName, "color")); } catch { color = new Color(assetDictionary.LookupVector3(themeName, "color")); } offset = assetDictionary.LookupVector2(themeName, "offset"); //optional bool anchorParseSuccess = Enum.TryParse<Anchor>(assetDictionary.LookupString(themeName, "anchor"), out anchor); if (!anchorParseSuccess) anchor = Anchor.TopLeft; try { smoothness = assetDictionary.LookupSingle(themeName, "smoothness"); } catch { smoothness = 0f; } }
public static ParallaxBackgroundSet Build(AssetManager assets, Camera camera, Vector2 seamstressStart, string assetName) { TextDictionary assetDictionary = new TextDictionary(assets.GetText("parallax")); int layers = assetDictionary.LookupInt32(assetName, "layers"); ParallaxBackground[] backgrounds = new ParallaxBackground[layers]; BackgroundParticleSet particles = new BackgroundParticleSet(assets, camera.Dimensions, Convert.ToInt32(assetName.Substring(3))); int particleLayer = -1; for (int i = 0; i < layers; i++) { Texture2D tex; if (assetDictionary.CheckPropertyExists(assetName, "name" + i)) tex = assets.GetTexture(assetDictionary.LookupString(assetName, "name" + i)); else tex = assets.GetTexture(assetName + "_layer" + i); float dist, scale; Vector2 offset, velocity, repeat; Anchor anchor; try { dist = assetDictionary.LookupSingle(assetName, "dist" + i); } catch { dist = 1; } try { offset = assetDictionary.LookupVector2(assetName, "offset" + i); } catch { offset = Vector2.Zero; } try { velocity = assetDictionary.LookupVector2(assetName, "velocity" + i); } catch { velocity = Vector2.Zero; } try { scale = assetDictionary.LookupSingle(assetName, "scale" + i); } catch { scale = 1; } try { repeat = assetDictionary.LookupVector2(assetName, "repeat" + i); } catch { repeat = new Vector2(1, 0); } if (!assetDictionary.CheckPropertyExists(assetName, "anchor" + i) || !Enum.TryParse<Anchor>(assetDictionary.LookupString(assetName, "anchor" + i), out anchor)) anchor = Anchor.BottomLeft; backgrounds[i] = new ParallaxBackground(assets, tex, offset, velocity, dist, scale, anchor, repeat); if (dist > particles.Distance) particleLayer = i; } ParallaxBackgroundSet pbs = new ParallaxBackgroundSet(); pbs.backgrounds = backgrounds; pbs.camera = new Camera(camera.Dimensions, camera.Position, camera.Rotation, camera.Scale); pbs.color = assetDictionary.LookupColor(assetName, "color"); pbs.particleLayer = particleLayer; pbs.particles = particles; pbs.seamstressStart = seamstressStart; return pbs; }
/// <summary> /// Constructs a new InputController. /// </summary> /// <param name="assets">The AssetManager object used in the game.</param> public InputController(AssetManager assets) { controllerConnected = GamePad.GetState(PlayerIndex.One).IsConnected; TextDictionary dict = new TextDictionary(assets.GetText("controls")); controls = new InputControl[controlNames.Length]; for (int i = 0; i < controls.Length; i++) { controls[i] = new InputControl(); if (dict.CheckObjectExists(controlNames[i])) { if (dict.CheckPropertyExists(controlNames[i], "key")) { Keys key = (Keys)Enum.Parse(typeof(Keys), dict.LookupString(controlNames[i], "key")); controls[i].AddKey(key); } else { int j = 0; while (dict.CheckPropertyExists(controlNames[i], "key" + j)) { Keys key = (Keys)Enum.Parse(typeof(Keys), dict.LookupString(controlNames[i], "key" + j)); controls[i].AddKey(key); j++; } } if (dict.CheckPropertyExists(controlNames[i], "button")) { Buttons button = (Buttons)Enum.Parse(typeof(Buttons), dict.LookupString(controlNames[i], "button")); controls[i].AddButton(button); } else { int j = 0; while (dict.CheckPropertyExists(controlNames[i], "button" + j)) { Buttons button = (Buttons)Enum.Parse(typeof(Buttons), dict.LookupString(controlNames[i], "button" + j)); controls[i].AddButton(button); j++; } } if (dict.CheckPropertyExists(controlNames[i], "leftjoystick")) { Vector2 dir = dict.LookupVector2(controlNames[i], "leftjoystick"); controls[i].SetLeftJoystick(dir); } if (dict.CheckPropertyExists(controlNames[i], "rightjoystick")) { Vector2 dir = dict.LookupVector2(controlNames[i], "rightjoystick"); controls[i].SetRightJoystick(dir); } if (dict.CheckPropertyExists(controlNames[i], "lefttrigger")) { bool activated = dict.LookupBoolean(controlNames[i], "lefttrigger"); controls[i].SetLeftTrigger(activated); } if (dict.CheckPropertyExists(controlNames[i], "righttrigger")) { bool activated = dict.LookupBoolean(controlNames[i], "righttrigger"); controls[i].SetRightTrigger(activated); } } } var keyNames = Enum.GetValues(typeof(Keys)); allKeys = new InputControl(); foreach (Keys key in keyNames) allKeys.AddKey(key); allKeys.AddButton(Buttons.A); allKeys.AddButton(Buttons.B); allKeys.AddButton(Buttons.Back); allKeys.AddButton(Buttons.LeftShoulder); allKeys.AddButton(Buttons.LeftTrigger); allKeys.AddButton(Buttons.RightShoulder); allKeys.AddButton(Buttons.RightTrigger); allKeys.AddButton(Buttons.Start); allKeys.AddButton(Buttons.X); allKeys.AddButton(Buttons.Y); }
public override void Initialize(AssetManager assets, string themeName) { TextDictionary assetDictionary = new TextDictionary(assets.GetText("option")); try { textureColor = new Color(assetDictionary.LookupVector4(themeName, "textureColor")); } catch { try { textureColor = new Color(assetDictionary.LookupVector3(themeName, "textureColor")); } catch { textureColor = Color.White; } } }