[WIP] GrimTK GUI Framework

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!
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: [WIP] GrimTK GUI Framework

Post by cromcrom » Tue Aug 18, 2015 10:00 pm

Thank you so very much for tha fast answer, I will try it out tomorrow :-)
A trip of a thousand leagues starts with a step.

User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: [WIP] GrimTK GUI Framework

Post by cromcrom » Wed Aug 19, 2015 8:52 am

I checked, I do have stored the informations already, but it still doesn't seem to work.
A trip of a thousand leagues starts with a step.

User avatar
JohnWordsworth
Posts: 1387
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: [WIP] GrimTK GUI Framework

Post by JohnWordsworth » Wed Aug 19, 2015 6:28 pm

Could you post the whole script file?
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.

User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: [WIP] GrimTK GUI Framework

Post by cromcrom » Thu Aug 20, 2015 8:11 am

Sure:

This is my updating script:

Code: Select all

function updateCraftingInfoWindow()
	if ( GTK.Core.GUI:getWindow(formName) == nil ) then return 
	else

	local emplacement = crafting_altar
	local window = GTK.Core.GUI:getWindow(formName)
	local craftName = window:findChild("craftName");
	local skillLevel = window:findChild("skillLevel");
	local recipeNumberandDigit = window:findChild("recipeNumberandDigit");
	local nameAndNumberOfItemToCraft = window:findChild("nameAndNumberOfItemToCraft");	
	local mainIcon1 = window:findChild("mainIcon1");
	local difficultyAndItemSpecificKnowledge = window:findChild("difficultyAndItemSpecificKnowledge");
	
	local majorAndMinorAttributes = window:findChild("majorAndMinorAttributes");
	
	local component1Name = window:findChild("component1Name");
	local component2Name = window:findChild("component2Name");	
	local component3Name = window:findChild("component3Name");	
	
	local compIcon1 = window:findChild("compIcon1");	
	local compIcon2 = window:findChild("compIcon2");
	local compIcon3 = window:findChild("compIcon3");
	
	local component1ReqDisp = window:findChild("component1ReqDisp");
	local component2ReqDisp = window:findChild("component2ReqDisp");
	local component3ReqDisp = window:findChild("component3ReqDisp");
	local copperReqDisp = window:findChild("copperReqDisp");	
	
	local launchCrafting = window:findChild("launchCrafting");	
	
	local itemList = {}
	if craftingSkills[counter_craft_skill] == "tinkering" then itemList = tinkering end
	if craftingSkills[counter_craft_skill] == "alchemy" then itemList = alchemy end
	if craftingSkills[counter_craft_skill] == "weaponsmith" then itemList = weaponsmith end
	if craftingSkills[counter_craft_skill] == "armorsmith" then itemList = armorsmith end
	if craftingSkills[counter_craft_skill] == "tailor" then itemList = tailor end
	if craftingSkills[counter_craft_skill] == "leathercrafter" then itemList = leathercrafter end
	if craftingSkills[counter_craft_skill] == "cook" then itemList = cook end
	if craftingSkills[counter_craft_skill] == "jewelry" then itemList = jewelry end
	if craftingSkills[counter_craft_skill] == "woodcrafter" then itemList = woodcrafter end
	
	
	local itemToCraft = itemList[counter_craft_item]
	if itemToCraft == nil then return end
	print(itemToCraft.item)
	local itemName,atlas,index
	local spawnedItem = spawn(itemToCraft.item)
	if spawnedItem ~= nil then 
		itemName = spawnedItem.item:getUiName()
		--name = qualityName:gsub("^%l", string.upper).." "..itemName
		atlas = spawnedItem.item:getGfxAtlas()
		index = spawnedItem.item:getGfxIndex()
	end
	spawnedItem:destroy()
	local recipeDifficulty = itemToCraft.difficulty
	local bonus,specificItemKnowledge = returnCraftingExpertise(itemToCraft.item)	
	local skillLevelNum = cromlibrary.script.checkSkillLevel(craftingSkills[counter_craft_skill])
	local skillLevelName = cromskills.script.translateLevel(skillLevelNum)	
	craftName.data.text = "You are now visiting the "..string.upper(craftingSkills[counter_craft_skill]).." workshop.";
	skillLevel.data.text = "Your skill in this craft is : ".. string.upper(skillLevelName) .. "";
	recipeNumberandDigit.data.text = "There are "..#itemList.." recipe(s) available. This is item N "..counter_craft_item..""
	nameAndNumberOfItemToCraft.data.text = "Craft "..counter_number_item_to_craft.." "..itemName..""	
	mainIcon1.data.gfxAtlas = atlas	
	mainIcon1.data.gfxIndex = index	
	difficultyAndItemSpecificKnowledge.data.text = "Recipe difficulty is "..recipeDifficulty..". Specific item knowledge is "..string.upper(specificItemKnowledge)..""
	majorAndMinorAttributes.data.text = "Major attribute: "..string.upper(itemToCraft.attributeMajor)..". Minor Attribute: "..string.upper(itemToCraft.attributeMinor).."."
	
	-- default none components
	
	component1Name.data.text = "None"
	compIcon1.data.gfxAtlas = "mod_assets/textures/TLC_items.tga"
	compIcon1.data.gfxIndex = 81	
	
	component2Name.data.text = "None"
	compIcon2.data.gfxAtlas = "mod_assets/textures/TLC_items.tga"
	compIcon2.data.gfxIndex = 81
	component2ReqDisp.data.text = ""
	
	component3Name.data.text = "None"
	compIcon3.data.gfxAtlas = "mod_assets/textures/TLC_items.tga"
	compIcon3.data.gfxIndex = 81
	component3ReqDisp.data.text = ""	
	
	
	local launchCraftBool = true
	
	--component 1
	local spawnedComp1 = spawn(itemToCraft.comp1)
	if spawnedComp1 ~= "" then 
		component1NameWritten = spawnedComp1.item:getUiName()
		--name = qualityName:gsub("^%l", string.upper).." "..itemName
		atlasComp1 = spawnedComp1.item:getGfxAtlas()
		indexComp1 = spawnedComp1.item:getGfxIndex()
		spawnedComp1:destroy()	
	end

	local numberComp1Location = countItemOnLocation(crom_base_crafting_alcove_1,itemToCraft.comp1)
	local numberComp1Global = itemToCraft.compnum1*counter_number_item_to_craft
	local color1 
	if numberComp1Location >= numberComp1Global then 
		color1 = {51,204,0,255}
	else 
		color1 = {204,0,51,255}
	end
	
	

	component1ReqDisp.data.text = ""..numberComp1Global.." / "..numberComp1Location..""	
	component1ReqDisp.data.textColor = color1
	component1Name.data.text = ""..component1NameWritten..""
	compIcon1.data.gfxAtlas = atlasComp1
	compIcon1.data.gfxIndex = indexComp1	

	if numberComp1Location < numberComp1Global then launchCraftBool = false end
	
	
	
	if itemToCraft.comp2 ~= "" then 
		local spawnedComp2 = spawn(itemToCraft.comp2)
		local component2NameWritten = spawnedComp2.item:getUiName()
		--name = qualityName:gsub("^%l", string.upper).." "..itemName
		local atlasComp2= spawnedComp2.item:getGfxAtlas()
		local indexComp2 = spawnedComp2.item:getGfxIndex()
		spawnedComp2:destroy()	
		local numberComp2Location = countItemOnLocation(crom_base_crafting_alcove_1,itemToCraft.comp2)
		local numberComp2Global = itemToCraft.compnum2*counter_number_item_to_craft
		local color2 
		if numberComp2Location >= numberComp2Global then 
			color2 = {51,204,0,255}
		else 
			color2 = {204,0,51,255}
		end
		
		if numberComp2Location < numberComp2Global then launchCraftBool = false end
		component2ReqDisp.data.text = ""..numberComp2Global.." / "..numberComp2Location..""	
		component2ReqDisp.data.textColor = color2
		
		component2Name.data.text = ""..component2NameWritten..""
		compIcon2.data.gfxAtlas = atlasComp2
		compIcon2.data.gfxIndex = indexComp2
	end

	
	


	
	if itemToCraft.comp3 ~= "" then	
		--local numberComp1countItemOnLocation(location,item)
		local spawnedComp3 = spawn(itemToCraft.comp3)
 		local component3NameWritten = spawnedComp3.item:getUiName()
		--name = qualityName:gsub("^%l", string.upper).." "..itemName
		local atlasComp3= spawnedComp3.item:getGfxAtlas()
		local indexComp3 = spawnedComp3.item:getGfxIndex()
		spawnedComp3:destroy()	
		local numberComp3Location = countItemOnLocation(crom_base_crafting_alcove_1,itemToCraft.comp3)
		local numberComp3Global = itemToCraft.compnum3*counter_number_item_to_craft
		local color3 
		if numberComp3Location >= numberComp3Global then 
			color3 = {51,204,0,255}
		else 
			color3 = {204,0,51,255}
		end	
		if numberComp3Location < numberComp3Global then launchCraftBool = false end
		
		component3ReqDisp.data.text = ""..numberComp3Global.." / "..numberComp3Location..""	
		component3ReqDisp.data.textColor = color3
		component3Name.data.text = ""..component3NameWritten..""
		compIcon3.data.gfxAtlas = atlasComp3
		compIcon3.data.gfxIndex = indexComp3	
	end
	if launchCraftBool then 
		launchCrafting.data.textColor = {51,204,0,255}
		launchCrafting.data.text = "Launch crafting."
	else
		launchCrafting.data.textColor = {204,0,51,255}
		launchCrafting.data.text = "CAN'T CRAFT."	
	end
	copperReqDisp.data.text = "None"
end	

end
and those are my window definitions:

Code: Select all

function gtkDidLoad()	
	GTK.Core.GUI:addImage({ name="panel-bg", path="assets/textures/gui/gui_items.tga", origin={548, 2304}, size={582, 118}, margin={10, 10, 10, 10} });



	form = {
		name = formName,
		type = "GWindow",
		gravity = GTK.Constants.Gravity.North,
		offset = {0, 0},
		size = {800, 500},
		bgColor = {0, 0, 0, 0},
		bgImage = "panel-bg",
		bgDrawMode = GTK.Constants.ImageDrawMode.Stretched,
		draggable = true,
		freezeAI = true,
		lockParty = true,
		children = {
			{
				type = "GLabel",
				position = {300, 30},
				size = {300, 20},
				--gravity = GTK.Constants.Gravity.North,
				text = "Crafting Station",
				font = GTK.Constants.Fonts.Large,
				--textAlign = GTK.Constants.TextAlign.Middle,
			},
			{
				type = "GPushButton",
				position = {680, 60},
				size = {75, 20},
				label = {
					padding = {4, 4, 4, 4},
					text = "Next",
				},
				--keyboardShortcut = "P",
				onPressed = self.go.id .. ".script.increaseCraft"
			},
			{
				type = "GPushButton",
				position = {20, 60},
				size = {90, 20},
				label = {
					padding = {4, 4, 4, 4},
					text = "Previous",
				},
				--keyboardShortcut = "P",
				onPressed = self.go.id .. ".script.decreaseCraft"
			},			
			{
				type = "GLabel",
				name = "craftName",
				position = {100, 57},
				size = {600, 20},
				text = "Welcome to the workshops. Choose a craft. ('Next' or 'Previous')",
				font = GTK.Constants.Fonts.Medium,
				textAlign = GTK.Constants.TextAlign.Center,
			},			
			{
				type = "GLabel",
				name = "skillLevel",
				position = {100, 80},
				size = {600, 20},
				text = "Choose a craft.",
				font = GTK.Constants.Fonts.Medium,
				textAlign = GTK.Constants.TextAlign.Center,
			},
			{
				type = "GLabel",
				name = "recipeNumberandDigit",
				position = {100, 105},
				size = {600, 20},
				text = "Choose a craft",
				font = GTK.Constants.Fonts.Medium,
				textAlign = GTK.Constants.TextAlign.Center,
			},
			{
				type = "GPushButton",
				position = {600, 145},
				size = {150, 20},
				label = {
					padding = {4, 4, 4, 4},
					text = "Next Recipe",
				},
				--keyboardShortcut = "P",
				onPressed = self.go.id .. ".script.increaseItem"
			},
			{
				type = "GPushButton",
				position = {40, 145},
				size = {160, 20},
				label = {
					padding = {4, 4, 4, 4},
					text = "Previous Recipe",
				},
				--keyboardShortcut = "P",
				onPressed = self.go.id .. ".script.decreaseItem"
			},
			{
				type = "GLabel",
				name = "nameAndNumberOfItemToCraft",
				position = {200, 145},
				size = {400, 20},
				text = "Craft 1 BIDULE",
				font = GTK.Constants.Fonts.Medium,
				textAlign = GTK.Constants.TextAlign.Center,
			},				
			{
				type = "GIcon",
				name = "mainIcon1",
				position = {350, 170},
				size = {100, 100},
				bgColor = {0, 0, 0, 50},
				borderColor = {0, 0, 0, 255},
				borders = {1, 1, 1, 1},
 				--gfxAtlas = "",				
				gfxIndex = 0,
			},
			{
				type = "GPushButton",
				position = {550, 145},
				size = {50, 20},
				label = {
					padding = {4, 4, 4, 4},
					text = "More",
				},
				--keyboardShortcut = "P",
				onPressed = self.go.id .. ".script.increasenumberOfItem"
			},
			{
				type = "GPushButton",
				position = {200, 145},
				size = {40, 20},
				label = {
					padding = {4, 4, 4, 4},
					text = "Less",
				},
				--keyboardShortcut = "P",
				onPressed = self.go.id .. ".script.decreasenumberOfItem"
			},
			{
				type = "GLabel",
				name = "difficultyAndItemSpecificKnowledge",
				position = {50, 280},
				size = {700, 20},
				text = "Recipe difficulty is XXX. Your specific item crafting knowledge is AAAA",
				font = GTK.Constants.Fonts.Medium,
				textAlign = GTK.Constants.TextAlign.Center,
			},				
			{
				type = "GLabel",
				name = "majorAndMinorAttributes",
				position = {50, 305},
				size = {700, 20},
				text = "Major Attribute: XXXX / Minor Attribute: YYYYYYYYYYY",
				font = GTK.Constants.Fonts.Medium,
				textAlign = GTK.Constants.TextAlign.Center,
			},				
			{
				type = "GLabel",
				name = "requiredAndDisposedComponents",
				position = {100, 330},
				size = {600, 20},
				text = "Required/On station Components",
				font = GTK.Constants.Fonts.Medium,
				textAlign = GTK.Constants.TextAlign.Center,
			},				
			{
				type = "GLabel",
				name = "component1Name",
				position = {80, 355},
				size = {160, 10},
				text = "Component 1 Name",
				font = GTK.Constants.Fonts.Tiny,
				textAlign = GTK.Constants.TextAlign.Center,
			},			
			{
				type = "GLabel",
				name = "component2Name",				
				position = {240, 355},
				size = {160, 10},
				text = "Component 2 Name",
				font = GTK.Constants.Fonts.Tiny,
				textAlign = GTK.Constants.TextAlign.Center,
			},	
			{
				type = "GLabel",
				name = "component3Name",
				position = {400, 355},
				size = {160, 10},
				text = "Component 3 Name",
				font = GTK.Constants.Fonts.Tiny,
				textAlign = GTK.Constants.TextAlign.Center,
			},
			{
				type = "GLabel",
				name = "cost",
				position = {560, 355},
				size = {160, 10},
				text = "Cost in copper",
				font = GTK.Constants.Fonts.Tiny,
				textAlign = GTK.Constants.TextAlign.Center,
			},			
			{
				type = "GIcon",
				name = "compIcon1",
				position = {135, 370},
				size = {50, 50},
				bgColor = {0, 0, 0, 50},
				borderColor = {0, 0, 0, 255},
				borders = {1, 1, 1, 1},
 				--gfxAtlas = "",				
				gfxIndex = 0,
			},
			{
				type = "GIcon",
				name = "compIcon2",
				position = {295, 370},
				size = {50, 50},
				bgColor = {0, 0, 0, 50},
				borderColor = {0, 0, 0, 255},
				borders = {1, 1, 1, 1},
 				--gfxAtlas = "",				
				gfxIndex = 0,
			},			
			{
				type = "GIcon",
				name = "compIcon3",
				position = {455, 370},
				size = {50, 50},
				bgColor = {0, 0, 0, 50},
				borderColor = {0, 0, 0, 255},
				borders = {1, 1, 1, 1},
 				--gfxAtlas = "",				
				gfxIndex = 0,
			},				
			{
				type = "GIcon",
				name = "copperIcon",
				position = {615, 370},
				size = {50, 50},
				bgColor = {0, 0, 0, 50},
				borderColor = {0, 0, 0, 255},
				borders = {1, 1, 1, 1},
				gfxAtlas = "mod_assets/textures/TLC_items.tga",
				gfxIndex = 20,
			},				
			{
				type = "GLabel",
				name = "component1ReqDisp",
				position = {80, 425},
				size = {160, 10},
				text = "/",
				font = GTK.Constants.Fonts.Tiny,
				textAlign = GTK.Constants.TextAlign.Center,
			},			
			{
				type = "GLabel",
				name = "component2ReqDisp",				
				position = {240, 425},
				size = {160, 10},
				text = "/",
				font = GTK.Constants.Fonts.Tiny,
				textAlign = GTK.Constants.TextAlign.Center,
			},	
			{
				type = "GLabel",
				name = "component3ReqDisp",
				position = {400, 425},
				size = {160, 10},
				text = "/",
				font = GTK.Constants.Fonts.Tiny,
				textAlign = GTK.Constants.TextAlign.Center,
			},
			{
				type = "GLabel",
				name = "copperReqDisp",
				position = {560, 425},
				size = {160, 10},
				text = "/",
				font = GTK.Constants.Fonts.Tiny,
				textAlign = GTK.Constants.TextAlign.Center,
			},
			{
				type = "GPushButton",
				position = {200, 450},
				size = {400, 20},
				name = "launchCrafting",
				label = {
					padding = {1, 1, 1, 1},
					text = "LAUNCH CRAFTING (or not)",
					font = GTK.Constants.Fonts.Large,
					textAlign = GTK.Constants.TextAlign.Center,				
				},
				--keyboardShortcut = "P",
				onPressed = self.go.id .. ".script.craftItem"
			},
			{
				type = "GPushButton",
				position = {20, 450},
				size = {100, 20},
				label = {
					padding = {4, 4, 4, 4},
					text = "Check tool",
				},
				--keyboardShortcut = "P",
				onPressed = self.go.id .. ".script.checkToolQuality"
			},
			{
				type = "GPushButton",
				position = {700, 450},
				size = {70, 20},
				name = "Exit",
				label = {
					padding = {1, 1, 1, 1},
					text = "Quit",
					font = GTK.Constants.Fonts.Small,
					textAlign = GTK.Constants.TextAlign.Center,				
				},
				--keyboardShortcut = "P",
				onPressed = self.go.id .. ".script.hideGui"
			},			
		}
	}

end
I am such a messy coder :-(
A trip of a thousand leagues starts with a step.

User avatar
Duncan1246
Posts: 402
Joined: Mon Jan 19, 2015 7:42 pm

Re: [WIP] GrimTK GUI Framework

Post by Duncan1246 » Fri Sep 04, 2015 12:55 pm

JohnWordsworth wrote:Could you post the whole script file?
Can you give a look at my precedent post? I am blocked, some help will be very appreciated! Thanks!
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?

User avatar
Duncan1246
Posts: 402
Joined: Mon Jan 19, 2015 7:42 pm

Re: [WIP] GrimTK GUI Framework

Post by Duncan1246 » Tue Sep 22, 2015 1:03 am

Several posts and no more answer.... John is really too busy ... I remember the proverb:" Help yourself and heaven will help you" and I try to resolve the issue.
Many hours of work and two results:
1. pay attention to the path in the lua install files: it point mod_assets/ext/grimtk... but if you copy the folder "grimtk" to mod_assets, the path must be mod_assets/grimtk instead.
2.the instance of grimtk has to be ON THE FIRST MAP of the mod: rebuilding a copy of my mod level by level, I find that it's the reason why grimtk wasn' t working .
Try to put grimtk elsewhere, and nothing works...

So I think some changes have to be done in the read me.... to avoid wasting time in searching non-existent bugs :mrgreen:
Duncan
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?

User avatar
THOM
Posts: 1126
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: [WIP] GrimTK GUI Framework

Post by THOM » Tue Sep 22, 2015 6:51 pm

I made good experiences in contacting John by PM. Probably he isn't always aware what's going on in the threads...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download

User avatar
Duncan1246
Posts: 402
Joined: Mon Jan 19, 2015 7:42 pm

Re: [WIP] GrimTK GUI Framework

Post by Duncan1246 » Tue Sep 22, 2015 8:00 pm

THOM wrote:I made good experiences in contacting John by PM. Probably he isn't always aware what's going on in the threads...
I send him a PM a few days ago, without any result , but I understand that it could be difficult for him to spent time in these exchanges about LG.
No matter now, I have found the solution...
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?

User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: [WIP] GrimTK GUI Framework

Post by cromcrom » Sun Nov 01, 2015 3:38 pm

Ok, I found my probelm:
instead of

Code: Select all

   if launchCraftBool then 
      launchCrafting.data.textColor = {51,204,0,255}
      launchCrafting.data.text = "Launch crafting."
   else
      launchCrafting.data.textColor = {204,0,51,255}
      launchCrafting.data.text = "CAN'T CRAFT."   
   end
It is

Code: Select all

   if launchCraftBool then 
      launchCrafting.label.data.textColor = {51,204,0,255}
      launchCrafting.label.data.text = "Launch crafting."
   else
      launchCrafting.label.data.textColor = {204,0,51,255}
      launchCrafting.label.data.text = "CAN'T CRAFT."   
   end
Thanks again for creating such an amazing code John. :)
A trip of a thousand leagues starts with a step.

minmay
Posts: 2654
Joined: Mon Sep 23, 2013 2:24 am

Re: [WIP] GrimTK GUI Framework

Post by minmay » Sun Nov 01, 2015 10:09 pm

John, do you expect that the API/structure of this framework will change much in the future? I'm at the point where I'd like to start using it and add the features I described in my post on the first page, but I'd also like to be able to use the most recent version.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.

Post Reply