Jump to content

Simple popup messages


randomdude
 Share

Recommended Posts

function Script:Start()
	self.enabled=false
end


function Script:Enable()--in
	if self.enabled==false then
		self.enabled=true
		--self:CallOutputs("Enable")
		local gui = GUI:Create(context)
		local base = gui:GetBase()
		base:SetScript("Scripts/GUI/Panel.lua")
		x=100
		y=50
		local sep=30
		widget = Widget:TextArea(x,y,500,100,base)
		widget:SetText("This function creates a textarea widget.\n\nA textarea is read-only widget that can display multiple lines of text.")
		y=y+sep
	end
end

function Script:Disable()--in
	if self.enabled then
		self.enabled=false
		--self:CallOutputs("Disable")
	end
end

Okay cool, thats fuctional. but how do  get only the window with text and the game as background? And how do I get it stopped after a specific time?

Link to comment
Share on other sites

I personally use my own UI system, so I am not much into the Leadwerks built in UI system, but I can help you with the stopping after a specific time. As far as I understand it you want the message just be displayed for a specific of time don't you?

For this simple add a timer, which disables the widget like this:

Script.timer = 0
Script.widgetLifeTime = 30

function Script:UpdateWorld()
   if self.enabled then
    self.timer = self.timer + Time:GetSpeed()
      if self.timer >= self.widgetLifeTime then 
         self.timer = 0 
         self:Disable() 
      end
   end
end

But your disable function won't work. I guess you have to release the widget somewhere, but at them moment I dont know how this exactly works with the leadwerks UI, maybe check the Reference for that.

I don't get what you mean with:

8 hours ago, randomdude said:

but how do  get only the window with text and the game as background?

 

Link to comment
Share on other sites

Okay Thanks. These Timers aren´t working somehow, I tried a lot of variations. Dont know what is wrong. Its either ignored or nothing happens.

But this DrawText function is what I need. This here is working correct but the app is stopping.

function Script:Start()
	self.enabled=false
end




function Script:Enable()--in
	if self.enabled==false then
		self.enabled=true
		--self:CallOutputs("Enable")
		local text = "Hello!asdasdasdasdasdasdasdasdasd"
        
        local font = context:GetFont()

        local x = window:GetWidth()/2
        local y = window:GetHeight()/2

        x = x - font:GetTextWidth(text)/2
        y = y - font:GetHeight()/2

        context:SetBlendMode(Blend.Alpha)
        context:SetColor(1,1,1)
        context:DrawText(text,x,y)
		context:Sync()
		Time:Delay(1000)
	end
end

function Script:Disable()--in
	if self.enabled then
		self.enabled=false
		--self:CallOutputs("Disable")
		
	end
end

I tried instead of Time:Delay this timer function but its not working.

Link to comment
Share on other sites

For people who want to use this, just make two triggers, one enables and one disables.

function Script:Start()
	self.enabled=false
	
end



function Script:Enable()--in
	
	if self.enabled==false then
		self.enabled=true
		
	end
end


function Script:PostRender(context)

    
    if self.enabled==true then
        local text = "Hello!"
        
		local font = context:GetFont()

		local x = window:GetWidth()/2
		local y = window:GetHeight()/2

		x = x - font:GetTextWidth(text)/2
		y = y - font:GetHeight()/2

		context:SetBlendMode(Blend.Alpha)
		context:SetColor(1,1,1)
		context:DrawText(text,x,y)
    end
end

	

function Script:Disable()--in
	if self.enabled then
		self.enabled=false
		--self:CallOutputs("Disable")
		
	end
end

 

Link to comment
Share on other sites

Haven't you tried my timer code? There is no built in timer function or something like that. Try that out:

Script.timer = 0
Script.widgetLifeTime = 30

function Script:UpdateWorld()
   if self.enabled then
    --This is the timer:
    self.timer = self.timer + Time:GetSpeed()
      if self.timer >= self.widgetLifeTime then 
         self.timer = 0 
         self:Disable() 
      end
   end
end

You need any function which updates every frame and put that timer code in there. Do NOT put this lines of code into a function which just gets called once. You can for example put this inside the post render function.

The "Time:Delay" function freezes your code for a specific amount of time I guess.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...