Example #1
0
    /// <summary>
    /// Draws the UI for the current town.
    /// </summary>

    void DrawTownUI()
    {
        Vector2 mousePos = UI.GetMousePos();
        Rect    rect     = new Rect(Screen.width * 0.5f + 130f, Screen.height * 0.5f - 260f, 292f, 270f);

        // Allow the opposite town's resources to be dragged straight to this window for simplicity's sake
        if (mDragResource != -1 && Input.GetMouseButtonUp(0) && rect.Contains(mousePos))
        {
            if (mDragTown == this)
            {
                mDragTown = null;
            }
            mSelectedRoute.SetExportedResource(mDragTown, mDragResource);
            CancelDrag();
        }

        // Draw the resources
        Rect inner = UI.DrawWindow(rect, name);

        DrawResources(this, inner);

        inner.y     += inner.height - 40f;
        inner.height = 40f;

        if (GUI.Button(inner, "Establish a New Trade Route", Config.Instance.skin.button))
        {
            showInfo = false;
            TradeRouteCreator.Instance.StartNewTradeRoute(this);
        }

        if (mSelectedRoute != null)
        {
            rect = new Rect(rect.x, Screen.height * 0.5f + 40f, 292f, 225f);

            // Allow main town's resources to be dragged straight to this window for simplicity's sake
            if (mDragResource != -1 && Input.GetMouseButtonUp(0) && rect.Contains(mousePos))
            {
                if (mDragTown != this)
                {
                    mDragTown = null;
                }
                mSelectedRoute.SetExportedResource(mDragTown, mDragResource);
                CancelDrag();
            }

            Town town = mSelectedRoute.GetConnectedTown(this);
            inner = UI.DrawWindow(rect, town.name);

            // See if we have more than one trade route
            TradeRoute next = TradeRoute.FindNext(mSelectedRoute, this, true);

            // Draw trade route navigation buttons
            if (next != mSelectedRoute)
            {
                if (GUI.Button(new Rect(rect.x + 20f, rect.y - 18f, 40f, 40f), "<<", Config.Instance.skin.button))
                {
                    mSelectedRoute = next;
                }
                else if (GUI.Button(new Rect(rect.x + rect.width - 60f, rect.y - 18f, 40f, 40f), ">>", Config.Instance.skin.button))
                {
                    mSelectedRoute = TradeRoute.FindNext(mSelectedRoute, this, false);
                }
            }
            DrawResources(town, inner);
        }
    }