The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: pacdiggity on April 11, 2011, 05:36:04 AM

Title: Fullscreen Choice
Post by: pacdiggity on April 11, 2011, 05:36:04 AM
Oh no, I made another script!
Fullscreen Choices
Version: 2.1a
Author: Welfare-Daddy Pacman
Date: 20/4/2011

Version History



Planned Future Versions


Description


This script is a rewrite of Main. Do not put it in Materials. Replace Main with this script. This script simply puts a choice of playing windowed or full-screened or simply quitting the game before the title screen shows.

Features


Screenshots

Hardly necessary.

Instructions

Follow the instructions in the script to the letter.

Script


Spoiler for Code:
Code: [Select]
=begin
================================================================================
Author: Welfare-Daddy Pacman (rmrk.net)
Based from Mr. Wiggles
Version 2.0
Last update: 19/4/2011

Description:
This script simply puts a choice of playing windowed or full-screened or
simply quitting the game before the title screen shows.
Instructions:
  -Replace Main with this script. Plug-and-play, unless you want to configure
  some stuff.
  -Configuration begins at line 17 and ends at line 35.
================================================================================
=end
#-------------------------------------------------------------------------------
# BEGIN EDITING SECTION
#-------------------------------------------------------------------------------

SKIP_TOGGLE = false # This will skip the toggle if you have a save slot.
COMMAND_OPACITY = 160 # Change this value to the opacity you want.
INPUT_KEY = Input::C # This is the key used to confirm the command prompt.
QUIT_KEY = Input::B # This is the key used to quit the command prompt.
SCENE = Scene_Title.new # The scene that is after or before Scene_Screenchoice.
FULLSCREENTEXT = "Full-screen" # The text displayed on the full-screen option.
WINDOWEDTEXT = "Windowed" # The text displayed on the windowed option.
QUITTEXT = "Quit" # The text displayed on the quit option.
WINDOWX = 272 # The x placement of the command window.
WINDOWY = 208 # The y placement of the command window.
WINDOWWIDTH = 192 # The width of the window. Alter this to accommodate
 # for large option texts.
 
#-------------------------------------------------------------------------------
# END EDITING SECTION A
#-------------------------------------------------------------------------------
# Start Scene_Screenchoice
#-------------------------------------------------------------------------------

class Scene_Screenchoice < Scene_Title
  def main
    if $BTEST # If battle test
      battle_test # Run battle test
    else
      @title = Scene_Title.new
      @title.load_database
      s1 = FULLSCREENTEXT # Check FULLSCREENTEXT
      s2 = WINDOWEDTEXT # Check WINDOWEDTEXT
      s3 = QUITTEXT # Check QUITTEXT
      @command_window = Window_Command.new(WINDOWWIDTH, [s1, s2, s3]) # Create
      @command_window.opacity = COMMAND_OPACITY # Check opacity
      @command_window.x = WINDOWX - @command_window.width / 2 # Check X
      @command_window.y = WINDOWY - @command_window.height / 2 # Check Y
      Graphics.transition # Transition
      loop do # Loop
        Graphics.update # Update graphics
        Input.update # Update input
        update # Duh.
        if $scene != self # If scene isn't self
          break # Stop updating
        end
      end
      Graphics.freeze # Freeze Graphics
      @command_window.dispose # Dispose command window
    end
  end
 
#-------------------------------------------------------------------------------
# Update
#-------------------------------------------------------------------------------

  def update
    @command_window.update
    if Input.trigger?(INPUT_KEY)
      case @command_window.index
      when 0
        Sound.play_decision
        unless $keybd
          call_fullscreen
        end
        call_scene_title
      when 1
        Sound.play_decision
        call_scene_title
      when 2
        close_window
      end
    end
    if Input.trigger?(QUIT_KEY)
      close_window
    end
  end

#-------------------------------------------------------------------------------
# Call Scene_Title
#-------------------------------------------------------------------------------

  def call_scene_title
    $scene = Scene_Title.new
  end

#-------------------------------------------------------------------------------
# Call Fullscreen
#-------------------------------------------------------------------------------
 
  def call_fullscreen
    $keybd = Win32API.new 'user32.dll', 'keybd_event', ['i', 'i', 'l', 'l'], 'v'
    $keybd.call 0xA4, 0, 0, 0
    $keybd.call 13, 0, 0, 0
    $keybd.call 13, 0, 2, 0
    $keybd.call 0xA4, 0, 2, 0
  end
   
#-------------------------------------------------------------------------------
# Close Window
#-------------------------------------------------------------------------------

  def close_window
    Sound.play_decision
    RPG::BGM.fade(800)
    RPG::BGS.fade(800)
    RPG::ME.fade(800)
    $scene = nil
  end
end

#-------------------------------------------------------------------------------
# Main Processing
#-------------------------------------------------------------------------------

begin
  Graphics.freeze
  if SKIP_TOGGLE and (Dir.glob('Save*.rvdata').size > 0)
    $scene = SCENE
  else
    $scene = Scene_Screenchoice.new
  end
  while $scene != nil
    $scene.main
  end
  Graphics.transition(20)
rescue Errno::ENOENT
  filename = $!.message.sub("No such file or directory - ", "")
  print("Unable to find file #{filename}.")
end

#-------------------------------------------------------------------------------
# END
#-------------------------------------------------------------------------------

Credit



Thanks


Support


I'm on RMRK a lot. Just post here or PM me.

Known Compatibility Issues

Will probably not work with debug scripts that refer to main.

Demo


Not applicable.

Author's Notes


Free for use in commercial and non-commercial games with credit. If you are using it in a commercial game, let me know.

Restrictions

Eh. Don't take credit for mine or Mr. Wiggles work.
 :ccbysa: :rmvx:
For indie games.  :nespad:
Title: Re: Fullscreen Choice
Post by: Zeriab on April 12, 2011, 07:45:40 AM
I have three suggestions:

*hugs*
Title: Re: Fullscreen Choice
Post by: pacdiggity on April 12, 2011, 07:50:35 AM
Yeah, I probably should've paid more attention to that stuff. However, I'm working on another script at the moment, and I'm a little swamped with other stuff. Also, I have a tingly feeling in my heart because you posted here. I feel special.
How could I forget to include the load_database method? Doi. Not quite sure what that second one means though...
Thanks for the suggestions!

EDIT: Don't really see the point of load_database in the script if it is made in Scene_Title, but I'll do it anyway.
Title: Re: Fullscreen Choice
Post by: Zeriab on April 12, 2011, 02:37:42 PM
Oh, nvm about the load_database method. I thought you wrote an rmxp script as Scene_ScreenChoice doesn't inherit from Scene_Base.

Your improper indentions does sorta hide my second bullet point.
Anyway your class is structured a bit like this:
Code: [Select]
class Scene_ScreenChoice < Scene_Base
  # ...
  begin
    # main  loop
  end
end

I suggest moving the main loop out of the class declaration. I.e.
Code: [Select]
class Scene_ScreenChoice < Scene_Base
  # ...
end

begin
  # main  loop
end

*hugs*
Title: Re: Fullscreen Choice
Post by: pacdiggity on April 12, 2011, 02:57:32 PM
Alrighty, I'll give that a shot.
At the moment, however, I'm working on putting music into the scene. I've never dealt with operating BGMs in script before, only terminating them. As a result, I don't know how to do it and I can't recall any scripts I could 'study' to get the function from.
Another thing I'm doing is to get rid of the window before battle tests, as it's just annoying. That shouldn't be difficult at all though.
I'll fix my indentation for you though (do you mean to put it all as far left as possible or that there's something wrong with the way it's put out?)
Title: Re: Fullscreen Choice
Post by: pacdiggity on April 18, 2011, 02:41:53 PM
Major update!
Done a lot of stuff to the script, namely:
The music is yet to come.

EDIT: I screwed up, don't use that version! I will fix it in several minutes. The full-screen function will not work with this script!
EDIT EDIT: Works now.
Title: Re: Fullscreen Choice
Post by: pacdiggity on April 18, 2011, 03:16:29 PM
Oh my good golly gosh, so many updates today!
I've taken out the scene in the battle test. It was really annoying, and it added some girth to my script that brought it closer to my 200 line goal. :P
Title: Re: Fullscreen Choice
Post by: pacdiggity on April 20, 2011, 05:13:52 AM
More updates!
I've updated this to 2.1a, allowing for quicker running by changing the inheritance from Scene_Base to Scene_Title, letting the battle test run smoother and the script to run faster.
Title: Re: Fullscreen Choice
Post by: Zeriab on April 20, 2011, 06:25:07 AM
Good work. Your script looks much better now ^_^

Since your scene inherits from Scene_Title there should be no need to create a new Scene_Title.
Code: [Select]
@title = Scene_Title.new
@title.load_database
That could just probably just be changed into:
Code: [Select]
load_database


Consider storing the wanted fullscreen option in the game.ini file. I have made a wrapper which does the Win32APi calls for you: http://pastebin.com/KZyTS6cB
You can then write the setting to the ini file like this:
Code: [Select]
Utility.write_ini('Fullscreen', '1') # Fullscreen mode on
Utility.write_ini('Fullscreen', '0') # Fullscreen mode off
To read from the ini file you can use something like this:
Code: [Select]
if Utility.read_ini('Fullscreen') == '1'
  # Turn fullscreen on automatically and continue
elsif Utility.read_ini('Fullscreen') == '0'
  # Continue in windowed mode
else
  # Fullscreen setting has not been set. Ask the player
end


*hugs*
Title: Re: Fullscreen Choice
Post by: pacdiggity on April 20, 2011, 06:40:47 AM
Dear lord that's helpful.
I was worrying a bit because if you boot the game up in full-screen and select windowed, it stays in fullscreen because I didn't write to put the game in windowed, just to start the scene.
Also thanks for that title pointout. Doesn't really change much, but it gets rid of a line and a half :P
I'll take a crack at that right now.
And thanks for dropping by on my CP thread.
EDIT: Works great Zeriab! Everything is functioning perfectly.
Title: Re: Fullscreen Choice
Post by: Adon on September 02, 2011, 09:12:06 PM
Awesome!
*adds to game*
Title: Re: Fullscreen Choice
Post by: ForeverZero on September 02, 2011, 09:53:23 PM
Just out of curiosity, but why is the keyboard handle a global variable?  If its to be used throughout a game, that's perfectly fine, but in this case its merely being called once when the game starts, so why not make it a local variable?
Title: Re: Fullscreen Choice
Post by: pacdiggity on September 03, 2011, 12:44:10 AM
Kinda glad you asked, Zer0. Yes, it's intended for people to be able to use it through other means. But you are quite right, and you know my hatred toward unneeded globals. And configuration data defined outside of a module. How dare I?!
This is in need of an update.
Title: Re: Fullscreen Choice
Post by: Infinate X on September 03, 2011, 02:05:21 PM
This is a neat script :D I'm going to use this (b'.')b

EDIT: I selected full-screen and itwindowed my game :(
Title: Re: Fullscreen Choice
Post by: pacdiggity on September 03, 2011, 10:57:18 PM
As I said, this script needs an update. I'm busy beyond reason today, but I'll see what I can do tomorrow.
Title: Re: Fullscreen Choice
Post by: crow5derlock on December 06, 2011, 07:58:12 AM
probably long past by now, but couldn't you always study on of the auto scripts in the game for the music thing... im sure its in there somewhere otherwise music wouldn't play in the game at all.
Title: Re: Fullscreen Choice
Post by: pacdiggity on December 06, 2011, 09:44:39 AM
I overcame problems like that many months ago. I simply haven't redone this script.
Title: Re: Fullscreen Choice
Post by: ShinobiChef on March 20, 2012, 05:35:11 AM
Great script mate , now that RMVX-Ace is out will you be making a new version that is compatible with RMVX-Ace?
Title: Re: Fullscreen Choice
Post by: pacdiggity on March 20, 2012, 09:57:46 AM
I have a draft for one. It has the same problem as this one; if the game is in fullscreen and you select windowed, it remains in fullscreen.
That said, you could probably easily fix this by making F12 exit instead of restart. Would you like me to post it?