Line 34: |
Line 34: |
| ===Template=== | | ===Template=== |
| | | |
− | <syntaxhighlight lang="python" line> | + | <syntaxhighlight lang="html4strict" line> |
− | import time
| + | <!DOCTYPE html> |
− | from ctypes import windll, byref, c_char, Structure, WinError, POINTER, WINFUNCTYPE
| + | <html lang="en"> |
− | from ctypes.wintypes import BOOL, HMONITOR, HDC, RECT, LPARAM, DWORD, BYTE, WCHAR, HANDLE
| + | <head> |
| + | <meta charset="UTF-8"> |
| + | <title>Sky Islands v0.2</title> |
| + | <meta name="description" content=""> |
| + | <meta name="viewport" content="width=device-width"> |
| + | <link rel="stylesheet" href="css/main.css"> |
| + | </head> |
| | | |
| + | <body> |
| + | <div id="container"> |
| + | <div id="game-wrapper"> |
| + | <div id="game-canvas-wrapper"></div> |
| + | <div id="game-gui"></div> |
| + | <div id="game-dialog"></div> |
| + | <div id="game-playerstats"> |
| + | <div id="player-avatar-container"><img id="player-avatar" src="res/avatar/f001.png" /></div> |
| + | <div id="player-stats"> |
| + | <div id="player-resources"> |
| + | <ul> |
| + | <li id="player-resource1" class="player-resource">0</li> |
| + | </ul> |
| + | </div> |
| + | <div id="player-name"> |
| + | <p id="player-name-tag"></p> |
| + | </div> |
| + | </div> |
| + | </div> |
| + | <div id="game-powers"> |
| + | <div id="power1" class="power"></div> |
| + | <div id="power2" class="power"></div> |
| + | </div> |
| + | <div id="game-menu"> |
| + | <div id="menu-start" class="menu-full"> |
| + | <div id="start-buttons"> |
| + | <ul> |
| + | <li id="start-button-start" onclick="onStart()">New Game</li> |
| + | </ul> |
| + | </div> |
| + | </div> |
| + | <div id="menu-avatar-select" class="menu-ingame"> |
| + | <div id="avatar-selector"> |
| + | <p>Select Avatar</p> |
| + | <div class="avatar-menu" onclick="onAvatar(0)"><img src="res/avatar/f001.png" /></div> |
| + | <div class="avatar-menu" onclick="onAvatar(1)"><img src="res/avatar/m001.png" /></div> |
| + | </div> |
| + | <div id="avatar-form-container"> |
| + | <p>Enter Name</p> |
| + | <form> |
| + | <input type="text" id="menu-name-input" /> |
| + | <br/><br/> |
| + | <input type="button" id="menu-name-submit" value="Continue" onclick="onAvatarSelect()" /> |
| + | </form> |
| + | </div> |
| + | </div> |
| + | <div id="menu-level-select" class="menu-ingame"> |
| + | <ul> |
| + | <li id="menu-level-1" class="menu-level-unlocked" onclick="onLevelSelect(1)">Level 1</li> |
| + | <li id="menu-level-2" class="menu-level-locked">???</li> |
| + | <li id="menu-level-3" class="menu-level-locked">???</li> |
| + | <li id="menu-level-4" class="menu-level-locked">???</li> |
| + | </ul> |
| + | </div> |
| + | <div id="menu-gameover" class="menu-ingame"> |
| + | <p>Oh no! You have lost an island!</p> |
| | | |
− | _MONITORENUMPROC = WINFUNCTYPE(BOOL, HMONITOR, HDC, POINTER(RECT), LPARAM)
| + | <p><a onclick="onRetry()">Try Again</a></p> |
| + | <p><a onclick="onBackToMenu()">Back to Menu</a></p> |
| + | </div> |
| + | <div id="menu-win" class="menu-ingame"> |
| + | <p>Congratulations! You are awesome!</p> |
| + | <p><a onclick="onRetry()">Play Again</a></p> |
| + | <p><a onclick="onBackToMenu()">Next Level</a></p> |
| + | </div> |
| + | <div id="menu-timeup" class="menu-full">Je bent nu klaar met dit onderdeel. Ga naar het volgende onderdeel door dit pop-up venster te sluiten, door middel van het rode kruisje.</div> |
| + | <div id="menu-tutorial" class="menu-full"> |
| + | <div id="menu-tutorial-button"> |
| + | <p onclick="pause()">Continue</p> |
| + | </div> |
| + | </div> |
| + | <div id="menu-pause-button" onclick="pause()"><p>||</p></div> |
| + | </div> |
| | | |
− | class _PHYSICAL_MONITOR(Structure):
| + | <div id="debug">Version 0.2.3.2</div> |
− | _fields_ = [('handle', HANDLE), ('description', WCHAR * 128)]
| |
| | | |
| + | </div> |
| + | </div> |
| | | |
− | def _iter_physical_monitors(close_handles=True):
| + | <script type="text/javascript" src="js/resources.min.js"></script> |
− | """Iterates physical monitors.
| + | <script type="text/javascript" src="js/sprite.min.js"></script> |
| + | <script type="text/javascript" src="js/game.min.js"></script> |
| + | </body> |
| + | </html> |
| | | |
− | The handles are closed automatically whenever the iterator is advanced.
| |
− | This means that the iterator should always be fully exhausted!
| |
− |
| |
− | If you want to keep handles e.g. because you need to store all of them and
| |
− | use them later, set `close_handles` to False and close them manually."""
| |
− |
| |
− | def callback(hmonitor, hdc, lprect, lparam):
| |
− | monitors.append(HMONITOR(hmonitor))
| |
− | return True
| |
− |
| |
− | monitors = []
| |
− | if not windll.user32.EnumDisplayMonitors(None, None, _MONITORENUMPROC(callback), None):
| |
− | raise WinError('EnumDisplayMonitors failed')
| |
− |
| |
− | for monitor in monitors:
| |
− | # Get physical monitor count
| |
− | count = DWORD()
| |
− | if not windll.dxva2.GetNumberOfPhysicalMonitorsFromHMONITOR(monitor, byref(count)):
| |
− | raise WinError()
| |
− | # Get physical monitor handles
| |
− | physical_array = (_PHYSICAL_MONITOR * count.value)()
| |
− | if not windll.dxva2.GetPhysicalMonitorsFromHMONITOR(monitor, count.value, physical_array):
| |
− | raise WinError()
| |
− |
| |
− | for physical in physical_array:
| |
− | handle = physical.handle
| |
− |
| |
− | # Get physical monitor capabilities. This may take a while...
| |
− | length = DWORD()
| |
− | if not windll.dxva2.GetCapabilitiesStringLength(HANDLE(handle), byref(length)):
| |
− | raise WinError()
| |
− | capabilities_string = (c_char * length.value)()
| |
− | if not windll.dxva2.CapabilitiesRequestAndCapabilitiesReply(HANDLE(handle), capabilities_string, length):
| |
− | raise WinError()
| |
− | raw_capabilities = capabilities_string.value.decode('ascii')
| |
− | capabilities = _parse_capabilities_string(raw_capabilities)
| |
− | if capabilities:
| |
− | # We only care about the model info for now.
| |
− | yield [capabilities['model'], handle]
| |
− | if close_handles:
| |
− | if not windll.dxva2.DestroyPhysicalMonitor(handle):
| |
− | raise WinError()
| |
− |
| |
− |
| |
− | def _parse_capabilities_string(capabilities_string):
| |
− | level = 0
| |
− | capabilities = {}
| |
− | open_p = {}
| |
− | close_p = {0: 0}
| |
− | id = {}
| |
− | for i, chr in enumerate(capabilities_string):
| |
− | if chr == '(':
| |
− | if i == 0:
| |
− | close_p[0] = 1
| |
− | continue
| |
− | open_p[level] = i
| |
− | if level == 0:
| |
− | id[0] = capabilities_string[close_p[0] + 1:i]
| |
− | level += 1
| |
− | elif chr == ')':
| |
− | level -= 1
| |
− | close_p[level] = i
| |
− | if level == 0:
| |
− | values = capabilities_string[open_p[0] + 1:i]
| |
− | # We only care about the model info for now.
| |
− | if id[0] == 'model':
| |
− | capabilities[id[0]] = values
| |
− | return capabilities
| |
− |
| |
− |
| |
− | def set_vcp_feature(monitor, code, value):
| |
− | """Sends a DDC command to the specified monitor.
| |
− |
| |
− | See this link for a list of commands:
| |
− | ftp://ftp.cis.nctu.edu.tw/pub/csie/Software/X11/private/VeSaSpEcS/VESA_Document_Center_Monitor_Interface/mccsV3.pdf
| |
− | """
| |
− | if not windll.dxva2.SetVCPFeature(HANDLE(monitor), BYTE(code), DWORD(value)):
| |
− | raise WinError()
| |
− |
| |
− |
| |
− | for model, handle in _iter_physical_monitors():
| |
− | if model == "XL2420Z":
| |
− | set_vcp_feature(handle, 0xDC, 12) # picture mode
| |
− |
| |
− | time.sleep(2) # wait for picture mode to load
| |
− |
| |
− | set_vcp_feature(handle, 0x10, 31) # brightness
| |
− | set_vcp_feature(handle, 0x12, 50) # contrast
| |
− | set_vcp_feature(handle, 0xF0, 0) # AMA (overdrive)
| |
| | | |
| </syntaxhighlight> | | </syntaxhighlight> |