public Item(int x, int y, MapCode code) { this.x = x; this.y = y; this.code = code; shoted = false; }
public static MapCode getInstance() { if(mapCode == null) mapCode = new MapCode(); return mapCode; }
/// <summary> /// Add button mapping. /// </summary> /// <param name="deadZone">Used when source is range/axis type.</param> public Map(MapCode code, string value, GamepadButtonFlags flag, string deadZone) { Target = TargetType.Button; Load(value); ButtonFlag = flag; int.TryParse(deadZone, out DeadZone); }
/// <summary> /// 类型:方法 /// 名称:Position /// 作者:taixihuase /// 作用:构造一个位置信息类实例 /// 编写日期:2015/8/16 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <param name="dir"></param> /// <param name="map"></param> public Position(float x = 0, float y = 0, float z = 0, float dir = 0, MapCode map = MapCode.World) { X = x; Y = y; Z = z; Direction = dir; Map = (byte) map; }
/// <summary> /// Add trigger and axis mapping: [Left|Right] [Trigger|ThumbAxisX|ThumbAxisY]. /// </summary> public Map(MapCode code, string value, TargetType target, string deadZone, string antiDeadZone, string linear) { Target = target; Load(value); int.TryParse(deadZone, out DeadZone); int.TryParse(antiDeadZone, out AntiDeadZone); int.TryParse(linear, out Linear); }
} // 朝向 /// <summary> /// 类型:方法 /// 名称:Position /// 作者:taixihuase /// 作用:构造一个位置信息类实例 /// 编写日期:2015/8/16 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <param name="dir"></param> /// <param name="map"></param> public Position(float x = 0, float y = 0, float z = 0, float dir = 0, MapCode map = MapCode.World) { X = x; Y = y; Z = z; Direction = dir; Map = (byte)map; }
public Item(int numOfFoxes, int x, int y, MapCode code) { this.numOfFoxes = numOfFoxes; this.x = x; this.y = y; this.code = code; shoted = false; }
internal Server(IPAddress IP, MapCode Code, int Port, string CustomName = null) { Endpoint = new IPEndPoint(IP, Port); if (IP.GetAddressBytes().All(Byte => Byte == 0)) { NoIP = true; } this.CustomName = CustomName; this.Code = Code; }
public ImageInfo(int image, MapCode code, double x, double y, Control label, Control control, GamepadButtonFlags button = GamepadButtonFlags.None) { Image = image; Label = label; Control = control; Button = button; Code = code; X = x; Y = y; }
public static bool IsButtonOrDirection(MapCode code) { return (MenuButtonCodes.Contains(code) || MainButtonCodes.Contains(code) || ShoulderButtonCodes.Contains(code) || TriggerButtonCodes.Contains(code) || ThumbDirections.Contains(code) || DPadDirections.Contains(code)); }
public string GetMiddleImageName(MapCode code) { if (code == MapCode.LeftTrigger || code == MapCode.RightTrigger) { return("Up"); } var rx = new Regex("(Up|Left|Right|Down)$"); var ms = rx.Matches(code.ToString()); var m = ms.Count > 0 ? ms[0].Value : ""; return(m); }
internal static void LoadServers(object State) { try { byte[] Data = TryDownloadData($"{RUSSIA}maps"); if (Data is null) { foreach (Server Server in Clusters[4].Servers) { Server.Refresh(-1); } } else { Server[] Servers; using (MemoryStream Stream = new MemoryStream(Data)) using (StreamReader Reader = new StreamReader(Stream)) { IPAddress IP = Parse(Reader.ReadLine()); int Count = int.Parse(Reader.ReadLine()); Servers = new Server[Count]; for (int Iterator = 0; Iterator < Count; Iterator++) { string[] Fields = Reader.ReadLine().Split(); int Port = int.Parse(Fields[0]); MapCode Map = (MapCode)int.Parse(Fields[1]); string CustomName = Fields.Length == 3 ? Fields[2].Replace('+', ' ') : null; Servers[Iterator] = new Server(IP, Map, Port, CustomName); } List <string> Info = new List <string>(); while (!Reader.EndOfStream) { string InfoLine = Reader.ReadLine(); string[] Fields = InfoLine.Split(); if (Fields.Length == 2 && Fields[0][0] == '{' && Fields[0][2] == '}') { InfoLine = string.Format(LocString(LocCode.MaxDinoLvl + int.Parse(Fields[0][1].ToString())), float.Parse(Fields[1])); } Info.Add(InfoLine); } Clusters[4].Info[string.Empty] = string.Join("\n", Info); } Sort(Servers, (A, B) => A.Code.CompareTo(B.Code)); Clusters[4].Servers = Servers; Current.Dispatcher.Invoke(RefreshClusterPage); foreach (Server Server in Clusters[4].Servers) { Server.Refresh(); } } } catch { } }
internal DLCItem GetItem(MapCode Code) { foreach (Panel Stack in RootGrid.Children) { foreach (DLCItem Item in Stack.Children) { if (Item.DLC.Code == Code) { return(Item); } } } return(null); }
internal static void LoadList(object State) { if (FileExists(UServersFile)) { using (FileStream Reader = OpenRead(UServersFile)) { byte[] Buffer = new byte[4]; Reader.Read(Buffer, 0, 2); int Count = ToInt16(Buffer, 0); for (int Iterator = 0; Iterator < Count; Iterator++) { Reader.Read(Buffer, 0, 4); IPAddress Address = new IPAddress(Buffer); MapCode Code = (MapCode)Reader.ReadByte(); Reader.Read(Buffer, 0, 2); int Port = ToUInt16(Buffer, 0); int MaxPlayers = Reader.ReadByte(), StringLength = Reader.ReadByte(); byte[] StringBuffer = new byte[StringLength]; Reader.Read(StringBuffer, 0, StringLength); string Hostname = null, Name = UTF8.GetString(StringBuffer); if (Address.GetAddressBytes().All(Byte => Byte == 0)) { Reader.Read(StringBuffer = new byte[StringLength = Reader.ReadByte()], 0, StringLength); Hostname = UTF8.GetString(StringBuffer); if (ResolvedIPs.ContainsKey(Hostname)) { Address = ResolvedIPs[Hostname]; } else { try { Address = GetHostAddresses(Hostname)[0]; ResolvedIPs.Add(Hostname, Address); } catch { } } } UServers.Add(new KeyValuePair <Server, string>(new Server(Address, Code, Port, Name) { MaxPlayers = MaxPlayers }, Hostname)); } CommitList(); } } }
public string GetMapName(MapCode map) { switch (map) { case MapCode.HowlingAbyss: return("Howling Abyss"); case MapCode.SummonersRift: return("Summoner's Rift"); case MapCode.TwistedTreeline: return("Twisted Treeline"); default: return("Uknown Map"); } }
internal static void LoadServers(object State) { try { byte[] Data = TryDownloadData($"{ARKdicted}workshop/ServersInfo.txt"); if (Data is null) { foreach (Server Server in Clusters[1].Servers) { Server.Refresh(-1); } } else { List <Server> Servers = new List <Server>(); using (MemoryStream Stream = new MemoryStream(Data)) using (StreamReader Reader = new StreamReader(Stream)) while (!Reader.EndOfStream) { string[] Fields = Reader.ReadLine().Split(); string Name = Fields[0].Substring(Fields[0].IndexOf('+') + 1).Replace('+', ' '); if (Fields[1] == "PVP") { Name += " PvP"; } MapCode Map = Name == "The Island" ? MapCode.TheIsland : MapCode.Mod; foreach (DLC DLC in DLCs) { if (Name == DLC.Name) { Map = DLC.Code; } } Servers.Add(new Server(Parse(Fields[2]), Map, int.Parse(Fields[3]), Map == MapCode.Mod ? Name : null)); } Servers.Sort((A, B) => A.Code.CompareTo(B.Code)); Clusters[1].Servers = Servers.ToArray(); Current.Dispatcher.Invoke(RefreshServers); foreach (Server Server in Clusters[1].Servers) { Server.Refresh(); } } } catch { } }
public MapCode GetNameCode(MapCode code) { if (code == MapCode.LeftThumbAxisX) { return(MapCode.LeftThumbRight); } if (code == MapCode.LeftThumbAxisY) { return(MapCode.LeftThumbUp); } if (code == MapCode.RightThumbAxisX) { return(MapCode.RightThumbRight); } if (code == MapCode.RightThumbAxisY) { return(MapCode.RightThumbUp); } return(code); }
public void SetImage(MapCode code, NavImageType type, bool show) { var nameCode = GetNameCode(code); var ii = Infos.First(x => x.Code == nameCode); var m = GetMiddleImageName(code); var resourceName = string.Format("Nav{0}{1}", m, type); var oldResourceName = ii.CurrentImageName; var isNameSame = ii.CurrentImageName == resourceName; var isShowSame = ii.CurrentImageShow == show; // Return if no changes must be made. // This will fix issue when click on image button is ignored. if (isNameSame && isShowSame) { return; } ii.CurrentImageName = resourceName; ii.CurrentImageShow = show; var button = FindName(nameCode.ToString()) as Button; if (button == null) { return; } var content = (ContentControl)button.Content; if (!isNameSame) { var vb = FindResource(resourceName) as Viewbox; content.Content = vb; } // Opacity must be reaplied if image changed. if (!isShowSame || !isNameSame) { content.Opacity = type == NavImageType.Record ? (show ? 0.8F : 0.2f) : (show ? 0.8F : 0.0f); } }
public CodeData CreateCodeData(TextCovertedData data, EventCodeScriptable scr) { if (data == null) { return(new EndCode()); } if (CheckChain(data)) { return(this); } CodeData result = null; switch (data._head) { case "": case "name": //name[name] result = new TextData(data); break; case "branch": //branch \nbranchName \n $#1... result = new BranchCode(data); break; case "flag": //flag[flagName] 5 result = new FlagCode(data); break; case "item": //item[itemName] 1 result = new ItemCode(data); break; case "map": //map[mapName] result = new MapCode(data); break; case "image": //image[setName,num] back (center) result = new ImageCode(data); break; case "music": //music[setName,0] result = new AudioCode(data); break; case "battle": //battle[enemySetName] result = new BattleCode(data); break; case "load": //load[black] 500 result = new LoadCode(data); break; case "wait": //wait[500] result = new WaitCode(data); break; default: return(null); } result._targetScr = scr; return(result); }
/// <summary> /// 类型:方法 /// 名称:SetMap /// 作者:taixihuase /// 作用:设置地图编号 /// 编写日期:2015/8/16 /// </summary> /// <param name="map"></param> public void SetMap(MapCode map) { Map = (byte)map; }
/// <summary> /// Add thumb mapping: [Left|Right] Thumb [Up|Left|Right|Down]. /// </summary> public Map(MapCode code, string value, TargetType target, short axisValue) { Target = target; Load(value); AxisValue = axisValue; }
static public SettingsMapItem AddMap <T>(string sectionName, Expression <Func <T> > setting, Control control, MapTo mapTo = MapTo.None, MapCode code = default) { // Get the member expression var me = (MemberExpression)setting.Body; // Get the property var prop = (PropertyInfo)me.Member; // Get the setting name by reading the property var keyName = (string)prop.GetValue(null, null); if (string.IsNullOrEmpty(keyName)) { keyName = prop.Name; } // Get the description attribute var descAttr = GetCustomAttribute <DescriptionAttribute>(prop); var desc = descAttr != null ? descAttr.Description : string.Empty; // Get the default value attribute var dvalAttr = GetCustomAttribute <DefaultValueAttribute>(prop); var dval = (string)(descAttr != null ? dvalAttr.Value : null); // Display help inside yellow header. // We could add settings EnableHelpTooltips=1, EnableHelpHeader=1 control.MouseHover += control_MouseEnter; control.MouseLeave += control_MouseLeave; var item = new SettingsMapItem(); item.Description = desc; item.IniSection = sectionName; item.IniKey = keyName; item.Code = code; item.Control = control; item.MapTo = mapTo; item.PropertyName = prop.Name; item.DefaultValue = dval; item.Property = prop; // Add to the map Current.SettingsMap.Add(item); return(item); }
static string[] CompareAxisAndSliders(int[] oldValues, int[] newValues, string name, MapCode mappingTo) { // Threshold mark at which action on axis/slider is detected. // [------|------------|------] // full half full // Full/Half depends on where original value was started: // [ 0 16383] - Full (16384 steps) // [16384 32767] - Half (16384 steps) // [32768 49151] - Half (16384 steps) // [49152 65535] - Full (16384 steps) // Inverted is added if new value is smaller (change is negative). var list = new List <string>(); if (oldValues.Length != newValues.Length) { return(list.ToArray()); } for (int i = 0; i < oldValues.Length; i++) { // Get difference between states (this object represents old value). var oldValue = oldValues[i]; var diff = newValues[i] - oldValue; var prefix = ""; // If moved more than 10%. if (Math.Abs(diff) > (ushort.MaxValue / 10)) { // If value is negative then add "I" prefix. if (diff < 0) { prefix += "I"; } // if starting point is located in the middle then... if ((oldValue > (ushort.MaxValue / 4)) && oldValue < (ushort.MaxValue * 3 / 4)) { // Note: Mapping wheel, which is centered in the middle, to the humb will use full axis. var thumb = mappingTo == MapCode.LeftThumbAxisX || mappingTo == MapCode.LeftThumbAxisY || mappingTo == MapCode.RightThumbAxisX || mappingTo == MapCode.RightThumbAxisY; // If target property is not thumb then... if (!thumb) { // Allow to add add half prefix. prefix += "H"; } } list.Add(string.Format("{0}{1} {2}", prefix, name, i + 1)); } } return(list.ToArray()); }
/// <summary> /// Compare to another state. /// </summary> public static string[] CompareTo(CustomDiState oldState, CustomDiState newState, MapCode mappingTo) { if (oldState == null) { throw new ArgumentNullException(nameof(oldState)); } if (newState == null) { throw new ArgumentNullException(nameof(newState)); } var list = new List <string>(); list.AddRange(CompareAxisAndSliders(oldState.Axis, newState.Axis, "Axis", mappingTo)); list.AddRange(CompareAxisAndSliders(oldState.Sliders, newState.Sliders, "Slider", mappingTo)); // Compare Buttons if (oldState.Buttons.Length == newState.Buttons.Length) { for (int i = 0; i < oldState.Buttons.Length; i++) { if (oldState.Buttons[i] != newState.Buttons[i]) { list.Add(string.Format("Button {0}", i + 1)); } } } ; // Compare POVs. if (oldState.Povs.Length == newState.Povs.Length) { for (int i = 0; i < oldState.Povs.Length; i++) { if (oldState.Povs[i] != newState.Povs[i]) { //list.Add(string.Format("DPad {0}", i + 1)); var v = newState.Povs[0]; if ((DPadEnum)v == DPadEnum.Up) { list.Add(string.Format("POV {0} {1}", i + 1, DPadEnum.Up.ToString())); } if ((DPadEnum)v == DPadEnum.Right) { list.Add(string.Format("POV {0} {1}", i + 1, DPadEnum.Right.ToString())); } if ((DPadEnum)v == DPadEnum.Down) { list.Add(string.Format("POV {0} {1}", i + 1, DPadEnum.Down.ToString())); } if ((DPadEnum)v == DPadEnum.Left) { list.Add(string.Format("POV {0} {1}", i + 1, DPadEnum.Left.ToString())); } } } } ; return(list.ToArray()); }
public void AddImageInfo(int image, MapCode code, double x, double y, object label, object control, GamepadButtonFlags button = GamepadButtonFlags.None) => _imageInfos.Add(new ImageInfo(image, code, x, y, label, control, button));
public void DrawState(ImageInfo ii, Gamepad gp) { bool on; // Show trigger axis state -green minus image. if (ii.Code == MapCode.LeftTrigger || ii.Code == MapCode.RightTrigger) { var isLeft = ii.Code == MapCode.LeftTrigger; var control = isLeft ? LeftTriggerStatus : RightTriggerStatus; var h = (float)(((System.Windows.FrameworkElement)control.Parent).Height - control.Height); var y = isLeft ? gp.LeftTrigger : gp.RightTrigger; var b = ConvertHelper.ConvertRangeF(byte.MinValue, byte.MaxValue, 0, h, y); var m = control.Margin; on = y > 0; control.Margin = new System.Windows.Thickness(m.Left, m.Top, m.Right, b); } // Draw thumb axis state - green cross image. if (ii.Code == MapCode.LeftThumbButton || ii.Code == MapCode.RightThumbButton) { var isLeft = ii.Code == MapCode.LeftThumbButton; var control = isLeft ? LeftThumbStatus : RightThumbStatus; var w = (float)((System.Windows.FrameworkElement)control.Parent).Width / 2F; var x = isLeft ? gp.LeftThumbX : gp.RightThumbX; var y = isLeft ? gp.LeftThumbY : gp.RightThumbY; var l = ConvertHelper.ConvertRangeF(short.MinValue, short.MaxValue, -w, w, x); var t = ConvertHelper.ConvertRangeF(short.MinValue, short.MaxValue, w, -w, y); var m = control.Margin; control.Margin = new System.Windows.Thickness(l, t, m.Right, m.Bottom); } // If D-Pad. if (ii.Code == MapCode.DPad) { on = gp.Buttons.HasFlag(GamepadButtonFlags.DPadUp) || gp.Buttons.HasFlag(GamepadButtonFlags.DPadLeft) || gp.Buttons.HasFlag(GamepadButtonFlags.DPadRight) || gp.Buttons.HasFlag(GamepadButtonFlags.DPadDown); } // If button is not specified then... else if (ii.Button == GamepadButtonFlags.None) { var t = 2000; // This is axis. short value = 0; if (ii.Code == MapCode.LeftThumbAxisX) { value = gp.LeftThumbX; } else if (ii.Code == MapCode.LeftThumbAxisY) { value = gp.LeftThumbY; } else if (ii.Code == MapCode.RightThumbAxisX) { value = gp.RightThumbX; } else if (ii.Code == MapCode.RightThumbAxisY) { value = gp.RightThumbY; } // Check when value is on. on = value <-t || value> t; if (ii.Code == MapCode.LeftThumbRight) { on = gp.LeftThumbX > t; } if (ii.Code == MapCode.LeftThumbLeft) { on = gp.LeftThumbX < -t; } if (ii.Code == MapCode.LeftThumbUp) { on = gp.LeftThumbY > t; } if (ii.Code == MapCode.LeftThumbDown) { on = gp.LeftThumbY < -t; } if (ii.Code == MapCode.RightThumbRight) { on = gp.RightThumbX > t; } if (ii.Code == MapCode.RightThumbLeft) { on = gp.RightThumbX < -t; } if (ii.Code == MapCode.RightThumbUp) { on = gp.RightThumbY > t; } if (ii.Code == MapCode.RightThumbDown) { on = gp.RightThumbY < -t; } } else { // Check when value is on. on = gp.Buttons.HasFlag(ii.Button); } MapCode recordingCode = ii.Code; var isRecordingItem = Recorder.Recording && ii.Code == Recorder.CurrentMap.Code; // If recording then... if (Recorder.Recording) { MapCode?redirect = null; if (Recorder.CurrentMap.Code == MapCode.RightThumbAxisX) { redirect = MapCode.RightThumbRight; } if (Recorder.CurrentMap.Code == MapCode.RightThumbAxisY) { redirect = MapCode.RightThumbUp; } if (Recorder.CurrentMap.Code == MapCode.LeftThumbAxisX) { redirect = MapCode.LeftThumbRight; } if (Recorder.CurrentMap.Code == MapCode.LeftThumbAxisY) { redirect = MapCode.LeftThumbUp; } if (redirect.HasValue) { recordingCode = redirect.Value; // Skip if redirected control. if (ii.Code == recordingCode) { return; } } } // If recording is in progress then... if (isRecordingItem) { ImageControl.SetImage(recordingCode, NavImageType.Record, Recorder.DrawRecordingImage); } else if ( ShowLeftThumbButtons && SettingsConverter.LeftThumbCodes.Contains(ii.Code) || ShowRightThumbButtons && SettingsConverter.RightThumbCodes.Contains(ii.Code) || ShowDPadButtons && SettingsConverter.DPadCodes.Contains(ii.Code) || ShowMainButtons && SettingsConverter.MainButtonCodes.Contains(ii.Code) || ShowMenuButtons && SettingsConverter.MenuButtonCodes.Contains(ii.Code) || ShowTriggerButtons && SettingsConverter.TriggerButtonCodes.Contains(ii.Code) || ShowShoulderButtons && SettingsConverter.ShoulderButtonCodes.Contains(ii.Code) ) { var nit = on ? NavImageType.Active : NavImageType.Normal; ImageControl.SetImage(ii.Code, nit, true); } else { var isAxisCode = SettingsConverter.AxisCodes.Contains(ii.Code); // Axis status will be displayed as image therefore can hide active button indicator. ImageControl.SetImage(ii.Code, NavImageType.Active, on && !isAxisCode); } if (ii.Label is Control cl) { setLabelColor(on, cl); } if (ii.Label is System.Windows.Controls.ContentControl cl2) { setLabelColor(on, cl2); } }
/// <summary> /// 类型:方法 /// 名称:SetMap /// 作者:taixihuase /// 作用:设置地图编号 /// 编写日期:2015/8/16 /// </summary> /// <param name="map"></param> public void SetMap(MapCode map) { Map = (byte) map; }
private static Server ResolveServer(IPAddress IP, int Port) { IPEndPoint Endpoint = new IPEndPoint(IP, Port); using (UdpClient Client = new UdpClient()) { Client.Client.SendTimeout = Client.Client.ReceiveTimeout = 4000; try { Client.Connect(Endpoint); byte[] Datagram = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x54, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x45, 0x6E, 0x67, 0x69, 0x6E, 0x65, 0x20, 0x51, 0x75, 0x65, 0x72, 0x79, 0x00 }; Client.Send(Datagram, 25); bool NS = false; int MaxPlayers; string Map = string.Empty, Name = string.Empty; using (MemoryStream Reader = new MemoryStream(Client.Receive(ref Endpoint))) { Reader.Position = 6L; int Char; while ((Char = Reader.ReadByte()) != 0) { Name += ToChar(Char); } while ((Char = Reader.ReadByte()) != 0) { Map += ToChar(Char); } while (Reader.ReadByte() != 0) { ; } while (Reader.ReadByte() != 0) { ; } byte[] Buffer = new byte[2]; Reader.Read(Buffer, 0, 2); if (ToInt16(Buffer, 0) != 480) { NS = true; } Reader.Position++; MaxPlayers = Reader.ReadByte(); } MapCode Code = MapCode.TheIsland; foreach (DLC DLC in DLCs) { if (Map.Contains(DLC.Name)) { Code = DLC.Code; } } if (Name.Length > 27) { Name = Name.Substring(0, 27); } return(new Server(IP, NS ? (MapCode)(-1) : Code, Port, Name) { MaxPlayers = MaxPlayers }); } catch { return(null); } } }
public void Add(int image, MapCode code, double x, double y, Control label, Control control, GamepadButtonFlags button = GamepadButtonFlags.None) => Add(new ImageInfo(image, code, x, y, label, control, button));