public void Update(CityLevel metaGame, CityUIBlackboard blackboard) { if (!movable) { return; } hovering = blackboard.inputState.hoveringElement == this;// cachedHandleRect.Contains(blackboard.inputState.MousePos); if (hovering && blackboard.inputState.WasMouseLeftJustPressed()) { dragging = true; blackboard.selectedObject = null; } if (cachedOffset.Y < 0) { ConnectTo(null); } if (dragging) { ConnectTo(null); CityObject overObject = metaGame.GetObjectAt(blackboard.inputState.MousePos); PipeSocket overSocket = null; if (overObject != null) { overSocket = overObject.GetNearestSocket(blackboard.inputState.MousePos); if (overSocket != null && overSocket.pos.Y < sourcePos.Y) { overSocket = null; } } Vector2 clampedPos = blackboard.inputState.MousePos; if (clampedPos.Y <= sourcePos.Y) { clampedPos.Y = sourcePos.Y; } if (blackboard.inputState.mouseLeft.isDown) { if (overSocket != null) { UpdateForTargetPos(overSocket.pos); } else { UpdateForTargetPos(clampedPos); } } else { dragging = false; if (overSocket != null && overSocket.parent != source) { ConnectTo(overSocket); } else { ShowDisconnected(); } } } }
public CityLevel(JSONTable template) { this.name = template.getString("name"); this.pos = template.getVector2("pos"); this.price = template.getInt("price"); this.isTutorial = template.getBool("isTutorial", false); blackboard.cityLevel = this; InitUI(); isNew = true; Dictionary <string, CityObject> objectsByName = new Dictionary <string, CityObject>(); JSONTable unlockTable = template.getJSON("unlocks", null); if (unlockTable != null) { foreach (string unlockName in unlockTable.Keys) { JSONTable unlockTemplates = unlockTable.getJSON(unlockName); List <CityObject> newObjects = new List <CityObject>(); List <UIElement> newUI = new List <UIElement>(); List <Weapon> newWeapons = new List <Weapon>(); foreach (string objectName in unlockTemplates.Keys) { /*if(unlockableUI.ContainsKey(objectName)) * { * newUI.Add(unlockableUI[objectName]); * } * else*/ if (Game1.instance.inventory.unlockableWeapons.ContainsKey(objectName)) { newWeapons.Add(Game1.instance.inventory.unlockableWeapons[objectName]); } else { CityObject newObj = CityObject.FromTemplate(this, unlockTemplates.getJSON(objectName)); objectsByName[objectName] = newObj; newObjects.Add(newObj); } } if (unlockName == "start") { foreach (CityObject obj in newObjects) { objects.Add(obj); //tutorial hack if (obj is ChemicalFactory) { blackboard.selectedObject = obj; } } foreach (UIElement element in newUI) { ui.Add(element); } foreach (Weapon w in newWeapons) { Game1.instance.inventory.UnlockWeapon(w); } } else { unlockRules.Add(new UnlockRule_Output(objectsByName[unlockName], newUI, newObjects, newWeapons)); } } // postprocess to add pipes foreach (string unlockName in unlockTable.Keys) { JSONTable unlockTemplates = unlockTable.getJSON(unlockName); foreach (string objectName in unlockTemplates.Keys) { //if (unlockableUI.ContainsKey(objectName) || if (Game1.instance.inventory.unlockableWeapons.ContainsKey(objectName)) { continue; } JSONTable objectTemplate = unlockTemplates.getJSON(objectName); JSONArray pipeTargets = objectTemplate.getArray("pipes", null); if (pipeTargets != null) { foreach (string pipeTarget in pipeTargets.asStrings()) { CityObject sourceObject = objectsByName[objectName]; CityObject targetObject = objectsByName[pipeTarget]; OutputPipe pipe = sourceObject.pipes.Last(); pipe.ConnectTo(targetObject.GetNearestSocket(targetObject.bounds.XY)); pipe.movable = false; } } } } } }