WohlSoft / LunaLua

LunaLua - LunaDLL with Lua, is a free extension mod for SMBX 1.3 game engine, core of the X2 project.
https://codehaus.moe/
GNU General Public License v3.0
33 stars 12 forks source link

Misc.setWindowPosition and Misc.runWhileUnfocused #39

Closed SolaceEllery closed 2 years ago

SolaceEllery commented 2 years ago

A thing I've done as a test for SMAS++. Requires a modded ffi_misc.lua.

Misc.setWindowPosition(x,y): Moves the window to the x/y coordinate as specified. Misc.runWhileUnfocused(bool): Set as true/false to either run the game while unfocused or run the game without focus outside of it's instance.

Bluenaxela commented 2 years ago

Allowing moving the window position from Lua code seems like a quite a bad idea to me. It's bad for user experience for programs to be moving their window around without user input, and it's also very easy to abuse in ways that that create nuisance that do very undesirable things like making it hard for the user to exit the program. It's unlikely I'll ever accept a patch allowing Lua code to do that, at least without some built-in restrictions/limitations to prevent abusive use.

Controlling whether the game runs when unfocused should be something configurable by the user, not something that legitimate level code should ever touch, and episode code should only be touching it as part of a user configuration menu. I'm open to considering allowing Lua code to change that setting for the latter case, but it may make sense to be more thoughtful about exactly how to do it than just doing this. To me this setting feels similar to the fullscreen setting and maybe should be handling them similarly but not completely sure.

MrDoubleA232 commented 2 years ago

There is one legitimate use case that I can think of for runWhileUnfocused, though it's very obscure. It may be useful if you're using socket for some basic online stuff.

SolaceEllery commented 2 years ago

There is one legitimate use case that I can think of for runWhileUnfocused, though it's very obscure. It may be useful if you're using socket for some basic online stuff.

I haven’t even considered doing the online idea for my episode for a long while though. I was gonna get back to it by the time the episode is almost fully done and at very late in development of v1.0.0.0

Oh and I also made Misc.centerWindow(), where it centers the game to the middle of the screen. I may make another commit with it here, but idk yet

MrDoubleA232 commented 2 years ago

I don't mean use cases for your episode specifically, I just mean in general.

SolaceEllery commented 2 years ago

I don't mean use cases for your episode specifically, I just mean in general.

Ah I understand now. Isn’t socket not accessible in code though unless you add socket.core/mime.core into the LuaMain list like io is on? I tried socket on normal LunaLua installs under repl but it says it’s nil

MrDoubleA232 commented 2 years ago

The user has the option to enable it in data/config/luna.ini.

SolaceEllery commented 2 years ago

Recently added Misc.centerWindow(). Add this to ffi_misc.lua to test:

ffi.cdef([[ typedef struct _LunaImageRef LunaImageRef;

 void LunaLuaSetWindowPosition(int x, int y);
 void LunaLuaToggleWindowFocus(bool enable);
 void LunaLuaCenterWindow();

]])

function Misc.centerWindow() LunaDLL.LunaLuaCenterWindow() end

Emral commented 2 years ago

There is one legitimate use case that I can think of for runWhileUnfocused, though it's very obscure. It may be useful if you're using socket for some basic online stuff.

I haven’t even considered doing the online idea

If I may pivot back to this for a moment: I am curious what use cases you did have in mind when making this feature. I have never seen a game need to move the game window, so I'm struggling to think of any cases where it would aid the player or dev.

SolaceEllery commented 2 years ago

There is one legitimate use case that I can think of for runWhileUnfocused, though it's very obscure. It may be useful if you're using socket for some basic online stuff.

I haven’t even considered doing the online idea

If I may pivot back to this for a moment: I am curious what use cases you did have in mind when making this feature. I have never seen a game need to move the game window, so I'm struggling to think of any cases where it would aid the player or dev.

Spoilers below!

Those code things were gonna be utilized for a secret final boss phase, as you play Frisk on the Genoside story in SMAS++. In the end of the game in the True Ending, you verse Sherbert Lussieback (An OC I made), a powerful hero that your objective is to kill him (Since it's Genoside and you killed everyone except him and the Mario Bros. at that point). There are three phases, and the third one is planned where Evil Me (As a "virus") takes control of Sherbert... and as he does, his eye start turning into rainbow colors, the game auto forces out of fullscreen (If in it), brings the game to the middle of the screen, starts shaking the game, the game title gets renamed slowly to EVILME.EXE (And the icon changes)... and as soon as Evil Me takes full control, the game stops shaking, we hear a familiar evil laugh, and the games tries to go full kaizo on you as it starts becoming a bullet hell where you try to survive till the end where in the end, Evil Me gets stopped by Windows Defender (As a joke, not for real as the game displays the messages in the window like from Windows 10)

Don't worry about it doing anything rational though, everything will be kept intact in game, and not do anything outside of it.

I've planned that for a few months now, and I'm just preparing myself for it whenever I get ready for it eventually as the game goes further into dev

(Oh and everything from that outside of the SEE Mod will not do any of those extra stuff, since I doubt you all would add the codes I submitted over to the og LunaLua. I only pulled it here because MDA gave me the idea)

SolaceEllery commented 2 years ago

It seems like LunaLua has coded in extra stuff which makes this merge branch conflict files. I’m gonna close this, since I assume this has been rejected.

I might make another merge request, but not atm. Might do that whenever I get something actually done for good use