Exemplo n.º 1
0
    void showClubs()
    {
        for (int i = 0; i < mClubs.Count; i++)
        {
            ClubInfo  club = mClubs[i];
            Transform item = getItem(i);

            setText(item, "name", club.name);
            setText(item, "desc", club.desc);
            setText(item, "id", "ID:" + club.id);
            setActive(item, "admin", club.is_admin);
            setText(item, "hc", club.member_num + " / " + club.max_member_num);
            setIcon(item, "bghead/icon", club.logo);

            UIButton btn = item.GetComponent <UIButton>();
            Color    cl  = club.is_admin ? new Color(0.26f, 0.26f, 0.26f) : new Color(0.06f, 0.06f, 0.06f);
            item.GetComponent <UISprite> ().color = cl;
            btn.hover   = cl;
            btn.pressed = cl;

            PUtils.onClick(item, () => {
                onBtnClub(club);
            });
        }

        updateItems(mClubs.Count);
    }
Exemplo n.º 2
0
    void showHistories()
    {
        List <RoomHistory> rooms = mHistory.rooms;

        onButtonSel(mHistory.statd);

        for (int i = 0; i < rooms.Count; i++)
        {
            Transform       item = getItem(i);
            RoomHistory     room = rooms[i];
            RoomHistoryInfo info = room.info;

            item.Find("roomid").GetComponent <UILabel>().text    = "房间号:" + room.room_tag;
            item.Find("club").GetComponent <UILabel>().text      = room.club_id == 1 ? room.club_name : "俱乐部:" + room.club_name;
            item.Find("desc").GetComponent <UILabel>().text      = info.huafen + "/" + info.huafen + (info.maima ? "带苍蝇" : "不带苍蝇") + info.maxGames + "局";
            item.Find("btn/score").GetComponent <UILabel>().text = "" + room.score;
            item.Find("date").GetComponent <UILabel>().text      = PUtils.formatTime(room.create_time, "MM-dd");
            item.Find("time").GetComponent <UILabel>().text      = PUtils.formatTime(room.create_time, "HH:mm");

            PUtils.onClick(item.Find("btn"), () => {
                enterDetail(room);
            });

            PUtils.onClick(item, () => {
                enterDetail(room);
            });
        }

        shrinkContent(rooms.Count);
        mGrid.GetComponent <UIGrid> ().Reposition();
        mGrid.GetComponentInParent <UIScrollView> ().ResetPosition();
    }
Exemplo n.º 3
0
    public void setBtnEvent(Transform item, string child, Action cb)
    {
        Transform btn = child == null ? item : getChild(item, child);

        if (btn != null)
        {
            PUtils.onClick(btn, cb);
        }
    }
Exemplo n.º 4
0
    public void showWait()
    {
        RoomMgr   rm    = RoomMgr.GetInstance();
        NetMgr    nm    = NetMgr.GetInstance();
        GameMaima maima = rm.state.maima;

        bool      act  = maima.seatindex == rm.seatindex;
        Transform mas  = tmaima.Find("mas");
        UIGrid    grid = mas.GetComponent <UIGrid>();

        tmaima.gameObject.SetActive(true);

        title.text = act ? "请选择飞苍蝇" : "请等待飞苍蝇";
        score.text = "";

        int count = maima.mas.Count;
        int i     = 0;

        for (i = 0; i < mas.childCount && i < count; i++)
        {
            Transform board = mas.GetChild(i);
            Transform tile  = board.Find("tile");
            FrameAnim anim  = board.GetComponent <FrameAnim>();

            board.gameObject.SetActive(true);

            tile.gameObject.SetActive(false);
            anim.reset();

            GameObject _fire = board.Find("fire").gameObject;
            _fire.SetActive(false);

            int j = i;

            PUtils.onClick(board, () => {
                if (!act)
                {
                    return;
                }

                nm.send("maima", "index", j);
            });
        }

        for (int j = i; j < mas.childCount; j++)
        {
            Transform board = mas.GetChild(j);
            board.gameObject.SetActive(false);
        }

        grid.Reposition();
    }
Exemplo n.º 5
0
    void Start()
    {
        RoomMgr rm = RoomMgr.GetInstance();

        Transform Seats = transform.Find("Seats");

        for (int i = 0; i < Seats.childCount; i++)
        {
            Transform s = Seats.GetChild(i);
            seats.Add(s.gameObject);

            Transform icon = s.Find("bghead");
            int       j    = rm.getSeatIndexByLocal(i);
            PUtils.onClick(icon, () => {
                PlayerInfo p = RoomMgr.GetInstance().players[j];
                GetComponent <UserPanel>().show(p.userid);
            });
        }

        Transform gs = transform.Find("Game/seats");

        for (int i = 0; i < gs.childCount; i++)
        {
            gseats.Add(gs.GetChild(i).gameObject);
        }

        InitSeats();
        InitEventHandlers();

        bool replay = ReplayMgr.GetInstance().isReplay();

        GameObject entries = transform.Find("Entries").gameObject;

        entries.SetActive(!replay);

        prepare.gameObject.SetActive(!replay);

        if (replay)
        {
            return;
        }

        NetMgr nm     = NetMgr.GetInstance();
        bool   isIdle = 0 == rm.info.numofgames;

        if (!isIdle)
        {
            nm.send("ready");
        }
    }
Exemplo n.º 6
0
    public void Awake()
    {
        layout();

        mGrid = transform.Find(listPath);
        if (mGrid != null)
        {
            mTemp        = mGrid.GetChild(0);
            mTemp.parent = null;
        }

        Transform btnBack = transform.Find("top/BtnBack");

        PUtils.onClick(btnBack, () => {
            back();
        });
    }
Exemplo n.º 7
0
    void Awake()
    {
        scroll = transform.Find(listPath).GetComponent <UIScrollView>();
        mGrid  = transform.Find(listPath + "/grid");
        InitEventHandler();

        Transform emojis = transform.Find("Chat/emoji/table");

        for (int i = 0; i < 20; i++)
        {
            int j = i;
            PUtils.onClick(emojis.GetChild(j), () => {
                onEmojiClicked(j);
            });
        }

        quicks.Add(new QuickChat("打快一点呀!", "1"));
        quicks.Add(new QuickChat("快点撒,我等到花儿都谢了!", "2"));
        quicks.Add(new QuickChat("牌太好了,打哪张呢?", "3"));
        quicks.Add(new QuickChat("不要乱催", "4"));
        quicks.Add(new QuickChat("别吵啦!", "5"));
        quicks.Add(new QuickChat("三缺一,我来的正好", "6"));
        quicks.Add(new QuickChat("被你这个老麻将盯上", "7"));
        quicks.Add(new QuickChat("见鬼了,这烂牌", "8"));
        quicks.Add(new QuickChat("喔天,打错牌了", "9"));
        quicks.Add(new QuickChat("风头不好,明天再约", "10"));
        quicks.Add(new QuickChat("输完回家睡觉", "11"));

        Transform qchats = transform.Find("Chat/qchats/grid");

        for (int i = 0; i < quicks.Count; i++)
        {
            int        j     = i;
            GameObject ob    = Instantiate(qcItem, qchats) as GameObject;
            UILabel    label = ob.GetComponentInChildren <UILabel>();
            QuickChat  qc    = quicks[i];

            label.text = qc.text;

            PUtils.onClick(ob, () => {
                onQuickChatClicked(j);
            });
        }

        qchats.GetComponent <UIGrid>().Reposition();
    }
Exemplo n.º 8
0
    void Awake()
    {
        info = transform.Find("UserPanel");

        nick = info.Find("nick").GetComponent <UILabel>();
        id   = info.Find("id").GetComponent <UILabel>();
        ip   = info.Find("ip").GetComponent <UILabel>();
        addr = info.Find("addr").GetComponent <UILabel>();
        icon = info.Find("bghead/icon").GetComponent <IconLoader>();

        Transform btnclose = info.Find("btn_close");

        PUtils.onClick(btnclose, () => {
            info.gameObject.SetActive(false);
        });

        Transform grid = info.Find("emojis/grid");

        for (int i = 0; i < grid.childCount; i++)
        {
            Transform child = grid.GetChild(i);
            int       j     = i;
            PUtils.onClick(child, () => {
                JsonObject ob = new JsonObject();
                ob.Add("id", j);
                ob.Add("target", userid);
                NetMgr.GetInstance().send("demoji", ob);
                close();
            });
        }

        grid = info.Find("semojis/grid");
        for (int i = 0; i < grid.childCount; i++)
        {
            Transform child = grid.GetChild(i);
            int       j     = i + 100;
            PUtils.onClick(child, () => {
                JsonObject ob = new JsonObject();
                ob.Add("id", j);
                ob.Add("target", userid);
                NetMgr.GetInstance().send("demoji", ob);
                close();
            });
        }
    }
Exemplo n.º 9
0
    void showChiOptions(int pai, List <int> types)
    {
        chiOpt.gameObject.SetActive(true);

        types.Sort((a, b) => { return(b - a); });

        NetMgr    nm   = NetMgr.GetInstance();
        Transform chis = chiOpt.Find("chis");

        int i = 0;

        for (i = 0; i < types.Count; i++)
        {
            int        type = types [i];
            Transform  chi  = chis.GetChild(i);
            List <int> arr  = RoomMgr.getChiArr(type * 100 + pai, true);

            chi.gameObject.SetActive(true);

            for (int j = 0; j < arr.Count; j++)
            {
                chi.GetChild(j).GetComponent <Mahjong2D>().setID(arr[j]);
            }

            PUtils.onClick(chi, () => {
                chiOpt.gameObject.SetActive(false);
                nm.send("chi", "type", type);
            });
        }

        for (int j = i; j < 3; j++)
        {
            chis.GetChild(j).gameObject.SetActive(false);
        }

        chis.GetComponent <UIGrid> ().Reposition();
    }
Exemplo n.º 10
0
        static int _m_onClick_xlua_st_(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);



                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 2 && translator.Assignable <UnityEngine.Transform>(L, 1) && translator.Assignable <System.Action>(L, 2))
                {
                    UnityEngine.Transform _ob = (UnityEngine.Transform)translator.GetObject(L, 1, typeof(UnityEngine.Transform));
                    System.Action         _cb = translator.GetDelegate <System.Action>(L, 2);

                    PUtils.onClick(_ob, _cb);



                    return(0);
                }
                if (gen_param_count == 2 && translator.Assignable <UnityEngine.GameObject>(L, 1) && translator.Assignable <System.Action>(L, 2))
                {
                    UnityEngine.GameObject _ob = (UnityEngine.GameObject)translator.GetObject(L, 1, typeof(UnityEngine.GameObject));
                    System.Action          _cb = translator.GetDelegate <System.Action>(L, 2);

                    PUtils.onClick(_ob, _cb);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to PUtils.onClick!"));
        }
Exemplo n.º 11
0
    public void showResult(Action cb)
    {
        RoomMgr   rm    = RoomMgr.GetInstance();
        NetMgr    nm    = NetMgr.GetInstance();
        GameMaima maima = rm.state.maima;

        bool      act  = false;
        Transform mas  = tmaima.Find("mas");
        UIGrid    grid = mas.GetComponent <UIGrid>();

        tmaima.gameObject.SetActive(true);

        title.text = "请等待飞苍蝇";
        score.text = "";

        int id    = maima.selected;
        int i     = 0;
        int count = maima.mas.Count;

        for (i = 0; i < mas.childCount && i < count; i++)
        {
            Transform board = mas.GetChild(i);
            Transform tile  = board.Find("tile");
            FrameAnim anim  = board.GetComponent <FrameAnim>();

            board.gameObject.SetActive(true);
            tile.gameObject.SetActive(false);
            anim.reset();

            PUtils.onClick(board, () => {});

            if (i == id)
            {
                continue;
            }

            int        _mjid = maima.mas[i];
            GameObject _fire = board.Find("fire").gameObject;
            _fire.SetActive(false);

            anim.run(() => {
                tile.gameObject.SetActive(true);
                UISprite t   = tile.GetComponent <UISprite>();
                t.spriteName = "" + _mjid;

                UISpriteData sp = t.GetAtlasSprite();
                t.width         = sp.width;
                t.height        = sp.height;
            });
        }

        for (int j = i; j < mas.childCount; j++)
        {
            Transform board = mas.GetChild(j);
            board.gameObject.SetActive(false);
        }

        grid.Reposition();

        int mjid = maima.mas[id];
        int add  = maima.scores[id];

        Transform  _board = mas.GetChild(id);
        FrameAnim  frame  = _board.GetComponent <FrameAnim>();
        Transform  _tile  = _board.Find("tile");
        GameObject fire   = _board.Find("fire").gameObject;

        fire.SetActive(true);

        frame.run(() => {
            _tile.gameObject.SetActive(true);
            UISprite t = _tile.GetComponent <UISprite>();

            t.spriteName    = "" + mjid;
            UISpriteData sp = t.GetAtlasSprite();
            t.width         = sp.width;
            t.height        = sp.height;

            _tile.localScale = new Vector3(1.8f, 1.8f, 1.0f);

            score.text = add > 0 ? "+" + add : "" + add;

            end(cb);
        });
    }
Exemplo n.º 12
0
    void addItem(ChatItem item)
    {
        Transform _item = getItem(mChatItems.Count);

        bool self = item.sender == GameMgr.getUserMgr().userid;

        Transform left    = _item.Find("left");
        Transform right   = _item.Find("right");
        Transform current = null;

        left.gameObject.SetActive(!self);
        right.gameObject.SetActive(self);
        current = self ? right : left;

        Debug.Log("setIcon: " + item.sender);
        GameObject icon   = current.Find("icon").gameObject;
        IconLoader loader = icon.AddComponent <IconLoader>();

        loader.setUserID(item.sender);
        //icon.GetComponent<IconLoader>().setUserID(item.sender);

        int        type      = item.type;
        GameObject btn_voice = current.Find("btn_voice").gameObject;
        GameObject voice     = current.Find("voice").gameObject;
        GameObject text      = current.Find("text").gameObject;
        GameObject len       = current.Find("len").gameObject;
        GameObject emoji     = current.Find("emoji").gameObject;

        item.vobj = voice;

        text.SetActive(type == 0 || type == 3);
        btn_voice.SetActive(type != 2);
        len.SetActive(type == 1);
        voice.SetActive(false);
        emoji.SetActive(type == 2);

        if (type == 1)
        {
            PUtils.onClick(current.Find("btn_voice"), () => {
                playVoiceItem(item);
            });

            len.GetComponent <UILabel> ().text = (item.voice.time / 1000) + "''";
        }
        else if (type == 0)
        {
            text.GetComponent <UILabel> ().text = item.text;
        }
        else if (type == 2)
        {
            emoji.GetComponent <UISprite> ().spriteName = "face_" + (item.emoji + 1);
        }
        else if (type == 3)
        {
            QuickChat qc = getQuickChat(item.qcid);
            text.GetComponent <UILabel> ().text = qc != null ? qc.text : "";
        }

        mChatItems.Add(item);
        updateItems(mChatItems.Count);
    }
Exemplo n.º 13
0
    void showRooms()
    {
        int    cnt = mRooms.Count;
        NetMgr nm  = NetMgr.GetInstance();
        int    uid = GameMgr.getUserMgr().userid;

        for (int i = 0; i < mRooms.Count; i++)
        {
            ClubRoomInfo room  = mRooms [i];
            Transform    item  = getItem(i);
            Transform    seats = item.Find("seats");
            bool         found = false;

            int readys   = 0;
            int nplayers = 0;

            bool idle = room.status == "idle";

            int j = 0;

            for (; j < room.players.Count && j < seats.childCount; j++)
            {
                ClubRoomPlayer p        = room.players [j];
                Transform      s        = seats.GetChild(j);
                GameObject     name     = s.Find("name").gameObject;
                GameObject     ready    = s.Find("ready").gameObject;
                GameObject     id       = s.Find("id").gameObject;
                GameObject     icon     = s.Find("icon").gameObject;
                GameObject     btn_kick = s.Find("btn_kick").gameObject;

                bool empty = p.id == 0;

                s.gameObject.SetActive(true);

                setActive(s, "icon", !empty);
                setActive(s, "name", !empty);
                setActive(s, "id", !empty);
                setActive(s, "ready", !empty && p.ready);
                setActive(s, "btn_kick", !empty && idle);

                if (!empty && idle)
                {
                    setBtnEvent(s, "btn_kick", () => {
                        onBtnKick(p.id, room.id, room.room_tag);
                    });
                }

                if (empty)
                {
                    continue;
                }

                nplayers += 1;
                if (p.ready)
                {
                    readys += 1;
                }

                setText(s, "name", p.name);
                setText(s, "id", "" + p.id);
                setIcon(s, "icon", p.id);

                if (p.id == uid)
                {
                    mRoomID = room.id;
                }
            }

            for (int k = j; k < seats.childCount; k++)
            {
                Transform s = seats.GetChild(k);
                s.gameObject.SetActive(false);
            }

            ClubRoomBaseInfo info = room.base_info;
            setText(item, "desc", info.huafen + "/" + info.huafen + (info.maima ? "带苍蝇" : "不带苍蝇") + info.maxGames + "局");
            setText(item, "progress", room.num_of_turns + " / " + info.maxGames);
            setText(item, "roomid", "ID:" + room.id);
            setText(item, "status", idle ? "开始" : "游戏中");

            Transform btn_play = item.Find("btn_play");
            btn_play.GetComponent <SpriteMgr> ().setIndex(idle ? 0 : 1);
            PUtils.onClick(btn_play, () => {
                if (room.status == "idle")
                {
                    if (readys != info.numOfSeats)
                    {
                        GameAlert.Show("玩家没有全部准备");
                        return;
                    }

                    nm.request_connector("start_room", "room_tag", room.room_tag, data => {
                        NormalReturn ret = JsonUtility.FromJson <NormalReturn> (data.ToString());
                        if (ret.errcode != 0)
                        {
                            Debug.Log("start room fail");
                            return;
                        }

                        refresh();
                    });
                }
                else
                {
                    nm.request_connector("stop_room", "room_tag", room.room_tag, data => {
                        NormalReturn ret = JsonUtility.FromJson <NormalReturn> (data.ToString());
                        if (ret.errcode != 0)
                        {
                            Debug.Log("stop room fail");
                            return;
                        }

                        refresh();
                    });
                }
            });

            setActive(item, "btn_edit", idle && nplayers == 0);
            setBtnEvent(item, "btn_edit", () => {
                EditRoom er = getPage <EditRoom>("PEditRoom");

                er.UpdateEvents += refresh;
                er.enter(room);
            });

            setActive(item, "btn_destroy", idle && nplayers == 0);
            setBtnEvent(item, "btn_destroy", () => {
                GameAlert.Show("确定解散房间吗?", () => {
                    JsonObject ob  = new JsonObject();
                    ob["roomid"]   = room.id;
                    ob["room_tag"] = room.room_tag;
                    ob["club_id"]  = room.club_id;

                    nm.request_apis("destroy_club_room", ob, data => {
                        NormalReturn ret = JsonUtility.FromJson <NormalReturn> (data.ToString());
                        if (ret.errcode != 0)
                        {
                            Debug.Log("destroy club room fail");
                            return;
                        }

                        refresh();
                    });
                }, true);
            });
        }

        updateItems(mRooms.Count);
    }