Beispiel #1
0
    public void addPair(Pair pair, bool lastPair = false, bool editMode = false)
    {
        var p = (Instantiate(Resources.Load("Prefabs/UI/schedule/Pair" + (editMode?"_editable":""))) as GameObject).GetComponent <TTPairScript>();

        p._pair = pair;

        p.transform.SetParent(pairsContainer, false);
        p.transform.localScale    = Vector3.one;
        p.transform.localScale    = Vector3.one;
        p.transform.localRotation = Quaternion.identity;

        p.pairTitle.text    = pair.name;
        p.lecturerName.text = pair.lecturer;

        var hasThisRoom = app.facilities.hasRoom(pair.room);


        p.locationText.text = hasThisRoom?pair.room:pair.location;

        if (lastPair)
        {
            p.divider.SetActive(false);
        }

        if (!editMode)
        {
            if (pair.now())
            {
                p.nowCircle.SetActive(true);
            }
            else
            {
                p.nowCircle.SetActive(false);
            }
        }



        //static bool _first_room_jump = true;
        // actions
        if (!editMode && hasThisRoom)
        {
            p.locationText.gameObject.SetActive(false);
            p.locationButtonContainer.gameObject.SetActive(true);

            // setup button
            p.locationButtonLabel.text = pair.room;
            p.locationButton.onClick.AddListener(() => {
                app.closeTimetable();
                /*if(_first_room_jump){*/
                Loom.QueueOnMainThread(() => {
                    app.facilities.goToRoom(pair.room);
                });

                /*}else{
                 *
                 * }*/
            });
        }
        else
        {
            p.locationText.gameObject.SetActive(true);
            p.locationText.text = hasThisRoom?pair.room:pair.location;

            if (editMode)
            {
                p.editButton.onClick.AddListener(() => {
                    Alerts.editPair("Редактировать пару", pair,
                                    (Pair oldPair, Pair newPair) => {
                        Debug.LogWarning("UPDATE PAIR");
                        Loom.QueueOnMainThread(() => {
                            app.timetableManager.updatePair(oldPair, newPair);
                            Loom.QueueOnMainThread(() => {
                                app.timetablePanel.UpdateContents(true);
                            });
                        });
                    });
                });


                var _pair_el = p;
                p.deleteButton.onClick.AddListener(() => {
                    Alerts.AskYesNo("Удаление пары", "Вы уверены, что хотите удалить пару?", () => {
                        //app.timetablePanel.setLoading(true);

                        Loom.QueueOnMainThread(() => {
                            var start1 = Time.realtimeSinceStartup;
                            app.timetableManager.setPairDeleted(pair);
                            Debug.Log("db actions time: " + (Time.realtimeSinceStartup - start1));

                            //var start2 = Time.realtimeSinceStartup;
                            app.timetablePanel.UpdateContents(true, true);
                            //Debug.Log("ui actions time: "+(Time.realtimeSinceStartup-start1));

                            DeletePairFromTime(_pair_el);
                            //var week = _pair_el.GetComponentInParent<TTWeekScript>();
                            //week.ReloadDay(_pair_el.GetComponentInParent<TTDayScript>(), true);
                        }, 0.2f);
                    }, null, "УДАЛИТЬ", "ОТМЕНА", true);
                });
            }
            else
            {
                p.locationButtonContainer.gameObject.SetActive(false);
            }
        }
    }
Beispiel #2
0
 public virtual void close()
 {
     app.closeTimetable();
 }