using Client.MirControls; using Client.MirGraphics; using Client.MirNetwork; using Client.MirScenes.Dialogs; using Client.MirSounds; using C = ClientPackets; using S = ServerPackets; namespace Client.MirScenes { public class SelectScene : MirScene { public MirImageControl Background, Title; private NewCharacterDialog _character; public MirLabel ServerLabel; public MirAnimatedControl CharacterDisplay; public MirButton StartGameButton, NewCharacterButton, DeleteCharacterButton, CreditsButton, ExitGame; public CharacterButton[] CharacterButtons; public MirLabel LastAccessLabel, LastAccessLabelLabel; public List Characters = new List(); private int _selected; public SelectScene(List characters) { SoundManager.PlayMusic(SoundList.SelectMusic, true); Disposing += (o, e) => SoundManager.StopMusic(); Characters = characters; SortList(); KeyPress += SelectScene_KeyPress; Background = new MirImageControl { Index = 65, Library = Libraries.Prguse, Parent = this, }; Title = new MirImageControl { Index = 40, Library = Libraries.Title, Parent = this, Location = new Point(468, 20) }; ServerLabel = new MirLabel { Location = new Point(432, 60), // Location = new Point(322, 44), Parent = Background, Size = new Size(155, 17), Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GameName), DrawFormat = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter }; var xPoint = ((Settings.ScreenWidth - 200) / 5); StartGameButton = new MirButton { Enabled = false, HoverIndex = 341, Index = 340, Library = Libraries.Title, Location = new Point(100 + (xPoint * 1) - (xPoint / 2) - 50, Settings.ScreenHeight - 32), Parent = Background, PressedIndex = 342 }; StartGameButton.Click += (o, e) => StartGame(); NewCharacterButton = new MirButton { HoverIndex = 344, Index = 343, Library = Libraries.Title, Location = new Point(100 + (xPoint * 2) - (xPoint / 2) - 50, Settings.ScreenHeight - 32), Parent = Background, PressedIndex = 345, }; NewCharacterButton.Click += (o, e) => OpenNewCharacterDialog(); DeleteCharacterButton = new MirButton { HoverIndex = 347, Index = 346, Library = Libraries.Title, Location = new Point(100 + (xPoint * 3) - (xPoint / 2) - 50, Settings.ScreenHeight - 32), Parent = Background, PressedIndex = 348 }; DeleteCharacterButton.Click += (o, e) => DeleteCharacter(); CreditsButton = new MirButton { HoverIndex = 350, Index = 349, Library = Libraries.Title, Location = new Point(100 + (xPoint * 4) - (xPoint / 2) - 50, Settings.ScreenHeight - 32), Parent = Background, PressedIndex = 351 }; CreditsButton.Click += (o, e) => { }; ExitGame = new MirButton { HoverIndex = 353, Index = 352, Library = Libraries.Title, Location = new Point(100 + (xPoint * 5) - (xPoint / 2) - 50, Settings.ScreenHeight - 32), Parent = Background, PressedIndex = 354 }; ExitGame.Click += (o, e) => Program.Form.Close(); CharacterDisplay = new MirAnimatedControl { Animated = true, AnimationCount = 16, AnimationDelay = 250, FadeIn = true, FadeInDelay = 75, FadeInRate = 0.1F, Index = 220, Library = Libraries.ChrSel, Location = new Point(260, 420), Parent = Background, UseOffSet = true, Visible = false }; CharacterDisplay.AfterDraw += (o, e) => { // if (_selected >= 0 && _selected < Characters.Count && characters[_selected].Class == MirClass.Wizard) Libraries.ChrSel.DrawBlend(CharacterDisplay.Index + 560, CharacterDisplay.DisplayLocationWithoutOffSet, Color.White, true); }; CharacterButtons = new CharacterButton[4]; CharacterButtons[0] = new CharacterButton { Location = new Point(637, 194), Parent = Background, Sound = SoundList.ButtonA, }; CharacterButtons[0].Click += (o, e) => { if (characters.Count <= 0) return; _selected = 0; UpdateInterface(); }; CharacterButtons[1] = new CharacterButton { Location = new Point(637, 298), Parent = Background, Sound = SoundList.ButtonA, }; CharacterButtons[1].Click += (o, e) => { if (characters.Count <= 1) return; _selected = 1; UpdateInterface(); }; CharacterButtons[2] = new CharacterButton { Location = new Point(637, 402), Parent = Background, Sound = SoundList.ButtonA, }; CharacterButtons[2].Click += (o, e) => { if (characters.Count <= 2) return; _selected = 2; UpdateInterface(); }; CharacterButtons[3] = new CharacterButton { Location = new Point(637, 506), Parent = Background, Sound = SoundList.ButtonA, }; CharacterButtons[3].Click += (o, e) => { if (characters.Count <= 3) return; _selected = 3; UpdateInterface(); }; LastAccessLabel = new MirLabel { Location = new Point(265, 609), Parent = Background, Size = new Size(180, 21), DrawFormat = TextFormatFlags.Left | TextFormatFlags.VerticalCenter, Border = true, }; LastAccessLabelLabel = new MirLabel { Location = new Point(-65, 0), Parent = LastAccessLabel, Text = GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.LastOnlineTitle), Size = new Size(100, 21), DrawFormat = TextFormatFlags.Left | TextFormatFlags.VerticalCenter, Border = true, }; UpdateInterface(); } private void SelectScene_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != (char)Keys.Enter) return; if (StartGameButton.Enabled) StartGame(); e.Handled = true; } public void SortList() { if (Characters != null) Characters.Sort((c1, c2) => c2.LastAccess.CompareTo(c1.LastAccess)); } private void OpenNewCharacterDialog() { if (_character == null || _character.IsDisposed) { _character = new NewCharacterDialog { Parent = this }; _character.OnCreateCharacter += (o, e) => { Network.Enqueue(new C.NewCharacter { Name = _character.NameTextBox.Text, Class = _character.Class, Gender = _character.Gender }); }; } _character.Show(); } public void StartGame() { if (!Libraries.Loaded) { MirAnimatedControl loadProgress = new MirAnimatedControl { Library = Libraries.Prguse, Index = 940, Visible = true, Parent = this, Location = new Point(470, 680), Animated = true, AnimationCount = 9, AnimationDelay = 100, Loop = true, }; loadProgress.AfterDraw += (o, e) => { if (!Libraries.Loaded) return; loadProgress.Dispose(); StartGame(); }; return; } StartGameButton.Enabled = false; Network.Enqueue(new C.StartGame { CharacterIndex = Characters[_selected].Index }); } public override void Process() { } public override void ProcessPacket(Packet p) { switch (p.Index) { case (short)ServerPacketIds.NewCharacter: NewCharacter((S.NewCharacter)p); break; case (short)ServerPacketIds.NewCharacterSuccess: NewCharacter((S.NewCharacterSuccess)p); break; case (short)ServerPacketIds.DeleteCharacter: DeleteCharacter((S.DeleteCharacter)p); break; case (short)ServerPacketIds.DeleteCharacterSuccess: DeleteCharacter((S.DeleteCharacterSuccess)p); break; case (short)ServerPacketIds.StartGame: StartGame((S.StartGame)p); break; case (short)ServerPacketIds.StartGameBanned: StartGame((S.StartGameBanned)p); break; case (short)ServerPacketIds.StartGameDelay: StartGame((S.StartGameDelay)p); break; default: base.ProcessPacket(p); break; } } private void NewCharacter(S.NewCharacter p) { _character.OKButton.Enabled = true; switch (p.Result) { case 0: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CreatingNewCharactersDisabled)); _character.Dispose(); break; case 1: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YourCharacterNameNotAcceptable)); _character.NameTextBox.SetFocus(); break; case 2: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.GenderNotExistContactGM)); break; case 3: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.ClassNotExistContactGM)); break; case 4: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.YouCannotMakeMoreCharacters), Globals.MaxCharacterCount)); _character.Dispose(); break; case 5: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.CharacterNameExists)); _character.NameTextBox.SetFocus(); break; } } private void NewCharacter(S.NewCharacterSuccess p) { _character.Dispose(); MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YourCharacterCreatedSuccessfully)); Characters.Insert(0, p.CharInfo); _selected = 0; UpdateInterface(); } private void DeleteCharacter() { if (_selected < 0 || _selected >= Characters.Count) return; MirMessageBox message = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.ConfirmDeleteCharacter), Characters[_selected].Name), MirMessageBoxButtons.YesNo); int index = Characters[_selected].Index; message.YesButton.Click += (o1, e1) => { MirInputBox inputBox = new MirInputBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.PleaseEnterCharacterName)); inputBox.OKButton.Click += (o, e) => { string name = Characters[_selected].Name.ToString(); if (inputBox.InputTextBox.Text == name) { DeleteCharacterButton.Enabled = false; Network.Enqueue(new C.DeleteCharacter { CharacterIndex = index }); } else { MirMessageBox failedMessage = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.IncorrectEntry), MirMessageBoxButtons.OK); failedMessage.Show(); } inputBox.Dispose(); }; inputBox.Show(); }; message.Show(); } private void DeleteCharacter(S.DeleteCharacter p) { DeleteCharacterButton.Enabled = true; switch (p.Result) { case 0: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.DeletingCharactersDisabled)); break; case 1: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.SelectedCharacterNotExist)); break; } } private void DeleteCharacter(S.DeleteCharacterSuccess p) { DeleteCharacterButton.Enabled = true; MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YourCharacterDeletedSuccessfully)); for (int i = 0; i < Characters.Count; i++) if (Characters[i].Index == p.CharacterIndex) { Characters.RemoveAt(i); break; } UpdateInterface(); } private void StartGame(S.StartGameDelay p) { StartGameButton.Enabled = true; long time = CMain.Time + p.Milliseconds; MirMessageBox message = new MirMessageBox(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.CannotLoginCharacterSeconds), Math.Ceiling(p.Milliseconds / 1000M))); message.BeforeDraw += (o, e) => message.Label.Text = GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.CannotLoginCharacterSeconds), Math.Ceiling((time - CMain.Time) / 1000M)); message.AfterDraw += (o, e) => { if (CMain.Time <= time) return; message.Dispose(); StartGame(); }; message.Show(); } public void StartGame(S.StartGameBanned p) { StartGameButton.Enabled = true; TimeSpan d = p.ExpiryDate - CMain.Now; MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization((ClientTextKeys.AccountBannedReasonExpiryDuration), p.Reason, p.ExpiryDate, Math.Floor(d.TotalHours), d.Minutes, d.Seconds)); } public void StartGame(S.StartGame p) { StartGameButton.Enabled = true; switch (p.Result) { case 0: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.StartingGameDisabled)); break; case 1: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YouNotLoggedIn)); break; case 2: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.YourCharacterNotFound)); break; case 3: MirMessageBox.Show(GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.NoActiveMapOrStartPointFound)); break; case 4: if (p.Resolution < Settings.Resolution || Settings.Resolution == 0) Settings.Resolution = p.Resolution; switch (Settings.Resolution) { default: case 1024: Settings.Resolution = 1024; CMain.SetResolution(1024, 768); break; case 1280: CMain.SetResolution(1280, 800); break; case 1366: CMain.SetResolution(1366, 768); break; case 1920: CMain.SetResolution(1920, 1080); break; } ActiveScene = new GameScene(); Dispose(); break; } } private void UpdateInterface() { for (int i = 0; i < CharacterButtons.Length; i++) { CharacterButtons[i].Selected = i == _selected; CharacterButtons[i].Update(i >= Characters.Count ? null : Characters[i]); } if (_selected >= 0 && _selected < Characters.Count) { CharacterDisplay.Visible = true; //CharacterDisplay.Index = ((byte)Characters[_selected].Class + 1) * 20 + (byte)Characters[_selected].Gender * 280; switch ((MirClass)Characters[_selected].Class) { case MirClass.Warrior: CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 20 : 300; //220 : 500; break; case MirClass.Wizard: CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 40 : 320; //240 : 520; break; case MirClass.Taoist: CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 60 : 340; //260 : 540; break; case MirClass.Assassin: CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 80 : 360; //280 : 560; break; case MirClass.Archer: CharacterDisplay.Index = (byte)Characters[_selected].Gender == 0 ? 100 : 140; //160 : 180; break; } LastAccessLabel.Text = Characters[_selected].LastAccess == DateTime.MinValue ? GameLanguage.ClientTextMap.GetLocalization(ClientTextKeys.Never) : Characters[_selected].LastAccess.ToString("yyyy/MM/dd HH:mm:ss"); LastAccessLabel.Visible = true; LastAccessLabelLabel.Visible = true; StartGameButton.Enabled = true; } else { CharacterDisplay.Visible = false; LastAccessLabel.Visible = false; LastAccessLabelLabel.Visible = false; StartGameButton.Enabled = false; } } #region Disposable protected override void Dispose(bool disposing) { if (disposing) { Background = null; _character = null; ServerLabel = null; CharacterDisplay = null; StartGameButton = null; NewCharacterButton = null; DeleteCharacterButton = null; CreditsButton = null; ExitGame = null; CharacterButtons = null; LastAccessLabel = null; LastAccessLabelLabel = null; Characters = null; _selected = 0; } base.Dispose(disposing); } #endregion public sealed class CharacterButton : MirImageControl { public MirLabel NameLabel, LevelLabel, ClassLabel; public bool Selected; public CharacterButton() { Index = 44; //45 locked Library = Libraries.Prguse; Sound = SoundList.ButtonA; NameLabel = new MirLabel { Location = new Point(107, 9), Parent = this, NotControl = true, Size = new Size(170, 18) }; LevelLabel = new MirLabel { Location = new Point(107, 28), Parent = this, NotControl = true, Size = new Size(30, 18) }; ClassLabel = new MirLabel { Location = new Point(178, 28), Parent = this, NotControl = true, Size = new Size(100, 18) }; } public void Update(SelectInfo info) { if (info == null) { Index = 44; Library = Libraries.Prguse; NameLabel.Text = string.Empty; LevelLabel.Text = string.Empty; ClassLabel.Text = string.Empty; NameLabel.Visible = false; LevelLabel.Visible = false; ClassLabel.Visible = false; return; } Library = Libraries.Title; Index = 660 + (byte)info.Class; if (Selected) Index += 5; NameLabel.Text = info.Name; LevelLabel.Text = info.Level.ToString(); ClassLabel.Text = info.Class.ToLocalizedString(); NameLabel.Visible = true; LevelLabel.Visible = true; ClassLabel.Visible = true; } } } }