Texts Library Beginner's Guide?

Language: JP EN DE FR
2010-09-08
New Items
users online
Forum » Windower » Support » Texts Library Beginner's Guide?
Texts Library Beginner's Guide?
Offline
By NiroAL 2018-12-03 01:34:57
Link | Quote | Reply
 
Hi everyone. I'm looking to try and start using the texts library to make some status displays in FFXI. I want to be able to track what ailments and buffs my character has in a seperate window. I know that there are addons or plugins that might have this functionality, but I'm interested in learning to do it myself.

However, my main problem is, as a total beginner to programming, I have no idea where to start. I've tried looking at other addons that utilize the texts library and reverse engineering their functionality, but most of the time I just end up confused. I also can't find very much documentation or any tutorials on how to use the library.

Are there any resources that anyone knows of that can help me out? Any help getting me started with the texts library would be greatly appreciated. Thank you so much!
 Bahamut.Shozokui
Offline
Server: Bahamut
Game: FFXI
user: Shozokui
Posts: 460
By Bahamut.Shozokui 2018-12-03 07:37:30
Link | Quote | Reply
 
The texts library is simple. The place where you're going to get hung up if you're a "total beginner" is going to be enumerating your buffs and determining which are buffs/debuffs. Spoiler alert, the game just considers everything a buff.

Creating a new text box and showing it
Code
settings = config.load('data\\settings.xml',default_settings)
box = texts.new('${current_string}', settings.text_box_settings, settings)
box.current_string = ''
box:show()


Setting text of a specific box
Code
box.current_string = txt



Storing your text box configuration in an xml file in data/settings.xml
Code
<?xml version="1.1" ?>
<settings>
    <global>
        <text_box_settings>
            <bg>
                <alpha>125</alpha>
                <blue>0</blue>
                <green>0</green>
                <red>0</red>
                <visible>true</visible>
            </bg>
            <flags>
                <bold>false</bold>
                <bottom>false</bottom>
                <draggable>true</draggable>
                <italic>false</italic>
                <right>false</right>
            </flags>
            <padding>10</padding>
            <pos>
                <x>1583</x>
                <y>349</y>
            </pos>
            <text>
                <alpha>255</alpha>
                <blue>255</blue>
                <font>Consolas</font>
                <fonts>

                </fonts>
                <green>255</green>
                <red>255</red>
                <size>12</size>
                <stroke>
                    <alpha>255</alpha>
                    <blue>0</blue>
                    <green>0</green>
                    <red>0</red>
                    <width>0</width>
                </stroke>
            </text>
        </text_box_settings>
    </global>
</settings>
[+]
Offline
By NiroAL 2018-12-04 00:49:57
Link | Quote | Reply
 
Thank you so much! This will be a great jumping off point for me. If it's not too much trouble, could you run me through your code and explain your syntax to me? Or is there some documentation for the texts library I can read somewhere?

Either way, thanks so much!
 Bismarck.Xurion
Offline
Server: Bismarck
Game: FFXI
user: Xurion
Posts: 693
By Bismarck.Xurion 2018-12-04 05:24:40
Link | Quote | Reply
 
I recommend looking into the Windower Github wiki: https://github.com/Windower/Lua/wiki. There's a lot of documentation available there.

Here's a brief line-by-line explanation of an addon example that creates a text box and displays your inventory space.
Code
--The name of your addon
_addon.name = 'Inventory Space'
--You (any format you want for this - this is just what I put)
_addon.author = 'Dean James (Xurion of Bismarck)'
--Current version of this addon. If you want to version "properly", look up semantic versioning
_addon.version = '1.0.0'

--This library generates text boxes
texts = require('texts')
--This library handles loading/saving configuration (the XML file in data/settings.xml)
config = require('config')

--These are the default settings we want
default_settings = {
  bg = {
    alpha = 75
  },
  padding = 3
}
--The first time we execute config.load, the data/settings.xml file is auto generated with the default_settings
settings = config.load(default_settings)
--Here we create a text box using the texts library. We tell it to use the settings that have been fetched or auto generated
--The texts library will now add additional configuration to the XML file
text_box = texts.new(settings)

--This is an event we tell Windower to execute at a certain point. In this case, it is when the addon loads
--There are a number of events that can be set. Check out: https://github.com/Windower/Lua/wiki/Events
windower.register_event('load', function()
  --Use windower.ffxi.get_items().inventory to get info about your inventory
  local inventory = windower.ffxi.get_items().inventory
  --Use the inventory info to generate text that will be soming like "64/80"
  local new_text = inventory.count .. '/' .. inventory.max
  --Use the :text function to set the text
  text_box:text(new_text)
  --Use the :visible function to set the text box to visible
  text_box:visible(true)
end)


I'll assume you know how to put this into your addons directory etc. and load it. When you do, it'll appear at the very top left of the UI because we haven't set it to be any different (most text-based addons do this).

You can now drag the text box around, and as you do, the texts library automatically saves the new position in the settings.xml file.
[+]
Offline
By NiroAL 2018-12-04 06:28:14
Link | Quote | Reply
 
Thank you so much! This is perfect. I'm going to mess with it later on.

I really appreciate the help!
 Bismarck.Xurion
Offline
Server: Bismarck
Game: FFXI
user: Xurion
Posts: 693
By Bismarck.Xurion 2018-12-04 07:08:51
Link | Quote | Reply
 
No worries. Another thing I forgot to mention is the texts library (as well as others) can be found in addons\libs\texts.lua.

You can browse all the functions available there. Good luck!
Offline
By NiroAL 2018-12-20 04:18:02
Link | Quote | Reply
 
Hi again everyone! Thanks again for all your help.

I was messing around with the texts library recently, and I've been trying to make an object change when the mouse 1) hovers over it 2) gets left clicked on while it's being hovered over. I wrote the following spaghetti code (I told you I was a total beginner, lol) which works for everything except the part where I set the text to "Click!".

Code
texts = require('texts')
config = require('config')

default_settings = {}

settings = config.load(default_settings)
t = texts.new(settings)

windower.register_event('load', function()
  local new_text = 'Hello world!'
  t:text(new_text)
  t:visible(true)
end)
windower.register_event('mouse', function(eventtype, x, y, delta, blocked)
	hovered = texts.hover(t,x,y)
	if blocked then
		return
	end
	if eventtype == 0 then
		if hovered then
			texts.bg_visible(t, true)
		else
			texts.bg_visible(t, false)
		end
	elseif eventtype == 1 then
		if texts.pos_x(t) == x and texts.pos_y(t) == y then
			texts.bg_color(t, 0, 255, 0)
			t:text('Click!')
		else
			texts.bg_color(t, 0, 0, 255)
			t:text('No click!')
		end
	elseif eventtype == 2 then
		t:text('Hello world!')
		t.bg_color(t,0,0,0)
	end
end)


Any help figuring out why it's not working would be greatly appreciated. Sorry for the spaghetti code, I have pretty much 0 functional knowledge in lua (or any other language, lol).
 Bismarck.Xurion
Offline
Server: Bismarck
Game: FFXI
user: Xurion
Posts: 693
By Bismarck.Xurion 2018-12-20 17:27:44
Link | Quote | Reply
 
On line 26, I'm pretty sure texts.pos_x(t) returns the x position of the text box. That is only 1 pixel. I managed to run your script and click on the top left of the box and see the click state you want. Same goes for the pos_y function.

Also, you can use t:pos_x() over texts.pos_x(t) (or any other method that takes the text instance as the first argument).

For someone who describes themselves as a total beginner, this is pretty good :)
[+]
Offline
By NiroAL 2018-12-20 17:46:49
Link | Quote | Reply
 
Haha, most of the code was copied from other addons, but thanks!

Oh! Is that why. Now that you mention it that makes a lot of sense. So if I wanted it to detect the whole box I'd have to define a range of x's and y's that cover the whole box in the if statement, instead of just the top left pixel, right? I'll give it a shot.

Thanks again for your help!
 Bismarck.Xurion
Offline
Server: Bismarck
Game: FFXI
user: Xurion
Posts: 693
By Bismarck.Xurion 2018-12-21 00:28:13
Link | Quote | Reply
 
Yeah I haven't looked into this so I'm not sure, but I don't think texts gives you a function to get the width or height.

There may be some other way of achieving this, but you'd essentially need to calculate if the current mouse x/y are between the box x/y and box width/height.

I've only really used texts to display arbitrary information.
Log in to post.