[Tool/Script] GuiItem browser

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

[Tool/Script] GuiItem browser

Post 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()
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [Tool/Script] GuiItem browser

Post by Drakkan »

really nice, now I am little aware what all could be changed regarding gui. thanks
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: [Tool/Script] GuiItem browser

Post 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.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: [Tool/Script] GuiItem browser

Post 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.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: [Tool/Script] GuiItem browser

Post 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!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: [Tool/Script] GuiItem browser

Post 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.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: [Tool/Script] GuiItem browser

Post 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.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: [Tool/Script] GuiItem browser

Post 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 :).
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Post Reply