using UnityEngine;

public class UIWrapMuchContent : UIWrapContent
{
	public override bool WrapContent()
	{
		bool result = false;
		bool flag = true;
		float num = (float)(itemSize * mChildren.Count) * 0.5f;
		float num2 = num * 2f;
		Vector3[] worldCorners = mPanel.worldCorners;
		for (int i = 0; i < 4; i++)
		{
			Vector3 position = worldCorners[i];
			position = mTrans.InverseTransformPoint(position);
			worldCorners[i] = position;
		}
		Vector3 vector = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f);
		if (mHorizontal)
		{
			float num3 = worldCorners[0].x - (float)itemSize;
			float num4 = worldCorners[2].x + (float)itemSize;
			float num5 = (worldCorners[2].x - worldCorners[0].x) * 0.5f - mPanel.clipSoftness.x;
			float num6 = num - num5;
			bool flag2 = 0f < num6 && num6 < (float)itemSize * 0.5f;
			int j = 0;
			for (int count = mChildren.Count; j < count; j++)
			{
				Transform transform = mChildren[j];
				float num7 = transform.localPosition.x - vector.x;
				if (num7 < 0f - num)
				{
					Vector3 localPosition = transform.localPosition;
					float num8 = Mathf.Ceil((0f - num - num7) / num2);
					localPosition.x += num2 * num8;
					num7 = localPosition.x - vector.x;
					int num9 = Mathf.RoundToInt(localPosition.x / (float)itemSize);
					if ((base.EnableNoLimit && minIndex == maxIndex) || (minIndex <= num9 && num9 <= maxIndex))
					{
						transform.localPosition = localPosition;
						UpdateItem(transform, j);
					}
					else
					{
						flag = false;
					}
				}
				else if (num7 > num)
				{
					Vector3 localPosition2 = transform.localPosition;
					float num10 = Mathf.Ceil((num7 - num) / num2);
					localPosition2.x -= num2 * num10;
					num7 = localPosition2.x - vector.x;
					int num11 = Mathf.RoundToInt(localPosition2.x / (float)itemSize);
					if ((base.EnableNoLimit && minIndex == maxIndex) || (minIndex <= num11 && num11 <= maxIndex))
					{
						transform.localPosition = localPosition2;
						UpdateItem(transform, j);
					}
					else
					{
						flag = false;
					}
				}
				else
				{
					if (mFirstTime)
					{
						UpdateItem(transform, j);
					}
					if (flag2)
					{
						float num12 = (float)itemSize * 0.5f - num6;
						if (num7 < 0f - (num - num12) || num7 > num - num12)
						{
							flag = false;
						}
					}
					result = true;
				}
				if (cullContent)
				{
					num7 += mPanel.clipOffset.x - mTrans.localPosition.x;
					if (!UICamera.IsPressed(transform.gameObject))
					{
						NGUITools.SetActive(transform.gameObject, num7 > num3 && num7 < num4, compatibilityMode: false);
					}
				}
			}
		}
		else
		{
			float num13 = worldCorners[0].y - (float)itemSize;
			float num14 = worldCorners[2].y + (float)itemSize;
			float num15 = (worldCorners[2].y - worldCorners[0].y) * 0.5f - mPanel.clipSoftness.y;
			float num16 = num - num15;
			bool flag3 = 0f < num16 && num16 < (float)itemSize * 0.5f;
			int k = 0;
			for (int count2 = mChildren.Count; k < count2; k++)
			{
				Transform transform2 = mChildren[k];
				float num17 = transform2.localPosition.y - vector.y;
				if (num17 < 0f - num)
				{
					Vector3 localPosition3 = transform2.localPosition;
					float num18 = Mathf.Ceil((0f - num - num17) / num2);
					localPosition3.y += num2 * num18;
					num17 = localPosition3.y - vector.y;
					int num19 = Mathf.RoundToInt(localPosition3.y / (float)itemSize);
					if ((base.EnableNoLimit && minIndex == maxIndex) || (minIndex <= num19 && num19 <= maxIndex))
					{
						transform2.localPosition = localPosition3;
						UpdateItem(transform2, k);
					}
					else
					{
						flag = false;
					}
				}
				else if (num17 > num)
				{
					Vector3 localPosition4 = transform2.localPosition;
					float num20 = Mathf.Ceil((num17 - num) / num2);
					localPosition4.y -= num2 * num20;
					num17 = localPosition4.y - vector.y;
					int num21 = Mathf.RoundToInt(localPosition4.y / (float)itemSize);
					if ((base.EnableNoLimit && minIndex == maxIndex) || (minIndex <= num21 && num21 <= maxIndex))
					{
						transform2.localPosition = localPosition4;
						UpdateItem(transform2, k);
					}
					else
					{
						flag = false;
					}
				}
				else
				{
					if (mFirstTime)
					{
						UpdateItem(transform2, k);
					}
					if (flag3)
					{
						float num22 = (float)itemSize * 0.5f - num16;
						if (num17 < 0f - (num - num22) || num17 > num - num22)
						{
							flag = false;
						}
					}
					result = true;
				}
				if (cullContent)
				{
					num17 += mPanel.clipOffset.y - mTrans.localPosition.y;
					if (!UICamera.IsPressed(transform2.gameObject))
					{
						NGUITools.SetActive(transform2.gameObject, num17 > num13 && num17 < num14, compatibilityMode: false);
					}
				}
			}
		}
		mScroll.restrictWithinPanel = !flag;
		return result;
	}
}
