Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAndreiM committed Jul 26, 2024
1 parent 0d05ae5 commit 32abf29
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/Juka/GUI/Clicked.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Juka.GUI
{
public class Clicked
{

public static void itemclicked()
{

Expand Down Expand Up @@ -85,7 +86,7 @@ public static void itemclicked()

myfile = videoInfos[i].VideoId + ".mp4";

currentscreen = Menus.MediaPlayer;
currentscreen = Menus.MediaDownloaded;
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/Juka/GUI/Colors.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using SDL2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Juka.GUI
{
Expand Down
2 changes: 1 addition & 1 deletion src/Juka/GUI/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public static void MouseHandler()
// Rumble the controller
SDL.SDL_GameControllerRumble(controller, 0xFFFF, 0xFFFF, 2000); // Strong rumble for 1 second
}
SDL.SDL_HapticRunEffect(JoyHaptic, effectID, 1);

SDL.SDL_GameControllerRumble(controller, 0xFFFF, 0xFFFF, 2000); // Strong rumble for 1 second


switch ((SDL.SDL_GameControllerButton)e.cbutton.button)
Expand Down
5 changes: 5 additions & 0 deletions src/Juka/GUI/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ public static class Globals
public static string version = CurrentVersion.GetVersion();

//SDL2
public static nint JoyHaptic;
public static int effectID;


public static int SCREEN_WIDTH = 1280;
public static int SCREEN_HEIGHT = 720;

public static string keypressed = SDL.SDL_GetKeyName(SDL.SDL_Keycode.SDLK_UNDEFINED);
public static bool rumble = false;
public static bool rumble2 = false;

public static nint window = nint.Zero;
public static nint renderer = nint.Zero;
Expand Down
32 changes: 24 additions & 8 deletions src/Juka/GUI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using SDL2;
using JukaCompiler;
using Microsoft.CodeAnalysis;
using static SDL2.SDL;
using VideoLibrary;
using Spectre.Console;
using static Juka.GUI.Globals;
using static Juka.GUI.Helper;
using static Juka.GUI.Renderer;
using static SDL2.SDL;

namespace Juka.GUI;

Expand All @@ -16,7 +12,7 @@ class Program
public static Task GUI(string[] args)
{
//Create window
if (SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING) < 0)
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_GAMECONTROLLER | SDL.SDL_INIT_HAPTIC | SDL.SDL_INIT_JOYSTICK) < 0)
{
Console.WriteLine("SDL could not initialize! SDL_Error: " + SDL.SDL_GetError());
}
Expand All @@ -36,6 +32,7 @@ public static Task GUI(string[] args)

try
{

string mapping = "030000005e0400008e02000014010000,Xbox 360 Controller,a:b0,b:b1,x:b2,y:b3,back:b6,guide:b8,start:b7,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,";
SDL.SDL_GameControllerAddMapping(mapping);
for (int i = 0; i < SDL.SDL_NumJoysticks(); i++)
Expand All @@ -45,12 +42,31 @@ public static Task GUI(string[] args)
controller = SDL.SDL_GameControllerOpen(i);
if (controller != nint.Zero)
{

SDL_HapticEffect effect = new SDL_HapticEffect()
{
type = SDL.SDL_HAPTIC_SINE,
constant = new SDL_HapticConstant() { level = 0, length = 0x4000, attack_length = 1000 }
};
JoyHaptic = SDL.SDL_HapticOpenFromJoystick(i);
if (JoyHaptic == nint.Zero)
{
// Joystick isn't haptic
Console.WriteLine("Joystick isn't haptic");
}
effectID = SDL.SDL_HapticNewEffect(JoyHaptic, ref effect);
SDL.SDL_HapticRunEffect(JoyHaptic, effectID, 1);

Console.WriteLine("Controller opened successfully!");
SDL.SDL_GameControllerRumbleTriggers(controller, 0xffff, 0xffff, 8000);
SDL.SDL_GameControllerRumble(controller, 0xffff, 0xffff, 8000);
if(SDL.SDL_GameControllerHasRumbleTriggers(controller) == SDL.SDL_bool.SDL_TRUE)
{
rumble2 = true;
}
if (SDL.SDL_GameControllerHasRumble(controller) == SDL.SDL_bool.SDL_TRUE)
{
rumble = true;
SDL.SDL_GameControllerRumbleTriggers(controller, 0xffff, 0xffff, 8000);
SDL.SDL_GameControllerRumble(controller, 0xffff, 0xffff, 8000);
Console.WriteLine("Rumble ON");
}
else
Expand Down
5 changes: 0 additions & 5 deletions src/Juka/GUI/Renderer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using SDL2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Juka.GUI.Globals;
using static Juka.GUI.Helper;

Expand Down

0 comments on commit 32abf29

Please sign in to comment.