Jump to content

GorzenDev

Members
  • Posts

    141
  • Joined

  • Last visited

Posts posted by GorzenDev

  1. at a first glanse i would say.


    This:

    butt1->Button("Quit",30,30,100,50,gui->GetBase());

    Should be this:

    butt1 = Widget::Button("Quit",30,30,100,50,gui->GetBase());


    Also i advice to always add a panel script to your gui when you create one.
    This neutralizes certain problems you could come across.

    	gui = GUI::Create(context);
    	gui->GetBase()->SetScript("Scripts/GUI/Panel.lua");
    	gui->GetBase()->SetObject("background", new Vec4(0,0,0,0));

     

  2. I'm trying to rotate a image around its center.
    And since there is no rotation parameter for DrawImage(),
    i thought i'd use Context:SetRotation() to achieve the result i need.
    But i think i must be doing something wrong or do i need some math to translate the context everytime i rotate so it stays centered.?

    Somehow a image always rotates around its topleft.
    While a rectangle with proper rotation and translation CAN rotate around its center.

    Can anybody help?


    I have tried some different approaches as you can see and added rectangles with color to visualize.

                --cp is the center of the screen (the topleft position of (center - halfimgsize))
    	    --newrot is controlled by the keyboard
    
    	    --Red Rectangle
                context:SetRotation(newrot)
                gui:SetColor(1.0, 0.0, 0.0)
                gui:DrawImage(needle, cp.x + 128, cp.y, 256, 256)
                gui:DrawRect(cp.x + 128, cp.y, 256, 256, 1, 1)
                context:SetRotation(0.0)
                --
                --Green Rectangle
                context:SetRotation(newrot)
                context:SetTranslation(cp.x, cp.y + 128)
                gui:SetColor(0.0, 1.0, 0.0)
                gui:DrawImage(needle, -128, -128, 256, 256)
                gui:DrawRect(-128, -128, 256, 256, 1, 1)
                context:SetRotation(0.0)
                context:SetTranslation(0, 0)
                --
                --Blue Rectangle
                context:SetTranslation(cp.x, cp.y)
                context:SetRotation(newrot)
                gui:SetColor(0.0, 0.0, 1.0)
                gui:DrawImage(needle, -128, -128, 256, 256)
                gui:DrawRect(-128, -128, 256, 256, 1, 1)
                context:SetRotation(0.0)
                context:SetTranslation(0, 0)

     

     

  3. most widgets by default only redraw when interacted with, in your example a simple click on the panel redraws it.

    solution: 
      add a call to imagePanel:Redraw() when you are finished creating your widgets or right after SetImage().

    • Like 1
  4. On 6/28/2018 at 3:48 PM, Phodex Games said:

    Still I wonder how it is possible to give my new button an automatic hover effect (e.g button is gets brigther) and disable the default rendered rectangle. I also wonder how to change the appearance of the UI, give it a new design etc. This topic is poorly documented, although the system is pretty cool and easy to work with. Would love to get some more input, tutorials etc.

    you can do all that inside each widget .lua script.

  5. gui->GetBase() will give you the base widget which is usually the size of the entire window.
    a position of 100, 100 with base as parent will end up 100, 100 in the window.
    but a position of 100, 100 with panel as parent will end up 100 + panelX, 100 + panelY inside your window.

    as for the Link button everything looks like it should.
    a Link button ignores any style or text align so wanting to center a link widget will have to manually reposition it.

    in my honest opinion do not use Link unless you actually want it to act like a Link.



     

  6. make sure your entity is actually a camera.

    tolua.cast(self.entity,"Camera")

    as gamecreator said color in code always use normalized values 0-1
    if thats a problem you can always do sometihng like

    self.entity:SetClearColor(12 / 255, 183 / 255, 242 / 255, 1.0)
    self.entity:SetClearColor(255 / 255, 0.0, 0.0, 1.0)

     

    • Thanks 1
  7. Smoothed the wire between nodes to look better laying on the ground.
    Player can now remove placed nodes to correct mistakes and continue placing new nodes.
    Added actual functionality to the wire.
    A quickmatch fuse in this case that lights a mortar rack.


     

    12 hours ago, AggrorJorn said:

    Very cool. What kind of game are making? 

    It is still very much a concept.
    But if i have to name it i guess it would be a pyrotechnics simulator.

     

    • Like 3
  8. Having an option to auto open the last used lua scripts when loading a project would very much speed up the workflow.

    Right now everytime you want to continue a project and the project becomes big,
    you would have to open all the scripts you where last working on by hand,
    which becomes painstakingly time consuming.
    It would realy help if there whas some kind of option so the Script Editor auto opens those scripts you worked on last.

  9. im not sure if it is what causes your problem.
    but i tested my own spritesheet (5x5) which works fine on animation cycles 1.
    but when i set my animation cycles to 2 i get some weird empty frames.

    try setting your aniimation cycles to 1 and see if that helps any

  10. Honestly it does annoy me in a way aswell.
    But have no fear i got a solution for you guys.
    The question tipforeveryone had about templates actually made me think about a permanent solution for this.
    It involves editing the Common Template though, which can cause problems if/when the Template gets an official update.

    Sorry for the windows only answer i have no experience with Linux.

    Open folder "Leadwerks/Templates/Common/Projects/Windows".

    Open file "$PROJECT_NAME.vcxproj.user" with your favorite text editor (i like notepad++).
    Change all instances of "$(SolutionDir)\..\..\.."  to  "$(SolutionDir)\..\..\".

    Open file "$PROJECT_NAME.vcxproj" with your favorite text editor.
    Change all instances of "$(SolutionDir)..\..\"  to  "$(SolutionDir)\..\..\".

    !!_WARNING_!!
    Making these changes lets the editor think there has been an update so ALL your projects would need to be updated.

    • Thanks 1
  11. I have never tried this before but after seeing your question i thought id give it a try.
    It is actually quite easy, look in the Templates folder in your leadwerks installation folder.
    Create a new folder inside Templates and put some files there they will be copied into your new project when you create one.
    The content from the Templates/Common folder will be copied to all projects you create.

    I tried this and it works.

     

    • Like 1
    • Thanks 2
  12. I agree there needs to be some official tutorial..

    Off topic:
    As for my "claim" that the widget system relies on lua scripts(even by using c++), proof exists and you can easily validate it.
     

    run this c++ code and you will see a panel is drawn.
    rename/remove the script "Scripts/GUI/Panel.lua" and you will see your gui no longer works.
    the reason for this is because each widget(gui element)  its functionality and rendering is done by those scripts.

    #include "Leadwerks.h"
    
    using namespace Leadwerks;
    
    int main(int argc, const char *argv[])
    {
    	Leadwerks::Window* window = Leadwerks::Window::Create();
    	Context* context = Context::Create(window);
    
    	GUI* gui = GUI::Create(context);
    
    	//this widget no longer works if you rename/remove "Scripts/GUI/Panel.lua" 
    	Widget* panel = Widget::Panel(25, 30, 150, 200, gui->GetBase());
    
    	while (true)
    	{
    		if (window->Closed() || window->KeyDown(Key::Escape)) return false;
    		context->SetColor(0, 0, 0, 0);
    		context->Clear();
    
    		context->Sync();
    	}
    	return 0;
    }



     

    • Upvote 1
  13. I understand and i agree.
    Although i do think that both can be combined.

    I have a small helper script to easily implement the ImageProgressBar widget so no rebuilding of your project would be needed.

    function CreateSimpleHealthBar() takes a Context to create a widget.      (for those that are not bothered to know how)
    function AddSimpleHealthBar() takes a GUI to create a widget.                (for those that like to add it to an existing GUI)
    function SimpleHealthBar() takes a Widget as a parent.                            (for those that like to add it to an existing Widget)

    --[[
    		---- SimpleHealthBar.lua ----
    
    ]]
    
    function CreateSimpleHealthBar(x, y, width, height, context, emptyimage_path, fillimage_path)
    	--GUI
    	local gui = GUI:Create(context)
    	gui:GetBase():SetScript("Scripts/GUI/Panel.lua")
    	gui:GetBase():SetObject("backgroundcolor",Vec4(0,0,0,0.0))
    	--
    	local HPBar = {}
    	HPBar = AddSimpleHealthBar(x, y, width, height, gui, emptyimage_path, fillimage_path)
    	HPBar.context = context
    	--
    	return HPBar
    end
    
    function AddSimpleHealthBar(x, y, width, height, gui, emptyimage_path, fillimage_path)
    	return SimpleHealthBar(x, y, width, height, gui:GetBase(), emptyimage_path, fillimage_path)
    end
    
    
    function SimpleHealthBar(x, y, width, height, parent, emptyimage_path, fillimage_path)
    	local HPBar = {}
    	local scale = 1
    	
    	--
    	HPBar.gui = parent:GetGUI()
    	HPBar.gui:SetScale(scale)
    	HPBar.parent = parent
    	HPBar.position = iVec2(x, y)
    	HPBar.size = iVec2(width, height)
    	
    	--
    	HPBar.maxHealth = 100.0
    	HPBar.health = 100.0
    	HPBar.hpChanged = false
    	
    	--
    	HPBar.zeroHP_CALLBACK = {}
    	HPBar.zeroHP_CALLBACK_script = nil
    	HPBar.fullHP_CALLBACK = {}
    	HPBar.fullHP_CALLBACK_script = nil
    	
    	--
    	HPBar.Fill = Widget:Create(emptyimage_path, HPBar.position.x, HPBar.position.y, HPBar.size.x, HPBar.size.y, parent, "Scripts/GUI/ImageProgressBar.lua")
    	HPBar.Fill:SetAlignment(0,0,0,1)
    	HPBar.Fill:SetBool("isBackground", false)
    	local imagefill = HPBar.gui:LoadImage(fillimage_path)
    	HPBar.Fill:SetImage(imagefill)
    	--HPBar.Fill:Redraw()
    	
    	--
    	function HPBar:SetMaxHealth(maxHP)
    		self.maxHealth = maxHP
    		if self.health > self.maxHealth then
    			self.health = self.maxHealth
    			--call callback script function
    			if self.fullHP_CALLBACK_script ~= nil then
    				self.fullHP_CALLBACK(self.fullHP_CALLBACK_script)
    			end
    		end
    		self.hpChanged = true
    	end
    	
    	function HPBar:SetHealth(HP)
    		self.health = HP
    		if self.health > self.maxHealth then
    			self.health = self.maxHealth
    			--call callback script function
    			if self.fullHP_CALLBACK_script ~= nil then
    				self.fullHP_CALLBACK(self.fullHP_CALLBACK_script)
    			end
    		elseif self.health < 0.0 then
    			self.health = 0.0
    			--call callback script function
    			if self.zeroHP_CALLBACK_script ~= nil then
    				self.zeroHP_CALLBACK(self.zeroHP_CALLBACK_script)
    			end
    		end
    		self.hpChanged = true
    	end
    	
    	--
    	function HPBar:AddHealth(amount)
    		self.health = self.health + amount
    		if self.health > self.maxHealth then
    			self.health = self.maxHealth
    			--call callback script function
    			if self.fullHP_CALLBACK_script ~= nil then
    				self.fullHP_CALLBACK(self.fullHP_CALLBACK_script)
    			end
    		end
    		self.hpChanged = true
    	end
    	
    	function HPBar:SubHealth(amount)
    		self.health = self.health - amount
    		if self.health < 0.0 then
    			self.health = 0.0
    			--call callback script function
    			if self.zeroHP_CALLBACK_script ~= nil then
    				self.zeroHP_CALLBACK(self.zeroHP_CALLBACK_script)
    			end
    		end
    		self.hpChanged = true
    	end
    	
    	--
    	function HPBar:SetZeroHPCallBack(callback, script)
    		self.zeroHP_CALLBACK = callback
    		self.zeroHP_CALLBACK_script = script
    	end
    	
    	function HPBar:SetFullHPCallBack(callback, script)
    		self.fullHP_CALLBACK = callback
    		self.fullHP_CALLBACK_script = script
    	end
    	
    	--
    	function HPBar:Show()
    		if self.Fill:Hidden() then
    			self.Fill:Show()
    		end
    	end
    	
    	function HPBar:Hidden()
    		return self.Fill:Hidden()
    	end
    	
    	function HPBar:Hide()
    		if self.Fill:Hidden() == false then
    			self.Fill:Hide()
    		end
    	end
    	
    	function HPBar:ProcessEvent(event)
    		if event.id == Event.WidgetAction then
    			if event.source == self.Fill then
    				--
    			end
    		end
    		return true
    	end
    
    	function HPBar:Update()
    		if self.Fill:Hidden() then return true end
    		
    		--Update widget progress
    		if self.hpChanged then
    			local progress = (self.health / self.maxHealth)
    			self.Fill:SetFloat("health", self.health)
    			self.Fill:SetFloat("maxHealth", self.maxHealth)
    			self.Fill:SetProgress(progress)
    			self.Fill:Redraw()
    			self.hpChanged = false
    		end
    		return true
    	end
    	
    	--
    	return HPBar
    end

     

  14. I meant to answer sooner but i had some hicups with loading the image.

    I have created a simple widget for leadwerks GUI that will get the results you are looking for i think.
    Usage is in the description.

    Result:
    hpbarA.thumb.JPG.3b6a8c54841e308e158f25e1d8d4a92f.JPGhpbarB.thumb.JPG.de7acb0bab8144d8779f7000a6ad12fa.JPG

     

    --[[
    
    	----ImageProgressBar.lua----
    	
    	Simulates a progress/health bar with images. 
    	Uses GUI:SetClipRegion() to clip the foreground image. 
    	Uses Widget:SetImage() as foreground image. 
    	Makes use of the widget text during creation to specify background image path. 
    	
    	--Create widget and set images
    	local HPBar = Widget:Create("Path/To/Background/Image.tex", x, y, width, height, parent, "Scripts/GUI/ImageProgressBar.lua")
    	local imagefill = gui:LoadImage("Path/To/Foreground/Image.tex")
    	HPBar:SetImage(imagefill)
    
    	--Update progress/health
    	local progress = (self.health / self.maxHealth)
    	HPBar:SetFloat("health", self.health)
    	HPBar:SetFloat("maxHealth", self.maxHealth)
    	HPBar:SetProgress(progress)
    	HPBar:Redraw()
    ]]
    
    Script.hovered = false
    Script.pushed = false
    Script.textToggle = false
    
    Script.bgImage = nil
    --
    Script.health = 0.0
    Script.maxHealth = 100.0
    
    
    function Script:Start()
    	local gui = self.widget:GetGUI()
    	
    	--Get background image path from widget text and load it
    	local bgImagePath = self.widget:GetText()
    	if bgImagePath ~= "" and bgImagePath ~= nil then
    		self.bgImage = gui:LoadImage(bgImagePath)
    	end
    end
    
    function Script:Draw(x,y,width,height)
    	local gui = self.widget:GetGUI()
    	local pos = self.widget:GetPosition(true)
    	local sz = self.widget:GetSize(true)
    	local scale = self.widget:GetGUI():GetScale()
    	
    	--Get 0 to 1 progress value
    	local widgetProgress = self.widget:GetProgress()
    	
    	--Draw background image
    	if self.bgImage ~= nil then
    		gui:SetColor(1.0, 1.0, 1.0, 1.0)
    		--
    		gui:DrawImage(self.bgImage, pos.x, pos.y, sz.x, sz.y)
    	end
    	
    	--Clip the drawing region based on progress
    	gui:SetClipRegion(pos.x, pos.y, sz.width * widgetProgress, sz.height)
    	
    	--Draw fill image
    	local fillimage = self.widget:GetImage()
    	if fillimage~=nil then
    		gui:SetColor(1.0, 1.0, 1.0, 1.0)
    		--
    		gui:DrawImage(fillimage, pos.x, pos.y, sz.x, sz.y)
    	end
    	
    	--Set drawing region back to widget size
    	gui:SetClipRegion(pos.x, pos.y, sz.width, sz.height)
    	
    	--Check if we want to draw text
    	local drawtext = false
    	if self.textToggle == true then
    		drawtext = true
    	elseif self.hovered == true then
    		drawtext = true
    	end
    	
    	--Draw health/maxHealth
    	if drawtext == true then
    		local style = Text.Center + Text.VCenter
    		local text = tostring(self.health).."/"..tostring(self.maxHealth)--.." = "..tostring(widgetProgress)
    		--
    		gui:SetColor(1.0,1.0,1.0,1.0)
    		if widgetProgress <= 0.2 then gui:SetColor(1.0,0.0,0.0,1.0) end
    		gui:DrawText(text, pos.x, pos.y, sz.width, sz.height, style)
    	end
    	
    end
    
    function Script:MouseEnter(x,y)
    	self.hovered = true
    	self.pushed = false
    	self.widget:Redraw()
    end
    
    function Script:MouseLeave(x,y)
    	self.hovered = false
    	self.pushed = false
    	self.widget:Redraw()
    end
    
    function Script:MouseDown(button,x,y)
    	if self.pushed == true then return end
    	if button == Mouse.Left then
    		self.pushed = true
    		self.widget:Redraw()
    	end
    end
    
    function Script:MouseUp(button,x,y)
    	if button == Mouse.Left then
    		if self.pushed == true then
    			self.textToggle = not self.textToggle
    		end
    		self.pushed = false
    		self.widget:Redraw()
    	end
    end

     

     

    • Like 4
  15. correct drawrect will draw a single color or some gradient if you want.
    DrawCircle and DrawPolygon are unfortunately not documented,
    they can be found in some widget scripts and offcourse in the header files if you have the c++ version.

    but for textures i'm not certain, i dont think widget system would give you any benefits.
    you might want to look into uv scaling/animation that might solve your texture scaling probems.

    as for a circular progressbar.
    personally i would create a custom widget that would animate single images as to appear loading circular (fake progress).
    you could always do some math to render a dynamic filled circular shape based on progressValue.

    some references for circular shapes.
    Segment of a circle (bottle):
    https://www.mathopenref.com/segmentareaht.html

    Sector of a circle (piepiece):
    https://www.mathopenref.com/arcsector.html

  16. You could take the ProgressBar.lua as an example.
    It just draws a rectangle the size of the progress value.
    That would eliminate your texture malforming.

    Using GUI for your progressbar allows you to use draw functions like DrawCircle(), DrawPolygon to make any shape you want.

  17. this could easily be achieved by adding 3 lines of code to any diffuse shader you can find in LE.
    for shadows you add the same lines of code in any shadow shader.

    //In the Fragment stage of the shader add to //Uniforms
    //You can use any texture slot you like
    //I used 4 since 1 till 3 are diffuse,normal,specular
    uniform sampler2D texture4;//Black and White map
    
    
    //In the void main(void) method add somewhere at the top
    vec4 alphamask = texture(texture4,ex_texcoords0);
    //Check for pure black color and discard
    if (alphamask.r == 0.0 && alphamask.g == 0.0 && alphamask.b == 0.0) discard;


    NOTE: make sure the Vertex stage of the shader passes ex_texcoords0 to the Fragment stage but any diffuse+alphamask shader does this.

    • Like 1
  18. I have been working on a menubar widget and it came out pretty nicely.
    I thought i would release it either for people to have an example of what would be possible with the widget's flexibility
    or just for people to use it.

    For now it only works in C++ since it makes use of CallFunction().

    MenubarElement.lua

    !! Make sure when you create the widget you create it last so it will render on top !!

    It allows horizontal rules and submenus.

    widgetPreview.JPG.5b1f9f7a397148c8283e439bca317384.JPG

    widgetPreview1.JPG.52f8841669caf71c1dcb5ce152082e9e.JPG


    How to use: (C++)

    Create the widget and fill the menu 

    float scale = gui->GetScale();
    
    mnuBarItem = Widget::Create("Name", 2 * scale, 2 * scale, 60 * scale, 26 * scale, gui->GetBase(), "Scripts/GUI/MenubarElement.lua");
    mnuBarItem->SetObject("backgroundcolor", new Vec4(0.7, 0.7, 0.7, 1.0));
    mnuBarItem->AddItem("Temp0");
    mnuBarItem->AddItem("Temp1");
    mnuBarItem->AddItem("@-");//create a horizontal rule(menu seperator)
    mnuBarItem->AddItem("&Submenu");//this will hold the submenu created next
    //create a submenu from the last added item in the list
    mnuBarItem->CallFunction("C_CreateSubMenuFromLastItem");
    mnuBarItem->CallFunction("C_AddItemToLastSubMenu", "Sub0_A");
    mnuBarItem->CallFunction("C_AddItemToLastSubMenu", "Sub0_B");
    mnuBarItem->CallFunction("C_AddItemToLastSubMenu", "Sub0_C");
    //
    mnuAccount->AddItem("Temp2");


    Catching widget events

    ProcessEvent(Event event)
    {
    	if (event.id == Event::WidgetAction)
    	{
        	if (event.source == mnuBarItem)
            {
                if (event.data == 0)
                {
                    //
                }
                else if (event.data == 1)
                {
                    //
                }
    	    //(event.data == 2) horizontal rule
    	    //
                else if (event.data == 3)//submenu
                {
                	int item = event.position.x;//submenu itemidx
                    if (item == 0)
                  	{
                    	//
                	}
                  	else if (item == 1)
                  	{
                    	//
                  	}
                  	else if (item == 2)
                  	{
                    	//
                  	}
                }
                else if (event.data == 4)
                {
                  //
                }
            }
        }
    }


    Also it needs a call to update somewhere in your loop.
    Which is just used to update some delay timing.

    mnuBarItem->CallFunction("C_Update");

     

    • Like 2
×
×
  • Create New...