示例#1
0
 public DialogRename(MatteredDay matteredDay)
 {
     _matteredDay = matteredDay;
     curName      = matteredDay.Name;
     _oldName     = curName;
 }
        private void DrawRow(Rect rect, MatteredDay matteredDay, int index)
        {
            GUI.BeginGroup(rect);

            Rect rectName = rect.AtZero();

            rectName.width -= COL_MARGIN * 4 + BTN_SEASON_WIDTH + LBL_DATE_WIDTH + BTN_DURATION_WIDTH + BTN_DELETE_WIDTH;
            rectName.xMin  += COL_MARGIN;

            Rect rectSeason = new Rect(rectName.xMax + COL_MARGIN, 2f, BTN_SEASON_WIDTH, rect.height - 4f);

            Rect rectDateMinus = new Rect(rectSeason.xMax + COL_MARGIN, (rect.height - BTN_DATE_CONTROL_WIDTH) / 2f, BTN_DATE_CONTROL_WIDTH, BTN_DATE_CONTROL_WIDTH);
            Rect rectDate      = new Rect(rectDateMinus.xMax, 0f, LBL_DATE_WIDTH - BTN_DATE_CONTROL_WIDTH * 2, rect.height);
            Rect rectDatePlus  = new Rect(rectDate.xMax, (rect.height - BTN_DATE_CONTROL_WIDTH) / 2f, BTN_DATE_CONTROL_WIDTH, BTN_DATE_CONTROL_WIDTH);

            Rect rectDuration  = new Rect(rectDatePlus.xMax + COL_MARGIN, 2f, BTN_DURATION_WIDTH, rect.height - 4f);
            Rect btnDeleteRect = new Rect(rectDuration.xMax + COL_MARGIN, Mathf.RoundToInt((ROW_HEIGHT - BTN_DELETE_HEIGHT) / 2f), BTN_DELETE_WIDTH, BTN_DELETE_HEIGHT);

            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.Label(rectName, matteredDay.Name);
            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(rectDate, matteredDay.DayOfQuadrum.ToString());
            Text.Anchor = TextAnchor.UpperLeft;

            if (Widgets.ButtonText(rectSeason, matteredDay.Quadrum.Label()))
            {
                FloatMenuUtility.MakeMenu(QUADRUMS, quadrum => quadrum.Label(), quadrum => delegate
                {
                    matteredDay.Quadrum = quadrum;
                });
            }

            if (Widgets.ButtonText(rectDuration, matteredDay.Duration.Label()))
            {
                FloatMenuUtility.MakeMenu(Enum.GetValues(typeof(Duration)).Cast <Duration>(), duration => duration.Label(), duration => delegate
                {
                    matteredDay.Duration = duration;
                });
            }

            if (Widgets.ButtonImage(btnDeleteRect, Textures.ROW_DELETE))
            {
                _store.MatteredDays.RemoveAt(index);
                SoundDefOf.Click.PlayOneShotOnCamera();
            }

            if (Widgets.ButtonImage(rectDateMinus, Textures.DAY_MINUS))
            {
                int tmp = matteredDay.DayOfQuadrum - 1;
                if (tmp < 1)
                {
                    tmp = 1;
                }
                matteredDay.DayOfQuadrum = tmp;
                SoundDefOf.Click.PlayOneShotOnCamera();
            }

            if (Widgets.ButtonImage(rectDatePlus, Textures.DAY_PLUS))
            {
                int tmp = matteredDay.DayOfQuadrum + 1;
                if (tmp > 15)
                {
                    tmp = 15;
                }
                matteredDay.DayOfQuadrum = tmp;
                SoundDefOf.Click.PlayOneShotOnCamera();
            }

            var interactingName = Mouse.IsOver(rectName);

            if (interactingName)
            {
                if (Event.current.control && Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    Find.WindowStack.Add(new DialogRename(matteredDay));
                    return;
                }
                TooltipHandler.ClearTooltipsFrom(rectName);
                TooltipHandler.TipRegion(rectName, "DM.Tab.RenameCustomDay".Translate());
            }

            GUI.EndGroup();
        }