Quantcast LoTROInterface - View Single Post - Lua Beginner has some questions
View Single Post
  #3  
Unread 06-14-2016, 06:50 AM
Hamkaas Hamkaas is offline
The Wary
 
Join Date: Jun 2016
Posts: 3
Thank you so much for the quick response and answers to my questions!

For the answers:
1.
Quote:
There's a few UI options for changing how tooltips function but nothing via Lua.
That is too bad as i think most people have tooltips turned on and it doesn't look nice if the tooltip pops up in front of a fancy button.

2.
Quote:
Unfortunately you've already found the best solution for that one which is the chat listener. FWIW, very few of the solutions to the Turbine limitations on Lua are elegant
Thats too bad as well

3.
Quote:
I suspect the crashes are due to the way you are creating your quickslots. I'd have to see your code to be sure. The unload event handler is more for cleaning up event handlers and command objects (the client used to crash if you created a command and exited without removing it but I believe that bug was fixed many years ago).
I've done some experimentation with it and this is my code:
Code:
DisplaySize = {Turbine.UI.Display:GetWidth(),Turbine.UI.Display:GetHeight()};
WindowSize = {200,100};


LotroWindow = Turbine.UI.Lotro.Window();
LotroWindow:SetSize(WindowSize[1]+12,WindowSize[2]+80);
LotroWindow:SetPosition((DisplaySize[1]*4/3-WindowSize[1])/2,(DisplaySize[2]*2/3-WindowSize[2])/2);
LotroWindow:SetText("Reversi");

MainWindow = Turbine.UI.Window();
MainWindow:SetParent(LotroWindow);
MainWindow:SetPosition(6,46);
MainWindow:SetSize(WindowSize[1],WindowSize[2]);
MainWindow:SetBackColor(Turbine.UI.Color(.1,.1,.1));
MainWindow:SetVisible(true);

MainWindow.Button = {};
MainWindow.Button[1] = Turbine.UI.Lotro.Quickslot();
MainWindow.Button[1]:SetParent(MainWindow);
MainWindow.Button[1]:SetSize(35,35);
Shortcut = Turbine.UI.Lotro.Shortcut( Turbine.UI.Lotro.ShortcutType.Alias, "/w Hamkaas hoifcdfgdsfgdsfgsdfgsdfgsdfgsdfgsdfgdfsgsdfgsdfgsdfgsdfgsdfgsdf");
MainWindow.Button[1]:SetShortcut(Shortcut);
MainWindow.Button[1]:SetZOrder(-1);
MainWindow.Button[1]:SetPosition(WindowSize[1]/2-17,WindowSize[2]/2-17);
-- MainWindow.Button[1]:SetAllowDrop(false);

MainWindow.ButtonHider = {};
MainWindow.ButtonHider[1] = Turbine.UI.Window();
MainWindow.ButtonHider[1]:SetParent(MainWindow.Button[1]);
MainWindow.ButtonHider[1]:SetBackColor(Turbine.UI.Color(0,0,0));
MainWindow.ButtonHider[1]:SetSize(MainWindow.Button[1]:GetWidth(),MainWindow.Button[1]:GetHeight());
MainWindow.ButtonHider[1]:SetVisible(true);
MainWindow.ButtonHider[1]:SetMouseVisible(false);
MainWindow.ButtonHider[1]:SetZOrder(1);
The client only crashes it seems if i enable the final "MainWindow.ButtonHider" part and then drag an item into the slot and unload the plugin. Am i somehow dragging the item onto the window instead or something?
It's not much of a problem as i would uncomment "MainWindow.Button[1]:SetAllowDrop(false);" if i would use it as a button, and i wouldn't try to hide it if i used it as a quickslot i want to drag stuff to.


4.
Quote:
I don't actually know what the max size for an image would be but it's several meg. However, Turbine's implementation of Lua probably does not handle animated images very well. I would recommend using separate images and controlling their loading via an Update event and a timer, that way you can also retain some control of the speed of the animation.
Sorry i did not make myself quite clear with this i noticed. I found my problem though. I did not set the size of the to be cropped control and it defaulted to ~50x50 pixels. For if you are curious:

Code:
MainWindow.AniCrop = Turbine.UI.Control();
MainWindow.AniCrop:SetParent(MainWindow);
MainWindow.AniCrop:SetSize(110,100);
MainWindow.AniCrop:SetPosition(WindowSize[1]/2-55,WindowSize[2]/2-50);

MainWindow.Ani = Turbine.UI.Control();
MainWindow.Ani:SetParent(MainWindow.AniCrop);
MainWindow.Ani:SetSize(1100,100);
MainWindow.Ani:SetBackground("Hamkaas/Test/Coinflip.tga");

Frames = 10;
FPS = 10;

framecount = 0
Timer = Turbine.Engine.GetGameTime();

MainWindow:SetWantsUpdates(true);
Winup = function(sender,args)
	if Turbine.Engine.GetGameTime() >= Timer then
		MainWindow.Ani:SetPosition(framecount*-110,0);
		
		if framecount < Frames-1 then 
			framecount = framecount+1;
		else
			framecount = 0;
		end
		
		Timer = Turbine.Engine.GetGameTime() + 1/FPS;
	end
end
AddCallback(MainWindow, "Update", Winup);
Here "Hamkaas/Test/Coinflip.tga" is an image with 10 times a 110x100 frame of an animation next to eachother. What went wrong is that i forgot the "MainWindow.Ani:SetSize(1100,100);" command before. Now it works perfectly

But what i meant with my question before regarding unloading was how do i unload this properly? i think i need 2 things here: "RemoveCallback(MainWindow, "Update", Winup);" and "MainWindow:SetWantsUpdates(false);". But where do i put them?
Maybe like this?

Code:
unload = function(sender,args)
	RemoveCallback(MainWindow, "Update", Winup);
	MainWindow:SetWantsUpdates(false);
end
AddCallback(Plugin, "Unload", unload);
But here i did not know what to put in the first argument of the "AddCallBack" command so i just put "Plugin" in there. Also in which file should i put it? in Main.lua? or should i make one for every file? and do i need to run the RemoveCallBack command for the unload event i just created as well? so add "RemoveCallback(Plugin, "Unload", unload);" in the function above?
I'm very confused sorry


5.
Quote:
You don't gain any advantage other than masking by putting the quickslot inside another control. The point of the excess size is so that the quickslot will still be clickable but will be positioned far enough behind the border of its parent so as to be properly clipped. If you have more than one quickslot then the window would not be sufficient - with only one, yes, you could just use the window as the parent.
Cool thanks.

Quote:
As to dragging the shortcut out of the quickslot, I believe it is still possible to accidentally drag a shortcut out of a quickslot if it is not prevented by the author. Are you possibly playing with a Mac or Linux install? That may make a difference to the shortcut drag behavior.
I'm playing on windows 10. When i drag the shortcut out of the quickslot it does visually show the shortcut while i drag it but it does not remove it when i drop it somewhere else. Also it does not copy/move it to another Quickslot when i release it on one.


Thanks again for helping me understand LUA and Turbines API a lot better!
Reply With Quote