Thread Tools Display Modes
07/02/15, 08:35 AM   #1
ZunaSW
Join Date: Mar 2014
Posts: 37
Display image depending on the zone

Hello,

I'm now trying some other things, mainly I want to display an image depending on the zone the player is.
My idea is this:
If for example the player is in Eastmarch zone, Image1 will be displayed as a key is pressed. If then the player changes to Stonefalls zone, Image2 will be displayed as the same key is pressed.

I got no problems with the keybindings, but I'm having problems displaying the different images. For now, when I press the key, I get a 1024x1024 blank image, as I stated here:

Code:
local wm = GetWindowManager()
local MainImage = wm:CreateTopLevelWindow(nil)
MainImage:SetDimensions(1024,1024)
MainImage:SetAnchor(CENTER,GuiRoot,CENTER,0,0)
MainImage0 = wm:CreateControl(nil, MainImage, CT_TEXTURE)
MainImage0:SetAnchorFill(MainImage)
MainImage0:SetHidden(true)
I got this code from other of my addons, I'm no expert, so that might be wrong :/ But for now, works.

Now I got the keybinding code:

Code:
function IM.OnKeyDown()
	MainImage0:SetHidden(false)
end

function IM.OnKeyUp()
	MainImage0:SetHidden(true)
end
That works perfectly.

And here is the code that I think it is wrong, even when I don't get any errors in game:

Code:
function IMOnZoneChanged(eventCode, zoneName, subZoneName, newSubzone)
	if zoneName == "Eastmarch" then
		MainImage0:SetTexture("IM/textures/Image1.dds")
	end
	if zoneName == "Stonefalls" then
		MainImage0:SetTexture("IM/textures/Image2.dds")
	end
end

EVENT_MANAGER:RegisterForEvent(IM.name, EVENT_ZONE_CHANGED, IMOnZoneChanged)
For now, as I said, this last part of the code seems to not work, or at least do what I want it to do. I press the key and get a blank image, instead of the images I stated in the last code.

Any ideas on how to make this work? Maybe I'm using the wrong event, I'm not sure, as I said, I'm no expert.

Thank you.
  Reply With Quote
07/02/15, 08:56 AM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
If you added/changed any .dds files while the game was running, you might need to restart the client. It caches textures (and their absence as well).
  Reply With Quote
07/02/15, 09:11 AM   #3
ZunaSW
Join Date: Mar 2014
Posts: 37
Hm, nothing, didn't work :c

Must be something from the code.
  Reply With Quote
07/02/15, 11:07 AM   #4
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by ZunaSW View Post
Hm, nothing, didn't work :c

Must be something from the code.
hmm, the first zone after loading does not trigger a "change".

You could try to call your zone change function like this in EVENT_PLAYER_ACTIVATED:
Code:
IMOnZoneChanged(0, GetUnitZone("player"))
  Reply With Quote
07/02/15, 11:23 AM   #5
ZunaSW
Join Date: Mar 2014
Posts: 37
Hm, nothing, doesn't seem to work, I'm using this code, might be wrong though:

Code:
function IMOnZoneChanged(0, GetUnitZone("player"))
	if zoneName == "Eastmarch" then
		MainImage0:SetTexture("IM/textures/Image1.dds")
	end
	if zoneName == "Stonefalls" then
		MainImage0:SetTexture("IM/textures/Image2.dds")
	end
end
And I'm getting this error:

Code:
user:/AddOns/IM/IM.lua:30: <name> or "..." expected near '0
I might have done something wrong with the event. I'm pretty new on this, so I don't really know :S
  Reply With Quote
07/02/15, 11:36 AM   #6
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by ZunaSW View Post
Hm, nothing, doesn't seem to work, I'm using this code, might be wrong though:

Code:
function IMOnZoneChanged(0, GetUnitZone("player"))
	if zoneName == "Eastmarch" then
		MainImage0:SetTexture("IM/textures/Image1.dds")
	end
	if zoneName == "Stonefalls" then
		MainImage0:SetTexture("IM/textures/Image2.dds")
	end
end
And I'm getting this error:

Code:
user:/AddOns/IM/IM.lua:30: <name> or "..." expected near '0
I might have done something wrong with the event. I'm pretty new on this, so I don't really know :S
I was not precise (or lazy?) Calling, not declaring.
Lua Code:
  1. local function IMOnZoneChanged(eventCode, zoneName, subZoneName, newSubzone)
  2.     if zoneName == "Eastmarch" then
  3.         MainImage0:SetTexture("IM/textures/Image1.dds")
  4.     end
  5.     if zoneName == "Stonefalls" then
  6.         MainImage0:SetTexture("IM/textures/Image2.dds")
  7.     end
  8. end
  9.  
  10. local function PlayerActivated()
  11.   EVENT_MANAGER:UnregisterForEvent(IM.name, EVENT_PLAYER_ACTIVATED)
  12.   IMOnZoneChanged(0, GetUnitZone("player"))
  13. end
  14.  
  15. EVENT_MANAGER:RegisterForEvent(IM.name, EVENT_ZONE_CHANGED, IMOnZoneChanged)
  16.  
  17. EVENT_MANAGER:RegisterForEvent(IM.name, EVENT_PLAYER_ACTIVATED, PlayerActivated)
^^ Typed without testing

About names from API you should read this.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Display image depending on the zone


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