25-08-2006, 01:41 PM
Author: Robin
Difficulty: Requires ability to understand.
This tutorial will allow user's to be able to choose from several options, including windowed, to make the game more suitable for them.
User configuration is really a good thing to add in.
For example, in Naruto Realm Beta, user's can choose which effects to add to text, they can choose font face, font size, resolution and can also enter optional details about themselves, for other people to see and also which way they would like to play music. eg. FMod or Mirage Default.
Now, because this is being made for a Vanilla MSE Build 1, and we are only adding in one option, I will add it into frmChars. I would suggest having an option menu for people when they open the client instead, though.
Now, add these items into frmChars:
Syn: Type | Name | Details
Combo | cmbFulllscreen | Enabled = false. List = 640x480, 800x600, 1024x768, 1280x1024. Type = Dropdown List.
Option | optFullscreen | Value = false
Option | optWindow | Value = true
Now we want it so that when people select Windowed, the combo box becomes disabled, and then enabled when Fullscreen is selected, so...
Add this code into frmChars:
Goto modDirectX, delete:
and replace with this:
What this does is finds which options they selected, and set the display mod accordingly. Then, if it is fullscreen, the cooperative level in frmMirage is set to fullscreen mode(?). If not, then we add a border into frmMirage, re-do the caption, then set the cooperative level to that of just normal(?).
Either create a new module and put this in, or add to another module (I had it in modGeneral. Don't think that exists in Vanilla Mirage)
I found that in these forums, posted by GSD. I think it may be in Tutorial Request, or general or something. Anyway, someone asked for some code to change the borderstyle, and I took it.
Now add this sub somewhere. Again, I had it in modGeneral.
This is a sub which get's the desktop hwnd, get's the DC, then, finds the number of colours. We then release the DC and now we have the desktop's colour setting's saved.
Add this into modGlobals:
For the above code.
I had this code in modEnum, you can add anywhere.
enumerate the colours.
Add these into modConstants
Just some code which came with the border changer.
Add these into modDeclares:
Again, came with the border change code.
And finally, goto frmMirage and change borderstyle to:
Obviously, GSD or whoever didn't know how to set the border style to 0, so we have to change frmMirage from 0 to something else. In this case, 2 - Sizable.
You should now have working fullscreen support.
It does look very rubbish with the default maps, but I am adding in scrolling maps into my client, which work in all resolutions.
Players can choose which resolution they want. If you want, you can change it so people choose their own colour quality. I simply added some code which get's the desktop's colour quality and uses that, for compatability reasons.
If you are really lazy, or not too confident programming, you can just as easily change it to a set resolution.
This is probably not the best way to go about things, but it works fine on both Naruto Realm and my SPRPG, Wind's Whisper.
Oh, by the way. This will look pretty bad with the default style of GUI (eg. Having the map in a box with pictures around it) and I would suggest having a small GUI blted on screen, or simply non at all. With Inventory, Spells, Shops and the such blted on screen to make your game look more professional.
Have Fun_^
P.S. No other forms will be able to be loaded. If you add this in you must convert frmTrade, frmTraining and all other external forms to either picture boxes, or to Blted objects, like I did. Having them blted will allow for cool alphablending shizzle like in Naruto Realm Beta
~Kite
Difficulty: Requires ability to understand.
This tutorial will allow user's to be able to choose from several options, including windowed, to make the game more suitable for them.
User configuration is really a good thing to add in.
For example, in Naruto Realm Beta, user's can choose which effects to add to text, they can choose font face, font size, resolution and can also enter optional details about themselves, for other people to see and also which way they would like to play music. eg. FMod or Mirage Default.
Now, because this is being made for a Vanilla MSE Build 1, and we are only adding in one option, I will add it into frmChars. I would suggest having an option menu for people when they open the client instead, though.
Now, add these items into frmChars:
Syn: Type | Name | Details
Combo | cmbFulllscreen | Enabled = false. List = 640x480, 800x600, 1024x768, 1280x1024. Type = Dropdown List.
Option | optFullscreen | Value = false
Option | optWindow | Value = true
Now we want it so that when people select Windowed, the combo box becomes disabled, and then enabled when Fullscreen is selected, so...
Add this code into frmChars:
Code:
Private Sub optFullscreen_Click()
cmbFullscreen.Enabled = True
End Sub
Private Sub optWindow_Click()
cmbFullscreen.Enabled = False
End Sub
Private Sub Form_Load()
cmbFullscreen.ListIndex = 0
End Sub
Goto modDirectX, delete:
Code:
' Indicate windows mode application
Call DD.SetCooperativeLevel(frmMirage.hWnd, DDSCL_NORMAL)
and replace with this:
Code:
If frmChars.optFullscreen.Value = True Then
Select Case frmChars.cmbFullscreen.ListIndex
Case 0
If Screen.Width 640 And Screen.Height 480 Then
Call DD.SetDisplayMode("640", "480", ColourDisplay, 0, DDSDM_DEFAULT)
End If
Case 1
If Screen.Width 800 And Screen.Height 600 Then
Call DD.SetDisplayMode("800", "600", ColourDisplay, 0, DDSDM_DEFAULT)
End If
Case 2
If Screen.Width 1024 And Screen.Height 768 Then
Call DD.SetDisplayMode("1024", "768", ColourDisplay, 0, DDSDM_DEFAULT)
End If
Case 3
If Screen.Width 1280 And Screen.Height 1024 Then
Call DD.SetDisplayMode("1280", "768", ColourDisplay, 0, DDSDM_DEFAULT)
End If
End Select
Call DD.SetCooperativeLevel(frmMirage.hWnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN Or DDSCL_ALLOWMODEX)
ElseIf frmChars.optWindow.Value = True Then
ChangeBorderStyle frmMirage, 2
frmMirage.Caption = GAME_NAME 'or w/e caption you want
Call DD.SetCooperativeLevel(frmMirage.hWnd, DDSCL_NORMAL)
End If
What this does is finds which options they selected, and set the display mod accordingly. Then, if it is fullscreen, the cooperative level in frmMirage is set to fullscreen mode(?). If not, then we add a border into frmMirage, re-do the caption, then set the cooperative level to that of just normal(?).
Either create a new module and put this in, or add to another module (I had it in modGeneral. Don't think that exists in Vanilla Mirage)
Code:
Public Sub ChangeBorderStyle(TheForm As Form, Style As Byte)
'code taken from GodSendDeaths post on www.miragesource.com/forums
Dim bToggleStyle As Boolean, bToggleExStyle As Boolean, cStyle As Byte
'This makes sure the selected style is within acceptable range
If Style > 5 Or Style < 0 Then Style = TheForm.BorderStyle
cStyle = TheForm.BorderStyle
TheForm.BorderStyle = Style
'Checks the current BorderStyle and changes the variables to comply with selected style
If Style = 0 Then
'Don't know yet >_>...
bToggleStyle = False
bToggleExStyle = False
ElseIf Style = 1 Then
If cStyle = 2 Then
bToggleStyle = True
ElseIf cStyle = 3 Then
bToggleStyle = False
ElseIf cStyle = 4 Then
bToggleExStyle = True
ElseIf cStyle = 5 Then
bToggleStyle = True
bToggleExStyle = True
End If
ElseIf Style = 2 Then
If cStyle = 1 Then
bToggleStyle = True
bToggleExStyle = False
ElseIf cStyle = 3 Then
bToggleStyle = True
ElseIf cStyle = 4 Then
bToggleStyle = True
bToggleExStyle = True
ElseIf cStyle = 5 Then
bToggleStyle = False
bToggleExStyle = True
End If
ElseIf Style = 3 Then
If cStyle = 1 Then
bToggleStyle = False
ElseIf cStyle = 2 Then
bToggleStyle = True
ElseIf cStyle = 4 Then
bToggleExStyle = True
ElseIf cStyle = 5 Then
bToggleStyle = True
bToggleExStyle = True
End If
ElseIf Style = 4 Then
If cStyle = 1 Then
bToggleExStyle = True
ElseIf cStyle = 2 Then
bToggleStyle = True
bToggleExStyle = True
ElseIf cStyle = 3 Then
bToggleExStyle = True
ElseIf cStyle = 5 Then
bToggleStyle = True
bToggleExStyle = False
End If
Else
If cStyle = 1 Then
bToggleStyle = True
bToggleExStyle = True
ElseIf cStyle = 2 Then
bToggleExStyle = True
ElseIf cStyle = 3 Then
bToggleStyle = True
bToggleExStyle = True
ElseIf cStyle = 4 Then
bToggleStyle = True
bToggleExStyle = False
End If
End If
If bToggleStyle Then 'Toggles between Fixed and Sizeable
Call SetWindowLong(TheForm.hWnd, GWL_STYLE, GetWindowLong(TheForm.hWnd, GWL_STYLE) Xor (WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX))
End If
If bToggleExStyle Then 'Toggles between ToolWindow and Regular Window
Call SetWindowLong(TheForm.hWnd, GWL_EXSTYLE, GetWindowLong(TheForm.hWnd, GWL_EXSTYLE) Xor WS_EX_TOOLWINDOW)
End If
Call SetWindowPos(TheForm.hWnd, 0&, 0&, 0&, 0&, 0&, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_FRAMECHANGED)
End Sub
I found that in these forums, posted by GSD. I think it may be in Tutorial Request, or general or something. Anyway, someone asked for some code to change the borderstyle, and I took it.
Now add this sub somewhere. Again, I had it in modGeneral.
Code:
Public Sub Getwindowcolours()
Dim hdesktopwnd As Long, hdccaps As Long
'Get the desktop hwnd
hdesktopwnd = GetDesktopWindow()
'Get the DC
hdccaps = GetDC(hdesktopwnd)
'Get the number of colours from the DC
ColourDisplay = GetDeviceCaps(hdccaps, 12)
'Release the DC
Call ReleaseDC(hdesktopwnd, hdccaps)
End Sub
This is a sub which get's the desktop hwnd, get's the DC, then, finds the number of colours. We then release the DC and now we have the desktop's colour setting's saved.
Add this into modGlobals:
Code:
' Fullscreen
Public ColourDisplay As ColourDepth
For the above code.
I had this code in modEnum, you can add anywhere.
Code:
Public Enum ColourDepth
High32 = 32
high24 = 24
True16 = 16
End Enum
enumerate the colours.
Add these into modConstants
Code:
'for the change form border subroutine
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOREDRAW = &H8
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_FRAMECHANGED = &H20
Public Const SWP_SHOWWINDOW = &H40
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_NOCOPYBITS = &H100
Public Const SWP_NOOWNERZORDER = &H200
Public Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Public Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
Public Const HWND_TOP = 0
Public Const HWND_BOTTOM = 1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const GWL_STYLE As Long = (-16&)
Public Const GWL_EXSTYLE As Long = (-20&)
Public Const WS_THICKFRAME As Long = &H40000
Public Const WS_MINIMIZEBOX As Long = &H20000
Public Const WS_MAXIMIZEBOX As Long = &H10000
Public Const WS_EX_TOOLWINDOW As Long = &H80&
Just some code which came with the border changer.
Add these into modDeclares:
Code:
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd&, ByVal hWndInsertAfter&, ByVal X&, ByVal Y&, ByVal CX&, ByVal CY&, ByVal wFlags&) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd&, ByVal nIndex&) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Again, came with the border change code.
And finally, goto frmMirage and change borderstyle to:
Code:
0 - None
Obviously, GSD or whoever didn't know how to set the border style to 0, so we have to change frmMirage from 0 to something else. In this case, 2 - Sizable.
You should now have working fullscreen support.
It does look very rubbish with the default maps, but I am adding in scrolling maps into my client, which work in all resolutions.
Players can choose which resolution they want. If you want, you can change it so people choose their own colour quality. I simply added some code which get's the desktop's colour quality and uses that, for compatability reasons.
If you are really lazy, or not too confident programming, you can just as easily change it to a set resolution.
This is probably not the best way to go about things, but it works fine on both Naruto Realm and my SPRPG, Wind's Whisper.
Oh, by the way. This will look pretty bad with the default style of GUI (eg. Having the map in a box with pictures around it) and I would suggest having a small GUI blted on screen, or simply non at all. With Inventory, Spells, Shops and the such blted on screen to make your game look more professional.
Have Fun_^
P.S. No other forms will be able to be loaded. If you add this in you must convert frmTrade, frmTraining and all other external forms to either picture boxes, or to Blted objects, like I did. Having them blted will allow for cool alphablending shizzle like in Naruto Realm Beta

~Kite