예제 #1
0
    /// <summary>
    /// Draws the traded resources.
    /// </summary>

    void DrawTradedResourcesUI(List <Vector2> grid, Town town)
    {
        int index = 0;

        foreach (TradeRoute.Item item in mSelectedRoute.items)
        {
            if (item.town == town)
            {
                Vector2      v  = grid[index];
                TownResource tr = TownResources.Instance.list[item.id];
                if (tr.icon != null)
                {
                    UI.DrawTexture(v.x, v.y, tr.icon);
                }
                Rect iconRect = new Rect(v.x, v.y, 50f, 50f);

                // It should be possible to drag these icons
                if (Input.GetMouseButtonDown(0) && iconRect.Contains(UI.GetMousePos()))
                {
                    CancelDrag();
                    mDragResource = item.id;
                    mDragTown     = item.town;
                }

                if (++index >= grid.Count)
                {
                    break;
                }
            }
        }
    }
예제 #2
0
    /// <summary>
    /// Draws the dragged resource icon.
    /// </summary>

    void DrawIconUI()
    {
        if (mDragResource != -1)
        {
            TownResource tr = TownResources.Instance.Get(mDragResource);

            if (tr.icon != null)
            {
                Vector2 mouse = UI.GetMousePos();
                UI.DrawTexture(mouse.x - tr.icon.width * 0.5f,
                               mouse.y - tr.icon.height * 0.5f, tr.icon);
            }
        }
        else
        {
            Texture2D icon = null;
            if (mDragPrefab != null)
            {
                icon = mDragPrefab.icon;
            }
            else if (mDragShip != null)
            {
                icon = mDragShip.prefab.icon;
            }

            if (icon != null)
            {
                // Draw the dragged icon
                Vector2 mouse = UI.GetMousePos();
                UI.DrawTexture(mouse.x - icon.width * 0.5f,
                               mouse.y - icon.height * 0.5f, icon);
            }
        }
    }
예제 #3
0
    public Vector2 GetIconSize()
    {
        TownResource tr = Get(0);

        if (tr != null && tr.icon != null)
        {
            return(new Vector2(tr.icon.width, tr.icon.height));
        }
        return(new Vector2(50.0f, 50.0f));
    }
예제 #4
0
    /// <summary>
    /// Tooltip callback function.
    /// </summary>

    void DrawTooltip(Vector2 pos, object param)
    {
        TownResource tr = param as TownResource;

        if (tr != null)
        {
            Rect rect = new Rect(pos.x - 100.0f, pos.y + 10.0f, 200.0f, 150.0f);
            rect = UI.DrawPanel(rect);

            GUILayout.BeginArea(rect);
            UI.DrawTitle(tr.name, Config.Instance.headerStyle);
            GUILayout.Label(tr.description, Config.Instance.skin.label);
            GUILayout.EndArea();
        }
    }
예제 #5
0
    /// <summary>
    /// Draws the town's resources.
    /// </summary>

    void DrawResources(Town town, Rect rect, Vector2 size, bool surplus)
    {
        // Draw the resource grid
        List <Vector2> grid = UI.DrawGrid(rect, size.x, size.y, 4f, 4f, 4f, 4);

        int  index     = 0;
        Town otherTown = (mSelectedRoute == null) ? null : mSelectedRoute.GetConnectedTown(town);

        foreach (Vector2 pos in grid)
        {
            if (index >= town.mResources.Count)
            {
                break;
            }

            // Run through all resources until we find the one we can draw
            for (; index < town.mResources.Count; ++index)
            {
                ResourceEntry ent = town.mResources[index];

                if ((surplus && ent.production > 0) || (!surplus && ent.production < 0))
                {
                    float alpha    = 1f;
                    Rect  iconRect = new Rect(pos.x, pos.y, size.x, size.y);

                    // Positive resources that the city is producing can be dragged
                    bool canDrag = (ent.production > 0);

                    // Don't allow dragging of resources which the other town doesn't actually need
                    if (mSelectedRoute == null)
                    {
                        canDrag = false;
                    }
                    else if (otherTown != null)
                    {
                        // If the other town doesn't need this resource, don't allow it to be dragged
                        if (otherTown.resources[index].production >= 0)
                        {
                            canDrag = false;
                        }
                    }

                    // If the resource cannot be dragged and it's in the surplus section, make it transparent
                    if (!canDrag && surplus)
                    {
                        alpha = 0.5f;
                    }

                    // If we're currently dragging this resource, make it transparent
                    if (mDragResource == index)
                    {
                        alpha = 0.5f;
                    }

                    // Allow dragging of positive production resources
                    if (canDrag && mSelectedRoute != null && Input.GetMouseButtonDown(0) && UI.ContainsMouse(iconRect))
                    {
                        mDragResource = index;
                        mDragTown     = town;
                    }

                    TownResource tr = TownResources.Instance.Get(index);

                    if (tr.icon != null)
                    {
                        Color prev = GUI.color;
                        GUI.color = new Color(1f, 1f, 1f, prev.a * alpha);
                        UI.DrawTexture(pos.x, pos.y, tr.icon);
                        GUI.color = prev;
                    }
                    Tooltip.AddArea(iconRect, DrawTooltip, tr);

                    // Stockpile amount caption (bottom-right)
                    {
                        int   amount = Mathf.RoundToInt(ent.warehouse);
                        Color color  = Color.white;
                        if (amount > 0)
                        {
                            color = Color.green;
                        }
                        else if (amount < 0)
                        {
                            color = Color.red;
                        }
                        UI.DrawLabel(iconRect, amount.ToString(), Config.Instance.infoStyle, color, Color.black, true);
                    }

                    // Production caption (top-left)
                    {
                        int   amount = ent.production;
                        Color color  = Color.white;
                        if (amount > 0)
                        {
                            color = Color.green;
                        }
                        else if (amount < 0)
                        {
                            color = Color.red;
                        }

                        TextAnchor anchor = Config.Instance.infoStyle.alignment;
                        Config.Instance.infoStyle.alignment = TextAnchor.UpperLeft;
                        UI.DrawLabel(iconRect, (amount < 0) ? amount.ToString() : ("+" + amount),
                                     Config.Instance.descStyle, color, new Color(0f, 0f, 0f, 0.5f), true);
                        Config.Instance.infoStyle.alignment = anchor;
                    }
                    ++index;
                    break;
                }
            }
        }
    }