public override void Draw(GameTime gameTime, VariableBundle gameState, SpriteBatch spriteBatch) { spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, Window.rasterizerState, null, this.mxTWindowToScreen); spriteBatch.DrawString(_spriteFont, _text, new Vector2(this.center.X - (_v2TextSize.X / 2), textTopBuffer), Color.Black); spriteBatch.End(); //_buttonOK.background = this.background; _buttonOK.decorations = this.decorations; _buttonOK.Draw(gameTime, gameState, spriteBatch, this.baseGame, this.mxTWindowToScreen); }
public Frame getCurrentFrame(GameTime gameTime, VariableBundle gameState) { if ((this.animations == null) || (this.animations.Count <= 0)) return null; // Get the appropriate animation based on the conditions. // TODO: Consider a scoring system, one with most matches wins? foreach (Animation animation in this.animations) { if (!animation.isValid(gameState)) continue; return animation.getCurrentFrame(gameTime); } // Have to return something... // TODO: Consider just returning null? return this.animations[0].getCurrentFrame(gameTime); }
public void Draw(GameTime gameTime, VariableBundle gameState, SpriteBatch spriteBatch, Rectangle destinationRectangle, Color color, float rotation, Vector2 origin, float layerDepth) { // NOTE: origin is in SOURCE (frame) coordinates! Frame frame = getCurrentFrame(gameTime, gameState); spriteBatch.DrawEx(this.texture, destinationRectangle, frame.bounds, color, rotation, origin, SpriteEffects.None, layerDepth); }
public void Draw(GameTime gameTime, VariableBundle gameState, SpriteBatch spriteBatch, Point destinationPoint) { Frame frame = getCurrentFrame(gameTime, gameState); spriteBatch.DrawEx(this.texture, new Rectangle(destinationPoint.X, destinationPoint.Y, frame.bounds.Width, frame.bounds.Height), frame.bounds, Color.White); }
public void Draw(GameTime gameTime, VariableBundle gameState, SpriteBatch spriteBatch, Rectangle destinationRectangle, Color color) { Frame frame = getCurrentFrame(gameTime, gameState); spriteBatch.DrawEx(this.texture, destinationRectangle, frame.bounds, color); }
public void Draw(GameTime gameTime, VariableBundle gameState, SpriteBatch spriteBatch, Rectangle destinationRectangle) { Draw(gameTime, gameState, spriteBatch, destinationRectangle, Color.White); }
// TODO: Consider moving this somewhere (Condition?) and we need to implement some sort of "scoring" system -- // so that two conditions matching is better than just one (note in either case, a non-match is a non-starter), // and even maybe some operations "mean" more than others. // For example, if you have one Animation with a condition of A=0 and another with A=0 and B=0 then gameState // with both A and B=0 should pick the second, not the first, animation, since it is a more exact match. // Also, a condition with A=5 and another with 2<A<6 should favor the second if A=5 in the gameState. public bool isValid(VariableBundle gameState) { if ((_conditions == null) || (_conditions.Count <= 0)) return true; // AND if (Animation._conditionAND) { foreach (Condition condition in _conditions) { if (condition.isValid(gameState)) continue; return false; } return true; } // OR foreach (Condition condition in _conditions) { if (!condition.isValid(gameState)) continue; return true; } return false; }
private void drawArrow(SpriteBatch spriteBatch, GameTime gameTime, VariableBundle gameState, int offset, int arrowY, int arrowLeftX, int arrowRightX, int middleLeftTraderX, int middleRightTraderX, int middleBufferX, int itemWidth, string tradeItem) { // Set the correct arrow direction based on whether the trade item is being given away or received. Arrow arrow = _arrowLtR; VariableBundle trader = this.leftTrader; if (offset < 0) { arrow = _arrowRtL; trader = this.rightTrader; } // Load the current frame for the arrow parts. Frame fTail = arrow.gTail.getCurrentFrame(gameTime, gameState); Frame fBody = arrow.gBody.getCurrentFrame(gameTime, gameState); Frame fHead = arrow.gHead.getCurrentFrame(gameTime, gameState); // Determine the available width of the arrow -- this is the space between the head and tail, i.e. the body. // This width will scale with the amount of the item being traded (relative to the total amount available to trade). int arrowAvailableWidth = ((middleLeftTraderX - middleBufferX) - arrowLeftX) - fTail.bounds.Width - fHead.bounds.Width; _arrowAvailableL = new Rectangle(arrowLeftX + fTail.bounds.Width, 0, arrowAvailableWidth, 0); _arrowAvailableR = new Rectangle(middleRightTraderX + itemWidth + middleBufferX + fHead.bounds.Width, 0, arrowAvailableWidth, 0); if (offset == 0) return; // Get the current sum of the good. This will be the original value supplied to the dialog, as it // isn't adjusted in place until a successful trade -- offset stores the changes in the meantime so Cancel // can just undo everything "for free". int sum = trader.getValue<int>(tradeItem); if (tradeItem == "food") sum = IntoTheNewWorld.Instance.totalFoodToWeeks(sum, leftTrader.getValue<int>("men")); // Determine the actual width of the body. int arrowWidth = (int)(((float)Math.Abs(offset) / (float)sum) * (float)arrowAvailableWidth); int tailX = arrowLeftX; int bodyX = arrowLeftX + fTail.bounds.Width; int headX = arrowLeftX + fTail.bounds.Width + arrowWidth; if (offset < 0) { tailX = arrowRightX - fTail.bounds.Width; bodyX = arrowRightX - fTail.bounds.Width - arrowWidth; headX = arrowRightX - fTail.bounds.Width - arrowWidth - fHead.bounds.Width; } // Draw tail, body and head. arrow.gTail.Draw(fTail, spriteBatch, new Point(tailX, arrowY)); arrow.gBody.Draw(fBody, spriteBatch, new Rectangle(bodyX, arrowY, arrowWidth, fBody.bounds.Height)); arrow.gHead.Draw(fHead, spriteBatch, new Point(headX, arrowY)); }
public TradeWindow(Vector2 v2Center, int width, VariableBundle leftTrader, VariableBundle rightTrader, TradingPartner partner, int unlocks, string leftTraderString, string rightTraderString) : base(v2Center, IntoTheNewWorld.Instance) { this.bounds = new Rectangle(this.bounds.X, this.bounds.Y, width, this.bounds.Height); this.leftTrader = leftTrader; this.rightTrader = rightTrader; _partner = partner; _unlocks = unlocks; _leftTraderString = leftTraderString; _rightTraderString = rightTraderString; _dictValueByTradeItem = getAcceptedTradeItems(); List<string> leftTradeItems = this.leftTrader.variables.Where(variable => (this.leftTrader.getValue<int>(variable) > 0) && _dictValueByTradeItem.ContainsKey(variable)).ToList(); List<string> rightTradeItems = this.rightTrader.variables.Where(variable => (this.rightTrader.getValue<int>(variable) > 0) && _dictValueByTradeItem.ContainsKey(variable)).ToList(); // The list of items that can be traded is the union of the two traders' pile of items to trade. //_tradeItems = this.leftTrader.variables.Union(this.rightTrader.variables).Distinct().ToList(); _tradeItems = leftTradeItems.Union(rightTradeItems).Distinct().ToList(); _dictIndexByTradeItem = new Dictionary<string, int>(); for (int i = 0; i < _tradeItems.Count; i++) _dictIndexByTradeItem.Add(_tradeItems[i], i); _offsets = new List<int>(_tradeItems.Count); _tradeItems.ForEach(ti => _offsets.Add(0)); _values = new List<int>(_tradeItems.Count); _tradeItems.ForEach(ti => _values.Add(1)); for (int i = 0; i < _tradeItems.Count; i++) _values[i] = _dictValueByTradeItem[_tradeItems[i]]; //_sums = new List<int>(_tradeItems.Count); //foreach (string tradeItem in _tradeItems) //{ // int sum = 0; // int val; // if (leftTrader.getValue(tradeItem, out val)) // sum += val; // if (rightTrader.getValue(tradeItem, out val)) // sum += val; // _sums.Add(sum); //} //_tradeItemHotspots = new List<Rectangle>(_tradeItems.Count); //_tradeItems.ForEach(ti => _tradeItemHotspots.Add(new Rectangle(0, 0, 0, 0))); Graphic gArrowLtRTail = IntoTheNewWorld.Instance.dictGraphics["trade_ltr_arrow_tail"]; Graphic gArrowLtRBody = IntoTheNewWorld.Instance.dictGraphics["trade_ltr_arrow_body"]; Graphic gArrowLtRHead = IntoTheNewWorld.Instance.dictGraphics["trade_ltr_arrow_head"]; _arrowLtR = new Arrow(gArrowLtRTail, gArrowLtRBody, gArrowLtRHead); Graphic gArrowRtLTail = IntoTheNewWorld.Instance.dictGraphics["trade_rtl_arrow_tail"]; Graphic gArrowRtLBody = IntoTheNewWorld.Instance.dictGraphics["trade_rtl_arrow_body"]; Graphic gArrowRtLHead = IntoTheNewWorld.Instance.dictGraphics["trade_rtl_arrow_head"]; _arrowRtL = new Arrow(gArrowRtLTail, gArrowRtLBody, gArrowRtLHead); _lockedLeft = new List<LockedState>(_tradeItems.Count); _tradeItems.ForEach(ti => _lockedLeft.Add(LockedState.None)); _lockedRight = new List<LockedState>(_tradeItems.Count); _tradeItems.ForEach(ti => _lockedRight.Add(LockedState.None)); _desired = new List<bool>(_tradeItems.Count); _tradeItems.ForEach(ti => _desired.Add(false)); _undesired = new List<bool>(_tradeItems.Count); _tradeItems.ForEach(ti => _undesired.Add(false)); if (isAIPartner()) initializeAIState(); initializeButtons(); initializeHotspots(); _textHeight = (int)_font.MeasureString("1").Y; int height = _itemsTop + _tradeItems.Count * (gArrowLtRBody.defaultBounds.Height + _itemsYBuffer + _textHeight) + _itemsBottom + _buttonOK.bounds.Height + this.buttonBottomBuffer; this.bounds = new Rectangle(this.bounds.X, this.bounds.Y, this.bounds.Width, height); }
public override void Draw(GameTime gameTime, VariableBundle gameState, SpriteBatch spriteBatch) { _buttonOK.decorations = this.decorations; _buttonCancel.decorations = this.decorations; if (_buttonTakeAll != null) _buttonTakeAll.decorations = this.decorations; Color textColor = Color.Black; Graphic gPixel = IntoTheNewWorld.Instance.dictGraphics["trade_onepixel"]; Frame fPixel = gPixel.getCurrentFrame(gameTime, gameState); Graphic gLocked = IntoTheNewWorld.Instance.dictGraphics["trade_locked"]; Frame fLocked = gLocked.getCurrentFrame(gameTime, gameState); Graphic gUnlocked = IntoTheNewWorld.Instance.dictGraphics["trade_unlocked"]; Frame fUnlocked = gUnlocked.getCurrentFrame(gameTime, gameState); Graphic gDesired = IntoTheNewWorld.Instance.dictGraphics["trade_desired"]; Frame fDesired = gDesired.getCurrentFrame(gameTime, gameState); Graphic gUpGreen = IntoTheNewWorld.Instance.dictGraphics["trade_upgreen"]; Frame fUpGreen = gUpGreen.getCurrentFrame(gameTime, gameState); Graphic gDownRed = IntoTheNewWorld.Instance.dictGraphics["trade_downred"]; Frame fDownRed = gDownRed.getCurrentFrame(gameTime, gameState); // TODO: Just let Window handle this? Or have it everywhere? spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, Window.rasterizerState, null, this.mxTWindowToScreen); Graphic g; // Draw the background if it wasn't already provided to the Window. if (this.background == null) { g = IntoTheNewWorld.Instance.dictGraphics["trade_background"]; //spriteBatch.Draw(IntoTheNewWorld.Instance.getTexture(g), new Rectangle(0, 0, this.bounds.Width, this.bounds.Height), g.getCurrentFrame(gameTime, gameState).bounds, Color.White); gPixel.Draw(fPixel, spriteBatch, new Rectangle(0, 0, this.bounds.Width, this.bounds.Height), Color.Tan); } // TODO: Combine items and arrows drawing, cache Graphics, etc. // Draw items... int itemsXBuffer = 20; int leftTraderX = itemsXBuffer + (isAIPartner() ? fUpGreen.bounds.Width : 0); int rightTraderX = -1; int middleLeftTraderX = -1; int middleRightTraderX = -1; int itemsMaxWidth = 0; int middleTraderX = -1; int currentY = _itemsTop; for (int i = 0; i < _tradeItems.Count; i++) { string tradeItem = _tradeItems[i]; g = IntoTheNewWorld.Instance.dictGraphics["trade_" + tradeItem]; Frame f = g.getCurrentFrame(gameTime, gameState); itemsMaxWidth = Math.Max(itemsMaxWidth, f.bounds.Width); rightTraderX = this.bounds.Width - itemsXBuffer - f.bounds.Width; middleLeftTraderX = (int)this.center.X - (f.bounds.Width) - itemsXBuffer; middleRightTraderX = (int)this.center.X + itemsXBuffer; if (_offsets[i] > 0) middleTraderX = middleLeftTraderX; else middleTraderX = middleRightTraderX; // Draw the hover background. _tradeItemHotspots[i].bounds = new Rectangle(leftTraderX, currentY, (rightTraderX + f.bounds.Width) - leftTraderX, f.bounds.Height); if (this.pointerOverHotspot == _tradeItemHotspots[i]) gPixel.Draw(fPixel, spriteBatch, this.pointerOverHotspot.bounds, Color.Beige); // Draw the desired green up arrow. if (_desired[i]) gUpGreen.Draw(fUpGreen, spriteBatch, new Point(leftTraderX - fUpGreen.bounds.Width, currentY + ((f.bounds.Height - fUpGreen.bounds.Height) / 2))); else if (_undesired[i]) gDownRed.Draw(fDownRed, spriteBatch, new Point(leftTraderX - fDownRed.bounds.Width, currentY + ((f.bounds.Height - fDownRed.bounds.Height) / 2))); // Draw left. g.Draw(f, spriteBatch, new Point(leftTraderX, currentY)); if (isAIPartnerActive()) { if (_lockedLeft[i] == LockedState.Locked) gLocked.Draw(fLocked, spriteBatch, new Point(leftTraderX, currentY)); else if (_lockedLeft[i] == LockedState.Unlocked) gUnlocked.Draw(fUnlocked, spriteBatch, new Point(leftTraderX, currentY)); if (_desired[i]) gDesired.Draw(fDesired, spriteBatch, new Point(leftTraderX + f.bounds.Width - fDesired.bounds.Width, currentY)); } // Draw right. g.Draw(f, spriteBatch, new Point(rightTraderX, currentY)); if (isAIPartnerActive()) { if (_lockedRight[i] == LockedState.Locked) gLocked.Draw(fLocked, spriteBatch, new Point(rightTraderX, currentY)); else if (_lockedRight[i] == LockedState.Unlocked) gUnlocked.Draw(fUnlocked, spriteBatch, new Point(rightTraderX, currentY)); } // Draw middle. if (_offsets[i] != 0) g.Draw(f, spriteBatch, new Point(middleTraderX, currentY)); int textY = currentY + f.bounds.Height; int leftMen = leftTrader.getValue<int>("men"); bool food = (tradeItem == "food"); int sum = leftTrader.getValue<int>(tradeItem); int adjustedValue = (sum - _offsets[i]); string svalue = "" + sum + ((adjustedValue != sum) ? (" (" + adjustedValue + ")") : ""); if (food) { sum = IntoTheNewWorld.Instance.totalFoodToWeeks(sum, leftMen); adjustedValue = IntoTheNewWorld.Instance.totalFoodToWeeks(adjustedValue, leftMen); svalue = "" + sum + "w" + ((adjustedValue != sum) ? (" (" + adjustedValue + "w)") : ""); } spriteBatch.DrawString(_font, svalue, new Vector2(leftTraderX, textY), textColor); sum = rightTrader.getValue<int>(tradeItem); adjustedValue = (sum + _offsets[i]); svalue = ((adjustedValue != sum) ? ("(" + adjustedValue + ") ") : "") + sum; if (food) { sum = IntoTheNewWorld.Instance.totalFoodToWeeks(sum, leftMen); adjustedValue = IntoTheNewWorld.Instance.totalFoodToWeeks(adjustedValue, leftMen); svalue = ((adjustedValue != sum) ? ("(" + adjustedValue + "w) ") : "") + sum + "w"; } Vector2 v2svalueDims = _font.MeasureString(svalue); spriteBatch.DrawString(_font, svalue, new Vector2(rightTraderX + f.bounds.Width - v2svalueDims.X, textY), textColor); int offset = _offsets[i]; if (_offsets[i] != 0) { offset = Math.Abs(offset); svalue = ("" + offset); if (food) { offset = IntoTheNewWorld.Instance.totalFoodToWeeks(offset, leftMen); svalue = (offset + "w"); } //int textWidth = (int)_font.MeasureString("" + Math.Abs(_offsets[i])).X; //spriteBatch.DrawString(_font, "" + Math.Abs(_offsets[i]), new Vector2((middleTraderX + (f.bounds.Width / 2)) - (textWidth / 2), textY), textColor); int textWidth = (int)_font.MeasureString(svalue).X; spriteBatch.DrawString(_font, svalue, new Vector2((middleTraderX + (f.bounds.Width / 2)) - (textWidth / 2), textY), textColor); } currentY += f.bounds.Height + _itemsYBuffer + _textHeight; } _leftItem = new Rectangle(leftTraderX, 0, itemsMaxWidth, 0); _rightItem = new Rectangle(rightTraderX, 0, itemsMaxWidth, 0); _middleLeftItem = new Rectangle(middleLeftTraderX, 0, itemsMaxWidth, 0); _middleRightItem = new Rectangle(middleRightTraderX, 0, itemsMaxWidth, 0); // Draw arrows... int arrowXBuffer = 10; int arrowY; int arrowHeight = _arrowLtR.gBody.getCurrentFrame(gameTime, gameState).bounds.Height; currentY = _itemsTop; for (int i = 0; i < _offsets.Count; i++) { //int arrowLeftX = itemsXBuffer + itemsMaxWidth + arrowXBuffer; int arrowLeftX = leftTraderX + itemsMaxWidth + arrowXBuffer; int arrowRightX = this.bounds.Width - itemsXBuffer - itemsMaxWidth - arrowXBuffer; string tradeItem = _tradeItems[i]; int offset = _offsets[i]; if (tradeItem == "food") offset = IntoTheNewWorld.Instance.totalFoodToWeeks(offset, leftTrader.getValue<int>("men")); g = IntoTheNewWorld.Instance.dictGraphics["trade_" + tradeItem]; Frame f = g.getCurrentFrame(gameTime, gameState); arrowY = currentY + ((f.bounds.Height - arrowHeight) / 2); //drawArrow(spriteBatch, gameTime, gameState, offset, arrowY, arrowLeftX, arrowRightX, middleLeftTraderX, middleRightTraderX, (f.bounds.Width / 2) + arrowXBuffer, tradeItem); drawArrow(spriteBatch, gameTime, gameState, offset, arrowY, arrowLeftX, arrowRightX, middleLeftTraderX, middleRightTraderX, arrowXBuffer, itemsMaxWidth, tradeItem); currentY += f.bounds.Height + _itemsYBuffer + _textHeight; } if (isAIPartner()) { //spriteBatch.DrawString(_font, _tradeAdviceMessage + " (" + _receiveToOfferRatio + ")", new Vector2(itemsXBuffer, currentY), textColor); spriteBatch.DrawString(_font, _tradeAdviceMessage, new Vector2(itemsXBuffer, currentY), textColor); } // Draw traders... spriteBatch.DrawString(_font, _leftTraderString, new Vector2(itemsXBuffer, _itemsYBuffer), textColor); Vector2 textSize = _font.MeasureString(_rightTraderString); spriteBatch.DrawString(_font, _rightTraderString, new Vector2(this.bounds.Width - itemsXBuffer - (int)textSize.X, _itemsYBuffer), textColor); // Draw offer / receive... if (_offsets.Any(offset => offset != 0)) { string leftText = "offer"; string rightText = "receive"; if (_partner == TradingPartner.Cache) { leftText = "store"; rightText = "retrieve"; } else if (_partner == TradingPartner.Loot) { leftText = "drop"; rightText = "take"; } spriteBatch.DrawString(_font, leftText, new Vector2(middleLeftTraderX, _itemsYBuffer), Color.Red); spriteBatch.DrawString(_font, rightText, new Vector2(middleRightTraderX, _itemsYBuffer), Color.Green); } //// Draw Deal / NO Deal. //if (_partnerAcceptsTrade) //{ // textSize = _font.MeasureString("Deal"); // spriteBatch.DrawString(_font, "Deal", new Vector2((int)this.center.X - ((int)textSize.X / 2), this.bounds.Height - 25), Color.Green); //} //else //{ // textSize = _font.MeasureString("NO Deal"); // spriteBatch.DrawString(_font, "NO deal", new Vector2((int)this.center.X - ((int)textSize.X / 2), this.bounds.Height - 25), Color.Red); //} //spriteBatch.Draw(IntoTheNewWorld.Instance.getTexture(gPixel), new Rectangle(_arrowAvailableL.X, 0, _arrowAvailableL.Width, 200), fPixel.bounds, Color.Red); //spriteBatch.Draw(IntoTheNewWorld.Instance.getTexture(gPixel), new Rectangle(_arrowAvailableR.X, 0, _arrowAvailableR.Width, 200), fPixel.bounds, Color.Green); spriteBatch.End(); // Draw OK / Cancel _buttonOK.bounds = new Rectangle(this.leftBuffer, this.bounds.Height - this.buttonBottomBuffer - _buttonOK.bounds.Height, _buttonOK.bounds.Width, _buttonOK.bounds.Height); //_buttonOK.Draw(gameTime, gameState, spriteBatch, IntoTheNewWorld.Instance, this.mxTWindowToScreen); _buttonCancel.bounds = new Rectangle(this.bounds.Width - this.rightBuffer - _buttonCancel.bounds.Width, this.bounds.Height - this.buttonBottomBuffer - _buttonCancel.bounds.Height, _buttonCancel.bounds.Width, _buttonCancel.bounds.Height); //_buttonCancel.Draw(gameTime, gameState, spriteBatch, IntoTheNewWorld.Instance, this.mxTWindowToScreen); // Draw Take All if (_buttonTakeAll != null) _buttonTakeAll.bounds = new Rectangle((this.bounds.Width / 2) - (_buttonTakeAll.bounds.Width / 2), this.bounds.Height - this.buttonBottomBuffer - _buttonTakeAll.bounds.Height, _buttonTakeAll.bounds.Width, _buttonTakeAll.bounds.Height); }