/// <summary> /// Shows the gui element /// </summary> public void Show() { lock (SceneGame._lock_guiDrawCall) { // setup the form and centre it sceneGame.HideForms(); canvas.RemoveChild(form); form = new Form(formConfig, canvas); form.CentreControl(); // get and setup the for elements Button btnSaveGame = (Button)form.GetChildByName("btnSaveGame"); // NYI Button btnLoadGame = (Button)form.GetChildByName("btnLoadGame"); // NYI Button btnOptions = (Button)form.GetChildByName("btnOptions"); btnOptions.MouseClick += (s, a) => { guiSettings.Show(); }; Button btnMainMenu = (Button)form.GetChildByName("btnMainMenu"); btnMainMenu.MouseClick += (s, a) => { // TODO add a confirmation dialogue client.Dissconnect(); SceneManager.Instance.ChangeScene(0); }; Button btnReturnToGame = (Button)form.GetChildByName("btnReturnToGame"); btnReturnToGame.MouseClick += (s, a) => { Hide(); }; Label lblEmpire = (Label)form.GetChildByName("lblEmpireValue"); lblEmpire.Text = client.DataManager.Empire.GetEmpire(client.Player.EmpireID).Name.ToRichText(); Label lblWorldType = (Label)form.GetChildByName("lblWorldTypeValue"); lblWorldType.Text = client.LobbyState.WorldType.GetName().ToRichText(); Label lblWorldSize = (Label)form.GetChildByName("lblWorldSizeValue"); lblWorldSize.Text = client.LobbyState.WorldSize.GetName().ToRichText(); Label lblDifficulty = (Label)form.GetChildByName("lblDifficultyValue"); lblDifficulty.Text = "NYI".ToRichText(); Label lblGameSpeed = (Label)form.GetChildByName("lblGameSpeedValue"); lblGameSpeed.Text = client.LobbyState.GameSpeed.ToString().ToRichText(); Label lblPlayerCount = (Label)form.GetChildByName("lblPlayerCountValue"); lblPlayerCount.Text = client.LobbyState.Players.Count.ToString().ToRichText(); } }
/// <summary> /// Opens the gui element /// </summary> public void Show() { lock (SceneGame._lock_guiDrawCall) { sceneGame.HideForms(); // hide other forms canvas.RemoveChild(form); // remove this form from the canvas form = new Form(formConfig, canvas); // re build the form from the config string gfx_res = ConfigManager.Instance.GetVar(Constants.CONFIG_GFX_RESOLUTION); int res_w = int.Parse(gfx_res.Split('x')[0]); form.Location = new Point(res_w - form.Size.Width, 100); // position the form // retrieve form components and set them up ScrollBox sbCities = (ScrollBox)form.GetChildByName("sbCityList"); sbCities.Items = cityListItems; sbCities.SelectedIndex = -1; sbCities.SelectedChanged += SbCities_SelectedChanged; } }
/// <summary> /// Opens the gui elements /// </summary> public void Show() { lock (SceneGame._lock_guiDrawCall) { // setup the form sceneGame.HideForms(); canvas.RemoveChild(form); form = new Form(formConfig, canvas); string gfx_res = ConfigManager.Instance.GetVar(Constants.CONFIG_GFX_RESOLUTION); int res_w = int.Parse(gfx_res.Split('x')[0]); form.Location = new Point(res_w - form.Size.Width, 100); // position the form // get and setup the form elements ScrollBox sbUnitList = (ScrollBox)form.GetChildByName("sbUnitList"); sbUnitList.SelectedIndex = -1; sbUnitList.Items = unitListItems; sbUnitList.SelectedChanged += SbUnitList_SelectedChanged; } }
/// <summary> /// Opens the gui element /// </summary> public void Show() { lock (SceneGame._lock_guiDrawCall) { // setup the form sceneGame.HideForms(); canvas.RemoveChild(form); form = new Form(formConfig, canvas); form.Draggable = false; form.Drawn += Form_Drawn; form.CentreControl(); form.Location = new Point(form.Location.X, 35); // get and setup the form elements ScrollBox sbSocialPolicyTrees = (ScrollBox)form.GetChildByName("sbSocialPolicyTrees"); sbSocialPolicyTrees.SelectedIndex = selectedIndex; sbSocialPolicyTrees.Items = GetPolicyTreeListItems(); sbSocialPolicyTrees.SelectedChanged += SbPolicyTrees_SelectedChanged; PolicyTreeListItem selectedItem = (PolicyTreeListItem)sbSocialPolicyTrees.Selected; lines = new List <Line>(); int offsetX = sbSocialPolicyTrees.AbsoluteBounds.Width + 10; int offsetY = 50; int itemWidth = 200; int itemHeight = 70; int sepX = 70; int sepY = 50; // build a button for every node in the social policy tree foreach (SocialPolicy policy in client.Player.SocialPolicyInstance.GetAllSocialPoliciesInTree(selectedItem.SocialPolicyTree.ID)) { Rectangle dest = new Rectangle(offsetX + policy.GridX * (itemWidth + sepX), offsetY + policy.GridY * (itemHeight + sepY), itemWidth, itemHeight); Button b = new Button(dest, form); string text = policy.Name; // format the button text b.Text = text.ToRichText(); // pick an appropriate sprite bool unlockable = true; foreach (string prereqID in policy.Prerequisites) { SocialPolicy prereq = client.Player.SocialPolicyInstance.GetSocialPolicy(prereqID); if (prereq != null && !prereq.Unlocked) { unlockable = false; } } if (policy.Unlocked) { b.Sprite = policyUnlockedSprite; } else if (unlockable) { b.Sprite = policyAdoptable; } else { b.Sprite = policyLockedSprite; } string policyID = policy.ID; // cache id because of closure b.MouseClick += (s, a) => { // only tell the server to select a new tech if all the prereqs are unlocked SocialPolicy clicked = client.DataManager.SocialPolicy.GetSocialPolicy(policyID); foreach (string prereqID in clicked.Prerequisites) { SocialPolicy prereq = client.Player.SocialPolicyInstance.GetSocialPolicy(prereqID); if (prereq != null && !prereq.Unlocked) { return; } } client.CommandPlayer(new PlayerCommand(PlayerCommandID.UnlockPolicy, policyID)); }; // add a tool tip with more info about the policy b.ToolTip = new ToolTip(policy.Description.ToRichText(), 500); b.ToolTip.FollowCurosr = true; // add a line from the current policy to all its prereqs foreach (string prereqID in policy.Prerequisites) { SocialPolicy prereq = client.DataManager.SocialPolicy.GetSocialPolicy(prereqID); if (prereq == null) { continue; } Rectangle prereqRect = new Rectangle(offsetX + prereq.GridX * (itemWidth + sepX), offsetY + prereq.GridY * (itemHeight + sepY), itemWidth, itemHeight); lines.Add(new Line(new Vector2(form.AbsoluteLocation.X + dest.X, dest.Y + itemHeight / 2 + offsetY), new Vector2(form.AbsoluteLocation.X + prereqRect.X + itemWidth, prereqRect.Y + itemHeight / 2 + offsetY))); } } } }
/// <summary> /// Shows the gui element /// </summary> public void Show() { lock (SceneGame._lock_guiDrawCall) { // hide other forms sceneGame.HideForms(true, false); // don't show try showing the form if no unit is selected if (client.SelectedUnit == null) { Hide(); return; } // programatically build the form int height = 250; int width = 400; canvas.RemoveChild(form); form = new Form(new Rectangle(0, canvas.Bounds.Height - height, width, height), canvas); form.Draggable = false; form.CloseButtonEnabled = true; // format the form text form.Text = $"Unit - {client.DataManager.Empire.GetEmpire(client.Player.EmpireID).Adjective} {client.SelectedUnit.Name}".ToRichText(); form.CloseButton.MouseClick += (s, a) => { // when the form is closed, deselect the selected unit client.SelectedUnit = null; }; // construct the command buttons based on the selected unit's abilities int xOffset = 0; int yOffset = 40; int btnWidth = 50; int btnHeight = 50; int maxPerLine = 5; int index = 0; commandIds = client.SelectedUnit.Commands; if (commandIds == null) // if the unit has no commands, don't try build any buttons { return; } for (int i = 0; i < commandIds.Count; i++) { // move the buttons to the next line if appropriate if (i != 0 && i % maxPerLine == 0) { index = 0; yOffset = 40 + btnHeight; } // build button Button btnCmd = new Button(new Rectangle((xOffset + btnWidth) * index, yOffset, btnWidth, btnHeight), form); btnCmd.Text = UnitCommand.GetCommandIcon(commandIds[i]); btnCmd.ToolTip = new ToolTip(UnitCommand.FormatName((commandIds[i]).ToString()).ToRichText(), 200); int locali = i; // closure means we can't just use i btnCmd.MouseClick += (s, a) => { // execute the unit command UnitCommandID cmdID = commandIds[locali]; ConsoleManager.Instance.WriteLine($"Select a new command, {cmdID}"); // if the command is instant, cast is instantly if (UnitCommand.GetTargetType(cmdID) == UnitCommandTargetType.Instant) { // command the unit if (client.SelectedUnit != null) { client.CommandUnit(new UnitCommand(cmdID, client.SelectedUnit, null)); } if (cmdID == UnitCommandID.UNITCMD_DISBAND || cmdID == UnitCommandID.UNITCMD_SETTLE) { // disbanding and settling cause the unit to be removed, to close the form and deselect the unit client.SelectedUnit = null; Hide(); } } // otherwise select it else { client.SelectedCommand = cmdID; } }; index++; } } }
/// <summary> /// opens the gui element /// </summary> public void Show() { lock (SceneGame._lock_guiDrawCall) { sceneGame.HideForms(false); // hide other forms if (client.SelectedCity == null) // dont't continue if there is no selected city { return; } int yOffset = 40; int itemHeight = 50; // setup the production list/selection form canvas.RemoveChild(frmProduction); frmProduction = new Form(frmProductionConfig, canvas); frmProduction.Location = new Point(0, 1080 - frmProduction.Size.Height); // setup the stats form canvas.RemoveChild(frmStats); frmStats = new Form(frmStatsConfig, canvas); frmStats.Location = new Point(frmProduction.Size.Width, yOffset); // setup the citizen focus form canvas.RemoveChild(frmFocus); frmFocus = new Form(frmFocusConfig, canvas); frmFocus.Location = new Point(1920 - frmFocus.Size.Width, yOffset); // setup the form in the bottom middle of the screen that allows the user to leave the city screen canvas.RemoveChild(frmReturnBuy); frmReturnBuy = new Form(frmReturnBuyConfig, canvas); frmReturnBuy.CentreControl(); frmReturnBuy.Location = new Point(frmReturnBuy.Location.X, 1080 - 100 - frmReturnBuy.Size.Height); // get and format the stats form elements Label lblPopulationValue = (Label)frmStats.GetChildByName("lblPopulationValue"); lblPopulationValue.Text = $"{client.SelectedCity.Population}".ToRichText(); Label lblPopGrowthValue = (Label)frmStats.GetChildByName("lblPopGrowthValue"); int turnsUntilGrowth = client.SelectedCity.TurnsUntilPopulationGrowth; if (turnsUntilGrowth == -1) { lblPopGrowthValue.Text = $"Inf".ToRichText(); } else if (turnsUntilGrowth == -2) { lblPopGrowthValue.Text = $"~".ToRichText(); } else { lblPopGrowthValue.Text = $"{turnsUntilGrowth}".ToRichText(); } Label lblFoodValue = (Label)frmStats.GetChildByName("lblFoodValue"); lblFoodValue.Text = $"+{client.SelectedCity.IncomeFood}".ToRichText(); Label lblProductionValue = (Label)frmStats.GetChildByName("lblProductionValue"); lblProductionValue.Text = $"+{client.SelectedCity.IncomeProduction}".ToRichText(); Label lblGoldValue = (Label)frmStats.GetChildByName("lblGoldValue"); lblGoldValue.Text = $"+{client.SelectedCity.IncomeGold}".ToRichText(); Label lblScienceValue = (Label)frmStats.GetChildByName("lblScienceValue"); lblScienceValue.Text = $"+{client.SelectedCity.IncomeScience}".ToRichText(); Label lblFaithValue = (Label)frmStats.GetChildByName("lblFaithValue"); lblFaithValue.Text = $"+{client.SelectedCity.IncomeFaith}".ToRichText(); Label lblTourismValue = (Label)frmStats.GetChildByName("lblTourismValue"); lblTourismValue.Text = $"+{client.SelectedCity.IncomeTourism}".ToRichText(); Label lblCultureValue = (Label)frmStats.GetChildByName("lblCultureValue"); lblCultureValue.Text = $"+{client.SelectedCity.IncomeCulture}".ToRichText(); Label lblBorderGrowthValue = (Label)frmStats.GetChildByName("lblBorderGrowthValue"); lblBorderGrowthValue.Text = $"+{client.SelectedCity.IncomeCulture}".ToRichText(); int turnsUntilBorderGrowth = client.SelectedCity.TurnsUntilBorderGrowth; if (turnsUntilBorderGrowth == -1) { lblBorderGrowthValue.Text = $"Inf".ToRichText(); } else if (turnsUntilBorderGrowth == -2) { lblBorderGrowthValue.Text = $"~".ToRichText(); } else { lblBorderGrowthValue.Text = $"{turnsUntilBorderGrowth}".ToRichText(); } TextBox tbName = (TextBox)frmStats.GetChildByName("tbName"); tbName.Text = client.SelectedCity.Name; tbName.EnterPressed += TbName_EnterPressed; // get and setup the production form elements sbProductionQueue = (ScrollBox)frmProduction.GetChildByName("sbProductionQueue"); sbProductionQueue.ItemHeight = itemHeight; sbProductionQueue.Items = GetProductionQueueListItems(); sbProductionQueue.SelectedIndex = sbProductionQueueSelected; sbProductionQueue.SelectedChanged += (s, a) => sbProductionQueueSelected = sbProductionQueue.SelectedIndex; sbProductionList = (ScrollBox)frmProduction.GetChildByName("sbProductionList"); sbProductionList.ItemHeight = itemHeight; sbProductionList.Items = GetProductionListListItems(); sbProductionList.SelectedIndex = sbProductionListSelected; sbProductionList.SelectedChanged += (s, a) => sbProductionListSelected = sbProductionList.SelectedIndex; Button btnCancelProduction = (Button)frmProduction.GetChildByName("btnCancelProduction"); btnCancelProduction.MouseClick += BtnCancelProduction_MouseClick; Button btnMoveUp = (Button)frmProduction.GetChildByName("btnMoveUp"); btnMoveUp.MouseClick += BtnMoveUp_MouseClick; Button btnMoveDown = (Button)frmProduction.GetChildByName("btnMoveDown"); btnMoveDown.MouseClick += BtnMoveDown_MouseClick; Button btnChangeProduction = (Button)frmProduction.GetChildByName("btnChangeProduction"); btnChangeProduction.MouseClick += BtnChangeProduction_MouseClick; Button btnQueueProduction = (Button)frmProduction.GetChildByName("btnQueueProduction"); btnQueueProduction.MouseClick += BtnQueueProduction_MouseClick; Button btnPurchase = (Button)frmProduction.GetChildByName("btnPurchase"); btnPurchase.MouseClick += BtnPurchase_MouseClick; // get and setup the citizen focus form elements sbCitizenFocus = (ScrollBox)frmFocus.GetChildByName("sbCitizenFocus"); sbCitizenFocus.Items = GetCitizenFocusListItems(); sbCitizenFocus.SelectedIndex = (int)client.SelectedCity.CitizenFocus; sbCitizenFocus.SelectedChanged += SbCitizenFocus_SelectedChanged; sbBuildingList = (ScrollBox)frmFocus.GetChildByName("sbBuildingList"); sbBuildingList.ItemHeight = itemHeight; sbBuildingList.Items = GetBuildingList(); sbBuildingList.SelectedIndex = 0; Button btnDemolish = (Button)frmFocus.GetChildByName("btnDemolish"); btnDemolish.MouseClick += BtnDemolish_MouseClick; // get and setup the return/buy tiles form elements Button btnBuyTile = (Button)frmReturnBuy.GetChildByName("btnBuyTile"); btnBuyTile.MouseClick += (s, a) => buyingTiles = true; Button btnReturnToMap = (Button)frmReturnBuy.GetChildByName("btnReturnToMap"); btnReturnToMap.MouseClick += (s, a) => Hide(); } }
/// <summary> /// Opens the gui element /// </summary> public void Show() { lock (SceneGame._lock_guiDrawCall) { // programatically build the form sceneGame.HideForms(); canvas.RemoveChild(form); form = new Form(new Rectangle(0, 40, 1920, 650), canvas); form.DrawTitlebar = false; form.Draggable = false; form.MouseWheel += Form_MouseWheel; form.Drawn += Form_Drawn; lines = new List <Line>(); int offsetX = 10; int offsetY = 50; int itemWidth = 250; int itemHeight = 50; int sepX = 30; int sepY = 10; // build a button for every node in the tech tree foreach (Technology tech in client.Player.TechTreeInstance.GetAllTechnologies()) { Rectangle dest = new Rectangle(offsetX + tech.GridX * (itemWidth + sepX) + scrollIndex * (itemWidth + tech.GridX + sepX), offsetY + tech.GridY * (itemHeight + sepY), itemWidth, itemHeight); Button b = new Button(dest, form); int turnsLeft = GetTurnsUntilTech(tech); string text = tech.Name; if (!tech.Unlocked) { // -2 indicates the tech will take a very long time to research if (turnsLeft == -2) { text = $"{tech.Name} - ~ turns"; } else if (turnsLeft != -1) { text = $"{tech.Name} - {turnsLeft} turns"; } } // format the button text b.Text = text.ToRichText(); // pick an appropriate sprite bool prereqsUnlocked = true; foreach (string prereqID in tech.Prerequisites) { Technology prereq = client.Player.TechTreeInstance.GetTech(prereqID); if (prereq != null && !prereq.Unlocked) { prereqsUnlocked = false; } } if (tech.Unlocked) { b.Sprite = techUnlockedSprite; } else if (client.Player.SelectedTechNodeID == tech.ID) { b.Sprite = techSelectedSprite; } else if (prereqsUnlocked) { b.Sprite = techSelectable; } else { b.Sprite = techLockedSprite; } string techID = tech.ID; // cache id because of closure b.MouseClick += (s, a) => { // only tell the server to select a new tech if all the prereqs are unlocked Technology clicked = client.Player.TechTreeInstance.GetTech(techID); foreach (string prereqID in clicked.Prerequisites) { Technology prereq = client.Player.TechTreeInstance.GetTech(prereqID); if (prereq != null && !prereq.Unlocked) { return; } } client.CommandPlayer(new PlayerCommand(PlayerCommandID.SelectTech, techID)); }; // register events b.MouseWheel += Form_MouseWheel; // add a tool tip with more info about the tech b.ToolTip = new ToolTip(tech.Description.ToRichText(), 500); b.ToolTip.FollowCurosr = true; // add a line from the current tech to all its prereqs foreach (string prereqID in tech.Prerequisites) { Technology prereq = client.Player.TechTreeInstance.GetTech(prereqID); if (prereq == null) { continue; } Rectangle prereqRect = new Rectangle(offsetX + prereq.GridX * (itemWidth + sepX) + scrollIndex * (itemWidth + prereq.GridX), offsetY + prereq.GridY * (itemHeight + sepY), itemWidth, itemHeight); lines.Add(new Line(new Vector2(dest.X, dest.Y + itemHeight / 2 + offsetY), new Vector2(prereqRect.X + itemWidth + sepX * scrollIndex, prereqRect.Y + itemHeight / 2 + offsetY))); } } } }