Thread Tools Display Modes
05-17-11, 03:45 AM   #1
Tabinou
A Deviate Faerie Dragon
Join Date: May 2011
Posts: 11
Number of decimals in castbar time

Hi,

I'm quite new to lua and oUF.

Took a layout, and try to customize it my way.
I'm trying to have a castbar with the time having 2 decimals (I have 1.7, when i want 1.67). I can't find where to set this up (in my layout ? in oUF directly ?)

My code looks like this:
Code:
self.Castbar = CreateFrame('StatusBar', nil, self)
					self.Castbar:SetFrameStrata('MEDIUM')
					self.Castbar:SetFrameLevel(10)
					self.Castbar:SetWidth(300)
					self.Castbar:SetHeight(26)
					self.Castbar:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -10)
					self.Castbar:SetStatusBarTexture(cfg.Statusbar)
					self.Castbar:SetStatusBarColor(1,1,0)
self.Castbar.Time = self.Castbar:CreateFontString(nil, 'OVERLAY') 
					self.Castbar.Time:SetFont(cfg.Font, 14, 'THINOUTLINE')
					self.Castbar.Time:SetPoint('RIGHT', self.Castbar,'RIGHT',-2, 0)
					self.Castbar.Time:SetWidth(50)
					self.Castbar.Time:SetTextColor(1,1,1)
					self.Castbar.Time:SetJustifyH('RIGHT')
Thanks in advance.
  Reply With Quote
05-17-11, 04:39 AM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
You need to implement your own CustomDelayText and CustomTimeText. The defaults should be:
Lua Code:
  1. local CustomDelayText = function(Castbar, duration)
  2.    self.Time:SetFormattedText("%.1f|cffff0000-%.1f|r", duration, self.delay)
  3. end
  4.  
  5. local CustomTimeText = function(Castbar, duration)
  6.    self.Time:SetFormattedText("%.1f", duration)
  7. end

Change %.1f to %.2f and do:
Lua Code:
  1. self.Castbar.CustomDelayText = CustomDelayText
  2. self.Castbar.CustomTimeText = CustomTimeText
__________________
「貴方は1人じゃないよ」
  Reply With Quote
05-17-11, 05:53 AM   #3
Tabinou
A Deviate Faerie Dragon
Join Date: May 2011
Posts: 11
I tried to set this up without success.

As i'm the newbie, that's definitely my fault.
I found your method in Castbar.lua and changed 1 by 2, it's working. That's a first step. If I understand right, the customdelay should look like "duration" - "delay". The |c is to change the color, but what does the |r (reset maybe ?)

- I can add one of the two, or both, right ? These are separated, and I can use one or the other depending on what I want to see, can't I ?
- Should they be added in my layout, or directly in Castbar.lua from oUF ? My layout, I think, that would make more sense, but I prefer to be sure.
- In my code, should I create a new "object" to replace self.Castbar.Time (self.Castbar.CustomTimeText = self.Castbar:CreateFontString(nil, 'OVERLAY') and the following) or just put the line you wrote below what i've written before ?

I'm sorry if that looks obvious to you, but to me, not that much.
And thanks again for the time spent improving oUF and answering newbies like me.
  Reply With Quote
05-17-11, 07:21 AM   #4
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
1. Both code pieces are tied together, but the functions defined are optional. One is for the ordinary cast time display, while the other is for when you have a delay on the cast.
2. You should add it to your layout, as modifying oUF directly is bad and wrong.
3. CustomTimeText and CustomDelayText are functions, not fontstrings. oUF will call these functions when they are defined at self.Castbar.CustomTimeText and self.Castbar.CustomDelayText, instead of using the internal solution.

You add the top piece of code somewhere above your style function and add the bottom piece of code somewhere inside your style function. The second piece of code needs to be added after/where you define your Castbar element.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
05-17-11, 08:17 AM   #5
Tabinou
A Deviate Faerie Dragon
Join Date: May 2011
Posts: 11
Ok, it worked (I had to change the functions to be Castbar.Time instead of self.Time, but whatever)

I'm wondering if it would be possible to add this directly to oUF.
Having a default value set to 1, with the possibility to change it in the layout, and do (something like) this :
lua Code:
  1. self.Time:SetFormattedText("%."..value.."f", duration)

Again, I'm not even sure that's possible, but if it's the only thing to do (or something like that), that would be awesome.
  Reply With Quote
05-17-11, 08:25 AM   #6
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by Tabinou View Post
Ok, it worked (I had to change the functions to be Castbar.Time instead of self.Time, but whatever)
yeah, that was my fault. I just wrote the code in my browser, then fetched the default code from my terminal and forgot to update the reference.

Originally Posted by Tabinou View Post
I'm wondering if it would be possible to add this directly to oUF.
Having a default value set to 1, with the possibility to change it in the layout, and do (something like) this :
lua Code:
  1. self.Time:SetFormattedText("%."..value.."f", duration)

Again, I'm not even sure that's possible, but if it's the only thing to do (or something like that), that would be awesome.
Well, you already have it directly in oUF. You just have to do it through a function hook. The main reason is that people generally want to do (in)sane things and giving them a function to work with allows that. While letting them just override the format just allows you to do that.
__________________
「貴方は1人じゃないよ」
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Number of decimals in castbar time


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off