mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Layers are finally being drawn to keyboard
This commit is contained in:
parent
36bdfa5aaa
commit
e95b33e9bb
@ -314,6 +314,7 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Modules\Games\CounterStrike\CounterStrikeDataModel.cs" />
|
||||
<Compile Include="Modules\Games\CounterStrike\CounterStrikeModel.cs" />
|
||||
<Compile Include="Modules\Games\CounterStrike\CounterStrikeSettings.cs" />
|
||||
<Compile Include="Modules\Games\Dota2\Dota2.Designer.cs">
|
||||
|
||||
@ -6,7 +6,6 @@ using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using Artemis.Models;
|
||||
using Artemis.Models.Profiles;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.DAL
|
||||
{
|
||||
@ -48,7 +47,7 @@ namespace Artemis.DAL
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
var serializer = new XmlSerializer(typeof(ProfileModel));
|
||||
var serializer = new XmlSerializer(typeof (ProfileModel));
|
||||
using (var file = new StreamWriter(path + $@"\{prof.Name}.xml"))
|
||||
{
|
||||
serializer.Serialize(file, prof);
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows;
|
||||
using Size = System.Windows.Size;
|
||||
|
||||
namespace Artemis.KeyboardProviders
|
||||
{
|
||||
@ -28,5 +30,7 @@ namespace Artemis.KeyboardProviders
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap KeyboardBitmap(int scale) => new Bitmap(Width*scale, Height*scale);
|
||||
|
||||
public Rect KeyboardRectangle(int scale) => new Rect(new Size(Width*scale, Height*scale));
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,15 @@
|
||||
using Artemis.Managers;
|
||||
using Artemis.Models.Interfaces;
|
||||
using Artemis.Models.Profiles;
|
||||
|
||||
namespace Artemis.Models
|
||||
{
|
||||
public abstract class GameModel : EffectModel
|
||||
{
|
||||
public bool Enabled;
|
||||
public string ProcessName;
|
||||
public bool Enabled { get; set; }
|
||||
public string ProcessName { get; set; }
|
||||
public IGameDataModel GameDataModel { get; set; }
|
||||
public ProfileModel Profile { get; set; }
|
||||
|
||||
protected GameModel(MainManager mainManager) : base(mainManager)
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Dynamic;
|
||||
using Artemis.Models.Interfaces;
|
||||
|
||||
@ -9,13 +10,25 @@ namespace Artemis.Models.Profiles
|
||||
public string Field { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Operator { get; set; }
|
||||
public string Type { get; set; }
|
||||
|
||||
public bool ConditionMet<T>(IGameDataModel subject)
|
||||
{
|
||||
// Put the subject in a list, allowing Dynamic Linq to be used.
|
||||
var subjectList = new List<T> {(T) subject};
|
||||
var res = subjectList.Where($"{Field} {Operator} {Value}").Any();
|
||||
return res;
|
||||
if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Type))
|
||||
return false;
|
||||
try
|
||||
{
|
||||
// Put the subject in a list, allowing Dynamic Linq to be used.
|
||||
var subjectList = new List<T> {(T) subject};
|
||||
var res = Type == "String"
|
||||
? subjectList.Where($"{Field}.ToLower() {Operator} @0", Value.ToLower()).Any()
|
||||
: subjectList.Where($"{Field} {Operator} {Value}").Any();
|
||||
return res;
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,6 @@ using System.Windows.Media;
|
||||
using System.Xml.Serialization;
|
||||
using Artemis.Models.Interfaces;
|
||||
using Artemis.Utilities;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Models.Profiles
|
||||
{
|
||||
@ -57,10 +56,9 @@ namespace Artemis.Models.Profiles
|
||||
if (!ConditionsMet<T>(dataModel))
|
||||
return;
|
||||
|
||||
Update<T>(dataModel);
|
||||
|
||||
if (LayerType == LayerType.Folder)
|
||||
DrawChildren<T>(dataModel, c);
|
||||
foreach (var layerModel in Children)
|
||||
layerModel.Draw<T>(dataModel, c);
|
||||
else if (LayerType == LayerType.KeyboardRectangle || LayerType == LayerType.KeyboardEllipse)
|
||||
_drawer.Draw(c);
|
||||
else if (LayerType == LayerType.KeyboardGif)
|
||||
@ -71,18 +69,19 @@ namespace Artemis.Models.Profiles
|
||||
_drawer.UpdateHeadset();
|
||||
}
|
||||
|
||||
private void Update<T>(IGameDataModel dataModel)
|
||||
public void Update<T>(IGameDataModel dataModel)
|
||||
{
|
||||
if (LayerType == LayerType.Folder)
|
||||
{
|
||||
foreach (var layerModel in Children)
|
||||
layerModel.Update<T>(dataModel);
|
||||
return;
|
||||
}
|
||||
|
||||
GeneralHelpers.CopyProperties(LayerCalculatedProperties, LayerUserProperties);
|
||||
foreach (var dynamicProperty in LayerProperties)
|
||||
dynamicProperty.ApplyProperty<T>(dataModel, LayerUserProperties, LayerCalculatedProperties);
|
||||
}
|
||||
|
||||
private void DrawChildren<T>(IGameDataModel dataModel, DrawingContext c)
|
||||
{
|
||||
foreach (var layerModel in Children)
|
||||
layerModel.Draw<T>(dataModel, c);
|
||||
}
|
||||
}
|
||||
|
||||
public enum LayerType
|
||||
|
||||
@ -4,9 +4,9 @@ using System.Xml.Serialization;
|
||||
|
||||
namespace Artemis.Models.Profiles
|
||||
{
|
||||
[XmlInclude(typeof(LinearGradientBrush))]
|
||||
[XmlInclude(typeof(RadialGradientBrush))]
|
||||
[XmlInclude(typeof(MatrixTransform))]
|
||||
[XmlInclude(typeof (LinearGradientBrush))]
|
||||
[XmlInclude(typeof (RadialGradientBrush))]
|
||||
[XmlInclude(typeof (MatrixTransform))]
|
||||
public class LayerPropertiesModel
|
||||
{
|
||||
public int X { get; set; }
|
||||
|
||||
@ -0,0 +1,124 @@
|
||||
using Artemis.Models.Interfaces;
|
||||
|
||||
namespace Artemis.Modules.Games.CounterStrike
|
||||
{
|
||||
public class CounterStrikeDataModel : IGameDataModel
|
||||
{
|
||||
public Provider provider { get; set; }
|
||||
public Map map { get; set; }
|
||||
public Round round { get; set; }
|
||||
public Player player { get; set; }
|
||||
public Previously previously { get; set; }
|
||||
}
|
||||
|
||||
public class Provider
|
||||
{
|
||||
public string name { get; set; }
|
||||
public int appid { get; set; }
|
||||
public int version { get; set; }
|
||||
public string steamid { get; set; }
|
||||
public int timestamp { get; set; }
|
||||
}
|
||||
|
||||
public class TeamCt
|
||||
{
|
||||
public int score { get; set; }
|
||||
}
|
||||
|
||||
public class TeamT
|
||||
{
|
||||
public int score { get; set; }
|
||||
}
|
||||
|
||||
public class Map
|
||||
{
|
||||
public string mode { get; set; }
|
||||
public string name { get; set; }
|
||||
public string phase { get; set; }
|
||||
public int round { get; set; }
|
||||
public TeamCt team_ct { get; set; }
|
||||
public TeamT team_t { get; set; }
|
||||
}
|
||||
|
||||
public class Round
|
||||
{
|
||||
public string phase { get; set; }
|
||||
}
|
||||
|
||||
public class State
|
||||
{
|
||||
public int health { get; set; }
|
||||
public int armor { get; set; }
|
||||
public bool helmet { get; set; }
|
||||
public int flashed { get; set; }
|
||||
public int smoked { get; set; }
|
||||
public int burning { get; set; }
|
||||
public int money { get; set; }
|
||||
public int round_kills { get; set; }
|
||||
public int round_killhs { get; set; }
|
||||
}
|
||||
|
||||
public class Weapon0
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string paintkit { get; set; }
|
||||
public string type { get; set; }
|
||||
public string state { get; set; }
|
||||
}
|
||||
|
||||
public class Weapon1
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string paintkit { get; set; }
|
||||
public string type { get; set; }
|
||||
public int ammo_clip { get; set; }
|
||||
public int ammo_clip_max { get; set; }
|
||||
public int ammo_reserve { get; set; }
|
||||
public string state { get; set; }
|
||||
}
|
||||
|
||||
public class Weapon2
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string paintkit { get; set; }
|
||||
public string type { get; set; }
|
||||
public string state { get; set; }
|
||||
}
|
||||
|
||||
public class Weapons
|
||||
{
|
||||
public Weapon0 weapon_0 { get; set; }
|
||||
public Weapon1 weapon_1 { get; set; }
|
||||
public Weapon2 weapon_2 { get; set; }
|
||||
}
|
||||
|
||||
public class MatchStats
|
||||
{
|
||||
public int kills { get; set; }
|
||||
public int assists { get; set; }
|
||||
public int deaths { get; set; }
|
||||
public int mvps { get; set; }
|
||||
public int score { get; set; }
|
||||
}
|
||||
|
||||
public class Player
|
||||
{
|
||||
public string steamid { get; set; }
|
||||
public string name { get; set; }
|
||||
public string team { get; set; }
|
||||
public string activity { get; set; }
|
||||
public State state { get; set; }
|
||||
public Weapons weapons { get; set; }
|
||||
public MatchStats match_stats { get; set; }
|
||||
}
|
||||
|
||||
public class Round2
|
||||
{
|
||||
public string phase { get; set; }
|
||||
}
|
||||
|
||||
public class Previously
|
||||
{
|
||||
public Round2 round { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,23 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using Artemis.KeyboardProviders;
|
||||
using System.Drawing;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Artemis.Managers;
|
||||
using Artemis.Models;
|
||||
using Artemis.Utilities;
|
||||
using Artemis.Utilities.GameState;
|
||||
using Artemis.Utilities.Keyboard;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Artemis.Modules.Games.CounterStrike
|
||||
{
|
||||
public class CounterStrikeModel : GameModel
|
||||
{
|
||||
private KeyboardRegion _topRow;
|
||||
|
||||
public CounterStrikeModel(MainManager mainManager, CounterStrikeSettings settings) : base(mainManager)
|
||||
{
|
||||
Settings = settings;
|
||||
@ -30,14 +23,6 @@ namespace Artemis.Modules.Games.CounterStrike
|
||||
|
||||
public CounterStrikeSettings Settings { get; set; }
|
||||
|
||||
public KeyboardRectangle EventRect { get; set; }
|
||||
public KeyboardRectangle TeamRect { get; set; }
|
||||
public KeyboardRectangle AmmoRect { get; set; }
|
||||
public JObject CsJson { get; set; }
|
||||
|
||||
public bool DrawingSmoke { get; set; }
|
||||
public bool DrawingFlash { get; set; }
|
||||
|
||||
public int Scale { get; set; }
|
||||
|
||||
public override void Dispose()
|
||||
@ -50,23 +35,7 @@ namespace Artemis.Modules.Games.CounterStrike
|
||||
{
|
||||
Initialized = false;
|
||||
|
||||
// Some keyboards have a different baseline, Corsair F-keys start at row 1
|
||||
_topRow = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRegions.First(r => r.RegionName == "TopRow");
|
||||
AmmoRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, _topRow.TopLeft.X,
|
||||
new List<Color>(),
|
||||
LinearGradientMode.Horizontal) {Height = Scale, ContainedBrush = false};
|
||||
TeamRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, _topRow.TopLeft.X + 1,
|
||||
new List<Color>(),
|
||||
LinearGradientMode.Horizontal)
|
||||
{
|
||||
Height = MainManager.KeyboardManager.ActiveKeyboard.Height*Scale - Scale
|
||||
};
|
||||
EventRect = new KeyboardRectangle(MainManager.KeyboardManager.ActiveKeyboard, 0, _topRow.TopLeft.X + 1,
|
||||
new List<Color>(),
|
||||
LinearGradientMode.Horizontal)
|
||||
{
|
||||
Height = MainManager.KeyboardManager.ActiveKeyboard.Height*Scale - Scale
|
||||
};
|
||||
GameDataModel = new CounterStrikeDataModel();
|
||||
MainManager.GameStateWebServer.GameDataReceived += HandleGameData;
|
||||
|
||||
Initialized = true;
|
||||
@ -74,124 +43,33 @@ namespace Artemis.Modules.Games.CounterStrike
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (CsJson == null)
|
||||
if (Profile == null || GameDataModel == null)
|
||||
return;
|
||||
|
||||
if (Settings.AmmoEnabled)
|
||||
UpdateAmmo();
|
||||
if (Settings.TeamColorEnabled)
|
||||
UpdateTeam();
|
||||
if (Settings.LowHpEnabled)
|
||||
UpdateHealth();
|
||||
if (Settings.FlashEnabled)
|
||||
UpdateFlash();
|
||||
if (Settings.SmokeEnabled)
|
||||
UpdateSmoke();
|
||||
}
|
||||
|
||||
private void UpdateHealth()
|
||||
{
|
||||
if (CsJson["player"]?["state"]?["health"] == null)
|
||||
return;
|
||||
|
||||
var health = CsJson["player"]["state"]["health"].Value<int>();
|
||||
if (health > 25 || health < 1)
|
||||
return;
|
||||
|
||||
TeamRect.Colors = new List<Color> {Color.Red, Color.OrangeRed, Color.Red, Color.OrangeRed};
|
||||
}
|
||||
|
||||
private void UpdateSmoke()
|
||||
{
|
||||
if (CsJson["player"]?["state"]?["smoked"] == null)
|
||||
return;
|
||||
|
||||
var smoked = CsJson["player"]["state"]["smoked"].Value<int>();
|
||||
if (smoked == 0 && !DrawingSmoke)
|
||||
return;
|
||||
|
||||
EventRect.Colors = new List<Color> {Color.FromArgb(smoked, 255, 255, 255)};
|
||||
DrawingSmoke = smoked != 0;
|
||||
}
|
||||
|
||||
private void UpdateFlash()
|
||||
{
|
||||
if (CsJson["player"]?["state"]?["flashed"] == null)
|
||||
return;
|
||||
|
||||
var flashed = CsJson["player"]["state"]["flashed"].Value<int>();
|
||||
if (flashed == 0 && !DrawingFlash)
|
||||
return;
|
||||
|
||||
EventRect.Colors = new List<Color> {Color.FromArgb(flashed, 255, 255, 255)};
|
||||
DrawingFlash = flashed != 0;
|
||||
}
|
||||
|
||||
private void UpdateTeam()
|
||||
{
|
||||
var currentTeam = CsJson["player"]?["team"];
|
||||
if (currentTeam == null)
|
||||
return;
|
||||
|
||||
var t1 = Color.FromArgb(255, 255, 129, 0);
|
||||
var t2 = Color.FromArgb(255, 255, 170, 125);
|
||||
|
||||
var ct1 = Color.FromArgb(255, 203, 238, 255);
|
||||
var ct2 = Color.FromArgb(255, 0, 173, 255);
|
||||
|
||||
TeamRect.Colors = currentTeam.Value<string>() == "T"
|
||||
? new List<Color> {t1, t2, t1, t2}
|
||||
: new List<Color> {ct1, ct2, ct1, ct2};
|
||||
TeamRect.Rotate = true;
|
||||
}
|
||||
|
||||
private void UpdateAmmo()
|
||||
{
|
||||
if (CsJson["player"]["weapons"] == null)
|
||||
return;
|
||||
|
||||
var activeWeapon =
|
||||
CsJson["player"]["weapons"].Children()
|
||||
.Select(c => c.First)
|
||||
.FirstOrDefault(w => w["state"]?.Value<string>() == "active");
|
||||
|
||||
// Update the ammo display
|
||||
if (activeWeapon?["ammo_clip_max"] == null || activeWeapon["ammo_clip"] == null)
|
||||
return;
|
||||
|
||||
var maxAmmo = activeWeapon["ammo_clip_max"].Value<int>();
|
||||
var ammo = activeWeapon["ammo_clip"].Value<int>();
|
||||
|
||||
if (maxAmmo < 0)
|
||||
return;
|
||||
|
||||
var ammoPercentage = (int) Math.Ceiling(100.00/maxAmmo)*ammo;
|
||||
AmmoRect.Width = (int) Math.Floor(_topRow.BottomRight.Y/100.00*ammoPercentage)*Scale;
|
||||
AmmoRect.Colors = new List<Color>
|
||||
{
|
||||
ColorHelpers.ToDrawingColor(Settings.AmmoMainColor),
|
||||
ColorHelpers.ToDrawingColor(Settings.AmmoSecondaryColor)
|
||||
};
|
||||
|
||||
// Low ammo indicator
|
||||
if (ammoPercentage < 37)
|
||||
AmmoRect.StartBlink(1000);
|
||||
else
|
||||
AmmoRect.StopBlink();
|
||||
foreach (var layerModel in Profile.Layers)
|
||||
layerModel.Update<CounterStrikeDataModel>(GameDataModel);
|
||||
}
|
||||
|
||||
public override Bitmap GenerateBitmap()
|
||||
{
|
||||
var bitmap = MainManager.KeyboardManager.ActiveKeyboard.KeyboardBitmap(Scale);
|
||||
var keyboardRect = MainManager.KeyboardManager.ActiveKeyboard.KeyboardRectangle(Scale);
|
||||
|
||||
using (var g = Graphics.FromImage(bitmap))
|
||||
var visual = new DrawingVisual();
|
||||
using (var drawingContext = visual.RenderOpen())
|
||||
{
|
||||
g.Clear(Color.Transparent);
|
||||
AmmoRect.Draw(g);
|
||||
TeamRect.Draw(g);
|
||||
EventRect.Draw(g);
|
||||
// Setup the DrawingVisual's size
|
||||
drawingContext.PushClip(new RectangleGeometry(keyboardRect));
|
||||
drawingContext.DrawRectangle(new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)), null, keyboardRect);
|
||||
|
||||
// Draw the layers
|
||||
foreach (var layerModel in Profile.Layers)
|
||||
layerModel.Draw<CounterStrikeDataModel>(GameDataModel, drawingContext);
|
||||
|
||||
// Remove the clip
|
||||
drawingContext.Pop();
|
||||
}
|
||||
return bitmap;
|
||||
|
||||
return ImageUtilities.DrawinVisualToBitmap(visual, keyboardRect);
|
||||
}
|
||||
|
||||
public void HandleGameData(object sender, GameDataReceivedEventArgs e)
|
||||
@ -203,7 +81,7 @@ namespace Artemis.Modules.Games.CounterStrike
|
||||
return;
|
||||
|
||||
// Parse the JSON
|
||||
CsJson = JsonConvert.DeserializeObject<JObject>(jsonString);
|
||||
GameDataModel = JsonConvert.DeserializeObject<CounterStrikeDataModel>(jsonString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -19,11 +19,6 @@
|
||||
<RowDefinition Height="80" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
|
||||
</Grid.RowDefinitions>
|
||||
@ -58,73 +53,11 @@
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Ammo display -->
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Width="130" VerticalAlignment="Center"
|
||||
Height="16" Margin="0,10,0,9">
|
||||
Display ammo on F-keys
|
||||
</TextBlock>
|
||||
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.AmmoEnabled, Mode=TwoWay}"
|
||||
Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
|
||||
Margin="0,0,-5,0" Width="114" />
|
||||
|
||||
<!-- Ammo main color -->
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" HorizontalAlignment="Left" Width="94" VerticalAlignment="Center"
|
||||
Height="16" Margin="0,8">
|
||||
Main ammo color
|
||||
</TextBlock>
|
||||
<xctk:ColorPicker x:Name="MainColor"
|
||||
SelectedColor="{Binding Path=GameSettings.AmmoMainColor, Mode=TwoWay}"
|
||||
Grid.Row="3" Grid.Column="1" Width="110" HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
|
||||
|
||||
<!-- Ammo secondary color -->
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" HorizontalAlignment="Left" Width="122" VerticalAlignment="Center"
|
||||
Height="16" Margin="0,8">
|
||||
Secondary ammo color
|
||||
</TextBlock>
|
||||
<xctk:ColorPicker x:Name="SecondaryColor"
|
||||
SelectedColor="{Binding Path=GameSettings.AmmoSecondaryColor, Mode=TwoWay}"
|
||||
Grid.Row="4" Grid.Column="1" Width="110" HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center" Margin="0,5,-1,5" Height="22" />
|
||||
|
||||
<!-- Smoke effect -->
|
||||
<TextBlock Grid.Row="5" Grid.Column="0" HorizontalAlignment="Left" Width="116" VerticalAlignment="Center"
|
||||
Height="16" Margin="0,9,0,10">
|
||||
Display smoked effect
|
||||
</TextBlock>
|
||||
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.SmokeEnabled, Mode=TwoWay}"
|
||||
Grid.Row="5" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
|
||||
Margin="0,0,-5,0" Width="114" />
|
||||
|
||||
<!-- Flash effect -->
|
||||
<TextBlock Grid.Row="6" Grid.Column="0" HorizontalAlignment="Left" Width="113" VerticalAlignment="Center"
|
||||
Height="16" Margin="0,10,0,9">
|
||||
Display flashed effect
|
||||
</TextBlock>
|
||||
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.FlashEnabled, Mode=TwoWay}"
|
||||
Grid.Row="6" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
|
||||
Margin="0,0,-5,0" Width="114" />
|
||||
|
||||
<!-- Team color -->
|
||||
<TextBlock Grid.Row="7" Grid.Column="0" HorizontalAlignment="Left" Width="181" VerticalAlignment="Center"
|
||||
Height="16" Margin="0,9,0,10">
|
||||
Color keyboard according to team
|
||||
</TextBlock>
|
||||
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.TeamColorEnabled, Mode=TwoWay}"
|
||||
Grid.Row="7" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
|
||||
Margin="0,0,-5,0" Width="114" />
|
||||
|
||||
<!-- Team color -->
|
||||
<TextBlock Grid.Row="8" Grid.Column="0" HorizontalAlignment="Left" Width="160" VerticalAlignment="Center"
|
||||
Height="16" Margin="0,10,0,9">
|
||||
Color keyboard red on low HP
|
||||
</TextBlock>
|
||||
<controls:ToggleSwitch IsChecked="{Binding Path=GameSettings.LowHpEnabled, Mode=TwoWay}"
|
||||
Grid.Row="8" Grid.Column="1" HorizontalAlignment="Right" OnLabel="Yes" OffLabel="No"
|
||||
Margin="0,0,-5,0" Width="114" />
|
||||
<!-- Profile editor -->
|
||||
<ContentControl Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" x:Name="ProfileEditor" />
|
||||
|
||||
<!-- Buttons -->
|
||||
<StackPanel Grid.Column="0" Grid.Row="9" Orientation="Horizontal" VerticalAlignment="Bottom">
|
||||
<StackPanel Grid.Column="0" Grid.Row="4" Orientation="Horizontal" VerticalAlignment="Bottom">
|
||||
<Button x:Name="ResetSettings" Content="Reset effect" VerticalAlignment="Top" Width="100"
|
||||
Style="{DynamicResource SquareButtonStyle}" />
|
||||
<Button x:Name="SaveSettings" Content="Save changes" VerticalAlignment="Top" Width="100"
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Windows.Forms;
|
||||
using Artemis.Managers;
|
||||
using Artemis.Properties;
|
||||
using Artemis.ViewModels;
|
||||
using Artemis.ViewModels.Abstract;
|
||||
|
||||
namespace Artemis.Modules.Games.CounterStrike
|
||||
@ -19,8 +20,14 @@ namespace Artemis.Modules.Games.CounterStrike
|
||||
GameModel = new CounterStrikeModel(mainManager, (CounterStrikeSettings) GameSettings);
|
||||
MainManager.EffectManager.EffectModels.Add(GameModel);
|
||||
PlaceConfigFile();
|
||||
|
||||
ProfileEditor = new ProfileEditorViewModel<CounterStrikeDataModel>(MainManager, GameModel);
|
||||
|
||||
GameModel.Profile = ProfileEditor.SelectedProfileModel;
|
||||
}
|
||||
|
||||
public ProfileEditorViewModel<CounterStrikeDataModel> ProfileEditor { get; set; }
|
||||
|
||||
public static string Name => "CS:GO";
|
||||
public string Content => "Counter-Strike: GO Content";
|
||||
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
||||
|
||||
namespace Artemis.Utilities
|
||||
{
|
||||
@ -38,12 +40,12 @@ namespace Artemis.Utilities
|
||||
{
|
||||
var width = srs.PixelWidth;
|
||||
var height = srs.PixelHeight;
|
||||
var stride = width * ((srs.Format.BitsPerPixel + 7) / 8);
|
||||
var stride = width*((srs.Format.BitsPerPixel + 7)/8);
|
||||
var ptr = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
ptr = Marshal.AllocHGlobal(height * stride);
|
||||
srs.CopyPixels(new Int32Rect(0, 0, width, height), ptr, height * stride, stride);
|
||||
ptr = Marshal.AllocHGlobal(height*stride);
|
||||
srs.CopyPixels(new Int32Rect(0, 0, width, height), ptr, height*stride, stride);
|
||||
using (var btm = new Bitmap(width, height, stride, PixelFormat.Format1bppIndexed, ptr))
|
||||
{
|
||||
// Clone the bitmap so that we can dispose it and
|
||||
@ -57,5 +59,22 @@ namespace Artemis.Utilities
|
||||
Marshal.FreeHGlobal(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap DrawinVisualToBitmap(DrawingVisual visual, Rect rect)
|
||||
{
|
||||
var bmp = new RenderTargetBitmap((int) rect.Width, (int) rect.Height, 96, 96, PixelFormats.Pbgra32);
|
||||
bmp.Render(visual);
|
||||
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(bmp));
|
||||
|
||||
Bitmap bitmap;
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
encoder.Save(stream);
|
||||
bitmap = new Bitmap(stream);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -25,6 +25,8 @@ namespace Artemis.Utilities
|
||||
{
|
||||
if (_layerModel.LayerCalculatedProperties.Brush == null)
|
||||
return;
|
||||
if (!_layerModel.LayerCalculatedProperties.Brush.IsFrozen)
|
||||
return;
|
||||
|
||||
// Set up variables for this frame
|
||||
_rectangle = new Rect(_layerModel.LayerCalculatedProperties.X*Scale,
|
||||
|
||||
@ -10,7 +10,7 @@ namespace Artemis.ViewModels.Abstract
|
||||
|
||||
public GameModel GameModel { get; set; }
|
||||
public MainManager MainManager { get; set; }
|
||||
|
||||
public event OnLayersUpdatedCallback OnLayersUpdatedCallback;
|
||||
public GameSettings GameSettings
|
||||
{
|
||||
get { return _gameSettings; }
|
||||
@ -54,4 +54,6 @@ namespace Artemis.ViewModels.Abstract
|
||||
SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void OnLayersUpdatedCallback(object sender);
|
||||
}
|
||||
@ -162,6 +162,7 @@ namespace Artemis.ViewModels.LayerEditor
|
||||
LayerConditionModel.Field = SelectedDataModelProp.Path;
|
||||
LayerConditionModel.Operator = SelectedOperator.Value;
|
||||
LayerConditionModel.Value = UserValue;
|
||||
LayerConditionModel.Type = SelectedDataModelProp.Type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -173,6 +174,7 @@ namespace Artemis.ViewModels.LayerEditor
|
||||
SelectedDataModelProp = DataModelProps.FirstOrDefault(m => m.Path == LayerConditionModel.Field);
|
||||
SelectedOperator = Operators.FirstOrDefault(o => o.Value == LayerConditionModel.Operator);
|
||||
UserValue = LayerConditionModel.Value;
|
||||
LayerConditionModel.Type = SelectedDataModelProp.Type;
|
||||
_preselecting = false;
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Artemis.DAL;
|
||||
using Artemis.KeyboardProviders;
|
||||
using Artemis.Models.Profiles;
|
||||
using Artemis.Utilities;
|
||||
using Artemis.ViewModels.LayerEditor;
|
||||
@ -16,13 +15,15 @@ namespace Artemis.ViewModels
|
||||
{
|
||||
public class LayerEditorViewModel<T> : Screen
|
||||
{
|
||||
private readonly ProfileModel _profile;
|
||||
private readonly KeyboardProvider _activeKeyboard;
|
||||
private readonly BackgroundWorker _previewWorker;
|
||||
private readonly ProfileModel _profile;
|
||||
private LayerModel _layer;
|
||||
private LayerPropertiesModel _proposedProperties;
|
||||
|
||||
public LayerEditorViewModel(ProfileModel profile, LayerModel layer)
|
||||
public LayerEditorViewModel(KeyboardProvider activeKeyboard, ProfileModel profile, LayerModel layer)
|
||||
{
|
||||
_activeKeyboard = activeKeyboard;
|
||||
_profile = profile;
|
||||
Layer = layer;
|
||||
|
||||
@ -76,13 +77,11 @@ namespace Artemis.ViewModels
|
||||
{
|
||||
// For the preview, put the proposed properties into the calculated properties
|
||||
_layer.LayerCalculatedProperties = ProposedProperties;
|
||||
var keyboardRect = _activeKeyboard.KeyboardRectangle(4);
|
||||
|
||||
var visual = new DrawingVisual();
|
||||
using (var drawingContext = visual.RenderOpen())
|
||||
{
|
||||
// TODO: Get active keyboard's size * 4
|
||||
var keyboardRect = new Rect(new Size(280, 105));
|
||||
|
||||
// Setup the DrawingVisual's size
|
||||
drawingContext.PushClip(new RectangleGeometry(keyboardRect));
|
||||
drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, keyboardRect);
|
||||
@ -94,6 +93,7 @@ namespace Artemis.ViewModels
|
||||
drawingContext.Pop();
|
||||
}
|
||||
var image = new DrawingImage(visual.Drawing);
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +44,10 @@ namespace Artemis.ViewModels
|
||||
{
|
||||
if (Equals(value, _selectedProfileModel)) return;
|
||||
_selectedProfileModel = value;
|
||||
foreach (var layerModel in SelectedProfileModel.Layers)
|
||||
{
|
||||
layerModel.LayerUserProperties.Brush?.Freeze();
|
||||
}
|
||||
NotifyOfPropertyChange();
|
||||
}
|
||||
}
|
||||
@ -94,7 +98,7 @@ namespace Artemis.ViewModels
|
||||
public void LayerEditor(LayerModel layer)
|
||||
{
|
||||
IWindowManager manager = new WindowManager();
|
||||
_editorVm = new LayerEditorViewModel<T>(SelectedProfileModel, layer);
|
||||
_editorVm = new LayerEditorViewModel<T>(_mainManager.KeyboardManager.ActiveKeyboard, SelectedProfileModel, layer);
|
||||
dynamic settings = new ExpandoObject();
|
||||
|
||||
settings.Title = "Artemis | Edit " + layer.Name;
|
||||
|
||||
@ -26,10 +26,16 @@
|
||||
HorizontalAlignment="Center" VerticalAlignment="Top">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel DataContext="{Binding}" Orientation="Horizontal">
|
||||
<TextBlock FontWeight="Bold" Text="{Binding Path=DisplayType}"/>
|
||||
<TextBlock Text="{Binding Path=Display}"/>
|
||||
</StackPanel>
|
||||
<Grid MinWidth="522">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Text="{Binding Path=Display}" HorizontalAlignment="Left" />
|
||||
<TextBlock Grid.Column="1" FontWeight="Bold" Text="{Binding Path=DisplayType}"
|
||||
HorizontalAlignment="Right" />
|
||||
</Grid>
|
||||
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
@ -42,19 +48,20 @@
|
||||
<!-- Right -->
|
||||
<Grid Grid.Column="3" HorizontalAlignment="Left" Margin="10,0,0,0" Width="148">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Column="0" x:Name="UserValueIsVisible" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<TextBox x:Name="UserValue" VerticalAlignment="Center" HorizontalAlignment="Left" Width="110"/>
|
||||
<TextBox x:Name="UserValue" VerticalAlignment="Center" HorizontalAlignment="Left" Width="110" />
|
||||
</StackPanel>
|
||||
<Button Grid.Column="1" x:Name="Delete" Width="26" Height="26" Style="{DynamicResource SquareButtonStyle}" VerticalAlignment="Top" HorizontalAlignment="Right" >
|
||||
<Button Grid.Column="1" x:Name="Delete" Width="26" Height="26" Style="{DynamicResource SquareButtonStyle}"
|
||||
VerticalAlignment="Top" HorizontalAlignment="Right">
|
||||
<Button.Content>
|
||||
<Rectangle Fill="Black" Width="12" Height="12">
|
||||
<Rectangle.OpacityMask>
|
||||
<VisualBrush Visual="{StaticResource appbar_delete}" Stretch="Fill" />
|
||||
</Rectangle.OpacityMask>
|
||||
</Rectangle>
|
||||
<Rectangle Fill="Black" Width="12" Height="12">
|
||||
<Rectangle.OpacityMask>
|
||||
<VisualBrush Visual="{StaticResource appbar_delete}" Stretch="Fill" />
|
||||
</Rectangle.OpacityMask>
|
||||
</Rectangle>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user