Player library

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
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Player library

Post by Duncan1246 »

So... I wanted to create a library to store the important notes and scrolls found by the player ( and add new ones automatically). Player may access it by a click on a special "book", opening a first panel with themes buttons , like this:
... EDIT : new images see below

Then, a second panel give one of the text menus (for now, three) , like this:
...
and on this same screen, clicking one title display the related text, like this:
...


I have tried to do this with gtk only (first panel) but I failed to create the full screen others windows (i can't see for now how to change dynamically the window parameters in GTK to take in account screen resizing).

The second and third panels use a party.onDrawGui hook to change context. It works, but something is terribly wrong: if you try use it twice, you got a black screen

Duncan
If you have any lead, you are welcome...
Last edited by Duncan1246 on Tue Nov 29, 2016 11:21 am, edited 1 time in total.
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: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Player library

Post by Duncan1246 »

Hi, folks,
Perhaps some code could made my question more easy to answer, so here is the script:
SpoilerShow

Code: Select all

function gtkDidLoad()

------------  small grafic objects	

	GTK.Core.GUI:addImage({ name="balance_button", path="mod_assets/textures/balance_button.tga", origin={0, 0}, size={56, 53}, margin={10, 10, 10, 10} })
	GTK.Core.GUI:addImage({ name="air_button", path="mod_assets/textures/air_button.tga", origin={0, 0}, size={56, 53}, margin={10, 10, 10, 10} })
	GTK.Core.GUI:addImage({ name="spirit_button", path="mod_assets/textures/spirit_button.tga", origin={0, 0}, size={56, 53}, margin={10, 10, 10, 10} })

	GTK.Core.GUI:addImage({ name="ButtonClose", path="assets/textures/gui/gui_items.tga", origin={1969, 2483}, size={110, 34}, margin={10, 10, 10, 10} })
	
------------  big grafic objects	
	GTK.Core.GUI:addImage({ name="panel-bg3", path="mod_assets/textures/dc_octogon2_panel.tga", origin={0, 0}, size={836, 949}, margin={10, 10, 10, 10} })
	GTK.Core.GUI:addImage({ name="panel-bg", path="mod_assets/textures/dc_octog4_panel.tga", origin={0, 0}, size={487, 318}, margin={10, 10, 10, 10} })

-----------------------------------------------------------------------------------------------------first panel to choose the texts to show
textrecord_form = {
		name = "gtk_textrecord",
		type = "GWindow",
		gravity = GTK.Constants.Gravity.NorthWest,
		offset = {130, 0},
		size = {836, 949},
		bgImage = "panel-bg3",
		bgDrawMode = GTK.Constants.ImageDrawMode.Stretched,
		draggable = true,
		children = {		
		{type = "GLabel",
				position = {162,38},
				size = {540,40},
				text = "Choose your path to see the related texts",
				textAlign = GTK.Constants.TextAlign.Center,
				font = GTK.Constants.Fonts.Large,
		},
		{
			type = "GPushButton",
			name = "Cancel",
			position = {630, 800},
			size = {110, 30},
			bgColor = {0, 0, 0, 0},
			borders = {0, 0, 0, 0},
			bgImage = "ButtonClose",
			onPressed = self.go.id .. ".script.close",
		},
		{
			type = "GPushButton",
			name = "rec_up",
			position = {388, 608},
			size = {56, 53},
			bgColor = {0,0,0,0},
			borders = {0,0,0,0},
			bgImage = "spirit_button",
			onPressed = self.go.id .. ".script.goS",
		},
		{
			type = "GPushButton",
			name = "rec_down",
			position = {385, 433},
			size = {56, 53},
			bgColor = {0,0,0,0},
			borders = {0,0,0,0},
			bgImage = "balance_button",
			onPressed = self.go.id .. ".script.goB",
		},
		{
			type = "GPushButton",
			name = "rec_right",
			position = {500, 313},
			size = {56, 53},
			bgColor = {0,0,0,0},
			borders = {0,0,0,0},
			bgImage = "air_button",
			onPressed = self.go.id .. ".script.goA",
		},
	}
	}

function showGui()
	if ( GTK.Core.GUI:getWindow("gtk_textrecord") == nil ) then 	
		GTK.Core.GUI:createWindow(textrecord_form)
	else 
		GTK.Core.GUI:showWindow("gtk_textrecord")
	end
end

------------------------------------------------------------------------------buttons commands
reading = false
drawFlag = true

function close(self)
		GTK.Core.GUI:unlockParty()
		GTK.Core.GUI:destroyWindow("gtk_textrecord")
end

function goS()
	buttonpress=1
	drawFlag = true
	follow()
end
function goA()
	buttonpress=3
	drawFlag = true
	follow()
end
function goB()
	buttonpress=2
	drawFlag = true
	follow()
end


function follow()
	
	if drawFlag then
		if buttonpress == 1 then  party.party:addConnector( "onDrawGui", self.go.id, "newsheetS")
			elseif buttonpress == 2 then party.party:addConnector( "onDrawGui", self.go.id, "newsheetB")
			elseif buttonpress == 3 then party.party:addConnector( "onDrawGui", self.go.id, "newsheetA")
		end
		
	end
end


---------------------------------------------------------------CREATE LIST of TEXTs to DISPLAY

story = 0


function newsheetS(self, context)

	if drawFlag == true then

		local width = context.width
		local height = context.height
		local offset = context.width * .05

			context.drawImage2("mod_assets/textures/dc_octog4_panel.tga",5,5,0,0,487, 318, width, height)
			context.drawRect(width*.9, (0.9 * height), 90, 30)
			context.color(0,0,0,255)
			context.drawText("CLOSE", width*.91, (0.922 * height))
			context.font("large")

		if ( context.button("CLOSE", width*.91, (0.92 * height), 90, 90) ) then
			
			reading = false
			story = 0
			-- party.party:removeConnector( "onDrawGui", self.go.id, "newsheetS")
			drawFlag = false
			return
		end
		for i= 1, 26 do
			if Stexts_toshow[i] == 1  then 
				context.drawParagraph(spirit_titles[i], offset, context.height * (.05 + ( .033 * i )), width*.4)	    	
			end
		end
		for i= 1,26 do
			if ( context.button(spirit_titles[i], offset+10, context.height * (.05 + ( .033 * i )), width*.2, 20) ) then
				 reading = true
				 story = i
			end
		end	
		if reading then
				context.drawParagraph(spirit_texts[story], width*.42, context.height * .1, width*.55)
		end
	end
end

function newsheetA(self, context)

	if drawFlag == true then
	 
		local width = context.width
		local height = context.height
		local offset = context.width * .05

		context.drawImage2("mod_assets/textures/dc_octog4_panel.tga",5,5,0,0,487, 318, width, height)
		context.drawRect(width*.9, (0.9 * height), 90, 30)
		context.color(0,0,0,255)
		context.drawText("CLOSE", width*.91, (0.922 * height))
		context.font("large")

		if ( context.button("CLOSE", width*.91, (0.92 * height), 90, 90) ) then
			
			reading = false
			story = 0
			-- party.party:removeConnector("onDrawGui", self.go.id, "newsheetA")
			drawFlag = false
			return
		end

		for i= 1, 9 do
			if Atexts_toshow[i] == 1 then 
				context.drawParagraph(air_titles[i], offset, context.height * (.05 + ( .033 * i )), width*.4)   			    	
			end
		end
		for i= 1, 9 do
			if ( context.button(air_titles[i], offset+10, context.height * (.05 + ( .033 * i )), width*.2, 20) ) then
				reading = true
				story = i
			end
		end						
		if reading then						
				context.drawParagraph(air_texts[story], width*.42, context.height * .1, width*.55)
		end
	end
end

function newsheetB(self, context)

	if drawFlag == true then
	 
		local width = context.width
		local height = context.height
		local offset = context.width * .05

		context.drawImage2("mod_assets/textures/dc_octog4_panel.tga",5,5,0,0,487, 318, width, height)
		context.drawRect(width*.9, (0.9 * height), 90, 30)
		context.color(0,0,0,255)
		context.drawText("CLOSE", width*.91, (0.922 * height))
		context.font("large")

		if ( context.button("CLOSE", width*.91, (0.92 * height), 90, 90) ) then
			
			reading = false
			story = 0
			-- party.party:removeConnector( "onDrawGui", self.go.id, "newsheetB")
			drawFlag = false
			return
		end
		
		for i= 1, 12 do
    		if Btexts_toshow[i] == 1 then 
    			    context.drawParagraph(balance_titles[i], offset, context.height * (.05 + ( .033 * i )), width*.4)
    		end
    	end
    	for i= 1, 12 do
    		if ( context.button(balance_titles[i], offset+10, context.height * (.05 + ( .033 * i )), width*.2, 20) ) then
    			    reading = true
    			    story = i
    		end
    	end
    	if reading then	
	   				context.drawParagraph(balance_texts[story], width*.42, context.height * .1, width*.55)
		end
	end
end


---------------------------------------------TEXTS LIBRARY
----------------------------------------------------------------------------------------------------

spirit_texts = { }
spirit_titles = { }
air_texts = { }
air_titles = { }
balance_texts = { }
balance_titles = { }

-----------------------------------------------------------------------SPIRIT TEXTS

spirit_titles[1] = "Watchman's warning (Under Wreck Cape)"

spirit_texts[1] = "I placed here numerous documents which will be useful for you if you decide to \
help Edenia to find its past magnificence. In case you would prefer to find as quickly as possible \
your homes without caring you of these sorry lands, I left you a map which can help you there. \
But I have to warn you: any life here will be hostile to you and to cross these lands will be anyway a \
precarious journey. In the doubt, I protected some of this information as well as equipments which I \
reserve for those who will accept this mission. You will excuse me, it was the only way to assure me \
that all this would be of use to the revival of Edenia. \
\
The WATCHMAN"
----------------------------------------------------------and so on
end
It's not clean code, I know, but it works... one time. The second time I use it, a black screen is shown (but everything else still works) . :mrgreen:
I understand that "onDrawGui" is already used by gtk and so my hook bypass the gtk hook, probably it's the cause of the issue. Using fw hooks seems a better way, but my trials are unsuccessful.
Any idea?
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: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Player library

Post by Duncan1246 »

I found it... the issue wasn't so hard to find, it was under my nose all the time: the context.color wasn't reinitialized, so the black screen! :lol:

Now (with some conditions added) it works as intended. Next steps: add a hook to the related scrolls and notes to actualize the library when the player pick them up, and change the graphics to get a better looking.
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: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Player library

Post by THOM »

I appreciate it much that you try to implement a kind of notebook.

How will it work? Will all found notes be added automaticly (and all other items with a ScrollItemComponent?) Do they have to be written (coded) in an certain way?

Why is your first panel designed like a rune-circle? What kind of connection do you see between notes and the 9 elements?

And a last question: Will it be possible to add lines of own notes?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Player library

Post by Duncan1246 »

First, thanks for your interest in the project!
THOM wrote:IHow will it work? Will all found notes be added automaticly (and all other items with a ScrollItemComponent?) .../ Why is your first panel designed like a rune-circle? What kind of connection do you see between notes and the 9 elements? . .../ And a last question: Will it be possible to add lines of own notes?[
My project is to make an add-on to my mod, so it fits the story: in it, all is linked to one (or several) of the runes, so the first design. The players often complain about the difficulty finding a particular text in a huge stock, so I hope this will help them to organize the collected informations and to improve the readability.
All scrollitem might be involved, but update of the library is scripted and the player can't add himself a text. The library classes the texts in themes (in my mod runes themes).
The list of available texts and the grouping in themes gives also supplementary clues to the player .
To do this, I will add a hook to the scrolls, probably by UsableItem component onuseitem (I work on it now).
With a few modifications, it will be possible to store all the texts found, to change the first panel (background, buttons, title).
The texts needs to have a title to display a summary and to select them, and to add a specific hook as I says. But I think it's possible easily to adapt this behavior to your specific needs, except for adding lines (perhaps a specific script can do this).

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
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Player library

Post by Isaac »

Duncan,
Perhaps its a silly question, but have you seen or played any LoG1 mods with the Notebook addon?
https://www.dropbox.com/s/6env9dv7wyigt ... k.avi?dl=0

It would seem similar (in some ways) to what you describe, except for lack of index tabs (like in a hard bound dictionary).
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Player library

Post by THOM »

Isaac wrote: LoG1 mods with the Notebook addon?
...I would love to see this notebook raise again. It's quiet simple but the player can add lines and founded notes as he wants...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Player library

Post by Duncan1246 »

Isaac wrote:Duncan,
Perhaps its a silly question, but have you seen or played any LoG1 mods with the Notebook addon?
https://www.dropbox.com/s/6env9dv7wyigt ... k.avi?dl=0

It would seem similar (in some ways) to what you describe, except for lack of index tabs (like in a hard bound dictionary).
Yes, I know it, and J Wordsworth has included it in gtk project but left unfinished, afak. I don't like it so much because of the size : imo, we don't need to see dungeon background when reading the notes, we needs readability and quick search. I think it's absolutely necessary in an real openworld: some players tell me that they are totally lost because of that (no predetermined path to follow). We will see... :)
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: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Player library

Post by Duncan1246 »

I have made important changes to the player_library:
_ Now GTK is no longer used, all is done with onDrawGui and contexts commands.
_ Thanks to Zimberzimber, I thrown away the rought draft background, add a new book icon and image object.
First panel is now the title page :
SpoilerShow
Image
Second panel (reading one) is here:
SpoilerShow
Image
So this magic_book can be used to:
1. Store and show important texts found, ordered by script (and not by the player)
2. Show steps to make in current quests

To do:
- A better presentation on the title page (left) to see the clickable zones
- A clues system ( needs to add a bunch of floortriggers or hooks in the mod)... and obviously its integration in my mod.

Although it's done to fit my needs, this can be fitted to more general purpose.

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
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: Player library

Post by Mysterious »

I do hope we get to use this work soon as I really need this book in my Mod, as I have lots of text notes. :)
Post Reply