switch gui?

For collaboration on developing the mod capabilities of VS; request new features, report bugs, or suggest improvements

Moderator: Mod Contributor

dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

switch gui?

Post by dagg »

I want to change the main menu in game when I click a button, how can I do this?

thanks
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Re: switch gui?

Post by ace123 »

The whole main menu is done in bases/main_menu.py
If you look in that file you should be able to copy the examples of a few of the buttons.

If you aren't sure then could you be more specific with your question?
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

I'm working with that file, you mean that I can just call the GUI.GUIRoomButton function with the right parameters and it will work?

OT: I've added import time and added a sleep command to the quitgame, but when I run it, I get no menu and an error message says no room has been created... why is that happening?
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: switch gui?

Post by chuck_starchaser »

If you figure it out, dagg, let me know; I wanted to make a "room" off the main menu for multiplayer, for PU, but I could never figured out the python code.
Spiritplumber once said she was going to do it for us, but then she got pissed; --didn't want to be a 'code slave', or something along the lines--, and refused to do it. (I suspect she tried but couldn't figure out the code either.)
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

chuck_starchaser wrote:If you figure it out, dagg, let me know; I wanted to make a "room" off the main menu for multiplayer, for PU, but I could never figured out the python code.
Spiritplumber once said she was going to do it for us, but then she got pissed; --didn't want to be a 'code slave', or something along the lines--, and refused to do it. (I suspect she tried but couldn't figure out the code either.)
did she provided any information that we ca use?
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: switch gui?

Post by chuck_starchaser »

Nope. Never got Spirit to explain anything to me... --about anything, in fact. There's a PU svn branch called Spirit187, which was a brach she started working on to implement a more dynamic universe, but it's been dead since she stopped working on it, as she wouldn't tell anybody what she was doing. We'd have to diff the files to find out what changed, and I know there were gazillions of files involved. Anyways, I tried copying the code for button and room and whatnot and tried a million things and all I ever got was "no room specified", and finally gave up.
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

chuck_starchaser wrote:Nope. Never got Spirit to explain anything to me... --about anything, in fact. There's a PU svn branch called Spirit187, which was a brach she started working on to implement a more dynamic universe, but it's been dead since she stopped working on it, as she wouldn't tell anybody what she was doing. We'd have to diff the files to find out what changed, and I know there were gazillions of files involved. Anyways, I tried copying the code for button and room and whatnot and tried a million things and all I ever got was "no room specified", and finally gave up.
I would happy to take a look on them.
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: switch gui?

Post by chuck_starchaser »

That would be fantastic.
It's here:
https://svn.wcjunction.com/priv_pu/branches/spirit187
It never worked, though. If you fly to Perry, you'll find dozens and dozens of kilrathis all over the place. The game becomes unplayable.
And we tweaked and tweaked the numbers, but the perry problem remained, no matter. Thing is, dynamic universe stuff is completely
and utterly undocumented. I believe Spiritplumber got some insights into how it works, but she's not the type to share knowledge; she
makes changes for you, if you're lucky, and then like them or leave them. And we couldn't really use her branch the way it was; so it's
just sitting there, gathering svn dust.
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

ok, got a little question, how can I delete all clickable areas in a screen using the GUI class?
can I change the background of the currently displayed menu using the GUIStaticImage function?
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

anyone?
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Re: switch gui?

Post by chuck_starchaser »

Not me; looks like everybody is in vacations around here.
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

sorry for the bump again, I'm still stuck in this issue, I need to switch gui for 8 seconds but, I cant even switch gui, not to mention wait for 8 seconds.
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Re: switch gui?

Post by ace123 »

Sorry, I missed your post and I've been a bit busy the past week with finals.

To delay, use the Base.RunScript(room_id, "some_identifier", "#\npythoncode", seconds)
The "#\npythoncode" is a string of python code, of the same type that you pass into Base.LinkPython.
The reason to pass in a id is so you can remove it with Base.EraseObj if you decide not to wait for the timeout.

To change the background, the way it was supposed to be done is to create a new "room" in your base that has the new background. If you have a lot of sprites on the base screen you can also change them around using
Base.EraseObj("sprite_id")
Base.EraseLink("link_id")
Base.Texture(...)

I think the GUI system also has an undraw or some function like that which calls EraseObj.

To put this together, if you want to switch the background for 8 seconds and then come back, what you probably want to do this (I'm using Base code, directly, not with the GUI wrapper library... isn't directly possible with GUI afaik)

Code: Select all

room1 = Base.Room("Starting room")
... intialize room1 ...
waiting_room = Base.Room("Sit here for 8 seconds")
Base.Texture(waiting_room, ... arguments for background image ...)
Base.Link(room1, "go_to_waiting_room", 0.2, 0.2, 0.1, 0.1, "Go to another room for 8 seconds", waiting_room)
Base.RunScript(waiting_room, "wait_and_go_back", "#\nimport Base\nBase.SetCurRoom(%d)"%(room1), 8.0)
What that will do is after setting up room1, it creates another room with a background image, then creates a clickable link from the first room (room1) to the waiting_room. And it adds a script that will send you to back to room1. (a python script string must start with "#\nimport Base\n").

The GUI library should let you create a room as well as make links. You just need to add the RunScript.

Note that the way the RunScript code is written, it will actually trigger every 8 seconds, until you call EraseObj. However, time is only counted if you are in the same room as the python script, and if you go back to the starting room, the effect is that you will wait exactly 8 seconds each time you visit waiting_room, and then go back.

Hopefully this convoluted system makes some sense.
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

thanks for the detailed answer, I'll try it later.
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

if I want to use this in a menu that is already uses the gui wrapper, do I need to rewrite it so it wont use the gui wrapper?
can I find a Base functions equivalent to the gui wrappers one?
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

bump...
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Re: switch gui?

Post by ace123 »

Wow, missed your message. thanks for bumping.

It is entirely your choice whether you want to use the GUI wrapper or not. I used normal base code because it was simpler in this case. However, you should be able to create a GUIButton and make it do the same thing (it might even allow you to pass a function in instead of resorting to the embedded code.

If you have a specific example it would help as I don't exactly understand what you are trying to do.
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

ace123 wrote:Wow, missed your message. thanks for bumping.

It is entirely your choice whether you want to use the GUI wrapper or not. I used normal base code because it was simpler in this case. However, you should be able to create a GUIButton and make it do the same thing (it might even allow you to pass a function in instead of resorting to the embedded code.

If you have a specific example it would help as I don't exactly understand what you are trying to do.
thanks for the replay, I've thought you have forgot about this topic, like I've wrote before, I need to make the gui change to another pic for 8 seconds after I click the exit button, and then exit, you have supplied an example for doing that without the gui wrapper, the guy currently allows relating certain areas with actions like new game so all you need to do is click the area and the action will occur, my question is, can this be done without using the GUI wrapper? if so, what is the command to do that?

thanks again.
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Re: switch gui?

Post by ace123 »

Here is the same segment in GUI-style code.

The only one without an equivalent is Base.RunScript, but that is a pretty generic function.

Code: Select all

import GUI
import Base

def someFunction():
    ...
    # mainroom = some GUIRoom that you initailized before
    waiting_room = GUI.GUIRoom(Base.Room("Sit here for 8 seconds"))
    waiting_background = GUI.GUIStaticImage(waiting_room, "mybg", "somesprite.spr")
    waiting_background.draw()
    GUI.GUIRoomButton(mainroom, waiting_room, "Exit program after 8 seconds" , "go_to_waiting_room", GUI.GUIRect(0.2, 0.2, 0.1, 0.1, "normalized"))
    Base.RunScript(waiting_room.getIndex(), "exit_after_8_seconds", "#\nimport Base\nBase.ExitGame()", 8.0)
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

ok, I've updated the menu, in general it works but nither of the background images shows up... any hints on what can be the cause?
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Re: switch gui?

Post by ace123 »

could you post the source code, or else point me to the SVN repository?

If you are creating an image/sprite, you must reference a ".spr" sprite file with the on-screen width (0.0-1.0), height and actual image filename, relative to the "sprites" directly. Linking to an image directly will not work.

For example:

Code: Select all

bases/Lava/landscape.image true
1.94 1.94
0 0
The last two are the center coordinates. You want a center at 0,0 (the middle of the screen), but they are ignored since you pass parameters in from Python anyway.
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

here is the main menu code and an example spr file

Code: Select all

import Base
import VS
import GUI
import ShowProgress

import computer_lib

def StartNewGame(self,params):
	ShowProgress.activateProgressScreen("loading",3)
	VS.loadGame(VS.getNewGameSaveName())

# this uses the original coordinate system of Privateer
GUI.GUIInit(320,200)

# Create menu room
room_menu = Base.Room ("VT_Main_Menu")
guiroom  = GUI.GUIRoom(room_menu)

# Create credits room
credits_guiroom = GUI.GUIRoom(Base.Room("Credits"))
credits_bk = GUI.GUIStaticImage(credits_guiroom, "background","interfaces/main_menu/credits.spr")
credits_bk.draw()
# Quit game
sprite_loc = GUI.GUIRect(0.2, 0.2, 0.1, 0.1, "normalized")
GUI.GUIRoomButton(guiroom,credits_guiroom,"Quit Game", "Quit_Game_after_display_credits","go_to_credits_guiroom",sprite_loc)
Base.RunScript(credits_guiroom.getIndex(), "exit_after_8_secs_of_credits", "#\nimport Base\nBase.ExitGame()",8.0)

# Create background
GUI.GUIStaticImage(guiroom, "background","interfaces/main_menu/menu.spr")

# Create the Quine 4000 screens
rooms_quine = computer_lib.MakePersonalComputer(room_menu, room_menu,
	0, # do not make links
	0, 0, 0, # no missions, finances or manifest
	1, # do enable load
	0, # but disable save
	1) # and return room map, rather than only root room
rooms_quine['computer'].setMode('load')

# Link 
sprite_loc = GUI.GUIRect(567,610,654,644,"pixel",(1280,1024))
GUI.GUIRoomButton(guiroom, rooms_quine['load'], "Load Game", "Load_Game",0,sprite_loc) #sprite,sprite_loc)

# New game
sprite_loc = GUI.GUIRect(245,5,462,97,"pixel",(1280,1024))
btn = GUI.GUIButton(guiroom, "New Game", "New_Game",0,sprite_loc,"enabled",StartNewGame)

# Draw everything
GUI.GUIRootSingleton.broadcastMessage("draw",None)

Code: Select all

interfaces/main_menu/menu.png 0
1.94 1.94
0 0
my main goal now is to get this to work and sort out the bugs later
ace123
Lead Network Developer
Lead Network Developer
Posts: 2560
Joined: Sun Jan 12, 2003 9:13 am
Location: Palo Alto CA
Contact:

Re: switch gui?

Post by ace123 »

where do you reference the interfaces/main_menu/menu.sprite file? Could you paste that line of code, like GUI.Sprite(...) or Base.Texture(...)

Does anything show up in stderr.txt regarding the texture? (Though somehow I doubt that anything useful gets printed).

Also, make sure that "interfaces/main_menu/menu.png" is in an acceptable format. That is, a power-of-two 1024x1024 or 2048x2048 image.

Not too much else I can think of--you can try changing that "0" to a "true" after the .png. But I think that flag is only needed for images with alpha.
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

ace123 wrote:where do you reference the interfaces/main_menu/menu.sprite file? Could you paste that line of code, like GUI.Sprite(...) or Base.Texture(...)
if you mean in the code, then it is in my previous posts, anyway, the lines are:

Code: Select all

GUI.GUIStaticImage(guiroom, "background","interfaces/main_menu/menu.spr")

and

Code: Select all

credits_bk = GUI.GUIStaticImage(credits_guiroom, "background","interfaces/main_menu/credits.spr")
ace123 wrote:Does anything show up in stderr.txt regarding the texture? (Though somehow I doubt that anything useful gets printed).
nope, no output in stderr.txt
ace123 wrote:Also, make sure that "interfaces/main_menu/menu.png" is in an acceptable format. That is, a power-of-two 1024x1024 or 2048x2048 image.
yes they are.
ace123 wrote:Not too much else I can think of--you can try changing that "0" to a "true" after the .png. But I think that flag is only needed for images with alpha.
will try
dagg
Bounty Hunter
Bounty Hunter
Posts: 138
Joined: Thu May 22, 2008 8:53 am

Re: switch gui?

Post by dagg »

yes! got it to work :) started from scratch and done it :)
Post Reply