Jump to content

Type text input/parser, How?


Core
 Share

Recommended Posts

Ok, I found TextArea and TextField scripts from GUI scripts. But did not know where to start with those. I know, I'm thick headed, but how those GUI widgets work? Or how I use them?

Example, how to do this: I have terminal in my game world. When player uses/interacts with it, it opens a menu, where is only one thing, area where player can type text. When player hits enter, it stores what ever player typed to a variable.

Again, I'm not looking for a full code, just pointers to the right direction and where to even start, thanks!

 

Edit. So I found this. I think it is what I need...

 

Edited by Core
added link
Link to comment
Share on other sites

Thank you again for your help, @GorzenDev, I just got working the first iteration of the interface. This was a big milestone for me! I might never have looked Josh's chat example without your tip.

One question arised though. How can I make/add own modified widgets or load modified script file to default ones? Now I just modified the stock ones (made backups).

 

20170925032847_1.jpg

  • Like 1
Link to comment
Share on other sites

38 minutes ago, Core said:

Thank you again for your help, @GorzenDev, I just got working the first iteration of the interface. This was a big milestone for me! I might never have looked Josh's chat example without your tip.

One question arised though. How can I make/add own modified widgets or load modified script file to default ones? Now I just modified the stock ones (made backups).


you would need to have the widget point to your script. 

Widget:Create("text", x, y, w, h, parent, "scriptfile");

that would create a custom widget with your own behaviour.
change values in your script with:

widget:SetBool("variableName", false)
widget:GetBool("variableName")

widget:SetFloat("variableName", 0.0)
widget:GetFloat("variableName")

widget:SetString("variableName", "value")
widget:GetString("variableName")

there are more Get/Set functions in the documentation:
https://www.leadwerks.com/learn?page=API-Reference_Object_Widget_Create
 

alternatively you could do:

newbutton = Widget:Button("button",10,10,300,20, gui:GetBase())
newbutton:SetSript("Scripts/GUI/customButton.lua")

 

  • Thanks 1
  • Upvote 1
Link to comment
Share on other sites

On 9/25/2017 at 3:56 AM, Core said:

Thank you again for your help, @GorzenDev, I just got working the first iteration of the interface. This was a big milestone for me! I might never have looked Josh's chat example without your tip.

One question arised though. How can I make/add own modified widgets or load modified script file to default ones? Now I just modified the stock ones (made backups).

 

20170925032847_1.jpg

I love love love our GUI implementation.  Using a per-widget script was sooooooo smart because it provides this extreme flexibility.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Another one with this... I try to autoscroll my text area and made this script:

	local i
	local offset = 10
	for i=1,offset do
		self.scroll1 = self.slider[0]:GetSliderValue()
		System:Print(self.scroll1)
		self.scroll2 = (self.scroll1+1)
		self.slider[0]:SetSliderValue(self.scroll2)
		System:Print(self.scroll2)

It works, unless there are more new lines than one. For some reason, it just won't scroll all the way down automatically if there are more lines than one added to the text area widget at the same time. I CAN scroll all the way down with mouse though. I tried with the unmodified TextArea script too, no luck. System:Print prints slider values long after the scrolling has stopped, so it is not that there is too few loops. Strange though, that no matter what "offset" I put, the result is the same.

So how I can make text area scroll automatically all the way down when text is added to it? Can I "emulate" mouse wheel somehow maybe? 

Link to comment
Share on other sites

7 hours ago, Core said:

Another one with this... I try to autoscroll my text area and made this script:


	local i
	local offset = 10
	for i=1,offset do
		self.scroll1 = self.slider[0]:GetSliderValue()
		System:Print(self.scroll1)
		self.scroll2 = (self.scroll1+1)
		self.slider[0]:SetSliderValue(self.scroll2)
		System:Print(self.scroll2)

It works, unless there are more new lines than one. For some reason, it just won't scroll all the way down automatically if there are more lines than one added to the text area widget at the same time. I CAN scroll all the way down with mouse though. I tried with the unmodified TextArea script too, no luck. System:Print prints slider values long after the scrolling has stopped, so it is not that there is too few loops. Strange though, that no matter what "offset" I put, the result is the same.

So how I can make text area scroll automatically all the way down when text is added to it? Can I "emulate" mouse wheel somehow maybe? 

I think you will need to post a working example to get any help with this.

The textarea widget was pretty difficult to write, and is only meant to be a static display of text, not a full text editor.  Scintilla is better suited for that.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Yes, I think I can work with this, it is allready working well enough for what I have in mind. I might create new text area widget for multiline texts instead off adding to the old one. All in all, this is one final piece, soon I can start to create actual gameplay content and assets to finally create something you can actually play. I think I'll start project thread and post details of my game project. And demo.

Link to comment
Share on other sites

honestly looking at the vanilla TextArea.lua it looks like it should support what you want.
try something like below. (not tested it)

function Script:AddText(text)
	self.updateslidersneeded=true
	local morelines = text:split("\n")
	local gui=self.widget:GetGUI()
	local n
	for n=1,#morelines do
		self.lines[#self.lines+1] = morelines[n]
		self.linewidth[#self.lines] = gui:GetTextWidth(morelines[n])
		self.maxlinewidth = math.max(self.maxlinewidth,self.linewidth[#self.lines])
	end
  	--try something like this
	self:MouseWheel(#morelines)
end

 

Link to comment
Share on other sites

Thanks, I actually figured out what was wrong... Text Area widget needs to be in focus for scrolling to work! I switched focus too quicly back to text input field so when I delayed the switch back to input field, scrolling was able to finish!

  • Like 1
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...