private void CreateButton(StructureButton data) { GameObject newBtn = Instantiate(diagramButtonPrefab); newBtn.name = "DiagramButton_" + data.title; newBtn.transform.SetParent(imageObject.transform); newBtn.GetComponent <DiagramButton>().SetupButton(data, textObject); }
private void CreateDiagramButtons(List <StructureButton> structures) { foreach (StructureButton structure in structures) { CreateButton(structure); if (structure.mirror) { StructureButton mirrored = ScriptableObject.CreateInstance <StructureButton>(); mirrored.yRatio = structure.yRatio; mirrored.title = structure.title; mirrored.dataKey = structure.dataKey; mirrored.xRatio = 1.0f - structure.xRatio; CreateButton(mirrored); } } }
public void SetupButton(StructureButton buttonInfo, GameObject textObject) { text = new TextGenerator("text_data", 1); this.buttonInfo = buttonInfo; this.textObject = textObject; // set button position RectTransform rt = gameObject.GetComponent <RectTransform>(); Vector2 anchor = new Vector2(buttonInfo.xRatio, buttonInfo.yRatio); rt.anchorMin = anchor; rt.anchorMax = anchor; rt.anchoredPosition = Vector2.zero; // set onclick Button button = gameObject.GetComponent <Button>(); button.onClick.AddListener(delegate { OnClick(); }); }
//unclick method can be used for deactivating button after it is used. public void unclick() { ClickedBtn = null; }
//picks up the structure when button is clicked in the production menu public void PickStructure(StructureButton sbutton) { this.ClickedBtn = sbutton; Hover.Instance.Activate(sbutton.Sprite); }
private void DisplayStructureMenu(StructureButton structureButton, MenuLayer menuLayer) { BuildMenu.TargetNode = structureButton.Structure.Position; StructureMenu.Structure = structureButton.Structure; menuLayer.DisplayMenu(StructureMenu); }
override public void Create() { base.Create(); var structures = new[] { KnownStructure.Basis5Y, KnownStructure.Basis7Y, KnownStructure.Basis10Y, KnownStructure.Basis30Y, KnownStructure.FV_3s, KnownStructure.TU_3s, KnownStructure.TY_US, KnownStructure.US_WN, KnownStructure.USASWFLY, KnownStructure.TYASWFLY }; var task = new Task(() => { try { var bonds = Generator.Go(Generator.CashBondRolling.Monthly); var dictionary = new Dictionary<BondCurves, List<CTDLine<BondSpreads>>> { {BondCurves.USD3mLibor, Generator.GetSpreads(bonds, BondCurves.USD3mLibor)} }; m_cd = new ChartDataSource(chartComponents_: new[] { new ChartComponent(), new ChartComponent(), new ChartComponent() }, bonds_: bonds, spreads_: dictionary ); } catch (Exception ex_) { Logger.Error("Error building CTD data for seasonality application", typeof(CTSeasonalityComponent), ex_); } }); foreach (var s in structures) { var button = new StructureButton(s); flowLayoutPanel1.Controls.Add(button); button.Click += (a_, b_) => { var b = (StructureButton)a_; try { if (m_cd == null) { displayMessage("Data is still being put together. Please try again in a sec.", "Data building...", MessageBoxIcon.Information); return; } var eventARgs = GiveMeEvents(); if (!canProcessArgs(eventARgs)) return; var o = Structures.StructureFactory.GetStructure(b.Structure); o.Configure(m_cd.Components); var data = m_cd.GetData(); var list = new List<SeasonalityAnalysis.DataAroundEvent>(); foreach (var v in eventARgs.Events) { list.Add(new SeasonalityAnalysis.DataAroundEvent(eventDate_: v.Date.Date, instrument_: o, data_: data.SmoothedData, numPointsAroundEvent_: eventARgs.NumberOfPointsAroundEvent, eventCode_: v.SourceEvent.EventCode)); } OnDataAroundEventsGenerated(new SeasonalityAnalysis.DataAroundEVentsGeneratedData() { DataAroundEvents = list.ToArray() }); } catch (Exception ex_) { Logger.Error("Error", typeof(CTSeasonalityComponent), ex_); } }; } task.Start(); }