DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[Tutorial] Adding new options to the Controls menu
Page 1 of 1
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 17 Sep 2018

Topics: 163
Posts: 8192
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Wed Sep 15, 2010 7:47 pm
   Subject: [Tutorial] Adding new options to the Controls menu
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Bottom of Posts

AFAIK, this is the first code tutorial for SDL concerning the Menus code. That is, the Main Menu, the Controls menu, and so on.

What this code does is add two options to the Controls menu - "Enable wall sounds" and "Color flashing". Disabling Color Flashing will make it "feel" more like the Mac version, and it's also a help for people who get seizures when exposed to bright flashes of light.

Note: If the CONFIG.WL6 file exists, delete it before running the EXE, or you'll have problems!

I've tried to break the code down as much as I can, as I'd really like you all to learn more about the Menu code, and how it works. I apologize if my descriptions are too elaborate or simplistic at times.

The code tutorial is written for the vanilla WOLF4SDL code by Ripper, *not* WolfDX, or BT's enhanced BunkerSDL or MMCSDL code.

First, go into VERSION.H. The first lines of code you should see are:
::: CODE :::
#ifndef _VERSION_H_
#define _VERSION_H_

Below that, insert this:
::: CODE :::
#define WALLCODE              // code to disable wall sounds from menu
This lets you disable the extra menu options code whenever you wish.

Now go into WL_DEF.H. Do a search for "mouseenabled". You should see this code:
::: CODE :::
extern  boolean     mouseenabled,joystickenabled;

Right above that, insert this:
::: CODE :::
#ifdef WALLCODE
extern  boolean     WallSndsEnabled, ClrFlashEnabled;
#endif
This is the two new variables the Customize menu will use.

With that done, let's go into FOREIGN.H. Do a search for "STR_CL". You should see this line of code:
::: CODE :::
#define   STR_CL   "Control"

That code should be replaced by this:
::: CODE :::
#ifdef WALLCODE
#define   STR_CL   "Options"
#else
#define   STR_CL   "Control"
#endif
This changes the "Control" name to "Options".

Now do a search for "STR_CUSTOM". You should see:
::: CODE :::
#define   STR_CUSTOM   "Customize controls"

Just below that, insert this:
::: CODE :::
#ifdef WALLCODE
#define   STR_WALLSND   "Enable wall sounds"
#define STR_COLORFLASH "Color flashing"
#endif
This tells the menus what text to write for the options we're adding in.

Now it's time to go into WL_MAIN.CPP. You do a bit more to this file. First, do a search for "O_RDONLY". You should be brought to:
::: CODE :::
    const int file = open(configname, O_RDONLY | O_BINARY);

Below that, insert this:
::: CODE :::
#ifdef WALLCODE
    WallSndsEnabled = true;
    ClrFlashEnabled = true;
#endif
This automatically turns the options on if the EXE finds no CONFIG file.

Now do a search for "&sds". You should see a line like this:
::: CODE :::
        read(file,&sds,sizeof(sds));

Below this line, you'll insert this code:
::: CODE :::
#ifdef WALLCODE
        read(file,&WallSndsEnabled,sizeof(WallSndsEnabled));
        read(file,&ClrFlashEnabled,sizeof(ClrFlashEnabled));
#endif
This tells the code to read the config file for the settings of the Wall Sounds and Color Flashes in the menu.

Next, do a search for "correct" (I'm not kidding). You should see this line:
::: CODE :::
        // make sure values are correct

Insert this code just below it:
::: CODE :::
#ifdef WALLCODE
        if(WallSndsEnabled) WallSndsEnabled=true;
        if(ClrFlashEnabled) ClrFlashEnabled=true;
#endif
This code is the EXE's "fail-safe" which fixes up any options that are given "bad" values. For example, the "mouseenabled" variable should have only two different settings. If it has a third, this fixes the problem.

Now do a search for "&mouseenabled". You should see this line of code:
::: CODE :::
        write(file,&mouseenabled,sizeof(mouseenabled));

Right above that, add this:
::: CODE :::
#ifdef WALLCODE
        write(file,&WallSndsEnabled,sizeof(WallSndsEnabled));
        write(file,&ClrFlashEnabled,sizeof(ClrFlashEnabled));
#endif
This tells the EXE to write the settings of the two new options to CONFIG.WL6 when the program exits.

Okay, the next file needs less work. Go into WL_MENU.H, and search for "MenuFadeOut". You should see a line like this now:

::: CODE :::
#define MenuFadeOut()   VL_FadeOut(0,255,0,0,51,10)

Insert this line just below it:
::: CODE :::
#ifdef WALLCODE
#define MenuFadeToBlack()   VL_FadeOut(0,255,0,0,0,10)
#endif
You'll have to do this twice in the file, once for Wolf3D mode and once for Spear.

The new code enables an extra routine called "MenuFadeToBlack", which has the menu fade to black rather than red.

Now do a search for "CTL_Y". You should see this line of code:
::: CODE :::
#define CTL_Y   86

It should be changed to this:
::: CODE :::
#ifdef WALLCODE
#define CTL_Y   73
#else
#define CTL_Y   86
#endif

Now scroll down to "CTL_H", about two lines below. You should now be at this line:
::: CODE :::
#define CTL_H   60

Completely replace that line with this:
::: CODE :::
#ifdef WALLCODE
#define CTL_H   86
#else
#define CTL_H   60
#endif
The spoiler below goes into detail about how the "CTL" variables work. Although many may find it informative, you don't need to read it to complete the tutorial.
Since expanding the Controls menu makes it "taller", we have to increase the size of the menu's "box" and re-center it. That is, the colored box the menu's text appears in.

To break things down for you, the Controls menu uses these variables:
::: CODE :::
CTL_X, CTL_Y, CTL_W, CTL_H
"CTL_X" and "CTL_Y" simply tell the code where the top-left corner of the "box" should be drawn. "CTL_W" says how wide the box should be. CTL_H says what its height should be. The variables before and after do the same thing, only they affect other menus, such as the Sounds menu or the Main Menu.

So where am I getting these numbers of "73" and "86"? I'll explain. First, the letters of the menus are each 13 pixels in height. Since I'm adding two extra lines of text to the Customize menu, that's an extra height of 26, or 13 multiplied by 2. The value of CTL_H is 86 because CTL_H is really:
::: CODE :::
#define CTL_H   60 + 26

To "center" the box, I take the extra height of the letters (13 times two, or 26) and divide it by two. I've given the CTL_Y variable the value of 73 because it's the same as:
::: CODE :::
#define CTL_Y   86 - (26 / 2)
Now, back to the code tutorial ...

Let's go to WL_MENU.CPP next. This file requires the most work of all. First, do a search for "CTL_MOUSEENABLE". You should see this line:
::: CODE :::
enum { CTL_MOUSEENABLE, CTL_MOUSESENS, CTL_JOYENABLE, CTL_CUSTOMIZE };

Change it to this:
::: CODE :::
#ifdef WALLCODE
enum { CTL_MOUSEENABLE, CTL_MOUSESENS, CTL_JOYENABLE, CTL_CUSTOMIZE, CTL_WALLSND, CTL_COLORFLASH};
#else
enum { CTL_MOUSEENABLE, CTL_MOUSESENS, CTL_JOYENABLE, CTL_CUSTOMIZE };
#endif

Now do a search for "STR_CUSTOM". You should see this line now:
::: CODE :::
    {1, STR_CUSTOM, CustomControls}

Change it to this:
::: CODE :::
#ifdef WALLCODE
    {1, STR_CUSTOM, CustomControls},
    {0, STR_WALLSND, 0},
    {0, STR_COLORFLASH, 0}
#else
    {1, STR_CUSTOM, CustomControls}
#endif
This tells the menu pointer *not* to mark "Customize keyboard controls" as the last item on the menu. Instead, "Color flashes" is considered the last item on the menu.

Now do a seach for "CTL_MOUSESENS:". You should see this line of code:

::: CODE :::
            case CTL_MOUSESENS:

Above that, insert this:
::: CODE :::
#ifdef WALLCODE
            case CTL_WALLSND:
                WallSndsEnabled ^= 1;
                DrawCtlScreen ();
                CusItems.curpos = -1;
                ShootSnd ();
                break;

            case CTL_COLORFLASH:
                ClrFlashEnabled ^= 1;
                DrawCtlScreen ();
                CusItems.curpos = -1;
                ShootSnd ();
                break;
#endif
This tells the Controls menu what to do with our two options when you select them in the menu. In this case, we're just switching them "on" and "off".

Now do a search for "&CtlItems". You should see this line of code:
::: CODE :::
    DrawMenu (&CtlItems, CtlMenu);

Right above that, you should insert this:
::: CODE :::
#ifdef WALLCODE
    CtlMenu[CTL_WALLSND].active = 1;
    CtlMenu[CTL_COLORFLASH].active = 1;
#endif
By default, the two new options are "shaded out", so the menu's pointer just moves right past them whenever you try to get to them. The code I've put here tells the menu, "Hey, don't do that. Allow the pointer to move to these options".

Now do a search for "PICK FIRST". You should see this line of comments:
[/code] //
// PICK FIRST AVAILABLE SPOT
//[/code]
Above that, insert these lines of code:
::: CODE :::
#ifdef WALLCODE
    y = CTL_Y + 54;
    if (WallSndsEnabled)
        VWB_DrawPic (x, y, C_SELECTEDPIC);
    else
        VWB_DrawPic (x, y, C_NOTSELECTEDPIC);

    y = CTL_Y + 67;
    if (ClrFlashEnabled)
        VWB_DrawPic (x, y, C_SELECTEDPIC);
    else
        VWB_DrawPic (x, y, C_NOTSELECTEDPIC);
#endif
This tells the code, "If the options are turned off, draw an unlit box in these spots. If they're turned on, draw a lit box in these spots."

Let's go back to the beginning of WL_MENU.CPP again. Search for "MenuFadeOut". Every time you see this line of code ...
::: CODE :::
                MenuFadeOut ();

... it should be replaced with this:
::: CODE :::
#ifdef WALLCODE
    if (ClrFlashEnabled)
#endif
                MenuFadeOut ();
#ifdef WALLCODE
    else
                MenuFadeToBlack ();
#endif
This code appears several times in WL_MENU.CPP. The new code tells the program to fade to black - not red - when Color Flashing is disabled.

Just two files left to go. We've added two options to the Customize menu now. It's time to make them actually *do* something. Let's start with the first of our new options, the wall sounds. Go into WL_AGENT.CPP. Do a search for "state info". This is the comment lines you should see:
::: CODE :::
//
// player state info
//

Above this, insert these three lines:
::: CODE :::
#ifdef WALLCODE
boolean WallSndsEnabled;
#endif
This tells the code to "remember" the setting of the wall sounds from the Customize menu.

Now do a search for "HITWALLSND". You should be brought to these lines of code:
::: CODE :::
    if (!SD_SoundPlaying())
        SD_PlaySound (HITWALLSND);

They should be changed to this:
::: CODE :::
    if (
#ifdef WALLCODE
    WallSndsEnabled &&
#endif
    !SD_SoundPlaying() )
            SD_PlaySound (HITWALLSND);
This tells the code not to play the "hit a wall" sound if the wall sounds are turned off.

Let's do a search now for "DONOTHINGSND". You should be brought to this line of code:
::: CODE :::
    else
        SD_PlaySound (DONOTHINGSND);

Insert some code in-between these two lines, so it looks like this:
::: CODE :::
    else
#ifdef WALLCODE
        if (WallSndsEnabled)
#endif
        SD_PlaySound (DONOTHINGSND);
This tells the code that if the player has pressed the "Use" button when there's nothing to "use", the "do nothing" sound shouldn't be played if Wall Sounds are turned off.

And now, here's the last file to change. Go into WL_PLAY.CPP. Do a search for "ammocheat". You should now be at this line:
::: CODE :::
boolean noclip, ammocheat;

Right above that, insert this:
::: CODE :::
#ifdef WALLCODE
boolean     ClrFlashEnabled;
#endif
This tells the code to "remember" the setting for the menu's color flashes.

Now do a search for "white shift". You should see this line now:
::: CODE :::
    bonuscount = NUMWHITESHIFTS * WHITETICS;    // white shift palette

Right above that, insert these lines:
::: CODE :::
#ifdef WALLCODE
    if (ClrFlashEnabled)
#endif
You've now allowed the Color Flashes option to work with the white flashes you see when getting treasure or power-ups.

Lastly, do a search for "damagecount". You should now be at this line:
::: CODE :::
    damagecount += damage;

Insert these lines just above it:
::: CODE :::
#ifdef WALLCODE
    if (ClrFlashEnabled)
#endif
This allows the color flashes when the player is "hit" to be disabled.

That should do it. I hope this tutorial has been helpful and informative to you all. Smile
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Announcement: Wolf4SDL released
Author: Ripper
522 208763 Mon May 22, 2017 2:04 pm
Tricob View latest post
No new posts [help] Adding teleporters in wolf4sdl
Author: Mortimer
35 10853 Fri May 26, 2017 8:19 am
Military View latest post
No new posts [WOLF4SDL Help] Blake Stone Style doors
Author: Haasboy
3 2998 Sun Jul 20, 2008 7:56 am
Haasboy View latest post
No new posts [help] Wolf4sdl's implemented tutorials
Author: Mortimer
6 3264 Tue May 06, 2008 1:15 pm
Ripper View latest post
No new posts [SDL] Apply 2nd ScaleFactor to selected (hi-res) vga gfx
Author: Andy_Nonymous
9 4477 Sun Apr 27, 2008 2:30 am
AlumiuN View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group