Aller au contenu

Photo

UIListbox and accessing prototypes from script


  • Veuillez vous connecter pour répondre
20 réponses à ce sujet

#1
Loki_999

Loki_999
  • Members
  • 430 messages

Got a listbox and entries are generated.

 

What i want is when i click on an entry in the listbox it changes the background (so i thought either using UIFrame states or from script with SetGUITexture).

 

However, no idea how to reference a prototype object from script, ie: the specific instance of a listbox object - by row number. Not certain it is possible,

 

Other option using frames, i have UIPanes with tupple=true as my buttons, but with frames it treats the pane as always active i think, its like there is no up/down state.

 

Anyone got any advice or experience with this?  Or better or change those UIPanes to UIButtons?



#2
Loki_999

Loki_999
  • Members
  • 430 messages

Picture here:

 

NWN2_SS_091914_160628.jpg



#3
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages
Hi Loki_999,

OK, I muddle my way through XML coding at the best of times, so hopefully I won't put my foot in it too much. ;)

Anyway, first, what do you mean by "change its background" exactly? Are the "object images" above supposed to start off with all black backgrounds (like you have it) and when each object is clicked on, what is the difference supposed to be exactly? What is supposed to take the place of the "Black background"?

i.e. If I clicked on "Ability Bonus", what is the background supposed to change to?

Hopefully, as I get to understand what you are trying to do, I *might* be able to suggest something. ;)

By the way, what placeables are those that you have used in your screenshot? (Assuming the background image for the GUI is a screenshot from your NWN2 game.)

Cheers,
Lance.
  • Loki_999 aime ceci

#4
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

Not sure if this answers it exactly but this might be it.

 

1. When you populate the listbox with UIButtons set local variables on the entries corresponding to the backgrounds you want. This is during the AddListBoxRow command and in the following example I'm assuming you used 1.

 

2. When you click the UIButton run multiple functions. The first is OnLeftClick0=UIObject_Misc_ExtractData(self:,string,1,local:1), which you use to extract data from the button and store it in one of the GUI local variables (be sure that it's only being used within the script). I wrote 1 but you might have to change it.

 

3. The second function is OnLeftClick1=UIObject_Misc_ExecuteServerScript(gui_myscript,local:1) which now takes the data you've extracted (supposedly a string corresponding to an image file) and runs a script with it. Here you'd write a GUI script to change the background to whatever you got from the first argument.

 

I can upload an example if you want but a good reference is the E6 or E8 systems on various servers that include feat selection windows.


  • Loki_999 aime ceci

#5
Loki_999

Loki_999
  • Members
  • 430 messages

@Lance - Basically so the buttons when you click on them highlight (ie: different background) so when you move to the next column the one to the left remains highlighted.  But then if you select a different one in the same column, the old one unhighlights.

 

And don't get excited about the placeables. The screenshot is from Skyrim :D

 

@Psionic - Ah, yes, i think that's what is needed. Was thinking there must be something like that, just didn't know what it was and couldn't find anything on the old Obsidian blog or Grinning Fool's reference.

 

Ill give it a go.



#6
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

@Lance - Basically so the buttons when you click on them highlight (ie: different background) so when you move to the next column the one to the left remains highlighted.  But then if you select a different one in the same column, the old one unhighlights.
 
And don't get excited about the placeables. The screenshot is from Skyrim :D
 
@Psionic - Ah, yes, i think that's what is needed. Was thinking there must be something like that, just didn't know what it was and couldn't find anything on the old Obsidian blog or Grinning Fool's reference.
 
Ill give it a go.


Hi Loki,

I just bought Skyrim, so I guess I would have learned that sooner or later then. ;)

Ah, now, that info does supply a little bit more of a clue as to an approach. P-E method sounds good to me, but it may be possible to consider "radio" buttons too, to activate changes. As I say, I really do have to experiment a lot myself with this kind of thing, but get there in the end usually.

One thing that may be helpful to know, is that you can define a "base" image for buttons that gets its texture changed via the GUI function that changes textures.

However, you are going a stage further than I have tried before...i.e. Changing images on objects within a list of objects ... not sure how I would go about that. I have lists with objects that have fixed images, and buttons whose images can change, but not a combination of both, as you describe.

If you get this working as you describe, I would be interested to see the GUI in action, as I could learn something from it hopefully.

P-E .. What are E6 and E8 systems? Can you upload the code for me to take a look at? Cheers!

Cheers,
Lance.
  • Loki_999 aime ceci

#7
Loki_999

Loki_999
  • Members
  • 430 messages

Sure, can share the code no problem.... if i get it working ;)



#8
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

Sure, can share the code no problem.... if i get it working ;)


Hi Loki_999,

Great ... :)
 
EDIT: You say, "But then if you select a different one in the same column, the old one unhighlights."
 
Doesn't your "list" already select/deselect according to which button you have pressed anyway? The reason I ask this, is because I think a basic principle of a "list" is that it automatically selects/deselects items from within itself.

You may have your frame definitions a bit wonky. Here are an example of mine used within a list (look at file name for comparisons of when used):-
 
<UIFrame state=up	fill="b_g_lg01_normal.tga" />
<UIFrame state=down	fill="b_g_lg01_pressed.tga" />
<UIFrame state=focused	fill="b_g_lg01_pressed.tga" />
<UIFrame state=hilited	fill="b_g_lg01_normal.tga" />
<UIFrame state=hifocus	fill="b_g_lg01_pressed.tga" />
<UIFrame state=disabled	fill="b_g_lg01_normal.tga" />
 
Original post may be irrelevant now, but left some in just to show I had posted more. ....

By the way, I just re-read your description and it sounds like you want something a lot simpler than I first thought. Let me just make this clear ... you want the buttons to remain "highlighted" in one column as you move to the next column. HOWEVER, if you click on a button in the same column, it removes the highlight from the first button and highlights the new clicked one instead?

The point being, I (and probably PE) initially thought you wanted to change/add a "picture" to the button you clicked on, rather than simply "highlight" it ... and remain highlighted.

By the way, to do the picture changes, it should be possible as PE and I describe, as I just messed around with my Bestiary code, and managed to make a button change its picture according to what I just clicked on, but (without further adjustments and testing) it always changed the same button in the column. I think it may be possible to fix this, but is not a normal kind of thing I have ever known to be required.


<DELETED>

Cheers,
Lance.

<EDIT DELETED>

#9
Loki_999

Loki_999
  • Members
  • 430 messages

Yes, the list should automatically deselect the old if i select another in the same column. What i simply need is an indication of that.  It may indeed be i had my Frame highlighting wrong, but there again, i copy/pasted from another bit of XML that was working.  Possible that i put the frame outside the listbox pane or something equally stupid though.

 

And i think you linked to your GUI guide in your original post, at least my email contained a link to it. That was one of my three bibles when i first started messing with GUIs.  The others were Sunjammer's guide and of course Grinning Fool's UI Reference.



#10
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

Yes, the list should automatically deselect the old if i select another in the same column. What i simply need is an indication of that.  It may indeed be i had my Frame highlighting wrong, but there again, i copy/pasted from another bit of XML that was working.  Possible that i put the frame outside the listbox pane or something equally stupid though.
 
And i think you linked to your GUI guide in your original post, at least my email contained a link to it. That was one of my three bibles when i first started messing with GUIs.  The others were Sunjammer's guide and of course Grinning Fool's UI Reference.


Hi Loki_999,

OK, so it sounds like you have that highlight working now then. Yes? If so, good. :) However, it's not totally clear if you have that working now or not. Do you still have any other issues?

I forget who I suggest that link to, so I repeat myself just to be safe. ;)

Cheers,
Lance.

#11
Loki_999

Loki_999
  • Members
  • 430 messages

Nope, not had a chance to play with the XML yet. Will let you know when done so.  RL takes priority today.



#12
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

Nope, not had a chance to play with the XML yet. Will let you know when done so.  RL takes priority today.


Hi Loki_999,

OK, no problem. I know how RL can be. :)

Just as a pointer, try starting with a "smaller" piece of XML code that you can get working with the buttons in the list ... and then add other elements (other lists) when you get at least one lot working.

Cheers,
Lance.

#13
Loki_999

Loki_999
  • Members
  • 430 messages

Just as a pointer, try starting with a "smaller" piece of XML code that you can get working with the buttons in the list ... and then add other elements (other lists) when you get at least one lot working.

 

 

Totally against my development policy, which is usually, write script like a madman for a month, then compile, discover things don't compile, fix those, then run, and find nothing works like I expected it to! Rinse and repeat until something works. :D



#14
4760

4760
  • Members
  • 1 212 messages

Totally against my development policy, which is usually, write script like a madman for a month, then compile, discover things don't compile, fix those, then run, and find nothing works like I expected it to! Rinse and repeat until something works. :D

:D

Good luck!



#15
Loki_999

Loki_999
  • Members
  • 430 messages

Strange. Copied your code Lance and now i'm getting all boxes highlighted.

 

I tried with exactly your code, and then again by adding prototype=true to all of them, just in case.  Same result regardless.

<UIPane name="ENCHANTPANE1" x=10 y=10 width=150 height=680 capturemouseclicks=false >

		<UIListBox name="ENCHLB1" x=10 y=10 showpartialchild=true scrollsegmentsize=1 height=660 width=130 unequalcontrols=false update=true scrollbaronright=true selectonleftclick=true >
			<UIPane name="ENCHPANELB1" x=0 y=0 width=110 height=50 capturemouseclicks=true draggable=false prototype=true tupple=true OnLeftClick=UIObject_Misc_ExecuteServerScript("gui_enchant_click",listboxrow:ENCHLB1,"1") >
				<UIText name="ENCHTEXT1" x=5 y=0 width=110 height=PARENT_HEIGHT valign=middle align=left fontfamily="Special_Font" style=1 prototype=true />
				<UIFrame state=up	fill="b_g_lg01_normal.tga" prototype=true />
				<UIFrame state=down	fill="b_g_lg01_pressed.tga" prototype=true />
				<UIFrame state=focused	fill="b_g_lg01_pressed.tga" prototype=true />
				<UIFrame state=hilited	fill="b_g_lg01_normal.tga" prototype=true />
				<UIFrame state=hifocus	fill="b_g_lg01_pressed.tga" prototype=true />
				<UIFrame state=disabled	fill="b_g_lg01_normal.tga" prototype=true />
			</UIPane>
			
			<UIScrollBar name="ENCHANTSB1" width=10 style="STYLE_SB_THIN" />
	
		</UIListBox>
		
		<UIFrame name="FRAMEPANEL1" topleft="tp_frame_tl.tga" topright="tp_frame_tr.tga" bottomleft="tp_frame_bl.tga"
		bottomright="tp_frame_BR.tga" top="tp_frame_t.tga" bottom="tp_frame_b.tga"
		left="tp_frame_l.tga" right="tp_frame_r.tga" fillstyle="stretch" border=5 />
		
	</UIPane>


#16
Loki_999

Loki_999
  • Members
  • 430 messages

Update: Ah, but if i change it to use UIButton instead of UI Frame, it works just fine.

 

Strange, the tupple value is meant to make a frame behave like a button, but maybe in this case it doesn't work, or there is something else at play here.



#17
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

Update: Ah, but if i change it to use UIButton instead of UI Frame, it works just fine.
 
Strange, the tupple value is meant to make a frame behave like a button, but maybe in this case it doesn't work, or there is something else at play here.


Hi Loki_999,

That's good to hear the piece of code worked for you in the end. :)

I must admit, I find XML code confusing as to when and where certain parts work and don't work. Hopefully now though, you can start to build you GUI more fully. :)

Cheers,
Lance.

#18
Psionic-Entity

Psionic-Entity
  • Members
  • 195 messages

Update: Ah, but if i change it to use UIButton instead of UI Frame, it works just fine.

 

Strange, the tupple value is meant to make a frame behave like a button, but maybe in this case it doesn't work, or there is something else at play here.

 

IIRC tupple makes it work like a button in the script sense (when it's clicked, when it's selected) but it won't properly enable the set of "button states" textures you can set on buttons. You could script something to make it work but that might be a lot of unnecessary code.



#19
Loki_999

Loki_999
  • Members
  • 430 messages

Yup, ill go with buttons, the new version works fine now, so as Lance says, i can start moving forward.



#20
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

Yup, ill go with buttons, the new version works fine now, so as Lance says, i can start moving forward.


Hi Loki_999,

I forgot to add that I figured mine by looking at the stylesheet.xml (which contains buttons info) and noticing all those frames are set within UIButton. All I did was "copy" that format and it worked.
 
Also, I found the comments in SetGUITexture interesting, as they mention how textures can be added to the different types of XML elements:-
 
//RWT-OEI 02/23/07
//This script function sets the texture for a Icon, Button, or Frame.
//If the object is an icon, the texture is set as the icon's image.
//If the object is a frame, the texture is set as the frame's FILL texture
//If the object is a button that has a base frame, the texture is set
//as the BASE frame's FILL texture.
//If the object is a button that has no base frame, the texture is set
//as the UP state's FILL texture.
//Texture names should include the extention (*.tga for example).
//The UIScene that contains the UIObject must have a scriptloadable=true
//attribute in it.
void SetGUITexture( object oPlayer, string sScreenName, string sUIObjectName, string sTexture );

Cheers,
Lance.
  • Loki_999 aime ceci

#21
Loki_999

Loki_999
  • Members
  • 430 messages

Yup, read that one before.