Page 1 of 1

[Tool/Script] GuiItem browser

Posted: Thu Feb 26, 2015 11:41 pm
by JKos
I made a quick and dirty script for browsing through GuiItems: https://github.com/JKos/log2doc/wiki/GuiItems
Currently this works with beta 2.2.4 only of course. You can use prev and next "buttons" or , and . keys for browsing.
Just copy paste this to some script entity (for example named guiItems):

Code: Select all

-- commented out non working guiItems
items = {
"AbilityMinusDown",
"AbilityMinusHover",
"AbilityMinusUp",
"AbilityPlusDown",
"AbilityPlusHover",
"AbilityPlusUp",
"AccuracySymbol",
"AttackFrame",
"AttackFrameBarBackground",
"AttackFrameBarBackgroundShort",
"AttackFrameConditionRect",
"AttackFrameDisabled",
"AttackFrameEnergy",
"AttackFrameEnergyShort",
"AttackFrameHealthGreen",
"AttackFrameHealthGreenShort",
"AttackFrameHealthRed",
"AttackFrameHealthRedShort",
"AttackFrameHealthYellow",
"AttackFrameHealthYellowShort",
--"AttackFrameItemSlot",
--"AttackFramePortraitRect",
--"AttackFrameSelected1",
"AttackFrameSelected2",
"AttackFrameShield",
--"AttackFrameSlotSpacing",
--"AttackFrameSpacing",
"AttackPowerSymbol",
--"Background",
"ButtonAccept",
"ButtonAcceptDisabled",
"ButtonAcceptHover",
"ButtonApply",
"ButtonApplyHover",
"ButtonCancel",
"ButtonCancelHover",
"ButtonChoose",
"ButtonChooseDisabled",
"ButtonChooseHover",
"ButtonClear",
"ButtonClearDisabled",
"ButtonClearHover",
"ButtonClose",
"ButtonCloseHover",
"ButtonDefaults",
"ButtonDefaultsHover",
"ButtonImport",
"ButtonImportDisabled",
"ButtonImportHover",
"ButtonKeyConfig",
"ButtonKeyConfigHover",
"ButtonNo",
"ButtonNoHover",
"ButtonSave",
"ButtonSaveHover",
"ButtonYes",
"ButtonYesHover",
"ChampionConditionOverlay",
"CharGenBackToMenu",
"CharGenBackToMenuHover",
"CharGenNameBox",
"CharGenPortraitSel128",
"CharGenPortraitSelBig",
"CharGenPortraitSelSmall",
"CharGenSkillMinusHover",
"CharGenSkillMinusImage",
"CharGenSkillPlusHover",
"CharGenSkillPlusImage",
"CharGenSkillSlot",
"CharGenSkillSlotHover",
"CharGenStartGame",
"CharGenStartGameDisabled",
"CharGenStartGameHover",
"CharSheet",
"CheckBox",
"CheckBoxChecked",
"CheckBoxCheckedHover",
"CheckBoxHover",
"ChooseDungeonBackground",
"ChooseDungeonDownload",
"ChooseDungeonDownloadHvr",
"ChooseDungeonUnsubscribe",
"ChooseDungeonUnsubscribeHvr",
"ChooseDungeonWorkshop",
"ChooseDungeonWorkshopHvr",
"ChoosePortraitDialog",
"CloseButtonHover",
"ComboBox",
"ComboBoxHover",
"ConfirmDialog",
"ContainerChest",
"ContainerSack",
"CraftPotionPanel",
"DamageSplash",
"DialogFrameCornerBottomLeft",
"DialogFrameCornerBottomRight",
"DialogFrameCornerTopLeft",
"DialogFrameCornerTopRight",
"DialogFrameSideBottom",
"DialogFrameSideLeft",
"DialogFrameSideRight",
"DialogFrameSideTop",
"DialogShadowCornerBottomLeft",
"DialogShadowCornerBottomRight",
"DialogShadowCornerTopLeft",
"DialogShadowCornerTopRight",
"DialogShadowSideBottom",
"DialogShadowSideLeft",
"DialogShadowSideRight",
"DialogShadowSideTop",
"EnterTextDialog",
"EquipmentSlots",
"ExpBar",
"ExpBarFrame",
"FoodBarFrame",
"FoodBarGreen",
"FoodBarRed",
"FoodBarYellow",
"GameOver",
"HandSlot1",
"HandSlot2",
"HandSlotHighlight1",
"HandSlotHighlight2",
"HitSplash",
"HitSplashLarge",
"HitSplashSmall",
"Injury",
"InjuryHand1",
"InjuryHand2",
"InjurySmall",
"InstructionsAttackPanel",
"InventoryTab",
"IslandMasterSymbol",
"KeyBindings",
"MapArrowLeft",
"MapArrowRight",
"MapButtonHover",
"MapClose",
"MapToolsBackground",
"MapToolsCenter",
"MapToolsCenterHover",
"MapToolsClose",
"MapToolsCloseHover",
"MapToolsCross",
"MapToolsCrossHover",
"MapToolsExclamation",
"MapToolsExclamationHover",
"MapToolsLevelDivider",
"MapToolsLevelDown",
"MapToolsLevelDownHover",
"MapToolsLevelUp",
"MapToolsLevelUpHover",
"MapToolsQuestion",
"MapToolsQuestionHover",
"MapToolsQuil",
"MapToolsQuilHover",
"MenuButtonHover",
"Moon",
"MovementArrowDown",
"MovementArrows",
"NewGame",
"NextChampionHover",
"PackSlotBgImage",
"PreviousChampionHover",
"QuickSwapButtonDown1",
"QuickSwapButtonDown2",
"QuickSwapButtonUp1",
"QuickSwapButtonUp2",
"RandomizeButton",
"RandomizeButtonHover",
"SaveGameBackground",
"SaveGameDeleteButton",
"SaveGameDeleteHover",
"SaveGamePortraitFrame",
"SaveGameSlot",
"SaveGameSlotHover",
"SaveGameTitleLoad",
"SaveGameTitleSave",
"Settings",
"SkillMinusImage",
"SkillPlusHover",
"SkillPlusImage",
"SkillSlots",
"SkillSlotsHighlight",
"SkillTick",
"SkillTickUpgrade",
"SkillTickUpgradeSelected",
"SkillsTab",
"SkillsTabHighlight",
"SkillsTabHighlightSel",
"SleepButtonHover",
"Slider",
"SliderKnob",
"SliderKnobHover",
"SmallFoodBarFrame",
"SmallFoodBarGreen",
"SmallFoodBarRed",
"SmallFoodBarYellow",
"SpellFizzle",
"SpellNoEnergy",
"SpellPanel",
"SpellPanelNoButtons",
"SpellRuneGlow",
"SpellRunes",
"SpellRunesGlow",
"Star",
"StatisticsDialog",
"StatsTab",
"Sun",
"TextButton",
"TextButtonHover",
"TextButtonLong",
"TextButtonLongHover",
"TraitSlot",
"TraitSlotHover",
"TraitSlotLong",
"TraitSlotLongHover",
"TraitsTab",
"UnarmedAttackBearLeft",
"UnarmedAttackBearRight",
"UnarmedAttackLeft",
"UnarmedAttackMageLeft",
"UnarmedAttackMageRight",
"UnarmedAttackRight"
}


i = 1

function showItem(item)
	if type(item) == 'number' then
		i = item
		return nil
	end
	
	for j=1,#items do
		if items[j] == item then
			i = j
			return nil
		end
	end
end

function next()
	i = i + 1
end

function prev()
	i = i - 1
end

keyPressed = false

function drawItem(party,g)

	g.drawText('Prev (,)',10,240)
	if g.button('Prev',10,230,50,20) or g.keyDown(',') and not keyPressed then
		prev()
	end
	
	g.drawText('Next (.)',70,240)
	if g.button('Next',70,230,50,20) or g.keyDown('.') and not keyPressed then
		next()
	end

	if g.keyDown(',') or g.keyDown('.') then
		keyPressed = true
	else
		keyPressed = false
	end	
	
	if i<1 then i = #items end
	if i>#items then i = 1 end
	local item = items[i]	
	g.drawGuiItem(item, 10, 270)	
	g.drawText(item,10, 260)

end

function enable()
	party.party:addConnector('onDrawGui',self.go.id,'drawItem')
end
function disable()
	party.party:removeConnector('onDrawGui',self.go.id,'drawItem')
end

enable()

Re: [Tool/Script] GuiItem browser

Posted: Fri Feb 27, 2015 12:20 am
by Drakkan
really nice, now I am little aware what all could be changed regarding gui. thanks

Re: [Tool/Script] GuiItem browser

Posted: Fri Feb 27, 2015 12:51 am
by JohnWordsworth
Very useful, thank you jkos!

I am contemplating whether I want to use the GuiItems in GrimTK. I am not sure if using the same textures directly using drawTexture(... BuiltInAssetPath ...) causes them to be loaded into the GPU again. If so, I will make a way to load GuiItems into GrimTK's texture loader.

Re: [Tool/Script] GuiItem browser

Posted: Fri Feb 27, 2015 8:16 am
by petri
Gui items are stored in one big atlas so if you use drawImage on a single texture it will be loaded twice in memory.

Also it's faster to draw gui items because no texture switches are needed.

Re: [Tool/Script] GuiItem browser

Posted: Fri Feb 27, 2015 8:53 am
by JohnWordsworth
Hi Petri, Sorry - I wasn't clear - I have been using the built in GUI Atlas already for most parts of my system by using drawImage2("assets/..."). I guess there is no texture switching using that method or double loading either as the textue is already loaded into memory for the built-in GUI? (I assuming user calls to drawTexture use the same texture manager as what you use under the hood).

On the one hand, there are a LOT of GUI items - so manually measuring their position and size on the atlas is a pain. BUT, when I define a sprite in my GUI toolkit, it is useful to have the image size for my Auto Layouts - so I'm not sure which path to go down!

Re: [Tool/Script] GuiItem browser

Posted: Fri Feb 27, 2015 10:45 am
by petri
Yes, that's correct. No performance or mem penalty if you use the atlas directly. The only downside is that you have to setup the texcoords manually, like you mentioned.

Re: [Tool/Script] GuiItem browser

Posted: Fri Feb 27, 2015 10:46 am
by petri
Be aware however that the location of gui items in the GUI atlas texture may change when we patch the game, it is automatically generated.

Re: [Tool/Script] GuiItem browser

Posted: Fri Feb 27, 2015 10:58 am
by JohnWordsworth
Ahh, that's good to know. I guess that means that the sprite locations could also change if you add a new sprite and your packer decides it can put things on the sheet more efficiently. Come to think of it, I think I will just allow users to add textures to GrimTK using @GuiItemName instead of a path (with a size entered manually where required) and have it automatically switch to drawGuiItem2 as required :).