public void ButtonPressed(ToolbarButton button) { SFX.Play("highClick", 0.3f); ContextMenu contextMenu1 = (ContextMenu)null; Vec2 vec2 = new Vec2(2f, 21f); if (button == this._newButton) { this.Closed(); this._newMenu = new ContextMenu((IContextListener)this, hasToproot: true, topRoot: button.position); this._newMenu.x = this.position.x - vec2.x; this._newMenu.y = this.position.y + vec2.y; this._newMenu.root = true; this._newMenu.depth = this.depth + 10; this.Selected(); this._newMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "NEW" }); this._newMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "NEW ONLINE" }); ContextMenu contextMenu2 = new ContextMenu((IContextListener)this); contextMenu2.itemSize.x = 60f; contextMenu2.text = "ARCADE"; contextMenu2.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "NEW ARCADE" }); contextMenu2.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "NEW CHALLENGE" }); contextMenu2.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "NEW ARCADE MACHINE" }); this._newMenu.AddItem(contextMenu2); this._newMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "CANCEL" }); Level.Add((Thing)this._newMenu); this._newMenu.opened = true; contextMenu1 = this._newMenu; } if (button == this._saveButton) { this.Closed(); this._saveMenu = new ContextMenu((IContextListener)this, hasToproot: true, topRoot: button.position); this._saveMenu.x = this.position.x - vec2.x; this._saveMenu.y = this.position.y + vec2.y; this._saveMenu.root = true; this._saveMenu.depth = this.depth + 10; this.Selected(); this._saveMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "SAVE" }); this._saveMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "SAVE AS" }); Level.Add((Thing)this._saveMenu); this._saveMenu.opened = true; contextMenu1 = this._saveMenu; } if (button == this._gridButton) { this.Closed(); this._gridMenu = new ContextMenu((IContextListener)this, hasToproot: true, topRoot: button.position); this._gridMenu.x = this.position.x - vec2.x; this._gridMenu.y = this.position.y + vec2.y; this._gridMenu.root = true; this._gridMenu.depth = this.depth + 10; this.Selected(); this._gridMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "8x8" }); this._gridMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "16x16" }); this._gridMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "32x32" }); Level.Add((Thing)this._gridMenu); this._gridMenu.opened = true; contextMenu1 = this._gridMenu; } if (button == this._loadButton) { Editor current = Level.current as Editor; current.Load(); current.CloseMenu(); } if (button == this._steamButton) { Editor current = Level.current as Editor; current.SteamUpload(); current.CloseMenu(); } if (button == this._playButton) { (Level.current as Editor).Play(); } if (button == this._quitButton) { this.Closed(); this._quitMenu = new ContextMenu((IContextListener)this, hasToproot: true, topRoot: button.position); this._quitMenu.x = this.position.x - vec2.x; this._quitMenu.y = this.position.y + vec2.y; this._quitMenu.root = true; this._quitMenu.depth = this.depth + 10; this.Selected(); this._quitMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "QUIT" }); this._quitMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 60f }, text = "CANCEL" }); Level.Add((Thing)this._quitMenu); this._quitMenu.opened = true; contextMenu1 = this._quitMenu; } if (contextMenu1 == null || (double)contextMenu1.y + (double)contextMenu1.menuSize.y <= (double)Layer.HUD.camera.height - 4.0) { return; } float y = contextMenu1.y; contextMenu1.y = Layer.HUD.camera.height - 4f - contextMenu1.menuSize.y; contextMenu1._toprootPosition.y += contextMenu1.y - y; if (this.owner is ContextMenu owner) { owner._openedOffset = 0.0f; owner.y = contextMenu1.y - 16f - owner.menuSize.y; owner.PositionItems(); } contextMenu1.PositionItems(); }
public override void Update() { if (this._doingPublish && this._currentItem != null) { if (!this._currentItem.finishedProcessing) { return; } if (this._uploading) { this._uploading = false; if (this._currentItem.needsLegal) { Steam.ShowWorkshopLegalAgreement("312530"); } this._upload.Close(); if (this._currentItem.result == SteamResult.OK) { this._notify.Open("Item published!"); } else { this._notify.Open("Failed (" + this._currentItem.result.ToString() + ")"); } this._doingPublish = false; } else if (this._currentItem.result == SteamResult.OK) { this._uploading = true; WorkshopItemData dat = new WorkshopItemData(); dat.name = this._nameBox.text; dat.description = this._descriptionBox.text; dat.visibility = RemoteStoragePublishedFileVisibility.Public; dat.tags = new List <string>(); if (this._levelType == LevelType.ArcadeMachine) { dat.tags.Add("Machine"); } else { dat.tags.Add("Map"); } dat.tags.Add(this._levelSize.ToString()); if (this._levelType != LevelType.Deathmatch) { dat.tags.Add(this._levelType.ToString()); } Editor.workshopName = dat.name; Editor.workshopDescription = dat.description; Editor.workshopAuthor = Steam.user.name; Editor.workshopID = this._currentItem.id; if (this._addDeathmatchTag) { dat.tags.Add("Deathmatch"); Editor.workshopLevelDeathmatchReady = true; } else if (this._addMachineTag) { dat.tags.Add("Arcade Machine"); Editor.workshopLevelDeathmatchReady = true; } else if (this._levelType == LevelType.Deathmatch) { dat.tags.Add("Strange"); } dat.tags.AddRange((IEnumerable <string>)Editor.workshopTags); if (this._extraTags != null && ((IEnumerable <string>) this._extraTags).Count <string>() > 0) { dat.tags.AddRange((IEnumerable <string>) this._extraTags); } (Level.current as Editor).Save(); this._workshopID = this._currentItem.id; string pathString1 = DuckFile.workshopDirectory + (object)this._workshopID + "/"; string pathString2 = DuckFile.workshopDirectory + (object)this._workshopID + "-preview/"; DuckFile.CreatePath(pathString1); DuckFile.CreatePath(pathString2); string withoutExtension = Path.GetFileNameWithoutExtension(this._filePath); string str = pathString1 + Path.GetFileName(this._filePath); if (File.Exists(str)) { File.Delete(str); } File.Copy(this._filePath, str); File.SetAttributes(this._filePath, FileAttributes.Normal); dat.contentFolder = pathString1; string path = pathString2 + withoutExtension + ".png"; if (File.Exists(path)) { File.Delete(path); } Stream stream = (Stream)DuckFile.Create(path); ((Texture2D)this._previewTarget.texture.nativeObject).SaveAsPng(stream, this._previewTarget.width, this._previewTarget.height); stream.Dispose(); dat.previewPath = path; this._currentItem.ApplyWorkshopData(dat); if (this._currentItem.needsLegal) { Steam.ShowWorkshopLegalAgreement("312530"); } this._upload.Open("Uploading...", this._currentItem); } else { this._notify.Open("Failed (" + this._currentItem.result.ToString() + ")"); this._doingPublish = false; } this._currentItem.ResetProcessing(); } else if (!this.opened || this._opening || (this._confirm.opened || this._upload.opened) || (this._deathmatchTest.opened || this._arcadeTest.opened || this._testSuccess.opened)) { if (this.opened) { Keyboard.keyString = ""; } this._opening = false; foreach (ContextMenu contextMenu in this._items) { contextMenu.disabled = true; } } else if (this._confirm.result) { if (this._levelType == LevelType.ArcadeMachine) { this._arcadeTest.Open("This machine can automatically show up in generated arcades, if you pass this validity test. You need to get the Developer trophy on all 3 challenges (oh boy)!"); } else { this._deathmatchTest.Open("In order to upload this map as a deathmatch level, all ducks need to be able to be eliminated. Do you want to launch the map and show that the map is functional? You don't have to do this, but the map won't show up with the DEATHMATCH tag without completing this test. If this is a challenge map, then don't worry about it!"); } this._confirm.result = false; } else if (this._testing) { Keyboard.keyString = ""; if (DeathmatchTestDialogue.success) { this._testSuccess.Open("Test success! The level can now be published as a deathmatch level!"); this._addDeathmatchTag = true; } else if (ArcadeTestDialogue.success) { if (this._arcadeTestIndex != 2) { ++this._arcadeTestIndex; ArcadeTestDialogue.success = false; ArcadeTestDialogue.currentEditor = Level.current as Editor; Level.current = this._arcadeTestIndex != 0 ? (this._arcadeTestIndex != 1 ? (Level) new ChallengeLevel(((Level.current as Editor).levelThings[0] as ArcadeMachine).challenge03Data, true) : (Level) new ChallengeLevel(((Level.current as Editor).levelThings[0] as ArcadeMachine).challenge02Data, true)) : (Level) new ChallengeLevel(((Level.current as Editor).levelThings[0] as ArcadeMachine).challenge01Data, true); this._testing = true; return; } this._testSuccess.Open("Test success! The arcade machine can now be published to the workshop!"); this._addMachineTag = true; } else if (DeathmatchTestDialogue.tooSlow) { this._notify.Open("Framerate too low!"); } else { this._notify.Open("Testing failed."); this._arcadeTestIndex = 0; } DeathmatchTestDialogue.success = false; ArcadeTestDialogue.success = false; this._testing = false; } else if (this._testSuccess.result) { this._doingPublish = true; if (this._currentItem == null) { this._currentItem = Steam.CreateItem(); } else { this._currentItem.SkipProcessing(); } this._testSuccess.result = false; } else if (this._deathmatchTest.result != -1) { if (this._deathmatchTest.result == 1) { this._doingPublish = true; if (this._currentItem == null) { this._currentItem = Steam.CreateItem(); } else { this._currentItem.SkipProcessing(); } } else if (this._deathmatchTest.result == 0) { DeathmatchTestDialogue.success = false; DeathmatchTestDialogue.currentEditor = Level.current as Editor; Level.current = (Level) new GameLevel(this._filePath, validityTest: true); this._testing = true; } this._deathmatchTest.result = -1; } else if (this._arcadeTest.result != -1) { if (this._arcadeTest.result == 1) { this._doingPublish = true; if (this._currentItem == null) { this._currentItem = Steam.CreateItem(); } else { this._currentItem.SkipProcessing(); } } else if (this._arcadeTest.result == 0) { ArcadeTestDialogue.success = false; ArcadeTestDialogue.currentEditor = Level.current as Editor; Level.current = (Level) new ChallengeLevel(((Level.current as Editor).levelThings[0] as ArcadeMachine).challenge01Data, true); this._testing = true; } this._arcadeTest.result = -1; } else { if (this._tagMenu != null) { return; } Vec2 vec2 = new Vec2((float)((double)this.layer.width / 2.0 - (double)this.width / 2.0) + this.hOffset, (float)((double)this.layer.height / 2.0 - (double)this.height / 2.0 - 15.0)) + new Vec2(7f, 276f); foreach (KeyValuePair <string, Vec2> tagPosition in this.tagPositions) { if ((double)Mouse.x > (double)tagPosition.Value.x && (double)Mouse.x < (double)tagPosition.Value.x + 8.0 && ((double)Mouse.y > (double)tagPosition.Value.y && (double)Mouse.y < (double)tagPosition.Value.y + 8.0) && Mouse.left == InputState.Pressed) { Editor.workshopTags.Remove(tagPosition.Key); return; } } if (this.tagPositions.Count != this._possibleTags.Count) { bool flag = false; if ((double)Mouse.x > (double)this._plusPosition.x && (double)Mouse.x < (double)this._plusPosition.x + 8.0 && ((double)Mouse.y > (double)this._plusPosition.y && (double)Mouse.y < (double)this._plusPosition.y + 8.0)) { flag = true; } if (flag && Mouse.left == InputState.Pressed) { ContextMenu contextMenu = new ContextMenu((IContextListener)this); contextMenu.x = this._plusPosition.x; contextMenu.y = this._plusPosition.y; contextMenu.root = true; contextMenu.depth = this.depth + 20; int num = 0; foreach (string possibleTag in this._possibleTags) { if (!Editor.workshopTags.Contains(possibleTag)) { contextMenu.AddItem(new ContextMenu((IContextListener)this) { itemSize = { x = 40f }, text = possibleTag }); ++num; } } contextMenu.y -= (float)(num * 16 + 10); Level.Add((Thing)contextMenu); contextMenu.opened = true; contextMenu.closeOnRight = true; this._tagMenu = contextMenu; return; } } Editor.lockInput = (ContextMenu)this; this._descriptionBox.Update(); this._nameBox.Update(); this._acceptHover = false; this._cancelHover = false; if ((double)Mouse.x > (double)this._acceptPos.x && (double)Mouse.x < (double)this._acceptPos.x + (double)this._acceptSize.x && ((double)Mouse.y > (double)this._acceptPos.y && (double)Mouse.y < (double)this._acceptPos.y + (double)this._acceptSize.y)) { this._acceptHover = true; } if ((double)Mouse.x > (double)this._cancelPos.x && (double)Mouse.x < (double)this._cancelPos.x + (double)this._cancelSize.x && ((double)Mouse.y > (double)this._cancelPos.y && (double)Mouse.y < (double)this._cancelPos.y + (double)this._cancelSize.y)) { this._cancelHover = true; } if (this._acceptHover && Mouse.left == InputState.Pressed) { if (this._nameBox.text == "") { this._notify.Open("Please enter a name :("); } else { this._confirm.Open("Upload to workshop?"); } } if (this._cancelHover && Mouse.left == InputState.Pressed) { this.Close(); } base.Update(); } }