Jump to content

GorzenDev

Members
  • Posts

    141
  • Joined

  • Last visited

Everything posted by GorzenDev

  1. if i remember correctly you need the GUI to initialize the image. example: logo = Widget::Panel( 0, 0, gui->GetBase()->GetClientSize().width, gui->GetBase()->GetClientSize().height, gui->GetBase()); logo->SetScript("Scripts/GUI/Custom/ImagePanel.lua"); Image* logoImg = gui->LoadImageA("Materials/Logo/leadwerks_logo.tex"); logo->SetImage(logoImg); logo->Redraw(); logoImg->Release();
  2. using a global variable like that will result in undefined behaviour. make sure you process each event before the while loop ends. you would be better off to store a pointer to mudaLocalGui as global variable, add a process function to your script, and call it from your event loop. (remove the pointer after closing the menu ) personally i would use some kind of guimanager script, instead of processing your events in Main.lua. example of a gui manager: import("Scripts/MainMenu.lua") import("Scripts/GameMap.lua") import("Scripts/GameGUI.lua") function BuildGUIManager(context) local Manager = {} -- Manager.gamemenu = BuildMenu(context, Manager) Manager.gamemenu:Show() -- Manager.gamemap = BuildGameMap(context) Manager.gamemap:Hide() -- Manager.gameui = BuildGameGUI(context, Manager) Manager.gameui:Hide() ------------------------------------------------ function Manager:MenuHidden() return self.gamemenu:Hidden() end function Manager:ShowGameMenu() self.gamemenu:Show() self.gameui:Hide() end function Manager:HideGameMenu() self.gameui:Show() self.gamemenu:Hide() end -- function Manager:Update() -- if self.gamemenu:Hidden() == false then self.gamemenu:Update() end if self.gamemap:Hidden() == false then self.gamemap:Update() end if self.gameui:Hidden() == false then self.gameui:Update() end -- while EventQueue:Peek() do local event = EventQueue:Wait() local event_processed = false --process menu if self.gamemenu:Hidden() == false then if self.gamemenu:ProcessEvent(event) == false then --exit game return false end end --process map if self.gamemap:Hidden() == false then event_processed = self.gamemap:ProcessEvent(event) end --process ui if event_processed == false and self.gameui:Hidden() == false then self.gameui:ProcessEvent(event) end end -- return true end -- -- return Manager end
  3. i used to do something like this... this will only add keyinfo to the Keys table when a key is actually used. to make it work you would need to add a call to PreUpdate() in your main loop. to check a key's state you would call eg: IsKeyUp(Key.W) or IsKeyDown(Key.W). function SetKeyboardInfoPack() local pack = { Keys = {}, -- FlushKeyInfo = function (self, resetHit, key) if key ~= nil then local nHit = 0 if self.Keys[key] ~= nil and resetHit == false then nHit = self.Keys[key].hit end self.Keys[key] = {down = false, up = false, hit = nHit} else local nHit = 0 for key,value in pairs(self.Keys) do if resetHit == false then nHit = self.Keys[key].hit end self.Keys[key] = {down = false, up = false, hit = nHit} end end end, -- PreUpdate = function (self) self:RefreshKeyStates() end, -- IsKeyDown = function (self, key) --create a key record if not already exists and check the keystate if self.Keys[key] == nil then self.Keys[key] = {down = false, up = false, hit = 0} self:RefreshKey(key) end --return keystate return self.Keys[key].down end, -- IsKeyUp = function (self, key) --create a key record if not already exists and check the keystate if self.Keys[key] == nil then self.Keys[key] = {down = false, up = false, hit = 0} self:RefreshKey(key) end --return keystate return self.Keys[key].up end, Keyhits = function (self, key) --create a key record if not already exists and check the keystate if self.Keys[key] == nil then self.Keys[key] = {down = false, up = false, hit = 0} self:RefreshKey(key) end --return keystate return self.Keys[key].hit end, -- RefreshKeyStates = function (self) for key,value in pairs(self.Keys) do self:RefreshKey(key) end end, RefreshKey = function (self, key) if key ~= nil then if self.Keys[key] ~= nil then if window:KeyDown(key) then self.Keys[key].down = true self.Keys[key].up = false elseif self.Keys[key].down == true then --last state down self.Keys[key].down = false self.Keys[key].up = true self.Keys[key].hit = self.Keys[key].hit + 1 elseif self.Keys[key].up == true then --last state up self.Keys[key].down = false self.Keys[key].up = false end end end end } -- return pack end
  4. they all definitly work no doubt about it. are you certain that the variable you try to read/write actually exists in the widget script?? i assume you are looking for. widget:SetFloat("radius", 2); widget:GetFloat("radius"); REMEMBER !!! call widget:Redraw() when you change a variable's value. often you would think "hey this does not work" while it usually does work but is not updated yet ?
  5. The BaseActor class i use to derive actors from. Use it just like you would use a entity script. Attach actor to a entity. baseActor = new BaseActor(); entity->SetActor(baseActor); BaseActor.h #include "Leadwerks.h" using namespace Leadwerks; const enum class ActorType : char { Base, Player, NPC}; class BaseActor : public Actor { //Built-in extendable functions // //virtual void EndAnimation(const int sequence); virtual void Sleep(); //virtual void Wake(); virtual void Attach(); //virtual void Detach(); //virtual void Collision(Entity* entity, const Vec3& position, const Vec3& normal, float speed); virtual void UpdateWorld(); virtual void UpdatePhysics(); //virtual void UpdateMatrix(); virtual void PostRender(Context* context); //virtual void Draw(); //virtual void DrawEach(Camera* camera); //virtual void ReceiveSignal(const std::string& inputname, Entity* sender); public: ActorType actorType = ActorType::Base; BaseActor(); virtual ~BaseActor(); }; BaseActor.cpp #include "BaseActor.h" BaseActor::BaseActor() { } BaseActor::~BaseActor() { } void BaseActor::Attach() { // //System::Print("BaseActor Attached."); } void BaseActor::Sleep() { // //System::Print("BaseActor Sleep."); } void BaseActor::UpdateWorld() { //System::Print("BaseActor UpdateWorld."); } void BaseActor::UpdatePhysics() { //System::Print("BaseActor UpdatePhysics."); } void BaseActor::PostRender(Context* context) { // }
  6. Definition Entity.h virtual int FindAnimationSequence(const std::string& sequence);//lua Entity::FindAnimationSequence("sequencename")
  7. whenevver i loose my motivation i actually force myself to do at least 4 hours of coding each week. which in turn motivates me because i progress. (even if its just small progress) this brings me in a vicious circle that keeps me going.
  8. You could always edit the "common" template and remove the files you dont want to be copied. Dont forget to backup before editing.
  9. create your own "BlankProject" template its very easy and saves you a lot of time. i remember i made a post somewhere on how to do it.
  10. The style system change results in a lot of manual source updating and since i make use of the GUI system in basicly all of my projects, that's alot of code to change. Maiby i will have to write a small tool that does it for me... i guess notepad++ could achieve it nonetheless nice work on the update.
  11. GorzenDev

    Project Release

    I decided to release the source/project for my GUIEditor. its an unfinished project and not at all optimized, although it is usable. you mite have to upgrade the source project to the latest version. written in c++. the project includes some custom gui scripts found in /Scripts/GUI/Custom. and a FileDialog i designed using widgets. GUIEditor.rar enjoy
  12. you could create your own pre-post processor function in your main.lua, and have that execute when you want.
  13. i'm thinking this is due to NVIDIA trying to force/overwrite game settings when you manually set them. try using default nvidia settings and let leadwerks do its thing...
  14. that is one option. i recommend moving the event loop outside of the menu file though. then call processevent(event) with a return value on any table that needs to process events. for example in my current c++ project i actualy have a class called GUIManager which holds the event loop. which in turn calls other gui classes to update and grab events. when that call returns true then the event is processed and there is no need to call other classes with that event. example code(C++) : //Handle GUI events while (EventQueue::Peek()) { Event event = EventQueue::Wait(); // //Update menu UI events if (!gamemenu->Hidden()) { //exit game if (gamemenu->ProcessEvent(event) == false) return false; } //update game UI events if (!gameui->Hidden()) gameui->ProcessEvent(event); }
  15. you can create multiple GUI to hold widgets. but only one event loop can be used.
  16. i think this will get you the answer you need.
  17. GorzenDev

    Custom Widgets

    why the sad face? you need any help
  18. almost forgot... checkout AggrorJorns plugin for visual studio code. very helpfull https://www.leadwerks.com/community/blogs/entry/2145-visual-studio-code-for-leadwerks/
  19. your best option would be to use the search function on the forum. other than that the demo projects that come with leadwerks basicly show all you can do.
  20. https://www.leadwerks.com/learn?page=Tutorials_Lua-Scripting_Introduction-to-Lua scroll all the way down. it is realy not that hard to find resources for Leadwerks to be honest.
  21. like spiderpig said only lua is accepted in that box. But....... The c++ Actor class is what your looking for.
  22. we basicly posted at the same time you could use different approaches. either send a widget event whenevver any text is typed into the field by using "Option 1". or send a widget event whenevver the "ENTER" key is pressed "Option 2". (assume the user is done typing) or send an widget event whenevver the "TAB" key is pressed "Option 3". (assume the user wants to switch to the next element in case of a form that needs filling) if a WidgetAction event interferes with other events you could always use WidgetSelect or WidgetMenu events --OPTION 1-- function Script:KeyChar(charcode) local s = self.widget:GetText() local c = String:Chr(charcode) if c=="\b" then --Backspace if String:Length(s)>0 then if self.sellen==0 then if self.caretposition==String:Length(s) then s = String:Left(s,String:Length(s)-1) elseif self.caretposition>0 then s = String:Left(s,self.caretposition-1)..String:Right(s,String:Length(s)-self.caretposition) end self.caretposition = self.caretposition - 1 self.caretposition = math.max(0,self.caretposition) else local c1 = math.min(self.caretposition,self.caretposition+self.sellen) local c2 = math.max(self.caretposition,self.caretposition+self.sellen) s = String:Left(s,c1)..String:Right(s,String:Length(s) - c2) self.caretposition = c1 self.sellen = 0 end self.widget:GetGUI():ResetCursorBlink() self.cursorblinkmode=true self.widget.text = s self.widget:Redraw() end elseif c~="\r" and c~="" then --Insert a new character local c1 = math.min(self.caretposition,self.caretposition+self.sellen) local c2 = math.max(self.caretposition,self.caretposition+self.sellen) s = String:Left(s,c1)..c..String:Right(s,String:Length(s) - c2) self.caretposition = self.caretposition + 1 if self.sellen<0 then self.caretposition = self.caretposition + self.sellen end self.sellen=0 self.widget:GetGUI():ResetCursorBlink() self.cursorblinkmode=true self.widget.text = s self.widget:Redraw() -- --OPTION 1-- --send event with data = 999 EventQueue:Emit(Event.WidgetAction,self.widget,999) end end function Script:KeyUp(keycode) if keycode==Key.Shift then self.shiftpressed=false end -- if keycode==Key.Enter then self.widget:GetGUI():SetFocus(nil) -- --OPTION 2-- --send event with data = 997 EventQueue:Emit(Event.WidgetAction,self.widget,997) elseif keycode==Key.Tab then self.widget:GetGUI():SetFocus(nil) -- --OPTION 3-- --send event with data = 998 EventQueue:Emit(Event.WidgetAction,self.widget,998) end end
  23. I'm not at my pc right now but from the top of my head I would say. Open textfield.lua, scroll all the way down and add a widget event call to the keychar or keydown/up method. You will find examples of calling an event inside any widget script. I will add a proper example when I get home.
  24. better yet c++ can call functions straight out of the widgetscript. so create a nice widget script set it to your widget and call functions from c++. other than that c++ can do exactly the same as lua can when it comes to widgets. sorry i forgot to add usage for the colorlabel. use the above colorlabel script like this: --create a custom widget colorlabel = Widget:Create("", 100, 100, 250, 12, gui:GetBase(), "Scripts/GUI/ColorLabel.lua") colorlabel:SetObject("textcolor", Vec4(1.0, 0.0, 0.0, 1.0))
×
×
  • Create New...