| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638 |
- 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<SelectInfo> Characters = new List<SelectInfo>();
- private int _selected;
- public SelectScene(List<SelectInfo> 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;
- }
- }
- }
- }
|