private bool DrawRow(Thing thing, String label, float y, int i, Rect r) { Thing t = (thing is MatchedThings) ? (thing as MatchedThings).First : thing; GUI.BeginGroup(new Rect(0, y + i * (HEIGHT + BUFFER), r.width, HEIGHT)); Widgets.ThingIcon(new Rect(0f, 0f, HEIGHT, HEIGHT), t); if (Widgets.InfoCardButton(40, 0, t)) { Find.WindowStack.Add(new Dialog_InfoCard(t)); } Widgets.Label(new Rect(70, 0, r.width - (80 + HEIGHT), HEIGHT), label); if (this.InfiniteStorage.IsOperational && Widgets.ButtonImage(new Rect(r.xMax - 20, 0, 20, 20), DropTexture)) { this.InfiniteStorage.AllowAdds = false; if (this.InfiniteStorage.TryRemove(t)) { BuildingUtil.DropThing(t, t.stackCount, this.InfiniteStorage, this.InfiniteStorage.Map); this.itemsDropped = true; } this.PopulateDisplayThings(); return(true); } GUI.EndGroup(); return(false); }
public static void Load(int id) { WebUtil.DetailSence(id, scene => { PanelLoading.current.SceneLoading(); string json = System.Text.Encoding.UTF8.GetString(scene.Content); Debug.Log(json); SenceSaveData saveData = Json.Parse <SenceSaveData>(json); //--floor Floor.current.Load(saveData.FloorSaveData.X, saveData.FloorSaveData.Z); //--building PanelList.current.Reset(); Coordinate.Target.SetTarget(null); foreach (BuildingSaveData data in saveData.BuildingRoomSaveData.BuildingSaveDatas) { PanelList.current.Add(BuildingUtil.Create(data)); } //--camera MyCamera.current.MoveAnim((TransformGroup)saveData.CameraTransformGroup); PanelLoading.current.Close(); }, err => { PanelLoading.current.Error(err); }); }
private void Awake() { LoadDicMaterial(); boxCollider = BuildingUtil.AddBoxCollider(this.gameObject); LoadDownToFloorY(); outlineList = new List <Outline>(); normalAnimDatas = new List <AnimData>(); appearanceAnimDatas = new List <AnimData>(); foreach (MeshRenderer mesh in this.transform.GetComponentsInChildren <MeshRenderer>()) { outlineList.Add(mesh.gameObject.AddComponent <Outline>()); } HideHighLight(); }
private void Load() { Manifest manifest = LocalAssetUtil.Manifest; itemDic = new Dictionary <int, Item>(manifest.ModelType.Count); manifest.ModelType.ForEach(p => { Transform clone = Instantiate(baseTypeItem.gameObject, baseTypeItem.parent).transform; clone.GetComponentInChildren <Text>().text = p.Name; itemDic.Add(p.Id, new Item(clone)); }); manifest.Models.ForEach(model => { Transform clone = Instantiate(baseItem.gameObject, baseItem.parent).transform; clone.GetComponentInChildren <Text>().text = model.Name.Substring(0, model.Name.LastIndexOf('.')); clone.GetComponentInChildren <Button>().onClick.AddListener(delegate { Building building = BuildingUtil.Create(model); PanelState.current.baseInputMouse.Catch(building); int maxBuilding = building.IsTooBig(); if (maxBuilding != int.MinValue) { building.gameObject.SetActive(false); PanelDialog.current.Open("场景过小,\n需扩建至(" + maxBuilding + "," + maxBuilding + ")", () => { Floor.current.Load(maxBuilding, maxBuilding); building.gameObject.SetActive(true); WhenTooBig(building); }, () => { building.gameObject.SetActive(true); WhenTooBig(building); }); } else { WhenTooBig(building); } }); clone.Find("Image").GetComponent <Image>().sprite = AssetBundleUtil.DicSprite[model.Id]; clone.gameObject.SetActive(false); itemDic[model.ModelTypeId].contents.Add(clone); }); baseTypeItem.gameObject.SetActive(false); baseItem.gameObject.SetActive(false); itemDic[manifest.ModelType[0].Id].Select(true); }
/// <summary> /// 右键点击事件,更新右键面板中的按钮的点击事件 /// </summary> /// <param name="go"></param> private void OnRigheDown(GameObject go) { Debug.Log("OnRigheDown"); rightClickPanel.SetActive(true); rightClickPanel.transform.position = Input.mousePosition; rightClickPanelButtonCloneAction = delegate { Item item = items.Find(p => p.ui.gameObject == go); BuildingUtil.Clone(item.building); Select(items[items.Count - 1]); }; rightClickPanelButtonDeleteAction = delegate { Item item = items.Find(p => p.ui.gameObject == go); Remove(item.building); PanelControl.current.Close(); }; }
/// <summary> /// 单击选择物体 /// </summary> protected override void OnMouseLeftClickDown() { Ray ray = MyCamera.current.Camera.ScreenPointToRay(Input.mousePosition); if (!Physics.Raycast(ray, out hit)) { Coordinate.Target.SetTarget(null); PanelList.current.LastRecovery(); PanelControl.current.Close(); state = STATE_NONE; return; } Transform hitTarget = hit.collider.transform; Debug.Log(hitTarget.name); if (state <= STATE_BUILDING) { Building building = BuildingUtil.FindBuilding(hitTarget); bool isNormal = PanelState.current.state == PanelState.State.NORMAL; if (building != null && isNormal) { PanelList.current.Select(building); state = STATE_BUILDING; } else if (Coordinate.Target.Hit(hitTarget)) { state = STATE_COORDINATE; targetToScreenPos = MyCamera.current.Camera.WorldToScreenPoint(Coordinate.Target.transform.position); mouseClickToWorldPos = MyCamera.current.Camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, targetToScreenPos.z)); } else if (isNormal) { //点击到其他地方 Coordinate.Target.SetTarget(null); PanelList.current.LastRecovery(); PanelControl.current.Close(); state = STATE_NONE; } } }
protected override void LoadNewPage() { WebUtil.PageSence(nowIndex, page => { if (page.Records != null && page.Records.Count > 0) { List <GameObject> list = new List <GameObject>(); item.SetActive(true); foreach (Scene scene in page.Records) { Transform clone = Instantiate(item, content).transform; clone.Find("Name").GetComponentInChildren <Text>().text = scene.Name; clone.Find("DeployTime").GetComponentInChildren <Text>().text = TimeUtil.Format(scene.DeployTime); Transform operate = clone.Find("Operate"); operate.Find("ButtonLoad").GetComponent <Button>().onClick.AddListener(delegate { BuildingUtil.Fresh(); SaveUtil.Load(scene.Id); UGUITree.current.CloseStart(); }); operate.Find("ButtonDelete").GetComponent <Button>().onClick.AddListener(delegate { }); list.Add(clone.gameObject); } item.SetActive(false); pageCache.Add(nowIndex, list); } pages = page.Pages; FreshNavigation(); }, err => { PanelLoading.current.Error(err); }); }
public override void DoWindowContents(Rect inRect) { #if TRACE ++i; #endif GUI.color = Color.white; Text.Font = GameFont.Small; try { float x = 0, y = 0; string label = ""; if (Settings.EnableAssignWeapons) { #region Assign To Widgets.Label(new Rect(x, y + 4, 100, 30), "WeaponStorage.AssignTo".Translate()); x += 80; if (this.selectablePawns.Count > 0 && GUI.Button(new Rect(x, y, 30, 30), previousTexture)) { --this.pawnIndex; if (this.pawnIndex < 0 || this.assignedWeapons == null) { this.pawnIndex = this.selectablePawns.Count - 1; } this.LoadAssignedWeapons(); } x += 30; label = (this.assignedWeapons != null) ? SelectablePawns.GetLabelAndStatsFor(this.assignedWeapons.Pawn) : ""; if (Widgets.ButtonText(new Rect(x, y, 400, 30), label)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (SelectablePawns p in this.selectablePawns) { options.Add(new FloatMenuOption(p.LabelAndStats, delegate { this.UpdatePawnIndex(p.Pawn); }, MenuOptionPriority.Default, null, null, 0f, null, null)); } Find.WindowStack.Add(new FloatMenu(options)); } x += 400; if (this.selectablePawns.Count > 0 && GUI.Button(new Rect(x, y, 30, 30), nextTexture)) { ++this.pawnIndex; if (this.pawnIndex >= this.selectablePawns.Count || this.assignedWeapons == null) { this.pawnIndex = 0; } this.LoadAssignedWeapons(); } x += 40; #endregion y += 40; } #region Weapon Storage x = 0; Widgets.Label(new Rect(x, y - 4, 100, 60), "WeaponStorage".Translate()); x += 80; if (WorldComp.HasStorages() && GUI.Button(new Rect(x, y, 30, 30), previousTexture)) { this.NextWeaponStorage(-1); } x += 30; label = (this.weaponStorage != null) ? this.weaponStorage.Label : ""; if (Widgets.ButtonText(new Rect(x, y, 400, 30), label)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (var ws in WorldComp.GetWeaponStorages()) { options.Add(new FloatMenuOption(ws.Label, delegate { this.weaponStorage = ws; this.RebuildPossibleWeapons(); }, MenuOptionPriority.Default, null, null, 0f, null, null)); } Find.WindowStack.Add(new FloatMenu(options)); } x += 400; if (WorldComp.HasStorages() && GUI.Button(new Rect(x, y, 30, 30), nextTexture)) { this.NextWeaponStorage(1); } x += 40; #endregion y += 40; Widgets.Label(new Rect(0, y + 4, 70, 30), "WeaponStorage.Search".Translate()); this.textBuffer = Widgets.TextField(new Rect(80, y, 200, 30), this.textBuffer); y += 40; const int HEIGHT = 30; const int BUFFER = 2; float width = inRect.width - 100; scrollPosition = GUI.BeginScrollView(new Rect(40, y, width, inRect.height - y - 121), scrollPosition, new Rect(0, 0, width - 16, this.PreviousY)); x = y = 0; if (this.PossibleWeapons != null) { ThingWithComps weapon; for (int i = 0; i < this.PossibleWeapons.Count; ++i) { x = 0; weapon = this.PossibleWeapons[i]; bool isChecked = false; if (this.assignedWeapons != null && this.weaponStorage != null) { isChecked = this.IsAssignedWeapon(i); if (!isChecked && !this.IncludeWeapon(weapon)) { continue; } bool backup = isChecked; Widgets.Checkbox(x, y, ref isChecked, 20); x += 20 + BUFFER; if (isChecked != backup) { if (this.IsAssignedWeapon(i)) { if (this.assignedWeapons.Pawn.equipment.Primary == weapon) { this.assignedWeapons.Pawn.equipment.Remove(weapon); if (this.assignedWeapons.Pawn.jobs.curJob.def == JobDefOf.Hunt) { this.assignedWeapons.Pawn.jobs.StopAll(); } } if (this.assignedWeapons.Remove(weapon)) { if (this.weaponStorage == null || (!this.weaponStorage.AddWeapon(weapon) && !WorldComp.Add(weapon))) { BuildingUtil.DropSingleThing(weapon, this.assignedWeapons.Pawn.Position, this.assignedWeapons.Pawn.Map); } } else { Log.Error("Unable to remove weapon " + weapon); } } else { if (this.weaponStorage != null && this.weaponStorage.RemoveNoDrop(weapon)) { this.assignedWeapons.Add(weapon); } else { Log.Error("Unable to remove weapon " + weapon); } } this.RebuildPossibleWeapons(); break; } } if (!isChecked && !this.IncludeWeapon(weapon)) { continue; } Widgets.ThingIcon(new Rect(x, y, HEIGHT, HEIGHT), weapon); x += HEIGHT + BUFFER; if (Widgets.InfoCardButton(x, y, weapon)) { Find.WindowStack.Add(new Dialog_InfoCard(weapon)); } x += HEIGHT + BUFFER; Widgets.Label(new Rect(x, y, 250, HEIGHT), weapon.Label); x += 250 + BUFFER; if (this.weaponStorage != null && Widgets.ButtonImage(new Rect(width - 16 - HEIGHT, y, 20, 20), DropTexture)) { if (this.IsAssignedWeapon(i)) { if (!this.assignedWeapons.Remove(weapon)) { Log.Error("Unable to drop assigned weapon"); } } else { if (this.weaponStorage == null || !this.weaponStorage.Remove(weapon)) { Log.Error("Unable to remove weapon " + weapon); } } this.RebuildPossibleWeapons(); break; } var biocodableComp = weapon.GetComp <CompBiocodable>(); if (biocodableComp?.CodedPawn != null) { y += HEIGHT - 4; Widgets.Label(new Rect(x - 250 - BUFFER, y, 250, 20), biocodableComp.CompInspectStringExtra()); y += 4; } this.PossibleWeapons[i] = weapon; y += HEIGHT + BUFFER; } } else { #if TRACE if (i > 600) { Log.Warning("WeaponStorage DoWindowContents: Display non-checkbox weapons. Count: " + this.weaponStorage.Count); } #endif if (this.weaponStorage != null) { foreach (ThingWithComps t in this.weaponStorage.GetWeapons(false)) { #if TRACE if (i > 600) { Log.Warning("-" + t.Label); } #endif //if (!IncludeWeapon(t)) // continue; if (!this.IncludeWeapon(t)) { continue; } x = 34; Widgets.ThingIcon(new Rect(x, y, HEIGHT, HEIGHT), t); x += HEIGHT + BUFFER; if (Widgets.InfoCardButton(x, y, t)) { Find.WindowStack.Add(new Dialog_InfoCard(t)); } x += HEIGHT + BUFFER; Widgets.Label(new Rect(x, y, 250, HEIGHT), t.Label); x += 250 + BUFFER; if (Widgets.ButtonImage(new Rect(x + 100, y, 20, 20), DropTexture)) { this.weaponStorage.Remove(t); break; } y += HEIGHT + BUFFER; } foreach (ThingWithComps t in this.weaponStorage.GetBioEncodedWeapons()) { #if TRACE if (i > 600) { Log.Warning("-" + t.Label); } #endif //if (!IncludeWeapon(t)) // continue; x = 34; Widgets.ThingIcon(new Rect(x, y, HEIGHT, HEIGHT), t); x += HEIGHT + BUFFER; if (Widgets.InfoCardButton(x, y, t)) { Find.WindowStack.Add(new Dialog_InfoCard(t)); } x += HEIGHT + BUFFER; Widgets.Label(new Rect(x, y, 250, HEIGHT), t.Label); x += 250 + BUFFER; if (Widgets.ButtonImage(new Rect(x + 100, y, 20, 20), DropTexture)) { this.weaponStorage.Remove(t); break; } var biocodableComp = t.GetComp <CompBiocodable>(); if (biocodableComp?.CodedPawn != null) { y += HEIGHT - 4; Widgets.Label(new Rect(x - 250 - BUFFER, y, 250, 20), biocodableComp.CompInspectStringExtra()); y += 4; } y += HEIGHT + BUFFER; } } } GUI.EndScrollView(); this.PreviousY = y; } catch (Exception e) { String msg = this.GetType().Name + " closed due to: " + e.GetType().Name + " " + e.Message; Log.Error(msg); Messages.Message(msg, MessageTypeDefOf.NegativeEvent); base.Close(); } finally { Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; } }
void GenerateNewChunk() { //Generate Road i++; GameObject o = BuildingUtil.GenerateRoad(this, i); o.name = "Chunk " + i; o.transform.position = new Vector3(0, 0, f); f += size_of_each; roads.Add(o); if (start_to_delete) { can_pass.Remove(i - roads.Count); can_pass_keys.Remove(i); Destroy(roads[0]); roads.RemoveAt(0); } //Generate road obstacles int[] pass = BuildingUtil.GenerateObstacles(this, i, o); if (pass != null) { can_pass[i] = pass; can_pass_keys.Add(i); last_can_pass = i; } //Generate sidewalk decoration BuildingUtil.GenerateSideWalkDecoration(this, i, o); //Generate building if need if (try_to_build_in_both_sides) { if (f >= building_z[0] && f >= building_z[1]) { if (building_z[0] == building_z[1]) { //Do the build float f = BuildingUtil.GenerateBothSideBulding(this, building_z[0], i); building_z[0] += f; building_z[1] += f; try_to_build_in_both_sides = false; last_both_side_building = building_z[0]; } else if (building_z[0] > building_z[1]) { float dif = Mathf.Abs(building_z[0] - building_z[1]); float ra = Mathf.Round(Random.Range(16, 30 - dif)); float rb = Mathf.Round(ra + Random.Range(1, dif)); building_z[0] += BuildingUtil.GenerateBuildWithFixedSize(this, (int)Mathf.Min(ra, rb), 0, building_z[0], o); building_z[1] += BuildingUtil.GenerateBuildWithFixedSize(this, (int)Mathf.Max(ra, rb), 1, building_z[1], o); } else { float dif = Mathf.Abs(building_z[0] - building_z[1]); float ra = Mathf.Round(Random.Range(16, 30 - dif)); float rb = Mathf.Round(ra + Random.Range(1, dif)); building_z[0] += BuildingUtil.GenerateBuildWithFixedSize(this, (int)Mathf.Max(ra, rb), 0, building_z[0], o); building_z[1] += BuildingUtil.GenerateBuildWithFixedSize(this, (int)Mathf.Min(ra, rb), 1, building_z[1], o); } } } else { for (int j = 0; j < 2; j++) { while (f >= building_z[j]) { //Create a build building_z[j] += BuildingUtil.GenerateBuild(this, 16, 30, j, building_z[j], o); } } } if (Mathf.Abs(f - last_both_side_building) >= 100 && !try_to_build_in_both_sides && (i % 50 != 0)) { try_to_build_in_both_sides = true; } //Parent to both side buildings for (int i = unparented_both_side_building.Count - 1; i >= 0; i--) { if (unparented_both_side_building[i].transform.position.z <= f) { unparented_both_side_building[i].transform.parent = o.transform; unparented_both_side_building.RemoveAt(i); } } }