Page 1 of 2

switch gui?

Posted: Mon Nov 17, 2008 2:49 pm
by dagg
I want to change the main menu in game when I click a button, how can I do this?

thanks

Re: switch gui?

Posted: Mon Nov 17, 2008 9:35 pm
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?

Re: switch gui?

Posted: Tue Nov 18, 2008 7:40 am
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?

Re: switch gui?

Posted: Wed Nov 19, 2008 8:07 pm
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.)

Re: switch gui?

Posted: Thu Nov 20, 2008 8:26 pm
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?

Re: switch gui?

Posted: Thu Nov 20, 2008 9:18 pm
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.

Re: switch gui?

Posted: Thu Nov 20, 2008 9:47 pm
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.

Re: switch gui?

Posted: Fri Nov 21, 2008 12:46 am
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.

Re: switch gui?

Posted: Fri Nov 28, 2008 10:53 am
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?

Re: switch gui?

Posted: Tue Dec 02, 2008 7:14 pm
by dagg
anyone?

Re: switch gui?

Posted: Wed Dec 03, 2008 6:29 am
by chuck_starchaser
Not me; looks like everybody is in vacations around here.

Re: switch gui?

Posted: Sun Dec 14, 2008 7:58 pm
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.

Re: switch gui?

Posted: Thu Dec 18, 2008 3:50 am
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.

Re: switch gui?

Posted: Thu Dec 18, 2008 3:52 pm
by dagg
thanks for the detailed answer, I'll try it later.

Re: switch gui?

Posted: Thu Jan 01, 2009 3:59 pm
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?

Re: switch gui?

Posted: Tue Jan 27, 2009 5:39 pm
by dagg
bump...

Re: switch gui?

Posted: Sat Jan 31, 2009 2:25 am
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.

Re: switch gui?

Posted: Sat Jan 31, 2009 7:33 am
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.

Re: switch gui?

Posted: Sun Feb 01, 2009 1:39 am
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)

Re: switch gui?

Posted: Sun Feb 08, 2009 9:01 pm
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?

Re: switch gui?

Posted: Thu Feb 26, 2009 4:16 am
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.

Re: switch gui?

Posted: Thu Feb 26, 2009 7:19 am
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

Re: switch gui?

Posted: Sat Feb 28, 2009 2:24 pm
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.

Re: switch gui?

Posted: Sat Feb 28, 2009 4:46 pm
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

Re: switch gui?

Posted: Sat Feb 28, 2009 8:16 pm
by dagg
yes! got it to work :) started from scratch and done it :)