Exemplo n.º 1
0
    }//end ShowGroup

    bool ShowItem(int g, int i, int sel)
    {//return a bool depending on if the item has buy or sell selected
        CallumP.TradeSys.Stock stock = nearPost.stock[g].stock[i];
        if (sel == 0 && stock.sell || sel == 1 && stock.buy)//if buy check and sell at tp enabled, or sell check and buy at tp enabled
            return true;//return true
        return false;//else return false
    }//end ShowItem
Exemplo n.º 2
0
    void ShowShop()
    {//show the shop view
        GUI.Label(new Rect(10, 50, 250, 80), "Cash: " + cash + "\nSpace remaining: " + spaceRemaining.ToString("F2") + unitLabel);
        //a label showing the cash that the player has and the space remaining plus the maximum unit

        selected = GUI.Toolbar(new Rect(Screen.width - 200, 10, 130, 30), selected, new string[] {
                        "Buy",
                        "Sell"
                });
        //show a toolbar with the options to exit, buy and sell goods		

        scrollPos = GUI.BeginScrollView(new Rect(10, 100, Screen.width - 20, Screen.height - 110), scrollPos, new Rect(0, 0, 910, HeightCalc(selected)));
        //show all of the items inside a scroll view

        int labelPos = 0;

        for (int g = 0; g < controller.goods.Count; g++)
        {//go through all groups
            if (ShowGroup(g, selected))
            {//only need to go through items if at least one is enabled
                GUI.Label(new Rect(10, labelPos * 30, 100, 30), controller.goods[g].name);//show the name of the group
                labelPos++;//increase label pos so next will be displayed a line below
                for (int i = 0; i < controller.goods[g].goods.Count; i++)
                {//go through all items
                    if (ShowItem(g, i, selected))
                    {//if the item is to be shown

                        CallumP.TradeSys.Goods cG = controller.goods[g].goods[i];//get the controller good details
                        CallumP.TradeSys.Stock pS = nearPost.stock[g].stock[i];//get the trade post stock details

                        GUI.Label(new Rect(50, labelPos * 30, 150, 30), cG.name);//show the name of the item
                        GUI.Label(new Rect(210, labelPos * 30, 150, 30), "Mass: " + cG.unit);//show the mass of the item with the unit
                        GUI.Label(new Rect(370, labelPos * 30, 150, 30), "Post has: " + pS.number);//the number that the trade post has

                        float itemCost = selected == 0 ? pS.price : Mathf.RoundToInt(pS.price * controller.purchasePercent);
                        //if is in buy mode, the item cost is the standard price, if selling, need to multiply by purhcase percent

                        GUI.Label(new Rect(530, labelPos * 30, 150, 30), "Price: " + itemCost);
                        //show the price of the item. if it is in sell mode, then multiply the price by the trade psost purchase percent

                        GUI.Label(new Rect(690, labelPos * 30, 150, 30), "You have: " + cargo[g][i]);
                        //above shows a label with the number the player is carrying. if cargo index is -1, then it is not carrying the item

                        if (GUI.Button(new Rect(850, labelPos * 30, 50, 30), (selected == 0 ? "Buy" : "Sell")))
                        {//show a buy/sell button
                            if (selected == 0)
                            {//if is buy mode
                                if (cash >= itemCost && spaceRemaining >= cG.mass && pS.number > 0)
                                {//check if valid purchase
                                    pS.number--;//remove from trade post
                                    nearPost.currencies[cG.currencyID] += itemCost;//pay trade post cash
                                    cash -= itemCost;//withdraw cash from trader
                                    spaceRemaining -= cG.mass;//remove cargo space

                                    cargo[g][i]++;//add to the cargo being carried
                                }//end purchase validity check
                            }
                            else
                            {//else sell mode
                                if (nearPost.currencies[cG.currencyID] >= itemCost && cargo[g][i] > 0)
                                {//check if valid sale
                                    pS.number++;//add to trade post
                                    nearPost.currencies[cG.currencyID] -= itemCost;//withdraw cash from trade post
                                    cash += itemCost;//receive cash
                                    spaceRemaining += cG.mass;//add space back

                                    cargo[g][i]--;
                                }//end sale validity check
                            }//end buy/sell mode
                        }//end if pressed buy/sell button

                        labelPos++;//increase labelPos
                    }//end if showing item
                }//end for all items
            }//end if group showing
        }//end for goods groups

        GUI.EndScrollView();//end the scroll view
    }//end ShowShop