[dockscreen request]

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

Fri Jan 06, 2012 10:28 pm

I need help with a dockscreen that will start with a list of UNIDs and let the user order them.

These are going to be ammo types so a itempicker is probably the best interface.
Literally is the new Figuratively

User avatar
Bobby
Militia Captain
Militia Captain
Posts: 675
Joined: Wed Jul 25, 2007 7:39 pm

Sat Jan 07, 2012 10:30 pm

I have a screen that will let the user order a list of star system nodes (from the captain's log), it shouldn't be too hard to modify to do what you want. I'll see what I can do with it in the 30 minutes before the library closes.


ok, here's a proof of concept: I thought there was a way to get an item description from a unid, but don't know how at the moment, but it will let you sort a list of unids, and it will give you the picture and name so you know what you're sorting.

It still uses variable names related to star systems, but it works with unids, you'll need to use the set data option first to see it in action.

Code: Select all

<globals>
	(setq unidList (lambda nil
		(block (data (custom (list)) index)
			(setq data (clGetData 'unidList))
			(setq index 0)
			(enum data sys
				(block Nil
					(lnkAppend custom (list
						(itmGetName (itmCreate sys 1) 4)
						(itmGetImageDesc (itmCreate sys 1))
						"item description"
						index
						sys
					))
					(setq index (add index 1))
				)
			)
			custom
		)
	))
</globals>


<DockScreen UNID="&clChangeSystemOrder;"
	name=             "ammo list"
	type=             "customPicker"
	backgroundID=     "&rsItemListScreen;"
	>
	<List	initialItem="=(clInitialSystem)">
	(unidList)
	</List>
	<Panes>
		<Default>
			<Actions>
				<Action name="move up" key="u">
					(block (index node2 nodelist)
						(setq nodeList (clGetData 'unidList))
						(setq index (item (scrGetListEntry gScreen) 3))
						(setq node (item (scrGetListEntry gScreen) 4))
						(setq node2 (item nodeList (subtract index 1)))
						(if (not (isError
								(block Nil
									(lnkReplace nodeList index node2)
									(lnkReplace nodeList (subtract index 1) node)
								)))
							(clSetData 'unidList nodeList)
						)
						(scrShowScreen gScreen &clChangeSystemOrder;)
					)
				</Action>
				<Action name="move Down" key="d">
					(block (index node2 nodelist)
						(setq nodeList (clGetData 'unidList))
						(setq index (item (scrGetListEntry gScreen) 3))
						(setq node (item (scrGetListEntry gScreen) 4))
						(setq node2 (item nodeList (add index 1)))
						
						(if (not (isError
								(block Nil
									(lnkReplace nodeList index node2)
									(lnkReplace nodeList (add index 1) node)
								)))
							(clSetData 'unidList nodeList)
						)
						(scrShowScreen gScreen &clChangeSystemOrder;)
					)
				</Action>
				<Action name="set data" >
					(clSetData 'unidList (list 0x00004014 0x00004015))
				</Action>
				<Action name="done" key="b" cancel="1">
					(block nil
						(scrExitDock gScreen)
					)
				</Action>
			</Actions>
		</Default>
	</Panes>
</DockScreen>


It relies on these functions too.

Code: Select all

	(setq clSetData (Lambda (name value)
		(typSetGlobalData &stCLMapper; name value)
	))
;retrieve the previously set data
	(setq clGetData (Lambda ('name)
		(typgetGlobalData &stCLMapper; name)
	))
	(setq clInitialSystem (lambda nil
		(block (entry)
			(setq entry (scrGetListEntry gScreen))
			(eq (item entry 4) clNode)
		)
	))
ImageImage
Thanks to digdug for the banners.

User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

Sun Jan 08, 2012 6:54 am

It also relies on clChangeSystemOrder and stCLMapper. I'm afraid it's rather too inscrutable for someone not good enough at dockscreens to write his own to adapt.
Literally is the new Figuratively

User avatar
Bobby
Militia Captain
Militia Captain
Posts: 675
Joined: Wed Jul 25, 2007 7:39 pm

Mon Jan 09, 2012 9:30 pm

stCLMapper is just the station the data is stored on, it could be set to any station or ship type, and clChangeSystemOrder is just the unid of the screen I was using for testing from within the captain's log.


I stripped out the dependencies and changed the variable and function names to make sense. aosGetData and aosSetData don't have to use typSetGlobalData, I use it because it makes for a convenient permanent data store that isn't on the player ship (ice farm in this case), but any data storage method would work, itmSetData on the weapon perhaps? (I'm guessing you want to make a weapon that lets the player choose in which order ammo is selected for firing?)

does it make any more sense now?

Code: Select all

<globals>
(block Nil
;produces a list of item types ready to be displayed in an item picker, complete with picture and name, from a list of unids
	(setq unidList (lambda nil
		(block (unidList (custom (list)) index)
			(setq unidList (aosGetData 'ammoList))
			(setq index 0)
			(enum unidList unid
				(block Nil
					(lnkAppend custom (list
						(itmGetName (itmCreate unid 1) 4)
						(itmGetImageDesc (itmCreate unid 1))
						"item description"
						index
						unid
					))
					(setq index (add index 1))
				)
			)
			custom
		)
	))
;functions to store and retrieve data, these could store the data on any source desired, I am using the ice farm station type for the example
;set data to a station
   (setq aosSetData (Lambda (name value)
      (typSetGlobalData &stIceFarm; name value)
   ))
;retrieve the previously set data
   (setq aosGetData (Lambda ('name)
      (typgetGlobalData &stIceFarm; name)
   ))
;when the screen is refreshed between switching ammo this is evaluated for each item
;it will keep the cursor on the ammo type that it was on before changing the list order
   (setq dsInitialAmmo (lambda nil
      (block (entry)
         (setq entry (scrGetListEntry gScreen))
         (eq (item entry 4) ammo)
      )
   ))
	
)
</globals>


<DockScreen UNID="&dsAmmoOrderSelector;"
	name=             "ammo list"
	type=             "customPicker"
	backgroundID=     "&rsItemListScreen;"
	>
	<List	initialItem="=(dsInitialAmmo)">
	(unidList)
	</List>
	<Panes>
		<Default>
			<Actions>
				<Action name="move up" key="u">
					(block (index ammo2 unidList) ;if ammo is declared here the cursor will not follow the moving item
						(setq unidList (aosGetData 'ammoList))
						(setq index (item (scrGetListEntry gScreen) 3))
						(setq ammo (item (scrGetListEntry gScreen) 4))
						(setq ammo2 (item unidList (subtract index 1)))
						(if (not (isError
								(block Nil
									(lnkReplace unidList index ammo2)
									(lnkReplace unidList (subtract index 1) ammo)
								)))
							(aosSetData 'ammoList unidList)
						)
					;refresh the screen so any changes are immediately visible
						(scrShowScreen gScreen &dsAmmoOrderSelector;)
					)
				</Action>
				<Action name="move Down" key="d"><!--same as move up, but backwards-->
					(block (index ammo2 unidList)
						(setq unidList (aosGetData 'ammoList))
						(setq index (item (scrGetListEntry gScreen) 3))
						(setq ammo (item (scrGetListEntry gScreen) 4))
						(setq ammo2 (item unidList (add index 1)))
						
						(if (not (isError
								(block Nil
									(lnkReplace unidList index ammo2)
									(lnkReplace unidList (add index 1) ammo)
								)))
							(aosSetData 'ammoList unidList)
						)
						(scrShowScreen gScreen &dsAmmoOrderSelector;)
					)
				</Action>
				<!--temporary option used for testing-->
				<Action name="set data" >
				(block Nil
					(aosSetData 'ammoList (list 0x00004014 0x00004015 0x00194005 0x00194006))
					(scrShowScreen gScreen &dsAmmoOrderSelector;)
				)
				</Action>
				<Action name="done" key="b" cancel="1">
					(block nil
						(scrExitDock gScreen)
					)
				</Action>
			</Actions>
		</Default>
	</Panes>
</DockScreen>
The set data option gives you a list of four unids you can re-order, if you need an example.
ImageImage
Thanks to digdug for the banners.

Post Reply