176 lines
5.3 KiB
C#
176 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using KMCCC.Authentication;
|
|
using KMCCC.Launcher;
|
|
using KMCCC.Tools;
|
|
using KMCCC.Modules;
|
|
using KMCCC.Modules.JVersion;
|
|
using CityCraft;
|
|
using System.IO;
|
|
using System.Windows.Threading;
|
|
|
|
namespace CTZLauncher
|
|
{
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
LauncherCore launcher = null;
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Window_Initialized(object sender, EventArgs e)
|
|
{
|
|
if (!Directory.Exists(".minecraft"))
|
|
{
|
|
Directory.CreateDirectory(".minecraft");
|
|
}
|
|
launcher = LauncherCore.Create(".minecraft");
|
|
}
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void Window_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void barclick_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
Label bar = (Label)sender;
|
|
MessageBox.Show(bar.Name);
|
|
switch (bar.Name.Substring(4))
|
|
{
|
|
case "l1":
|
|
break;
|
|
case "l2":
|
|
break;
|
|
case "l3":
|
|
break;
|
|
case "l4":
|
|
break;
|
|
case "r1":
|
|
break;
|
|
case "r2":
|
|
break;
|
|
case "r3":
|
|
break;
|
|
case "r4":
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void Login_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Login.IsEnabled = false;
|
|
CTZAuthenticator auth = new CTZAuthenticator(username.Text, password.Text, "127.0.0.1", 2000);
|
|
if (auth.isLogin())
|
|
{
|
|
MessageBox.Show("当前玩家已登录!");
|
|
}
|
|
else
|
|
{
|
|
if (!auth.Login())
|
|
{
|
|
MessageBox.Show("登录失败 账号不存在 或 密码错误 !");
|
|
}
|
|
else
|
|
{
|
|
ServerWindow.Visibility = System.Windows.Visibility.Visible;
|
|
}
|
|
}
|
|
Login.IsEnabled = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
|
|
/// </summary>
|
|
public void DoEvent()
|
|
{
|
|
DispatcherFrame frame = new DispatcherFrame();
|
|
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
|
|
Dispatcher.PushFrame(frame);
|
|
}
|
|
public object ExitFrame(object f)
|
|
{
|
|
((DispatcherFrame)f).Continue = false;
|
|
return null;
|
|
}
|
|
|
|
private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (e.LeftButton == MouseButtonState.Pressed)
|
|
this.DragMove();
|
|
}
|
|
|
|
private void StartGame_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Console.WriteLine("StartGame");
|
|
LaunchOptions option = new LaunchOptions();
|
|
option.Mode = LaunchMode.MCLauncher;
|
|
option.MaxMemory = 2048;
|
|
option.Authenticator = new OfflineAuthenticator(username.Text); // offline
|
|
option.Version = launcher.GetVersion("1.8");
|
|
launcher.JavaPath = SystemTools.FindJava().First();
|
|
launcher.GameLog += launcher_GameLog;
|
|
launcher.Launch(option);
|
|
}
|
|
|
|
void launcher_GameLog(LaunchHandle arg1, string log)
|
|
{
|
|
Console.WriteLine(log);
|
|
}
|
|
|
|
private void close_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void maxmem_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
//屏蔽中文输入和非法字符粘贴输入
|
|
TextBox textBox = sender as TextBox;
|
|
TextChange[] change = new TextChange[e.Changes.Count];
|
|
e.Changes.CopyTo(change, 0);
|
|
|
|
int offset = change[0].Offset;
|
|
if (change[0].AddedLength > 0)
|
|
{
|
|
double num = 0;
|
|
if (!Double.TryParse(textBox.Text, out num))
|
|
{
|
|
textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength);
|
|
textBox.Select(offset, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void register_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (username.Text.Length == 0 || password.Text.Length == 0)
|
|
{
|
|
MessageBox.Show("请输入账号密码!");
|
|
return;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|