public override void Update(GameTime gameTime, GameState state) { foreach (Component c in _components) { c.Update(gameTime, state); } var list = SelectionCells_BldgHouses_Btns; switch (SelectionCells_ViewIndex) { case 801: list = SelectionCells_BldgReso_Btns; break; case 802: list = SelectionCells_BldgDeco_Btns; break; default: list = SelectionCells_BldgHouses_Btns; break; } foreach (var e in list) { e.Update(gameTime, state); } DeleteBuildingBtn.Update(gameTime, state); // save gamestate State = state; }
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) { _currentMouse = Mouse.GetState(); var mouseRectangle = new Rectangle(_currentMouse.X, _currentMouse.Y, 1, 1); var show_spec_resource_toolip = false; var show_spec_resource_tooltip_id = 0; spriteBatch.Draw(_texture, DisplayRect, Color.DarkKhaki); spriteBatch.Draw(_texture, BorderRect, Color.Black); spriteBatch.Draw(SelectionCellsSection_Texture, SelectionCellsSection_Rectangle, Color.DarkKhaki); spriteBatch.Draw(InfographicsSection_Texture, InfographicsSection_Rectangle, Color.DarkOliveGreen); spriteBatch.Draw(DisplayInfo_Texture, DisplayInfo_Rectangle, Color.White); spriteBatch.Draw(ResourceBar_Texture, ResourceBar_Rectangle, Color.White); /** * DRAW RESOURCE AND STATE DATA TO HUD **/ if (State is null) { return; } #region DRAW RESOURCES string game_day = $"Day: {State.GSData.Day}"; var game_day_origin = new Vector2(0, _font.MeasureString(game_day).Y / 2); var game_day_position = _position + new Vector2(5, 15); spriteBatch.DrawString(_font, game_day, game_day_position, Color.Black, 0.0f, game_day_origin, 1.5f, SpriteEffects.None, 1.0f); string game_year = $"Year: {State.GSData.Year}"; var game_year_origin = new Vector2(0, _font.MeasureString(game_year).Y / 2); var game_year_position = game_day_position + new Vector2(0, _font.MeasureString(game_day).Y + 5); spriteBatch.DrawString(_font, game_year, game_year_position, Color.Black, 0.0f, game_year_origin, 1.5f, SpriteEffects.None, 1.0f); string version = "ALPHA VER 0.0"; var version_origin = new Vector2(0, _font.MeasureString(version).Y / 2); var version_position = new Vector2(game_year_position.X, (DisplayRect.Y + DisplayRect.Height) - (_font.MeasureString(version).Y * 0.75f)); spriteBatch.DrawString(_font, version, version_position, Color.Black, 0.0f, version_origin, 0.75f, SpriteEffects.None, 1.0f); var resource_vals = new int[] { State.GSData.PlayerInventory.Gold, State.GSData.PlayerInventory.Wood, State.GSData.PlayerInventory.Coal, State.GSData.PlayerInventory.Iron, State.GSData.PlayerInventory.Stone, State.GSData.PlayerInventory.Food, State.GSData.PlayerInventory.Energy, State.GSData.PlayerInventory.Workers }; var resource_string_vals = new string[] { "Gold", "Wood", "Coal", "Iron", "Stone", "Food", "Energy", "Workers" }; var icon_start_pos = new Vector2(ResourceBar_Rectangle.X, ResourceBar_Rectangle.Y); var icon_scale = new Vector2(2, 2); // display inventory icons in hud for (int i = 0; i < HUDIconIDs.Length; i++) { var icon_id = HUDIconIDs[i]; var icon_texture = _content.GetUiTexture(icon_id); var icon_position = icon_start_pos + new Vector2(ResourceCell_Dimension.X * i, 0); icon_position += new Vector2(ResourceCell_Dimension.X * 0.4f, ResourceCell_Dimension.Y * 0.5f); var icon_rect = new Rectangle((int)icon_position.X, (int)icon_position.Y, (int)(ResourceCell_Dimension .X * 0.4f), (int) (ResourceCell_Dimension.Y * 0.4f)); spriteBatch.Draw(icon_texture, icon_rect, Color.White); if (icon_rect.Contains(_currentMouse.Position)) { show_spec_resource_toolip = true; show_spec_resource_tooltip_id = i; } var resource_text = $"{resource_vals[i]}"; var resource_text_origin = new Vector2(_font.MeasureString(resource_text).X / 2, _font.MeasureString(resource_text).Y / 2); var resource_text_pos = icon_position + new Vector2(icon_rect.Width * 0.5f, -(icon_rect.Height * 0.6f)); spriteBatch.DrawString(_font, resource_text, resource_text_pos, Color.Black, 0.0f, resource_text_origin, 1.0f, SpriteEffects.None, 1.0f); } #endregion #region DRAW DIPLAY INFO SECTION if (State.CurrentlySelectedTile != null && BuildingData.ValidBuilding(State.CurrentlySelectedTile.Object)) { var obj = State.CurrentlySelectedTile.Object; var bldg = BuildingData.Dict_BuildingFromObjectID[obj.ObjectId]; // display bldg name var name_x = _font.MeasureString(bldg.Name).X; var name_y = _font.MeasureString(bldg.Name).Y; var name_o = new Vector2(0, name_y / 2); var name_pos = new Vector2(DisplayInfo_Rectangle.X + (DisplayInfo_Rectangle.Width * 0.05f), DisplayInfo_Rectangle.Y + (DisplayInfo_Rectangle.Height * 0.05f) + name_y); spriteBatch.DrawString(_font, bldg.Name, name_pos, Color.Black, 0.0f, name_o, 1.0f, SpriteEffects.None, 1.0f); // display bldg icon var dist = (DisplayInfo_Rectangle.Y + (DisplayInfo_Rectangle.Height * 0.8f)) - name_pos.Y; var offset = (dist * 0.5) / 2; var size = dist - (dist * 0.1); var bldg_txt_pos = new Vector2((int)DisplayInfo_Rectangle.X + (int)offset, (int)name_pos.Y + (int)offset); var bldg_txt_rect = new Rectangle((int)bldg_txt_pos.X, (int)bldg_txt_pos.Y, (int)size, (int)size); var bldg_txt = _content.GetTileTexture(bldg.TextureIndex); var src_rect = new Rectangle(0, (int)(bldg_txt.Height - (bldg_txt.Height * 0.3f)), (int)bldg_txt.Width, (int)(bldg_txt.Height * 0.3f)); spriteBatch.Draw(_content.GetTileTexture(State.CurrentlySelectedTile.Object.TextureIndex), destinationRectangle: bldg_txt_rect, sourceRectangle: src_rect, color: Color.White); DeleteBuildingBtn.Draw(gameTime, spriteBatch); } else { string nothing = "No building is selected :("; var str_pos = new Vector2(DisplayInfo_Rectangle.X + (DisplayInfo_Rectangle.Width / 2), DisplayInfo_Rectangle.Y + (DisplayInfo_Rectangle.Height / 2)); var str_x = _font.MeasureString(nothing).X; var str_y = _font.MeasureString(nothing).Y; var str_o = new Vector2(str_x / 2, str_y / 2); spriteBatch.DrawString(_font, nothing, str_pos, Color.Black, 0.0f, str_o, 1.0f, SpriteEffects.None, 1.0f); } #endregion var show_tooltip = false; Button ref_b = null; ShowBldgBtnTooltip = false; ShowBldgBtnId = 0; foreach (Component c in _components) { c.Draw(gameTime, spriteBatch); if (c is Button b) { if (b.IsHovering) { if (b.ID.Equals(800) || b.ID.Equals(801) || b.ID.Equals(802)) { ShowBldgBtnTooltip = true; ShowBldgBtnId = b.ID; } } } } // switch building page view var list = SelectionCells_BldgHouses_Btns; switch (SelectionCells_ViewIndex) { case 801: list = SelectionCells_BldgReso_Btns; break; case 802: list = SelectionCells_BldgDeco_Btns; break; default: list = SelectionCells_BldgHouses_Btns; break; } // foreach button in building page view foreach (var e in list) { e.Draw(gameTime, spriteBatch); if (e is Button b) { if (b.IsHovering) { if (b.ResourceLocked) { if (BuildingData.Dict_BuildingKeys.ContainsKey(b.ID)) { show_tooltip = true; ref_b = b; } } } } } if (show_tooltip) { var b = ref_b; var bld = BuildingData.Dict_BuildingKeys[b.ID]; var cost_vals = new Dictionary <int, int>() { { 0, bld.GoldUpfront }, { 1, bld.WoodUpfront }, { 2, bld.CoalUpfront }, { 3, bld.IronUpfront }, { 4, bld.StoneUpfront }, { 5, bld.WorkersUpfront }, { 6, bld.EnergyUpfront }, { 7, bld.FoodUpfront } }; var per_turn_cost_vals = new Dictionary <int, int>() { { 0, bld.GoldCost }, { 1, bld.WoodCost }, { 2, bld.CoalCost }, { 3, bld.IronCost }, { 4, bld.StoneCost }, { 5, bld.WorkersCost }, { 6, bld.EnergyCost }, { 7, bld.FoodCost } }; var per_turn_gain_vals = new Dictionary <int, int>() { { 0, bld.GoldOutput }, { 1, bld.WoodOutput }, { 2, bld.CoalOutput }, { 3, bld.IronOutput }, { 4, bld.StoneOutput }, { 5, bld.WorkersOutput }, { 6, bld.EnergyOutput }, { 7, bld.FoodOutput } }; var str_vals = new Dictionary <int, string>() { { 0, "gold" }, { 1, "wood" }, { 2, "coal" }, { 3, "iron" }, { 4, "stone" }, { 5, "workers" }, { 6, "energy" }, { 7, "food" } }; var bool_vals = new Dictionary <int, bool>() { { 0, false }, { 1, false }, { 2, false }, { 3, false }, { 4, false }, { 5, false }, { 6, false }, { 7, false } }; foreach (var d in cost_vals) { switch (str_vals[d.Key]) { case "gold": bool_vals[d.Key] = State.GSData.PlayerInventory.Gold >= d.Value; break; case "wood": bool_vals[d.Key] = State.GSData.PlayerInventory.Wood >= d.Value; break; case "coal": bool_vals[d.Key] = State.GSData.PlayerInventory.Coal >= d.Value; break; case "iron": bool_vals[d.Key] = State.GSData.PlayerInventory.Iron >= d.Value; break; case "stone": bool_vals[d.Key] = State.GSData.PlayerInventory.Stone >= d.Value; break; case "workers": bool_vals[d.Key] = State.GSData.PlayerInventory.Workers >= d.Value; break; case "energy": bool_vals[d.Key] = State.GSData.PlayerInventory.Energy >= d.Value; break; case "food": bool_vals[d.Key] = State.GSData.PlayerInventory.Food >= d.Value; break; } } // set dimensions of tooltip var tooltip_rect = new Rectangle((int)_currentMouse.X, (int)(_currentMouse.Y - Tooltip_Dimensions.Y), (int)Tooltip_Dimensions.X, (int)Tooltip_Dimensions.Y); // re position the tooltip if it is showing outside of the window if ((_currentMouse.X + tooltip_rect.Width + (ExtraTooltip_Dimensions.X * 3)) > _graphicsDevice.Viewport.Width) { tooltip_rect.X = (int)(_graphicsDevice.Viewport.Width - (tooltip_rect.Width + (ExtraTooltip_Dimensions.X * 3))); } else if ((_currentMouse.X + tooltip_rect.Width + (ExtraTooltip_Dimensions.X * 3)) < 0) { tooltip_rect.X = 0; } if ((_currentMouse.Y - (tooltip_rect.Height + ExtraTooltip_Dimensions.Y)) < 0) { tooltip_rect.Y = 0; } else if ((_currentMouse.Y - (tooltip_rect.Height + ExtraTooltip_Dimensions.Y)) > _graphicsDevice.Viewport.Height) { tooltip_rect.Y = _graphicsDevice.Viewport.Height - tooltip_rect.Height; } var bldg_name = bld.Name; // draw tooltip spriteBatch.Draw(Tooltip_Texture, destinationRectangle: tooltip_rect, color: Color.LightSlateGray); // draw resource strings in tooltip var complete_str = ""; int res_strt = 0; foreach (var val in str_vals) { var res_str = $"{val.Value}: "; complete_str += res_str; var res_pos = new Vector2(tooltip_rect.X, ((tooltip_rect.Y + Tooltip_Dimensions.Y) - ((_font.MeasureString(_baseString).Y + 10) * res_strt) - 5)); var origin = new Vector2(0, _font.MeasureString(res_str).Y); spriteBatch.DrawString(_font, res_str, res_pos, (bool_vals[val.Key] ? Color.Black : Color.DarkRed), 0, origin, new Vector2(1, 1), SpriteEffects.None, 1); // draw extra rec for display of per turn revenue for resource var xtra_dimen = new Rectangle((int)tooltip_rect.X + (int)Tooltip_Dimensions.X, (int)((tooltip_rect.Y + tooltip_rect.Height) - (ExtraTooltip_Dimensions.Y * (res_strt + 1))), (int)ExtraTooltip_Dimensions.X * 3, (int)ExtraTooltip_Dimensions.Y); spriteBatch.Draw(Tooltip_Texture, destinationRectangle: xtra_dimen, color: Color.LightGray); string[] rev_strs = { $"-{cost_vals[val.Key]}", $"-{per_turn_cost_vals[val.Key]}", $"+{per_turn_gain_vals[val.Key]}" }; for (int i = 0; i < rev_strs.Length; i++) { var rev_str_pos = new Vector2(xtra_dimen.X + (i * (xtra_dimen.Width / 3)), res_pos.Y); var rev_str_origin = new Vector2(0, _font.MeasureString(_baseString_PerTurnRevenue).Y); var friendly_string = ""; var offset_cnt = _baseString_PerTurnRevenue.Length - rev_strs[i].Length; for (int j = 0; j < offset_cnt; j++) { friendly_string += " "; } friendly_string += rev_strs[i]; spriteBatch.DrawString(_font, (rev_strs[i].Equals("-0") || rev_strs[i].Equals("+0") ? "" : friendly_string), rev_str_pos, (i.Equals(0) ? (bool_vals[val.Key] ? Color.Black : Color.Red) : (i.Equals(1) ? Color.Red : Color.Green)), 0, rev_str_origin, new Vector2(1, 1), SpriteEffects.None, 1); } res_strt++; } var xtra_tooltip_rect = new Rectangle((int)tooltip_rect.X, (int)((tooltip_rect.Y + tooltip_rect.Height) - (Tooltip_Dimensions.Y + (ExtraTooltip_Dimensions.Y * 1.6f))), (int)Tooltip_Dimensions.X + (int)(ExtraTooltip_Dimensions.X * 3), (int)(ExtraTooltip_Dimensions.Y * 1.6f)); spriteBatch.Draw(Tooltip_Texture, destinationRectangle: xtra_tooltip_rect, color: Color.DarkSlateGray); var head_str_pos = new Vector2(xtra_tooltip_rect.X, xtra_tooltip_rect.Y + xtra_tooltip_rect.Height); var head_str_origin = new Vector2(0, _font.MeasureString(_baseString_Header).Y); var name_str_pos = new Vector2(xtra_tooltip_rect.X + (xtra_tooltip_rect.Width / 2), xtra_tooltip_rect.Y + (_font.MeasureString(bldg_name).Y * 0.8f)); var name_str_origin = new Vector2(_font.MeasureString(bldg_name).X / 2, _font.MeasureString(bldg_name).Y / 2); spriteBatch.DrawString(_font, _baseString_Header, head_str_pos, Color.White, 0f, head_str_origin, new Vector2(0.9f, 0.9f), SpriteEffects.None, 1); spriteBatch.DrawString(_font, bldg_name, name_str_pos, Color.White, 0f, name_str_origin, new Vector2(0.9f, 0.9f), SpriteEffects.None, 1); } if (show_spec_resource_toolip) { // build string var spec_res_tooltip_txt = $"{resource_string_vals[show_spec_resource_tooltip_id]}'s current amount is {resource_vals[show_spec_resource_tooltip_id]} (+{CurrentIncomeReport.TotalGain[show_spec_resource_tooltip_id]} -{CurrentIncomeReport.TotalLoss[show_spec_resource_tooltip_id]} / per turn)"; // calculate dimensions var spec_res_tooltip_dimens = new Vector2(_font.MeasureString(spec_res_tooltip_txt).X, _font.MeasureString(spec_res_tooltip_txt).Y); var spec_res_tooltip_rect = new Rectangle((int)_currentMouse.X, (int)(_currentMouse.Y - spec_res_tooltip_dimens.Y), (int)spec_res_tooltip_dimens.X, (int)spec_res_tooltip_dimens.Y); spec_res_tooltip_rect.X = _currentMouse.X - (spec_res_tooltip_rect.Width / 2); Vector2 spec_res_tooltip_txt_pos = new Vector2(spec_res_tooltip_rect.X + (spec_res_tooltip_rect.Width / 2), spec_res_tooltip_rect.Y + _font.MeasureString(spec_res_tooltip_txt).Y); // draw tooltip and string spriteBatch.Draw(Tooltip_Texture, destinationRectangle: spec_res_tooltip_rect, color: Color.LightGray); spriteBatch.DrawString(_font, spec_res_tooltip_txt, spec_res_tooltip_txt_pos, Color.Black, 0, new Vector2(_font.MeasureString(spec_res_tooltip_txt).X / 2, _font.MeasureString(spec_res_tooltip_txt).Y), new Vector2(0.9f, 0.9f), SpriteEffects.None, 1); } if (ShowBldgBtnTooltip && ShowBldgBtnId != 0) { var str = string.Empty; switch (ShowBldgBtnId) { case 800: str = Btn_SelectHouses_String; break; case 801: str = Btn_SelectReso_String; break; case 802: str = Btn_SelectDeco_String; break; } var ref_tooltip_dimens = new Vector2(_font.MeasureString(str).X, _font.MeasureString(str).Y); var ref_tooltip_rect = new Rectangle((int)_currentMouse.X, (int)(_currentMouse.Y - ref_tooltip_dimens.Y), (int)ref_tooltip_dimens.X, (int)ref_tooltip_dimens.Y); ref_tooltip_rect.X = _currentMouse.X - (ref_tooltip_rect.Width / 2); Vector2 ref_tooltip_txt_pos = new Vector2(ref_tooltip_rect.X + (ref_tooltip_rect.Width / 2), ref_tooltip_rect.Y + _font.MeasureString(str).Y); spriteBatch.Draw(Tooltip_Texture, destinationRectangle: ref_tooltip_rect, color: Color.LightGray); spriteBatch.DrawString(_font, str, ref_tooltip_txt_pos, Color.Black, 0, new Vector2(_font.MeasureString(str).X / 2, _font.MeasureString(str).Y), new Vector2(0.9f, 0.9f), SpriteEffects.None, 1); } }