Aller au contenu

Photo

Dynamic Listbox Response


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

#1
DFDark

DFDark
  • Members
  • 9 messages
Hi there,

I have a little peculiar problem. I am trying to make a listbox prototype, which is filled by script. So far it work's as it should. Listbox is consisting of buttons and some titles in rows. I would like to react by script depending on which row button was pressed. And there is my problem. I don't have a clue how to obtain specific row value or at least row ID. Is it even possible? Only other way around is use custom tokens in conversation, but if it's possible I would like to have GUI version.

Any help appreciated.

#2
0100010

0100010
  • Members
  • 87 messages
Yes. Here is an example:

I have override then levelup gui for spells in order to create a custom spell listbox that I can control during levelup. The following is my function to add spells to the listbox.

[nwscript]
void CreateSpellListListBoxRow(object oChar, int nSpellID, string sName, string sIcon, string sLevel)
{   
    string sListbox = "CUSTOM_AVAILABLE_SPELL_LIST_";
    if (GetSpellKnown(oChar, nSpellID))
        sListbox = "CUSTOM_ADDED_SPELL_LIST_";
    sListbox = sListbox + sLevel;   
   
    string sRowName =  sName;
    string sTextFields = "SPELL_TEXT=" + sName;
    string sTextures = "SPELL_IMAGE=" + sIcon + ".tga";
    string sVariables = "0=" + IntToString(nSpellID);
    AddListBoxRow(oChar, "SCREEN_LEVELUP_SPELLS", sListbox, sRowName, sTextFields, sTextures, sVariables, "" );           
}
[/nwscript]

Note the sVariables value where you are able to specify a series of string values assigned to the index. See the toolset's code comments for the AddListBoxRow function for more details.


In the XML you'll want to extract the data from the row and send it to the script that is to be executed like so:

<UIListbox name="CUSTOM_AVAILABLE_SPELL_LIST_0" x=22 y=130 width=239 height=500 xPadding=0 yPadding=5 selectonleftclick=true hideoverride=true
        showpartialchild=true scrollbaronright=true unequalcontrols=true scrollsegmentsize=150 hidescrollbarwhennotneeded=false          
        update=true >
                <UIPane name="SPELLPANE_PROTO" x=0 y=0 width=225 height=40 prototype=true tupple=true 
                OnLeftClick0=UIObject_Misc_ExtractData("selected:CUSTOM_AVAILABLE_SPELL_LIST_0","string",0,local:101)                
                OnLeftClick1=UIObject_Misc_ExecuteServerScript("gui_elu_spelldesc",local:101) OnToolTip=UIObject_Tooltip_DisplayObject(OBJECT_X,OBJECT_Y,SCREEN_TOOLTIP_2,ALIGN_NONE,ALIGN_NONE,0,0,ALIGN_LEFT) 
                DefaultToolTip=179920 >
                    <UIButton name="SPELL_IMAGE" x=0 y=0 width=40 height=40 prototype=true >
                        <UIFrame state=base        fill="b_empty.tga" />
                        <UIFrame state=up        fill="b_empty.tga" />
                        <UIFrame state=down        fill="b_overlay.tga" />
                        <UIFrame state=focused    fill="b_empty.tga" />
                        <UIFrame state=hilited    fill="b_empty.tga" />
                        <UIFrame state=hifocus    fill="b_overlay.tga" />
                        <UIFrame state=disabled    fill="b_empty.tga" />
                    </UIButton>
                    <UIButton name="SPELL_TEXT" x=40 y=0 width=165 height=40 prototype=true >
                        <UIText name="SPELL_TEXTFIELD" x=10 y=0 indent=10 hangingindent=10 align=left valign=middle fontfamily="Title_Font" prototype=true />
                        <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" />
                    </UIButton>
                    <UIButton name="SPELL_ACTION" x=205 y=0 width=15 height=40 prototype=true
                    OnLeftClick=UIObject_Misc_ExecuteServerScript("gui_elu_spelladd") 
                    OnToolTip=UIObject_Tooltip_DisplayObject(OBJECT_X,OBJECT_Y,SCREEN_TOOLTIP_2,ALIGN_NONE,ALIGN_NONE,0,0,ALIGN_LEFT) 
                    DefaultToolTip=179918 >
                        <UIFrame state=up        fill="b_addr_normal.tga" />
                        <UIFrame state=down        fill="b_addr_pressed.tga" />
                        <UIFrame state=focused    fill="b_addr_pressed.tga" />
                        <UIFrame state=hilited    fill="b_addr_normal.tga" />
                        <UIFrame state=hifocus    fill="b_addr_pressed.tga" />
                        <UIFrame state=disabled    fill="b_addr_normal.tga" />
                    </UIButton>
                </UIPane>

            <UIScrollBar name="SB" style="STYLE_SB_THIN"></UIScrollBar>    
        </UIListbox>

I extract the spell ID I embedded into the listbox row into local variable 101, and then pass that variable to the script "gui_elu_spelldesc"  these actins occur on the leftclick callback and extract has to occur before the execute script.

LAter in the listbox prototype I have a left click callback for the spell's action button, which executes "gui_elu_spelladd."  I have not yet wired up the that script but it would need the same data passed in to it, so, I would add the extract callback above it in the exact same way.

Modifié par 0100010, 11 juillet 2011 - 10:59 .


#3
MasterChanger

MasterChanger
  • Members
  • 686 messages
Check out Sunjammer's Dynamic UIListBox Guide.

#4
DFDark

DFDark
  • Members
  • 9 messages
Thanks, I didn't know about 'UIObject_Misc_ExtractData'.