Thread: GUI's
View Single Post
05-28-05, 06:44 PM   #31
diiverr
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 67
OK, in an effort to get around the pesky un-named texture dilemma, I decided to pursue the earlier castbar example.

Sorry for the eyesores, but here is the code of my reconstruction of the castbar:

Lua:
Code:
CASTING_BAR_ALPHA_STEP = 0.05;
CASTING_BAR_FLASH_STEP = 0.2;
CASTING_BAR_HOLD_TIME = 1;

function DS_CastingBarFrame_OnLoad()
	this:RegisterEvent("SPELLCAST_START");
	this:RegisterEvent("SPELLCAST_STOP");
	this:RegisterEvent("SPELLCAST_FAILED");
	this:RegisterEvent("SPELLCAST_INTERRUPTED");
	this:RegisterEvent("SPELLCAST_DELAYED");
	this:RegisterEvent("SPELLCAST_CHANNEL_START");
	this:RegisterEvent("SPELLCAST_CHANNEL_UPDATE");
	this.casting = nil;
	this.holdTime = 0;
	CastingBarFrame_OnEvent = DS_CastingBarFrame_OnEvent
	CastingBarFrame_OnUpdate = DS_CastingBarFrame_OnUpdate
	--tried just using CastingBarFrame:Hide(); below too. that didn't work either
	if DS_CastingBarFrame:IsVisible() then
		CastingBarFrame:Hide();
	end
end

function DS_CastingBarFrame_OnEvent()
	if ( event == "SPELLCAST_START" ) then
		DS_CastingBarFrameStatusBar:SetStatusBarColor(1.0, 0.7, 0.0);
		DS_CastingBarSpark:Show();
		this.startTime = GetTime();
		this.maxValue = this.startTime + (arg2 / 1000);
		DS_CastingBarFrameStatusBar:SetMinMaxValues(this.startTime, this.maxValue);
		DS_CastingBarFrameStatusBar:SetValue(this.startTime);
		DS_CastingBarText:SetText(arg1);
		this:SetAlpha(1.0);
		this.DS_holdTime = 0;
		this.DS_casting = 1;
		this.fadeOut = nil;
		this:Show();

		this.mode = "DS_casting";
	elseif ( event == "SPELLCAST_STOP" ) then
		if ( not this:IsVisible() ) then
			this:Hide();
		end
		if ( this:IsShown() ) then
			DS_CastingBarFrameStatusBar:SetValue(this.maxValue);
			DS_CastingBarFrameStatusBar:SetStatusBarColor(0.0, 1.0, 0.0);
			DS_CastingBarSpark:Hide();
			DS_CastingBarFlash:SetAlpha(0.0);
			DS_CastingBarFlash:Show();
			this.DS_casting = nil;
			this.flash = 1;
			this.fadeOut = 1;

			this.mode = "flash";
		end
	elseif ( event == "SPELLCAST_FAILED" or event == "SPELLCAST_INTERRUPTED" ) then
		if ( this:IsShown() ) then
			DS_CastingBarFrameStatusBar:SetValue(this.maxValue);
			DS_CastingBarFrameStatusBar:SetStatusBarColor(1.0, 0.0, 0.0);
			DS_CastingBarSpark:Hide();
			if ( event == "SPELLCAST_FAILED" ) then
				DS_CastingBarText:SetText(FAILED);
			else
				DS_CastingBarText:SetText(INTERRUPTED);
			end
			this.DS_casting = nil;
			this.fadeOut = 1;
			this.DS_holdTime = GetTime() + CASTING_BAR_HOLD_TIME;
		end
	elseif ( event == "SPELLCAST_DELAYED" ) then
		if( this:IsShown() ) then
			this.startTime = this.startTime + (arg1 / 1000);
			this.maxValue = this.maxValue + (arg1 / 1000);
			DS_CastingBarFrameStatusBar:SetMinMaxValues(this.startTime, this.maxValue);
		end
	elseif ( event == "SPELLCAST_CHANNEL_START" ) then
		DS_CastingBarFrameStatusBar:SetStatusBarColor(1.0, 0.7, 0.0);
		DS_CastingBarSpark:Show();
		this.maxValue = 1;
		this.startTime = GetTime();
		this.endTime = this.startTime + (arg1 / 1000);
		this.duration = arg1 / 1000;
		DS_CastingBarFrameStatusBar:SetMinMaxValues(this.startTime, this.endTime);
		DS_CastingBarFrameStatusBar:SetValue(this.endTime);
		DS_CastingBarText:SetText(arg2);
		this:SetAlpha(1.0);
		this.DS_holdTime = 0;
		this.DS_casting = nil;
		this.channeling = 1;
		this.fadeOut = nil;
		this:Show();
	elseif ( event == "SPELLCAST_CHANNEL_UPDATE" ) then
		if ( arg1 == 0 ) then
			this.channeling = nil;
		elseif ( this:IsShown() ) then
			local origDuration = this.endTime - this.startTime
			this.endTime = GetTime() + (arg1 / 1000)
			this.startTime = this.endTime - origDuration
			--this.endTime = this.startTime + (arg1 / 1000);
			DS_CastingBarFrameStatusBar:SetMinMaxValues(this.startTime, this.endTime);
		end
	end
end

function DS_CastingBarFrame_OnUpdate()
	if ( this.DS_casting ) then
		local status = GetTime();
		if ( status > this.maxValue ) then
			status = this.maxValue
		end
		DS_CastingBarFrameStatusBar:SetValue(status);
		DS_CastingBarFlash:Hide();
		local sparkPosition = ((status - this.startTime) / (this.maxValue - this.startTime)) * 195;
		if ( sparkPosition < 0 ) then
			sparkPosition = 0;
		end
		DS_CastingBarSpark:SetPoint("CENTER", "DS_CastingBarFrameStatusBar", "LEFT", sparkPosition, 0);
	elseif ( this.channeling ) then
		local time = GetTime();
		if ( time > this.endTime ) then
			time = this.endTime
		end
		if ( time == this.endTime ) then
			this.channeling = nil;
			this.fadeOut = 1;
			return;
		end
		local barValue = this.startTime + (this.endTime - time);
		DS_CastingBarFrameStatusBar:SetValue( barValue );
		DS_CastingBarFlash:Hide();
		local sparkPosition = ((barValue - this.startTime) / (this.endTime - this.startTime)) * 195;
		DS_CastingBarSpark:SetPoint("CENTER", "DS_CastingBarFrameStatusBar", "LEFT", sparkPosition, 0);
	elseif ( GetTime() < this.DS_holdTime ) then
		return;
	elseif ( this.flash ) then
		local alpha = DS_CastingBarFlash:GetAlpha() + CASTING_BAR_FLASH_STEP;
		if ( alpha < 1 ) then
			DS_CastingBarFlash:SetAlpha(alpha);
		else
			this.flash = nil;
		end
	elseif ( this.fadeOut ) then
		local alpha = this:GetAlpha() - CASTING_BAR_ALPHA_STEP;
		if ( alpha > 0 ) then
			this:SetAlpha(alpha);
		else
			this.fadeOut = nil;
			this:Hide();
		end
	end
end

function DS_CastingBarFrame_UpdatePosition()
	local castingBarPosition = 60;
	if ( PetActionBarFrame:IsVisible() or ShapeshiftBarFrame:IsVisible() ) then
		castingBarPosition = castingBarPosition + 40;
	end
	if ( MultiBarBottomLeft:IsVisible() ) then
		castingBarPosition = castingBarPosition + 40;
	end
	DS_CastingBarFrame:SetPoint("BOTTOM", "UIParent", "BOTTOM", 0, castingBarPosition);
end
XML:
Code:
	<Frame name="DS_CastingBarFrame" toplevel="true" parent="UIParent" movable="true" enableMouse="true" hidden="true">
		<Size>
			<AbsDimension x="206" y="26"/>
		</Size>
		<Anchors>
			<Anchor point="BOTTOM">
				<Offset>
					<AbsDimension x="0" y="60"/>
				</Offset>
			</Anchor>
		</Anchors>
		<Layers>
			<Layer level="BACKGROUND">
				<Texture>
					<Size>
						<AbsDimension x="195" y="13"/>
					</Size>
					<Anchors>
						<Anchor point="TOP">
							<Offset>
								<AbsDimension x="0" y="-2"/>
							</Offset>
						</Anchor>
					</Anchors>
					<Color r="0" g="0" b="0" a="0.5"/>
				</Texture>		
			</Layer>
			<Layer level="OVERLAY">
				<FontString name="DS_CastingBarText" inherits="GameFontHighlight">
					<Size>
						<AbsDimension x="185" y="16"/>
					</Size>
					<Anchors>
						<Anchor point="TOP">
							<Offset>
								<AbsDimension x="0" y="0"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
				<Texture file="Interface\AddOns\DiivSkins\Skins\castingbar">
					<Size>
						<AbsDimension x="256" y="64"/>
					</Size>
					<Anchors>
						<Anchor point="TOP">
							<Offset>
								<AbsDimension x="0" y="25"/>
							</Offset>
						</Anchor>
					</Anchors>
				</Texture>
			</Layer>
		</Layers>
		<Frames>
			<Frame name="DS_CastingBarFlash" hidden="true">
				<Size>
					<AbsDimension x="256" y="64"/>
				</Size>
				<Anchors>
					<Anchor point="CENTER">
						<Offset>
							<AbsDimension x="0" y="4"/>
						</Offset>
					</Anchor>
				</Anchors>
				<Layers>
					<Layer level="BACKGROUND">
						<Texture file="Interface\AddOns\DiivSkins\Skins\castingbarflash" alphaMode="ADD">
							<Size>
								<AbsDimension x="256" y="64"/>
							</Size>
						</Texture>
					</Layer>
				</Layers>
			</Frame>
			<StatusBar name="DS_CastingBarFrameStatusBar">
				<Size>
					<AbsDimension x="195" y="13"/>
				</Size>
				<Anchors>
					<Anchor point="TOP">
						<Offset>
							<AbsDimension x="0" y="-2"/>
						</Offset>
					</Anchor>
				</Anchors>
				<Layers>
					<Layer level="OVERLAY">
						<Texture name="DS_CastingBarSpark" file="Interface\CastingBar\UI-CastingBar-Spark" alphaMode="ADD">
							<Size>
								<AbsDimension x="32" y="32"/>
							</Size>
							<Anchors>
								<Anchor point="CENTER">
									<Offset>
										<AbsDimension x="0" y="0"/>
									</Offset>
								</Anchor>
							</Anchors>
						</Texture>
					</Layer>
				</Layers>
				<Scripts>
					<OnLoad>
						this:SetFrameLevel(this:GetFrameLevel() - 1)
					</OnLoad>
				</Scripts>
				<BarTexture file="Interface\TargetingFrame\UI-StatusBar"/>
				<BarColor r="1.0" g="0.7" b="0.0"/>
			</StatusBar>
		</Frames>
		<Scripts>
			<OnLoad>
				DS_CastingBarFrame_OnLoad();
			</OnLoad>
			<OnEvent>
				DS_CastingBarFrame_OnEvent();
			</OnEvent>
			<OnUpdate>
				DS_CastingBarFrame_OnUpdate();
			</OnUpdate>
		</Scripts>
	</Frame>
Tha's basically the complete Blizz Casting Bar code, with a few elements renamed to include the "DS_" prefix.

Within an AddOn, the above perfectly duplicates the casting bar. However, I can't get the vestiges of the old one to dissappear. It no longer functions, it just sits there, full, with not text, and no "flash" animations, and the "spark" just hanging out dead center. It does still exhibit the behavior of only being present while casting, however. I noted what I tried in the onload function of the lua to get it to hide, but niether of those worked.

Oddly enough, the original casting bar would hide and remain hidden using MoveAnything!, but once I reset the MoveAnything! frame, it went back to ghosting my new casting bar.

Here's an image of what I get. Note the functioning "flash" in the inset:
(don't laugh at the graphics, I just tossed those together quick) :

http://img.photobucket.com/albums/v5...stbarsnafu.jpg

So... What am I missing? I'm not dying to change the castbar graphics, insomuch as I am dying to find out what I am doing wrong.

Last edited by diiverr : 05-30-05 at 02:28 PM.
  Reply With Quote