/// <summary> /// Creates an EventLogIWindowItem to give to EventLogWindow in UI consisiting of a button and a message /// </summary> /// <param name="eventType">the event's type</param> /// <param name="message">message for the user</param> /// <param name="width">width to fit the text to</param> /// <param name="spriteFont">textfont</param> /// <param name="director">basic director</param> /// <param name="onThis">the object where the event is happening</param> public EventLogIWindowItem(ELogEventType eventType, string message, float width, SpriteFont spriteFont, Director director, ISpatial onThis) { mShiftValue = spriteFont.MeasureString("// ").X; mText = new TextField(message, Vector2.Zero, new Vector2(width - mShiftValue, 0), spriteFont, Color.White); mInfoBox = new InfoBoxWindow(new List <IWindowItem> { new TextField("To event", Vector2.Zero, spriteFont.MeasureString("To event"), spriteFont, Color.White) }, spriteFont.MeasureString("To event"), Color.White, Color.Black, true, director); // button to jump to object that created the event mPositionButton = new Button("// " + eventType, spriteFont, Vector2.Zero, false, new SpatialPositionEventArgs(onThis)) { Opacity = 1f }; mPositionButton.ButtonHovering += ShowInfoBox; mPositionButton.ButtonHoveringEnd += HideInfoBox; mPositionButton.ButtonClicked += JumpToPosition; Size = new Vector2(width, mPositionButton.Size.Y + mText.Size.Y); Position = Vector2.Zero; mDirector = director; ActiveInWindow = true; }
/// <summary> /// Creates a PlatformAction IWindowItem which represents a platformaction with it's name, state and a button to (de)activate it. /// </summary> /// <param name="platformAction">the platformaction to be represented</param> /// <param name="spriteFont">spritefont for text</param> /// <param name="position">position of the IWindowItem (Vector.Zero if added to window)</param> /// <param name="size">size to fit the item in (width is important)</param> /// <param name="director">director</param> /// <param name="refineRes">the action is of type refineRes</param> public PlatformActionIWindowItem(IPlatformAction platformAction, SpriteFont spriteFont, Vector2 position, Vector2 size, Director director, bool refineRes = false) { Size = new Vector2(size.X, spriteFont.MeasureString("A").Y * 2 + 5); Position = position; mPlatformAction = platformAction; ActiveInWindow = true; // infobox items list var infoBoxItemsList = new List <IWindowItem>(); // get action description var name = platformAction.ToString().Split('.')[2]; if (refineRes) { // since the action is of type refine resource name = "refining to " + ((RefineResourceAction)platformAction).GetRefiningTo(); } // the platformAction's name mNameTextField = new TextField( text: name, position: Vector2.Zero, size: new Vector2(spriteFont.MeasureString(name).X, 0), // the size of the textfield should be as big as the string it contains spriteFont: spriteFont, color: Color.White); // the platformAction's current state ((de)active) var stateTextField = new TextField( text: platformAction.State.ToString(), position: Vector2.Zero, size: new Vector2(spriteFont.MeasureString(platformAction.State.ToString()).X, 0), // the size of the textfield should be as big as the string it contains spriteFont: spriteFont, color: Color.White); if (mPlatformAction is MakeFastMilitaryUnit || mPlatformAction is MakeHeavyMilitaryUnit || mPlatformAction is MakeStandardMilitaryUnit || mPlatformAction is MakeGeneralUnit || mPlatformAction is MakeSettlerUnit) { // don't use the standard text for the button since the action is different (just creat button - will toggle back when created) mStateToggleButton = new Button("create", spriteFont, Vector2.Zero) { Opacity = 1f }; } else { // button that (de)activates the platformAction mStateToggleButton = new Button("(de)activate", spriteFont, Vector2.Zero) { Opacity = 1f }; } // a textfiel that is just added to shift the button in the horizontal collection var emptyToShift = new TextField( text: "", position: Vector2.Zero, size: new Vector2(spriteFont.MeasureString(platformAction.State.ToString()).X, 0), // the size of the textfield should be as big as the string it contains spriteFont: spriteFont, color: Color.White); // button management mStateToggleButton.ButtonClicked += ActivateToggle; mStateToggleButton.ButtonReleased += ToggleButton; mStateToggleButton.ButtonHovering += ShowRequirements; mStateToggleButton.ButtonHoveringEnd += HideRequirements; // create a horizontal collection of the state and the button mCollection = new HorizontalCollection(new List <IWindowItem> { stateTextField, mStateToggleButton, emptyToShift }, new Vector2(size.X, spriteFont.MeasureString("A").Y + 5), Position); //mBottomBar = new BarIWindowItem(size.X - 50, Color.White); #region manage the requirements // set up var productionUnits = 0; var constructionUnits = 0; var logisticUnits = 0; var defenseUnits = 0; // count the required units foreach (var units in platformAction.UnitsRequired) { switch (units) { case JobType.Production: productionUnits += 1; break; case JobType.Construction: constructionUnits += 1; break; case JobType.Logistics: logisticUnits += 1; break; case JobType.Defense: defenseUnits += 1; break; } } // add a unit type + required count to infoBox if it's needed to enable the platformAction, disable it else if (productionUnits > 0) { infoBoxItemsList.Add(new TextField(productionUnits + " production units", Vector2.Zero, spriteFont.MeasureString(productionUnits + " prouduction units"), spriteFont, Color.White)); } if (constructionUnits > 0) { infoBoxItemsList.Add(new TextField(constructionUnits + " construction units", Vector2.Zero, spriteFont.MeasureString(constructionUnits + " construction units"), spriteFont, Color.White)); } if (logisticUnits > 0) { infoBoxItemsList.Add(new TextField(logisticUnits + " logistics units", Vector2.Zero, spriteFont.MeasureString(logisticUnits + " logistics units"), spriteFont, Color.White)); } if (defenseUnits > 0) { infoBoxItemsList.Add(new TextField(defenseUnits + " defense units", Vector2.Zero, spriteFont.MeasureString(defenseUnits + " defense units"), spriteFont, Color.White)); } // add required resources infoBox if (mPlatformAction is AMakeUnit) { infoBoxItemsList.AddRange(((AMakeUnit)platformAction).GetBuildingCost().Select(resource => new ResourceIWindowItem(resource.Key, resource.Value, Vector2.Zero, spriteFont))); } // create a infoBox containing all requirements to activate the platformAction mInfoBoxRequirements = new InfoBoxWindow(infoBoxItemsList, Vector2.Zero, Color.White, Color.Black, true, director); #endregion }