Jump to content

GorzenDev

Members
  • Posts

    141
  • Joined

  • Last visited

Everything posted by GorzenDev

  1. to set a label's text color you would need to either edit the default label.lua or create a custom one. here is code for a colorLabel: --Styles if Style==nil then Style={} end if Style.Label==nil then Style.Label={} end Style.Label.Left=0 Style.Label.Center=16 Style.Label.Right=8 Style.Label.VCenter=32 Script.bordercolor = Vec4(0.2,0.2,0.2,1) Script.textcolor = Vec4(0.7,0.7,0.7,1) --[[ Const LABEL_LEFT=0 Const LABEL_FRAME=1 Const LABEL_SUNKENFRAME=2 Const LABEL_SEPARATOR=3 Const LABEL_RIGHT=8 Const LABEL_CENTER=16 ]] 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 = gui:GetScale() local text = self.widget:GetText() local indent=4 if self.border==true then gui:SetColor(self.bordercolor.r, self.bordercolor.g, self.bordercolor.b, self.bordercolor.a) gui:DrawRect(pos.x,pos.y,sz.width,sz.height,1) end --gui:SetColor(0.7,0.7,0.7) gui:SetColor(self.textcolor.r,self.textcolor.g,self.textcolor.b,self.textcolor.a) if text~="" then local style=0 if self.align=="Left" then style = Text.Left end if self.align=="Center" then style = Text.Center end if self.align=="Right" then style = Text.Right end if self.valign=="Center" then style = style + Text.VCenter end if self.wordwrap==true then style = style + Text.WordWrap end if self.border==true then gui:DrawText(text,pos.x+scale*indent,pos.y+scale*indent,sz.width-scale*indent*2,sz.height-scale*indent*2,style) else gui:DrawText(text,pos.x,pos.y,sz.width,sz.height,style) end end end function Script:bitand(set, flag) return set % (2*flag) >= flag end
  2. the problem lies with window:HideMouse(), it is being called a couple times inside Menu.lua remove or comment out those lines and you wont have no problems anymore.
  3. Or edit the default Template so you dont have to do it everytime. Also discussed on the programming board.
  4. offcourse i should have thought about that ?‍♂️. i whas so focused on simply rotating a image that i havent thought of using a shader. thank you very much for your help, i whas about to give up and just use digits.
  5. 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));
  6. 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)
  7. 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().
  8. you can do all that inside each widget .lua script.
  9. 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.
  10. My personal reason's for rather buying through steam is because of the payment options. 90% of the dutch people do not have/use a creditcard. And the paypal payments are not always as smooth as it should be. Sometimes even fails in a way you end up paying twice. Steam gives us the option to pay through "IDEAL" which is a secure and instant transfer. but i think the IDEAL service is national only, i'm not sure about that. anyway i'm not saying you should change anything just giving my personal reasons why i prefer steam payments. I do think it's a good thing leadwerks becomes "Independent".
  11. i can't stress this enough. use the Leadwerks GUI widget system it is so flexible, its just amazing the things you can make with it. both in lua and cpp.
  12. have you tried? local specularIntensity = 1.0 entity:SetIntensity(specularIntensity, Color.Specular) this should allow you to control specular without having to change the rgb values.
  13. 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)
  14. 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. It is still very much a concept. But if i have to name it i guess it would be a pyrotechnics simulator.
  15. 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.
  16. 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
  17. I made a rudimentary system that uses SplineTools to connect 2 ends of a wire. I still have some tweaking to do to get the wire a bit smoother between nodes. But i thought i'd share anyway to show what can be done with AggrorJorn's SplineTools
  18. 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.
  19. 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.
  20. 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; }
  21. 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
  22. 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: --[[ ----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
  23. 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
  24. 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.
  25. 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.
×
×
  • Create New...