Exemplo n.º 1
0
    private /*static*/ DmiIcon tryGetInventoryIcon(/*DmiIconData dmi, string[] invSheetPaths, string icon = ""*/)
    {
        //determining invIcon
        for (int i = 0; i < invSheetPaths.Length; i++)
        {
            var iconPath = DmiIconData.getIconPath(invSheetPaths[i]); //add extension junk
            if (!iconPath.Equals("") && DmiIconData.Data.ContainsKey(iconPath) && icon.Equals(""))
            {
                //					Debug.Log(name + ": iSheet = dmi.DataHier[" + iconPath +"] = " + dmi.Data[iconPath]);
                return(DmiIconData.Data[iconPath]);
            }
        }

        if (!icon.Equals(""))
        {
            //				Debug.Log(name + ": iSheet = dmi.DataIcon["+icon+"] = "+iSheet);
            return(DmiIconData.Data[icon]);
        }
        //pretty bad choice, should use this only as last resort as it's usually pretty inaccurate
        var invIcon = dmi.getIconByState(icon_state);

        if (invIcon != null)
        {
            Debug.LogWarningFormat("{0} is doing bad dmi.getIconByState({1}) = {2}", name, icon_state, invIcon.icon);
            return(invIcon);
        }
        //			Debug.LogError();
        return(new DmiIcon());
    }
Exemplo n.º 2
0
    /// <summary>
    /// Tries to get the inventory icon for the unicloth with the specified hier string
    /// </summary>
    /// <param name="hier">hier to get the icon for</param>
    /// <param name="invSheetPaths">Pass the cached value here to speed up the method.
    /// Sheet paths to get it from, if null will be looked up from the hier.</param>
    /// <param name="icon">Pass a value here to speed up the method.
    /// icon to get, if null will be looked up from the hier.</param>
    /// <param name="icon_state">Pass a value here to speed up the method.
    /// icon_state of the icon to get, if null will be looked up from the hier.</param>
    /// <returns>DmiIcon for the specified hier, empty DmiIcon if unable</returns>
    public static DmiIcon GetInventoryIcon(string hier, string[] invSheetPaths = null, string icon = null, string icon_state = null)
    {
        EnsureInit();
        var objectAttrs = icon == null || icon_state == null?dm.getObject(hier) : null;

        if (icon == null)
        {
            objectAttrs.TryGetValue("icon", out icon);
            icon = icon ?? "";
        }
        if (icon_state == null)
        {
            objectAttrs.TryGetValue("icon_state", out icon_state);
            icon_state = icon_state ?? "";
        }

        invSheetPaths = invSheetPaths ?? GetItemClothSheetHier(GetItemType(hier));
        //determining invIcon
        for (int i = 0; i < invSheetPaths.Length; i++)
        {
            string iconPath = DmiIconData.getIconPath(invSheetPaths[i]);             //add extension junk
            if (!iconPath.Equals("") && DmiIconData.Data.ContainsKey(iconPath) && icon.Equals(""))
            {
                //					Logger.Log(name + ": iSheet = dmi.DataHier[" + iconPath +"] = " + dmi.Data[iconPath]);
                return(DmiIconData.Data[iconPath]);
            }
        }

        if (!icon.Equals(""))
        {
            //				Logger.Log(name + ": iSheet = dmi.DataIcon["+icon+"] = "+iSheet);
            return(DmiIconData.Data[icon]);
        }
        //pretty bad choice, should use this only as last resort as it's usually pretty inaccurate
        DmiIcon invIcon = dmi.getIconByState(icon_state);

        if (invIcon != null)
        {
            Logger.Log($"UniItemUtils is doing bad dmi.getIconByState({icon_state}) = {invIcon.icon}", Category.DmMetadata);
            return(invIcon);
        }
        //			Logger.LogError();
        return(new DmiIcon());
    }