/// <summary> /// Creates a new pinned critter row. /// </summary> /// <param name="species">The species to pin.</param> /// <param name="type">The critter type to pin.</param> /// <returns>A pinned row with that critter type and species displayed.</returns> internal HierarchyReferences Create(Tag species, CritterType type) { var newRow = Util.KInstantiateUI(pinnedResources.linePrefab, pinnedResources.rowContainer, false); var refs = newRow.GetComponent <HierarchyReferences>(); // Set the image var imageData = Def.GetUISprite(species, "ui", false); if (imageData != null) { var icon = refs.GetReference <Image>("Icon"); icon.sprite = imageData.first; icon.color = imageData.second; } refs.GetReference <LocText>("NameLabel").SetText(CritterInventoryUtils.GetTitle( species, type)); refs.GetReference("NewLabel").gameObject.SetActive(false); var pinRow = newRow.AddComponent <PinnedCritterEntry>(); pinRow.CritterType = type; pinRow.Species = species; refs.GetReference <MultiToggle>("PinToggle").onClick = pinRow.OnUnpin; newRow.GetComponent <MultiToggle>().onClick += pinRow.OnCycleThrough; return(refs); }
public async Task <IActionResult> Edit(int id, [Bind("CritterTypeId,Comment,GestrationPeriod,Name,Timestamp,VersionNumber")] CritterType val) { if (val.CritterTypeId != id) { return(NotFound()); } this.FixNullFields(val); if (ModelState.IsValid) { try { _context.Update(val); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Exists(val.CritterTypeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(val)); }
/// <summary> /// Manages compatibility with Favorites Category. /// /// This method is quite hacky. /// </summary> /// <param name="totals">The totals calculated from Update.</param> public static void FavoritesCategoryCompat(IDictionary <Tag, CritterTotals> totals, CritterType type) { ResourceCategoryHeader favCategory = null; var favTag = TagManager.Create("Favorites", "Favorites"); if ((ResourceCategoryScreen.Instance?.DisplayedCategories?.TryGetValue(favTag, out favCategory) ?? false) && favCategory != null) { // Favorites Category is installed foreach (var pair in favCategory.ResourcesDiscovered) { var species = pair.Key; var entry = pair.Value; var intendedType = entry.gameObject.GetComponent <CritterResourceInfo>(); if (totals.TryGetValue(species, out CritterTotals quantity) && intendedType != null && intendedType.CritterType == type) { // A critter in Favorites Category UpdateEntry(entry, quantity); entry.SetName("{0} ({1})".F(species.ProperName(), type)); } } } }
/// <summary> /// Applied after OnClick runs. /// </summary> /// <param name="__instance">The current resource entry.</param> /// <param name="___selectionIdx">The current selection index.</param> internal static void Postfix(ResourceEntry __instance, ref int ___selectionIdx) { var info = __instance.gameObject.GetComponentSafe <CritterResourceInfo>(); if (info != null) { var creaturesOfType = ListPool <CreatureBrain, ResourceCategoryHeader> . Allocate(); CritterType type = info.CritterType; var species = __instance.Resource; // Get a list of creatures that match this type CritterInventoryUtils.IterateCreatures((creature) => { if (creature.PrefabID() == species && type.Matches(creature)) { creaturesOfType.Add(creature); } }); int count = creaturesOfType.Count; if (count > 0) { // Rotate through valid indexes // Select the object and center it PUtil.CenterAndSelect(creaturesOfType[___selectionIdx++ % count]); } creaturesOfType.Recycle(); } }
/// <summary> /// Checks to see if a creature matches the critter type specified. /// </summary> /// <param name="type">The critter type.</param> /// <param name="creature">The creature to compare against.</param> /// <returns>true if the creature matches the type, or false otherwise.</returns> public static bool Matches(this CritterType type, CreatureBrain creature) { bool match; if (creature == null) { // Should not match any critter type match = false; } else { // Some creatures cannot be tamed (morbs) bool canBeTamed = creature.gameObject.GetDef <WildnessMonitor.Def>() != null; switch (type) { case CritterType.Tame: match = !creature.HasTag(GameTags.Creatures.Wild) && canBeTamed; break; case CritterType.Wild: match = creature.HasTag(GameTags.Creatures.Wild) || !canBeTamed; break; default: throw new InvalidOperationException("Unsupported critter type " + type); } } return(match); }
/// <summary> /// Populates a list of the creatures matching the critter type specified. /// </summary> /// <param name="totals">The location where the quantity of creatures will be stored.</param> /// <param name="type">The critter type to match.</param> public static CritterTotals FindCreatures(IDictionary <Tag, CritterTotals> totals, CritterType type) { if (totals == null) { throw new ArgumentNullException("totals"); } var all = new CritterTotals(); IterateCreatures((creature) => { var species = creature.PrefabID(); var go = creature.gameObject; if (type.Matches(creature)) { var alignment = go.GetComponent <FactionAlignment>(); // Create critter totals if not present if (!totals.TryGetValue(species, out CritterTotals total)) { total = new CritterTotals(); totals.Add(species, total); } total.Total++; all.Total++; // Reserve wrangled, marked for attack, and trussed/bagged creatures if ((go.GetComponent <Capturable>()?.IsMarkedForCapture ?? false) || ((alignment?.targeted ?? false) && alignment.targetable) || creature.HasTag(GameTags.Creatures.Bagged)) { total.Reserved++; all.Reserved++; } } }); return(all); }
/// <summary> /// Gets the species that are pinned for a given critter type. /// </summary> /// <param name="type">The critter type to look up.</param> /// <returns>The pinned species, or null if pins are not yet initialized.</returns> public ISet <Tag> GetPinnedSpecies(CritterType type) { if (pinned == null || !pinned.TryGetValue(type, out HashSet <Tag> result)) { result = null; } return(result); }
/// <summary> /// Updates a critter resource category header. /// </summary> /// <param name="header">The category header to update.</param> /// <param name="type">The critter type it contains (can be pulled from the CritterResourceInfo component).</param> public static void Update(this ResourceCategoryHeader header, CritterType type) { var totals = DictionaryPool <Tag, CritterTotals, ResourceCategoryHeader> .Allocate(); var all = CritterInventoryUtils.FindCreatures(totals, type); var discovered = header.ResourcesDiscovered; var trCategory = Traverse.Create(header); // Previously discovered but now extinct critters need an empty entry foreach (var pair in discovered) { var species = pair.Key; if (!totals.ContainsKey(species)) { totals.Add(species, new CritterTotals()); } } // Go through resource entries for each species and update them foreach (var pair in totals) { var quantity = pair.Value; var species = pair.Key; // Look up the species to see if we have found it already if (!discovered.TryGetValue(species, out ResourceEntry entry)) { entry = trCategory.CallMethod <ResourceEntry>("NewResourceEntry", species, GameUtil.MeasureUnit.quantity); entry.SetName(species.ProperName()); // Add component to tag it as wild/tame entry.gameObject.AddComponent <CritterResourceInfo>().CritterType = type; discovered.Add(species, entry); } UpdateEntry(entry, quantity); } bool anyDiscovered = discovered.Count > 0; // Enable display and open/close based on critter presence header.elements.QuantityText.SetText(all.Available.ToString()); trCategory.CallMethod("SetActiveColor", all.HasAny); trCategory.CallMethod("SetInteractable", anyDiscovered); // Still need to set this for expand/contract to work trCategory.SetField("anyDiscovered", anyDiscovered); // Update category tooltip var tooltip = trCategory.GetField <ToolTip>("tooltip"); if (tooltip != null) { tooltip.OnToolTip = null; tooltip.toolTip = CritterInventoryUtils.FormatTooltip(header.elements. LabelText.text, all); } // Disabled until coolazura's tags are up to date #if false FavoritesCategoryCompat(totals, type); #endif totals.Recycle(); }
private void FixNullFields(CritterType val) { if (String.IsNullOrWhiteSpace(val.Comment)) { val.Comment = "N/A"; } if (String.IsNullOrWhiteSpace(val.Name)) { val.Name = "N/A"; } }
public frmCompletion( frmMain main, CritterType crType = null ) { this.main = main; if( crType == null ) return; InitializeComponent(); CurrentCritterType = crType; radioText.Checked = true; }
/// <summary> /// Gets the total quantity of critters of a specific type. /// </summary> /// <param name="type">The critter type, wild or tame.</param> /// <param name="species">The critter species to examine.</param> /// <returns>The total quantity of critters of that type and species.</returns> internal CritterTotals GetBySpecies(CritterType type, Tag species) { if (!counts.TryGetValue(type, out CritterInventoryPerType byType)) { throw new ArgumentOutOfRangeException(nameof(type)); } if (!byType.TryGetValue(species, out CritterTotals totals)) { totals = new CritterTotals(); } return(totals); }
/// <summary> /// Applied after Hover runs. /// </summary> /// <param name="__instance">The current resource category header.</param> /// <param name="is_hovering">true if the user is hovering, or false otherwise.</param> /// <param name="___highlightColour">The highlight color from the instance.</param> internal static void Postfix(ResourceCategoryHeader __instance, bool is_hovering, Color ___highlightColour) { var info = __instance.gameObject.GetComponent<CritterResourceInfo>(); if (info != null) { CritterType type = info.CritterType; // It is a creature header, highlight all matching CritterInventoryUtils.IterateCreatures((creature) => { if (type.Matches(creature)) PUtil.HighlightEntity(creature, is_hovering ? ___highlightColour : Color.black); }); } }
public async Task <IActionResult> Create([Bind("CritterTypeId,Comment,GestrationPeriod,Name,Timestamp,VersionNumber")] CritterType val) { this.FixNullFields(val); if (ModelState.IsValid) { _context.Add(val); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(val)); }
/// <summary> /// Applied after Hover runs. /// </summary> /// <param name="__instance">The current resource entry.</param> /// <param name="is_hovering">true if the user is hovering, or false otherwise</param> /// <param name="___HighlightColor">The highlight color from the instance.</param> internal static void Postfix(ResourceEntry __instance, bool is_hovering, Color ___HighlightColor) { var info = __instance.gameObject.GetComponent<CritterResourceInfo>(); if (info != null) { var hlc = ___HighlightColor; CritterType type = info.CritterType; Tag species = __instance.Resource; CritterInventoryUtils.IterateCreatures((creature) => { if (creature.PrefabID() == species && type.Matches(creature)) PUtil.HighlightEntity(creature, is_hovering ? hlc : Color.black); }); } }
/// <summary> /// Creates a new resource entry. /// </summary> /// <param name="parent">The parent category of the entry.</param> /// <param name="species">The critter species of this entry.</param> /// <param name="type">The critter type of this entry.</param> /// <returns>The created resource entry (already added to the resource list).</returns> private static ResourceEntry NewResourceEntry(ResourceCategoryHeader parent, Tag species, CritterType type) { var re = Util.KInstantiateUI(parent.Prefab_ResourceEntry, parent. EntryContainer.gameObject, true); var entry = re.GetComponent <ResourceEntry>(); entry.SetTag(species, GameUtil.MeasureUnit.quantity); entry.SetName(species.ProperNameStripLink()); // Add component to tag it as wild/tame re.AddComponent <CritterResourceEntry>().CritterType = type; return(entry); }
public frmCompletion(frmMain main, CritterType crType = null) { this.main = main; if (crType == null) { return; } InitializeComponent(); CurrentCritterType = crType; radioText.Checked = true; }
public override void Start() { base.Start (); float time = Time.time; nextMoveTime = time + waitTime; nextPath = new GameObject(); pathPosition = spawnPosition; isCritterType = true; if (Random.Range(0f, 1f) > 0.5f) critterUpgradeType = CritterType.fast; else critterUpgradeType = CritterType.poisonous; SkinType = NPCSkinType.Critter; }
/// <summary> /// Retrieves the UI description of a critter type. /// </summary> /// <param name="type">The critter type.</param> /// <returns>The (translated?) name as it should appear in the UI.</returns> public static string GetDescription(this CritterType type) { string desc; switch (type) { case CritterType.Tame: desc = STRINGS.CREATURES.MODIFIERS.TAME.NAME; break; case CritterType.Wild: desc = STRINGS.CREATURES.MODIFIERS.WILD.NAME; break; default: throw new InvalidOperationException("Unsupported critter type " + type); } return(desc); }
/// <summary> /// Creates a resource category header for critters. /// </summary> /// <param name="resList">The parent category screen for this header.</param> /// <param name="prefab">The prefab to use for creating the headers.</param> /// <param name="type">The critter type to create.</param> internal void Create(ResourceCategoryScreen resList, GameObject prefab, CritterType type) { var tag = GameTags.BagableCreature; // Create a heading for Critter (Type) PUtil.LogDebug("Creating Critter ({0}) category".F(type.GetProperName())); var gameObject = Util.KInstantiateUI(prefab, resList.CategoryContainer.gameObject, false); gameObject.name = "CategoryHeader_{0}_{1}".F(tag.Name, type.ToString()); var header = gameObject.GetComponent <ResourceCategoryHeader>(); header.SetTag(tag, GameUtil.MeasureUnit.quantity); // Tag it with a wild/tame tag header.gameObject.AddComponent <CritterResourceHeader>().CritterType = type; header.elements.LabelText.SetText(CritterInventoryUtils.GetTitle(tag, type)); headers.Add(header); }
/// <summary> /// Creates a resource category header for critters. /// </summary> /// <param name="resList">The parent category screen for this header.</param> /// <param name="prefab">The prefab to use for creating the headers.</param> /// <param name="type">The critter type to create.</param> /// <returns>The heading for that critter type.</returns> public static ResourceCategoryHeader Create(ResourceCategoryScreen resList, GameObject prefab, CritterType type) { var tag = GameTags.BagableCreature; string typeStr = type.GetDescription(); // Create a heading for Critter (Type) PUtil.LogDebug("Creating Critter ({0}) category".F(typeStr)); var gameObject = Util.KInstantiateUI(prefab, resList.CategoryContainer.gameObject, false); gameObject.name = "CategoryHeader_{0}_{1}".F(tag.Name, type.ToString()); var header = gameObject.GetComponent <ResourceCategoryHeader>(); header.SetTag(tag, GameUtil.MeasureUnit.quantity); // Tag it with a wild/tame tag header.gameObject.AddComponent <CritterResourceInfo>().CritterType = type; header.elements.LabelText.SetText("{0} ({1})".F(tag.ProperName(), typeStr)); return(header); }
/// <summary> /// Gets the resource tracker which tracks critter counts over time. /// </summary> /// <typeparam name="T">The type of critter tracker to find.</typeparam> /// <param name="id">The world ID to match.</param> /// <param name="type">The critter type to look up.</param> /// <returns>The tracker for that critter type and world ID.</returns> internal static T GetTracker <T>(int id, CritterType type, Func <T, bool> filter = null) where T : BaseCritterTracker { var inst = TrackerTool.Instance; TrackerList trackers; T result = null; if (inst != null && (trackers = WORLD_TRACKERS.Get(inst)) != null) { foreach (var tracker in trackers) { // Search for tracker that matches both world ID and wildness type if (tracker is T ct && ct.WorldID == id && ct.Type == type && (filter == null || filter.Invoke(ct))) { result = ct; break; } } } return(result); }
/// <summary> /// Creates a resource category header for critters. /// </summary> /// <param name="type">The critter type to create.</param> /// <returns>The heading for that critter type.</returns> private CritterResourceRowGroup Create(CritterType type) { var spawn = Util.KInstantiateUI(allResources.categoryLinePrefab, allResources. rootListContainer, true); // Create a heading for Critter (Type) PUtil.LogDebug("Creating Critter ({0}) category".F(type.GetProperName())); var refs = spawn.GetComponent <HierarchyReferences>(); // Set up chart var graphBase = refs.GetReference <SparkLayer>("Chart").GetComponent <GraphBase>(); graphBase.axis_x.min_value = 0f; graphBase.axis_x.max_value = 600f; graphBase.axis_x.guide_frequency = 120f; graphBase.RefreshGuides(); // Component which actually handles updating var rg = spawn.AddComponent <CritterResourceRowGroup>(); rg.CritterType = type; refs.GetReference <LocText>("NameLabel").SetText(rg.Title); return(rg); }
/// <summary> /// Gets the total quantity of each critter of a specific type. /// </summary> /// <param name="type">The critter type, wild or tame.</param> /// <param name="results">The location to populate the results per species.</param> /// <returns>The total quantity of critters of that type.</returns> internal CritterTotals PopulateTotals(CritterType type, IDictionary <Tag, CritterTotals> results) { if (!counts.TryGetValue(type, out CritterInventoryPerType byType)) { throw new ArgumentOutOfRangeException(nameof(type)); } var all = new CritterTotals(); foreach (var pair in byType) { var totals = pair.Value; var species = pair.Key; if (results != null && !results.ContainsKey(species)) { results.Add(species, totals); } all.Total += totals.Total; all.Reserved += totals.Reserved; } return(all); }
/// <summary> /// Gets the description for a critter type, localized to ONI's language. /// </summary> /// <param name="type">The critter type.</param> /// <returns>The localized name for display.</returns> internal static string GetProperName(this CritterType type) { string typeStr; switch (type) { case CritterType.Tame: typeStr = STRINGS.CREATURES.MODIFIERS.TAME.NAME; break; case CritterType.Wild: typeStr = STRINGS.CREATURES.MODIFIERS.WILD.NAME; break; case CritterType.Artificial: typeStr = CritterInventoryStrings.CREATURES.MODIFIERS.ARTIFICIAL.NAME; break; default: throw new InvalidOperationException("Unsupported critter type " + type); } return(typeStr); }
internal string CompletionBBCode(CritterType crType, bool partial = false, int columns = 5, bool fonlineRu = false) { string newLine = string.Empty; string tableStart = !fonlineRu ? "[table]" : "[xtable]{tbody}"; string tableEnd = !fonlineRu ? "[/table]" : "{/tbody}[/xtable]"; char tagOpen = !fonlineRu ? '[' : '{'; char tagClose = !fonlineRu ? ']' : '}'; var rawtag = new Func <string, string, string>((id, text) => { string bb = id.Split(new char[] { '=' }, 2)[0]; return('[' + id + ']' + text + "[/" + bb + ']'); }); var tag = new Func <string, string, string>((id, text) => { string bb = id.Split(new char[] { '=' }, 2)[0]; return(tagOpen + id + tagClose + text + tagOpen + '/' + bb + tagClose); }); var td = new Func <string, string>(text => { return(tag("td", text)); }); var tr = new Func <string, string>(text => { return(tag("tr", text)); }); var animComplete = new Func <CritterAnimation, bool>((crAnim) => { foreach (CritterAnimationDir dir in crAnim.Dir) { if (dir == CritterAnimationDir.None) { return(false); } } return(true); }); string result = tableStart + newLine; List <List <string> > groups = new List <List <string> >(); foreach (string groupNameStr in main.ValidAnimationsGroups) { char groupNameChar = groupNameStr[0]; string groupName = main.GetControl(main.AnimGroup + groupNameChar).Text; if (partial && crType[groupNameChar] == null) { continue; } List <string> group = new List <string>(); group.Add(td(rawtag("b", groupName))); List <string> animList = main.ValidAnimations.FindAll(anim => anim.StartsWith(groupNameStr)); foreach (string anim in animList) { string animName = main.GetControl(main.AnimLink + anim).Text; CritterAnimation crAnim = crType[anim]; if (crAnim == null) { group.Add(td(rawtag("color=red", animName))); } else if (animComplete(crAnim)) { group.Add(td(rawtag("color=green", animName))); } else { string[] dirName = { "NE", "E", "SE", "SW", "W", "NW" }; List <string> dirDone = new List <string>(); for (int dir = 0; dir <= 5; dir++) { if (crAnim.Dir[dir] == CritterAnimationDir.None) { continue; } dirDone.Add(dirName[dir]); } animName += " (" + string.Join(",", dirDone.ToArray()) + ")"; group.Add(td(rawtag("color=yellow", animName))); } } groups.Add(group); } int curr = 0; List <string> lines = new List <string>(), rlines = new List <string>(); int linesH = 0; foreach (List <string> group in groups) { if (++curr > columns) { foreach (string line in lines) { result += tr(line) + newLine; } lines.Clear(); curr = 1; linesH = 0; } if (linesH < group.Count) { linesH = group.Count; } if (lines.Count == 0) { lines.AddRange(group); } else { for (int l = 0; l < linesH; l++) { if (l >= lines.Count) { string line = string.Empty; for (int x = 1; x < curr; x++) { line += td(""); } lines.Add(line); } if (l >= group.Count) { group.Add(td("")); } lines[l] += group[l]; } } } foreach (string line in lines) { result += tr(line) + newLine; } result += tableEnd + newLine; return(result); }
/// <summary> /// Gets the proper, localized heading for a critter resource entry. /// </summary> /// <param name="species">The critter species.</param> /// <param name="type">The critter domestication type.</param> /// <returns>The title for that entry.</returns> internal static string GetTitle(Tag species, CritterType type) { return(string.Format("{0} ({1})", species.ProperNameStripLink(), type. GetProperName())); }
private void frmChecker_DoWork( object sender, DoWorkEventArgs e ) { BackgroundWorker self = (BackgroundWorker)sender; frmCheckerConfig config = (frmCheckerConfig)e.Argument; List<object> files = new List<object>(); object datafile = null; if( !OpenDatafile( ref datafile, config.Target, config.LoadMode ) ) { self.ReportProgress( (int)ProgressData.ErrorMessage, "Error opening " + config.Target ); return; } switch( config.LoadMode ) { case LoadModeType.Directory: string[] tmpfiles = Directory.GetFiles( config.Target, "*.FR?", SearchOption.TopDirectoryOnly ); foreach( string file in tmpfiles ) { files.Add( Path.GetFileName( file ) ); } break; case LoadModeType.Zip: ZipStorer zip = (ZipStorer)datafile; foreach( ZipStorer.ZipFileEntry entry in zip.ReadCentralDir() ) { if( entry.CompressedSize == 0 ) continue; string filename = entry.FilenameInZip.ToUpper() .Replace( '\\', Path.DirectorySeparatorChar ) .Replace( '/', Path.DirectorySeparatorChar ); if( !filename.StartsWith( ArtCritters ) ) continue; string extmp = Path.GetExtension( filename ); if( extmp.Length != 4 || extmp.Substring( 1, 2 ) != "FR" ) continue; files.Add( entry ); } break; case LoadModeType.Dat: DAT dat = (DAT)datafile; int idx = -1; foreach( DATFile entry in dat.FileList ) { idx++; string filename = entry.Path.ToUpper() .Replace( '\\', Path.DirectorySeparatorChar ) .Replace( '/', Path.DirectorySeparatorChar ); if( !filename.StartsWith( ArtCritters ) ) continue; string extmp = Path.GetExtension( filename ); if( extmp.Length != 4 || extmp.Substring( 1, 2 ) != "FR" ) continue; // DATLib doesn't care about FileIndex, so we have to if( idx == int.MaxValue ) { self.ReportProgress( (int)ProgressData.ErrorMessage, "Too many files" ); CloseDatafile( ref datafile, config.LoadMode ); return; } entry.FileIndex = idx; files.Add( entry ); } break; default: throw new NotSupportedException(); } if( files.Count == 0 ) { self.ReportProgress( (int)ProgressData.ErrorMessage, "No critter animations found" ); CloseDatafile( ref datafile, config.LoadMode ); return; } string baseName = null, animName = null, ext = null; int dir = -1; List<CritterType> crTypesFound = new List<CritterType>(); int currFile = 0, lastPercent = -1, filesCount = files.Count; foreach( object file in files ) { if( self.CancellationPending ) { CloseDatafile( ref datafile, config.LoadMode ); return; } int percent = (++currFile * 100) / filesCount; if( percent != lastPercent ) { lastPercent = percent; self.ReportProgress( percent, "Checking " + config.Target ); } string filename = null; switch( config.LoadMode ) { case LoadModeType.Directory: filename = (string)file; break; case LoadModeType.Zip: ZipStorer.ZipFileEntry zipEntry = (ZipStorer.ZipFileEntry)file; filename = zipEntry.FilenameInZip; break; case LoadModeType.Dat: DATFile datEntry = (DATFile)file; filename = datEntry.FileName; break; default: throw new NotSupportedException(); } if( !ValidNameFRM( filename, ref baseName, ref animName, ref dir, ref ext ) ) continue; CritterType crType = crTypesFound.Find( cr => cr.Name == baseName ); if( crType == null ) { crType = new CritterType( baseName ); crTypesFound.Add( crType ); self.ReportProgress( (int)ProgressData.CritterTypeName, crType.Name ); } if( crType[animName] == null ) { CritterAnimation crAnim = new CritterAnimation( animName ); crType.Animations.Add( crAnim ); } if( ext == "FRM" ) { if( config.FastCheck ) { for( int d = 0; d <= 5; d++ ) { CritterAnimation crAnim = crType[animName]; crAnim.Dir[d] = CritterAnimationDir.Full; if( config.LoadMode == LoadModeType.Zip ) crAnim.ZipData[d] = (ZipStorer.ZipFileEntry)file; else if( config.LoadMode == LoadModeType.Dat ) { DATFile datFile = (DATFile)file; crAnim.DatData[d] = (int)datFile.FileIndex; } } } else // !config.FastCheck { FalloutFRM frm = LoadFRM( datafile, file, config.LoadMode ); for( int d = 0; d <= 5; d++ ) { if( frm != null && frm.GetAnimFrameByDir( d, 1 ) != null ) { CritterAnimation crAnim = crType[animName]; if( crAnim.Dir[d] != CritterAnimationDir.Partial ) crAnim.Dir[d] = CritterAnimationDir.Full; if( config.LoadMode == LoadModeType.Zip ) crAnim.ZipData[d] = (ZipStorer.ZipFileEntry)file; else if( config.LoadMode == LoadModeType.Dat ) crAnim.DatData[d] = (int)((DATFile)file).FileIndex; } } } } else // !ext == "FRM"; { CritterAnimation crAnim = crType[animName]; if( config.FastCheck ) { crAnim.Dir[dir] = CritterAnimationDir.Partial; if( config.LoadMode == LoadModeType.Zip ) crAnim.ZipData[dir] = (ZipStorer.ZipFileEntry)file; else if( config.LoadMode == LoadModeType.Dat ) crAnim.DatData[dir] = (int)((DATFile)file).FileIndex; } else // !config.FastCheck { FalloutFRM frm = LoadFRM( datafile, file, config.LoadMode ); if( frm != null && frm.GetAnimFrameByDir( 0, 1 ) != null ) { crAnim.Dir[dir] = CritterAnimationDir.Partial; if( config.LoadMode == LoadModeType.Zip ) crAnim.ZipData[dir] = (ZipStorer.ZipFileEntry)file; else if( config.LoadMode == LoadModeType.Dat ) crAnim.DatData[dir] = (int)((DATFile)file).FileIndex; } } } object[] data = { baseName, animName, crType[animName] }; self.ReportProgress( (int)ProgressData.CritterAnimation, data ); } currFile = 0; lastPercent = -1; filesCount = crTypesFound.Count; foreach( CritterType crType in crTypesFound ) { int percent = (++currFile * 100) / filesCount; if( percent != lastPercent ) { self.ReportProgress( 100 - percent, "Caching critters preview..." ); } foreach( string anim in ValidAnimations ) { bool found = false; CritterAnimation crAnim = crType[anim]; if( crAnim != null ) { Bitmap[] frm = LoadFRM( datafile, crType, crAnim.Name, config.LoadMode ); if( frm == null ) continue; int[] dirs = { 3, 2, 4, 1, 5, 0 }; foreach( int d in dirs ) { if( frm[d] != null ) { object[] data = { crType.Name, frm[d] }; self.ReportProgress( (int)ProgressData.CritterPreview, data ); found = true; break; } } if( found ) break; } } } CloseDatafile( ref datafile, config.LoadMode ); self.ReportProgress( (int)ProgressData.Finish, config ); }
void AddCritterType( ZipStorer zip, CritterType crType ) { object datafile = null; if( !OpenCurrentDatafile( ref datafile ) ) return; List<CritterAnimationPacked> zipFiles = new List<CritterAnimationPacked>(); foreach( CritterAnimation crAnim in crType.Animations ) { List<string> nameList = new List<string>(); List<byte[]> bytesList = new List<byte[]>(); List<DateTime> dateList = new List<DateTime>(); string crName = crType.Name + crAnim.Name; for( int d = 0; d <= 5; d++ ) { if( crAnim.Dir[d] == CritterAnimationDir.None ) continue; string ext = ".FR" + (crAnim.Full ? "M" : d.ToString()); switch( LoadedMode ) { case LoadModeType.Directory: string filename = openDirectory.SelectedPath + Path.DirectorySeparatorChar + crName + ext; if( File.Exists( filename ) ) { zipFiles.Add( new CritterAnimationPacked( ArtCrittersZip + crName + ext, File.ReadAllBytes( filename ), File.GetLastWriteTime( filename ) ) ); } break; case LoadModeType.Zip: ZipStorer zipDatafile = (ZipStorer)datafile; MemoryStream stream = new MemoryStream(); zipDatafile.ExtractFile( crAnim.ZipData[d], stream ); zipFiles.Add( new CritterAnimationPacked( ArtCrittersZip + crName + ext, stream.ToArray(), crAnim.ZipData[d].ModifyTime ) ); break; case LoadModeType.Dat: DAT dat = (DAT)datafile; zipFiles.Add( new CritterAnimationPacked( ArtCrittersZip + crName + ext, dat.FileList[crAnim.DatData[d]].GetData(), DateTime.Now ) ); break; } if( crAnim.Full ) break; } } CloseCurrentDatafile( ref datafile ); foreach( CritterAnimationPacked crAnimPacked in zipFiles ) { MemoryStream stream = new MemoryStream( crAnimPacked.Bytes, false ); zip.AddStream( ZipStorer.Compression.Deflate, crAnimPacked.Filename, stream, crAnimPacked.Date, "" ); } }
private void frmChecker_ProgressChanged( object sender, ProgressChangedEventArgs e ) { if( e.ProgressPercentage == (int)ProgressData.CritterTypeName ) { string text = (string)e.UserState; if( text != null ) { CritterType crType = CritterTypes.Find( cr => cr.Name == text ); if( crType == null ) { crType = new CritterType( text ); CritterTypes.Add( crType ); } if( !lstCritters.Items.Contains( text ) ) { lstCritters.Items.Add( text ); lstCritters.Update(); } } } else if( e.ProgressPercentage == (int)ProgressData.CritterAnimation ) { object[] data = (object[])e.UserState; string baseName = (string)data[0]; string animName = (string)data[1]; CritterAnimation anim = (CritterAnimation)data[2]; CritterType crType = CritterTypes.Find( cr => cr.Name == baseName ); crType.Animations.RemoveAll( a => a.Name == anim.Name ); crType.Animations.Add( anim ); } else if( e.ProgressPercentage == (int)ProgressData.CritterPreview ) { object[] data = (object[])e.UserState; string baseName = (string)data[0]; Bitmap preview = (Bitmap)data[1]; CritterType crType = CritterTypes.Find( cr => cr.Name == baseName ); crType.Preview = preview; } else if( e.ProgressPercentage == (int)ProgressData.ErrorMessage ) { string text = (string)e.UserState; if( text != null && text.Length > 0 ) { MessageBox.Show( text, BaseText, MessageBoxButtons.OK, MessageBoxIcon.Error ); } } else if( e.ProgressPercentage == (int)ProgressData.Finish ) { frmCheckerConfig config = (frmCheckerConfig)e.UserState; Text = BaseText + " : " + config.Target; LoadedMode = config.LoadMode; LoadedTarget = config.Target; LoadedFast = config.FastCheck; menuFileExport.Enabled = menuOptionsTarget.Enabled = true; if( config.ShowCompletion != null ) { if( lstCritters.Items.Contains( config.ShowCompletion ) ) { lstCritters.SelectedItem = config.ShowCompletion; button1_Click( null, null ); } else { MessageBox.Show( "Cannot find '" + config.ShowCompletion + "' critter" ); lstCritters.SelectedIndex = 0; } } else lstCritters.SelectedIndex = 0; EnableControls( true ); } else if( e.ProgressPercentage >= 0 ) { if( !statusProgress.Visible ) statusProgress.Visible = true; statusProgress.Value = e.ProgressPercentage; statusProgress.ToolTipText = e.ProgressPercentage + "%"; statusLabel.Text = "[" + e.ProgressPercentage + "%]"; string text = (string)e.UserState; if( text != null ) statusLabel.Text += " " + text; status.Update(); } else { MessageBox.Show( "Unknown progress type : " + e.ProgressPercentage ); } }
private void lstCritters_SelectedValueChanged( object sender, EventArgs e ) { ListBox self = (ListBox)sender; if( self.SelectedItem == null ) return; if( self.SelectedIndex == PrevSelectedCritterIndex ) return; else PrevSelectedCritterIndex = self.SelectedIndex; //ResetAnimations(); string baseName = (string)self.SelectedItem; CurrentCritterType = CritterTypes.Find( cr => cr.Name == baseName ); foreach( string crAnimName in ValidAnimations ) { CheckState state = CheckState.Unchecked; CritterAnimation crAnim = CurrentCritterType[crAnimName]; if( crAnim != null ) { if( crAnim.AllDirs ) state = CheckState.Checked; else state = CheckState.Indeterminate; } CheckBox check = (CheckBox)GetControl( AnimCheck + crAnimName ); check.CheckState = state; LinkLabel link = (LinkLabel)GetControl( AnimLink + crAnimName ); link.Enabled = state != CheckState.Unchecked; } RefreshFalloutFOnline( CurrentCritterType, true ); if( CurrentCritterType.Preview != null ) { animPreview.Size = new Size( CurrentCritterType.Preview.Width, CurrentCritterType.Preview.Height ); animPreview.Image = CurrentCritterType.Preview; animPreview.Update(); animPreview.Show(); } }
protected BaseCritterTracker(int worldID, CritterType type) : base(worldID) { Type = type; }
/// <summary> /// Refreshs text for falloutCrittersLst and fonlineCritterTypesCfg /// </summary> private void RefreshFalloutFOnline( CritterType crType = null, bool controls = false ) { if( crType == null ) { if( CurrentCritterType != null ) crType = CurrentCritterType; else return; } if( controls ) { falloutAlias.Value = crType.Alias; fonlineEnabled.CheckState = (crType.Enabled ? CheckState.Checked : CheckState.Unchecked); fonlineID.Value = crType.ID; fonlineAlias.Value = crType.Alias; fonlineMultihex.Value = crType.Multihex; fonlineAim.CheckState = (crType.Aim ? CheckState.Checked : CheckState.Unchecked); fonlineAim.CheckState = (crType.Armor ? CheckState.Checked : CheckState.Unchecked); fonlineRotate.CheckState = (crType.Rotate ? CheckState.Checked : CheckState.Unchecked); fonlineWalk.Value = crType.Walk; fonlineRun.Value = crType.Run; fonlineSteps1.Value = crType.Step1; fonlineSteps2.Value = crType.Step2; fonlineSteps3.Value = crType.Step3; fonlineSteps4.Value = crType.Step4; fonlineSound.Text = crType.Sound; fonlineComment.Text = crType.Comment; } falloutCrittersLst.Text = crType.ToFalloutString(); fonlineCritterTypesCfg.Text = crType.ToFOnlineString( fonlineCritterTypesCfg.Multiline ); }
public AllCritterTracker(int worldID, CritterType type) : base(worldID, type) { }
internal string CompletionBBCode( CritterType crType, bool partial = false, int columns = 5, bool fonlineRu = false ) { string newLine = string.Empty; string tableStart = !fonlineRu ? "[table]" : "[xtable]{tbody}"; string tableEnd = !fonlineRu ? "[/table]" : "{/tbody}[/xtable]"; char tagOpen = !fonlineRu ? '[' : '{'; char tagClose = !fonlineRu ? ']' : '}'; var rawtag = new Func<string, string, string>( ( id, text ) => { string bb = id.Split( new char[] { '=' }, 2 )[0]; return ('[' + id + ']' + text + "[/" + bb + ']'); } ); var tag = new Func<string, string, string>( ( id, text ) => { string bb = id.Split( new char[] { '=' }, 2 )[0]; return (tagOpen + id + tagClose + text + tagOpen + '/' + bb + tagClose); } ); var td = new Func<string, string>( text => { return (tag( "td", text )); } ); var tr = new Func<string, string>( text => { return (tag( "tr", text )); } ); var animComplete = new Func<CritterAnimation, bool>( ( crAnim ) => { foreach( CritterAnimationDir dir in crAnim.Dir ) { if( dir == CritterAnimationDir.None ) return (false); } return (true); } ); string result = tableStart + newLine; List<List<string>> groups = new List<List<string>>(); foreach( string groupNameStr in main.ValidAnimationsGroups ) { char groupNameChar = groupNameStr[0]; string groupName = main.GetControl( main.AnimGroup + groupNameChar ).Text; if( partial && crType[groupNameChar] == null ) continue; List<string> group = new List<string>(); group.Add( td( rawtag( "b", groupName ) ) ); List<string> animList = main.ValidAnimations.FindAll( anim => anim.StartsWith( groupNameStr ) ); foreach( string anim in animList ) { string animName = main.GetControl( main.AnimLink + anim ).Text; CritterAnimation crAnim = crType[anim]; if( crAnim == null ) group.Add( td( rawtag( "color=red", animName ) ) ); else if( animComplete( crAnim ) ) group.Add( td( rawtag( "color=green", animName ) ) ); else { string[] dirName = { "NE", "E", "SE", "SW", "W", "NW" }; List<string> dirDone = new List<string>(); for( int dir = 0; dir <= 5; dir++ ) { if( crAnim.Dir[dir] == CritterAnimationDir.None ) continue; dirDone.Add( dirName[dir] ); } animName += " (" + string.Join( ",", dirDone.ToArray() ) + ")"; group.Add( td( rawtag( "color=yellow", animName ) ) ); } } groups.Add( group ); } int curr = 0; List<string> lines = new List<string>(), rlines = new List<string>(); int linesH = 0; foreach( List<string> group in groups ) { if( ++curr > columns ) { foreach( string line in lines ) { result += tr( line ) + newLine; } lines.Clear(); curr = 1; linesH = 0; } if( linesH < group.Count ) linesH = group.Count; if( lines.Count == 0 ) lines.AddRange( group ); else { for( int l = 0; l < linesH; l++ ) { if( l >= lines.Count ) { string line = string.Empty; for( int x = 1; x < curr; x++ ) { line += td( "" ); } lines.Add( line ); } if( l >= group.Count ) { group.Add( td( "" ) ); } lines[l] += group[l]; } } } foreach( string line in lines ) { result += tr( line ) + newLine; } result += tableEnd + newLine; return (result); }
internal string CompletionText( CritterType crType, bool part = true ) { string result = crType.Name + Environment.NewLine; var groupComplete = new Func<char, bool>( ( groupName ) => { List<string> animList = main.ValidAnimations.FindAll( name => name.StartsWith( groupName.ToString() ) ); foreach( string anim in animList ) { CritterAnimation crAnim = crType[anim]; if( crAnim == null || !crAnim.Full ) return (false); } return (true); } ); var animComplete = new Func<CritterAnimation, bool>( ( crAnim ) => { foreach( CritterAnimationDir dir in crAnim.Dir ) { if( dir == CritterAnimationDir.None ) return (false); } return (true); } ); List<string> complete = new List<string>(); List<string> partial = new List<string>(); List<string> missing = new List<string>(); bool firstPartial = true; foreach( string groupNameStr in main.ValidAnimationsGroups ) { char groupNameChar = groupNameStr[0]; string groupName = main.GetControl( main.AnimGroup + groupNameChar ).Text; if( groupComplete( groupNameChar ) ) { complete.Add( " " + groupName ); } else { if( crType[groupNameChar] == null ) { if( !part ) missing.Add( " " + groupName ); continue; } if( firstPartial ) firstPartial = false; else partial.Add( "" ); partial.Add( " " + groupName + ":" ); List<CritterAnimation> list = crType.Animations.FindAll( cr => cr.Name.StartsWith( groupNameChar.ToString() ) ); foreach( CritterAnimation crAnim in list ) { string animName = " - " + main.GetControl( main.AnimLink + crAnim.Name ).Text; if( !animComplete( crAnim ) ) { string[] dirName = { "NE", "E", "SE", "SW", "W", "NW" }; List<string> dirDone = new List<string>(); for( int dir = 0; dir <= 5; dir++ ) { if( crAnim.Dir[dir] == CritterAnimationDir.None ) continue; dirDone.Add( dirName[dir] ); } animName += " (" + string.Join( ",", dirDone.ToArray() ) + ")"; } partial.Add( animName ); } } } if( complete.Count > 0 ) { result += Environment.NewLine; result += "Completed sets:" + Environment.NewLine; foreach( string name in complete ) { result += name + Environment.NewLine; } } if( partial.Count > 0 ) { result += Environment.NewLine; result += "Partial sets:" + Environment.NewLine; foreach( string name in partial ) { result += name + Environment.NewLine; } } if( missing.Count > 0 ) { result += Environment.NewLine; result += "Missing sets:" + Environment.NewLine; foreach( string name in missing ) { result += name + Environment.NewLine; } } return (result); }
internal string CompletionText(CritterType crType, bool part = true) { string result = crType.Name + Environment.NewLine; var groupComplete = new Func <char, bool>((groupName) => { List <string> animList = main.ValidAnimations.FindAll(name => name.StartsWith(groupName.ToString())); foreach (string anim in animList) { CritterAnimation crAnim = crType[anim]; if (crAnim == null || !crAnim.Full) { return(false); } } return(true); }); var animComplete = new Func <CritterAnimation, bool>((crAnim) => { foreach (CritterAnimationDir dir in crAnim.Dir) { if (dir == CritterAnimationDir.None) { return(false); } } return(true); }); List <string> complete = new List <string>(); List <string> partial = new List <string>(); List <string> missing = new List <string>(); bool firstPartial = true; foreach (string groupNameStr in main.ValidAnimationsGroups) { char groupNameChar = groupNameStr[0]; string groupName = main.GetControl(main.AnimGroup + groupNameChar).Text; if (groupComplete(groupNameChar)) { complete.Add(" " + groupName); } else { if (crType[groupNameChar] == null) { if (!part) { missing.Add(" " + groupName); } continue; } if (firstPartial) { firstPartial = false; } else { partial.Add(""); } partial.Add(" " + groupName + ":"); List <CritterAnimation> list = crType.Animations.FindAll(cr => cr.Name.StartsWith(groupNameChar.ToString())); foreach (CritterAnimation crAnim in list) { string animName = " - " + main.GetControl(main.AnimLink + crAnim.Name).Text; if (!animComplete(crAnim)) { string[] dirName = { "NE", "E", "SE", "SW", "W", "NW" }; List <string> dirDone = new List <string>(); for (int dir = 0; dir <= 5; dir++) { if (crAnim.Dir[dir] == CritterAnimationDir.None) { continue; } dirDone.Add(dirName[dir]); } animName += " (" + string.Join(",", dirDone.ToArray()) + ")"; } partial.Add(animName); } } } if (complete.Count > 0) { result += Environment.NewLine; result += "Completed sets:" + Environment.NewLine; foreach (string name in complete) { result += name + Environment.NewLine; } } if (partial.Count > 0) { result += Environment.NewLine; result += "Partial sets:" + Environment.NewLine; foreach (string name in partial) { result += name + Environment.NewLine; } } if (missing.Count > 0) { result += Environment.NewLine; result += "Missing sets:" + Environment.NewLine; foreach (string name in missing) { result += name + Environment.NewLine; } } return(result); }
private void updateCritterState() { if (waveLevel < Constants.CritterLevelLength) { crittersLevel = CritterType.LowLevel; } else if (waveLevel < (Constants.CritterLevelLength * 2)) { crittersLevel = CritterType.MediumLevel; } else { crittersLevel = CritterType.HighLevel; } }
public CritterTracker(int worldID, Tag creatureTag, CritterType type) : base(worldID, type) { Tag = creatureTag; }
Bitmap[] LoadFRM( object datafile, CritterType crType, string animName, LoadModeType loadMode ) { CritterAnimation crAnim = crType[animName]; object[] files = new object[crAnim.Full ? 1 : 6]; for( uint d = 0; d <= 5; d++ ) { if( crAnim.Dir[d] == CritterAnimationDir.None ) continue; switch( loadMode ) { case LoadModeType.Directory: string directory = (string)datafile; files[d] = crType.Name + animName + ".FR" + (crAnim.Dir[d] == CritterAnimationDir.Full ? "M" : d.ToString()); break; case LoadModeType.Zip: files[d] = crAnim.ZipData[d]; break; case LoadModeType.Dat: DAT dat = (DAT)datafile; files[d] = dat.FileList[crAnim.DatData[d]]; break; } if( crAnim.Full ) break; } Bitmap[] result = new Bitmap[6]; if( files.Length == 1 && files[0] != null ) { FalloutFRM frm = LoadFRM( datafile, files[0], loadMode ); if( frm != null ) { for( int d = 0; d <= 5; d++ ) { result[d] = frm.GetAnimFrameByDir( d, 1 ); } } } else { for( int d = 0; d <= 5; d++ ) { if( files[d] == null ) continue; FalloutFRM frm = LoadFRM( datafile, files[d], loadMode ); if( frm == null ) continue; foreach( Bitmap bmp in frm.Frames ) { if( bmp != null ) { result[d] = bmp; break; } } } } return (result); }