static void GuiHintTextSelectionFormula(ComponentDesignAttribute attribute) { Dictionary <string, ChainedExpression> dict = new Dictionary <string, ChainedExpression>(); _listNames = new string[dict.Count]; int i = 0; foreach (var kvp in attribute.GuidDictionary) { _listNames[i] = (string)kvp.Key; } if (compactmod) { ImGui.TextWrapped(attribute.Name + ": " + attribute.Description); ImGui.NewLine(); } else { ImGui.TextWrapped(attribute.Name + ":"); ImGui.SameLine(); ImGui.TextWrapped(attribute.Description); ImGui.NewLine(); } ImGui.TextWrapped(attribute.Value.ToString()); if (ImGui.Combo("Select", ref attribute.ListSelection, _listNames, _listNames.Length)) { var key = _listNames[attribute.ListSelection]; var value = attribute.GuidDictionary[key]; attribute.SetValueFromDictionaryExpression(_listNames[attribute.ListSelection]); } }
static void GuiHintEnumSelection(ComponentDesignAttribute attribute) { if (compactmod) { ImGui.TextWrapped(attribute.Name + ": " + attribute.Description); ImGui.NewLine(); } else { ImGui.TextWrapped(attribute.Name + ":"); ImGui.SameLine(); ImGui.TextWrapped(attribute.Description); ImGui.NewLine(); } int i = 0; //_techSDs = new TechSD[attribute.GuidDictionary.Count]; _listNames = Enum.GetNames(attribute.EnumType); ImGui.TextWrapped(attribute.Value.ToString()); if (ImGui.Combo("Select", ref attribute.ListSelection, _listNames, (int)attribute.MaxValue + 1)) { int enumVal = (int)Enum.Parse(attribute.EnumType, _listNames[attribute.ListSelection]); attribute.SetValueFromInput(enumVal); } ImGui.NewLine(); }
public ComponentDesigner(ComponentTemplateSD componentSD, FactionTechDB factionTech) { var staticData = StaticRefLib.StaticData; TypeName = componentSD.Name; Name = componentSD.Name; _design.ID = Guid.NewGuid(); MassFormula = new ChainedExpression(componentSD.MassFormula, this, factionTech, staticData); VolumeFormula = new ChainedExpression(componentSD.VolumeFormula, this, factionTech, staticData); CrewFormula = new ChainedExpression(componentSD.CrewReqFormula, this, factionTech, staticData); HTKFormula = new ChainedExpression(componentSD.HTKFormula, this, factionTech, staticData); ResearchCostFormula = new ChainedExpression(componentSD.ResearchCostFormula, this, factionTech, staticData); BuildCostFormula = new ChainedExpression(componentSD.BuildPointCostFormula, this, factionTech, staticData); CreditCostFormula = new ChainedExpression(componentSD.CreditCostFormula, this, factionTech, staticData); ComponentMountType = componentSD.MountType; IndustryType = componentSD.IndustryTypeID; CargoTypeID = componentSD.CargoTypeID; _design.CargoTypeID = componentSD.CargoTypeID; if (componentSD.MountType.HasFlag(ComponentMountType.PlanetInstallation)) { _design.GuiHints = ConstructableGuiHints.CanBeInstalled; } if (!string.IsNullOrEmpty(componentSD.DescriptionFormula)) { DescriptionFormula = new ChainedExpression(componentSD.DescriptionFormula, this, factionTech, staticData); } Dictionary <Guid, ChainedExpression> resourceCostForulas = new Dictionary <Guid, ChainedExpression>(); foreach (var kvp in componentSD.ResourceCostFormula) { if (staticData.CargoGoods.GetAny(kvp.Key) != null) { resourceCostForulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech)); } else //TODO: log don't crash. { throw new Exception("GUID object {" + kvp.Key + "} not found in resourceCosting for " + this.TypeName + " This object needs to be either a mineral, material or component defined in the Data folder"); } } ResourceCostFormulas = resourceCostForulas; foreach (ComponentTemplateAttributeSD attrbSD in componentSD.ComponentAtbSDs) { ComponentDesignAttribute designAttribute = new ComponentDesignAttribute(this, attrbSD, factionTech); ComponentDesignAttributes.Add(designAttribute.Name, designAttribute); ComponentDesignAttributeList.Add(designAttribute); } EvalAll(); }
static void GuiHintText(ComponentDesignAttribute attribute) { if (compactmod) { ImGui.TextWrapped(attribute.Name + ": " + attribute.Value.ToString() + " " + attribute.Unit); ImGui.NewLine(); } else { ImGui.TextWrapped(attribute.Name + ":"); ImGui.SameLine(); ImGui.TextWrapped(attribute.Value.ToString() + " " + attribute.Unit); ImGui.NewLine(); } }
static void GuiHintOrdnanceSelection(ComponentDesignAttribute attribute) { var dict = _state.Faction.GetDataBlob <FactionInfoDB>().MissileDesigns; _listNames = new string[dict.Count]; OrdnanceDesign[] ordnances = new OrdnanceDesign[dict.Count]; int i = 0; foreach (var kvp in dict) { _listNames[i] = kvp.Value.Name; ordnances[i] = kvp.Value; } if (compactmod) { ImGui.TextWrapped(attribute.Name + ": " + attribute.Description); ImGui.NewLine(); } else { ImGui.TextWrapped(attribute.Name + ":"); ImGui.SameLine(); ImGui.TextWrapped(attribute.Description); ImGui.NewLine(); } ImGui.TextWrapped(attribute.Value.ToString()); if (ImGui.Combo("Select", ref attribute.ListSelection, _listNames, _listNames.Length)) { attribute.SetValueFromComponentList(ordnances[attribute.ListSelection].ID); } ImGui.NewLine(); }
static void GuiHintTechSelection(ComponentDesignAttribute attribute) { if (compactmod) { ImGui.TextWrapped(attribute.Name + ": " + attribute.Description); ImGui.NewLine(); } else { ImGui.TextWrapped(attribute.Name + ":"); ImGui.SameLine(); ImGui.TextWrapped(attribute.Description); ImGui.NewLine(); } int i = 0; _techSDs = new TechSD[attribute.GuidDictionary.Count]; _techNames = new string[attribute.GuidDictionary.Count]; foreach (var kvp in attribute.GuidDictionary) { TechSD sd = StaticRefLib.StaticData.Techs[Guid.Parse((string)kvp.Key)]; _techSDs[i] = sd; _techNames[i] = sd.Name; i++; } ImGui.TextWrapped(attribute.Value.ToString()); if (ImGui.Combo("Select Tech", ref _techSelectedIndex, _techNames, _techNames.Length)) { attribute.SetValueFromGuidList(_techSDs[_techSelectedIndex].ID); } ImGui.NewLine(); }
static void GuiHintMaxMin(ComponentDesignAttribute attribute) { if (compactmod) { ImGui.TextWrapped(attribute.Name + ": " + attribute.Description); ImGui.NewLine(); } else { ImGui.TextWrapped(attribute.Name + ":"); ImGui.SameLine(); ImGui.TextWrapped(attribute.Description); ImGui.NewLine(); } attribute.SetMax(); attribute.SetMin(); //attribute.SetValue(); attribute.SetStep(); var max = attribute.MaxValue; var min = attribute.MinValue; double val = attribute.Value; double step = attribute.StepValue; double fstep = step * 10; IntPtr valPtr; IntPtr maxPtr; IntPtr minPtr; IntPtr stepPtr; IntPtr fstepPtr; unsafe { valPtr = new IntPtr(&val); maxPtr = new IntPtr(&max); minPtr = new IntPtr(&min); stepPtr = new IntPtr(&step); fstepPtr = new IntPtr(&fstep); } //ImGui.DragScalar("##slider" + attribute.Name, ImGuiDataType.Double, valPtr, 1f, minPtr, maxPtr); if (compactmod) { } else { //ImGui.PushItemWidth(-1); if (ImGui.SliderScalar("##scaler" + attribute.Name, ImGuiDataType.Double, valPtr, minPtr, maxPtr)) { attribute.SetValueFromInput(val); } } //ImGui.PushItemWidth(-1); if (ImGui.InputScalar("##input" + attribute.Name, ImGuiDataType.Double, valPtr, stepPtr, fstepPtr)) { attribute.SetValueFromInput(val); } ImGui.NewLine(); }
public ComponentDesigner(ComponentTemplateSD componentSD, FactionTechDB factionTech) { var staticData = StaticRefLib.StaticData; TypeName = componentSD.Name; Name = componentSD.Name; Description = componentSD.Description; _design.ID = Guid.NewGuid(); MassFormula = new ChainedExpression(componentSD.MassFormula, this, factionTech, staticData); VolumeFormula = new ChainedExpression(componentSD.VolumeFormula, this, factionTech, staticData); CrewFormula = new ChainedExpression(componentSD.CrewReqFormula, this, factionTech, staticData); HTKFormula = new ChainedExpression(componentSD.HTKFormula, this, factionTech, staticData); ResearchCostFormula = new ChainedExpression(componentSD.ResearchCostFormula, this, factionTech, staticData); BuildCostFormula = new ChainedExpression(componentSD.BuildPointCostFormula, this, factionTech, staticData); CreditCostFormula = new ChainedExpression(componentSD.CreditCostFormula, this, factionTech, staticData); ComponentMountType = componentSD.MountType; IndustryType = componentSD.IndustryTypeID; CargoTypeID = componentSD.CargoTypeID; _design.CargoTypeID = componentSD.CargoTypeID; if (componentSD.MountType.HasFlag(ComponentMountType.PlanetInstallation)) { _design.GuiHints = ConstructableGuiHints.CanBeInstalled; } Dictionary <Guid, ChainedExpression> resourceCostForulas = new Dictionary <Guid, ChainedExpression>(); //Dictionary<Guid, ChainedExpression> mineralCostFormulas = new Dictionary<Guid, ChainedExpression>(); //Dictionary<Guid, ChainedExpression> materalCostFormulas = new Dictionary<Guid, ChainedExpression>(); //Dictionary<Guid, ChainedExpression> componentCostForulas = new Dictionary<Guid, ChainedExpression>(); foreach (var kvp in componentSD.ResourceCostFormula) { /* * if (staticData.CargoGoods.IsMaterial(kvp.Key)) * { * materalCostFormulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData)); * } * else if (staticData.ComponentTemplates.ContainsKey(kvp.Key)) * { * componentCostForulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData)); * } * else if (staticData.CargoGoods.IsMineral(kvp.Key)) * { * mineralCostFormulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData)); * } * else //TODO: log don't crash. * throw new Exception("GUID object {" + kvp.Key + "} not found in materialCosting for " + this.TypeName + " This object needs to be either a mineral, material or component defined in the Data folder"); * */ if (staticData.CargoGoods.GetAny(kvp.Key) != null) { resourceCostForulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech)); } else //TODO: log don't crash. { throw new Exception("GUID object {" + kvp.Key + "} not found in resourceCosting for " + this.TypeName + " This object needs to be either a mineral, material or component defined in the Data folder"); } } ResourceCostFormulas = resourceCostForulas; //MineralCostFormulas = mineralCostFormulas; // MaterialCostFormulas = materalCostFormulas; //ComponentCostFormulas = componentCostForulas; foreach (ComponentTemplateAbilitySD abilitySD in componentSD.ComponentAbilitySDs) { ComponentDesignAttribute designAttribute = new ComponentDesignAttribute(this); if (abilitySD.Name == null) //TODO: Log this, and don't use this component instead of throwing. { throw new Exception("Bad Static Data. Ability name is null"); } designAttribute.Name = abilitySD.Name; designAttribute.Description = abilitySD.Description; designAttribute.GuiHint = abilitySD.GuiHint; if (abilitySD.AbilityFormula != null) { designAttribute.Formula = new ChainedExpression(abilitySD.AbilityFormula, designAttribute, factionTech, staticData); } if (abilitySD.GuidDictionary != null) { designAttribute.GuidDictionary = new Dictionary <object, ChainedExpression>(); if (designAttribute.GuiHint == GuiHint.GuiTechSelectionList) { foreach (var kvp in abilitySD.GuidDictionary) { if (factionTech.ResearchedTechs.ContainsKey(Guid.Parse(kvp.Key.ToString()))) { TechSD techSD = staticData.Techs[Guid.Parse(kvp.Key.ToString())]; designAttribute.GuidDictionary.Add(kvp.Key, new ChainedExpression(ResearchProcessor.DataFormula(factionTech, techSD).ToString(), designAttribute, factionTech, staticData)); } } } else { foreach (var kvp in abilitySD.GuidDictionary) { designAttribute.GuidDictionary.Add(kvp.Key, new ChainedExpression(kvp.Value, designAttribute, factionTech, staticData)); } } } if (designAttribute.GuiHint == GuiHint.GuiSelectionMaxMin) { designAttribute.MaxValueFormula = new ChainedExpression(abilitySD.MaxFormula, designAttribute, factionTech, staticData); designAttribute.MinValueFormula = new ChainedExpression(abilitySD.MinFormula, designAttribute, factionTech, staticData); designAttribute.StepValueFormula = new ChainedExpression(abilitySD.StepFormula, designAttribute, factionTech, staticData); } if (abilitySD.AbilityDataBlobType != null) { designAttribute.DataBlobType = Type.GetType(abilitySD.AbilityDataBlobType); } ComponentDesignAttributes.Add(designAttribute.Name, designAttribute); //TODO: get rid of this once json data is rewritten to use names instead of indexes ComponentDesignAttributeList.Add(designAttribute); } EvalAll(); }