Skip to content

Commit

Permalink
add bgm
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Mar 18, 2024
1 parent d7b3fec commit 005035d
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

<head>
<title>ps12exe Online</title>
<link rel="icon" type="image/x-icon" href="https://raw.githubusercontent.com/steve02081504/ps12exe/master/img/icon.ico">
<script type='text/javascript' src='https://www.midijs.net/lib/midi.js'></script>
<script type="module">
(async ({ chrome, netscape }) => {
if (!chrome && !netscape) await import('https://unpkg.com/@ungap/custom-elements')
Expand Down Expand Up @@ -43,6 +45,13 @@

const compileButton = document.getElementById('compileButton')
const inputText = document.getElementById('inputText')
var playing = false
inputText.addEventListener("focus", event => {
if (playing) MIDIjs.resume()
else MIDIjs.play('https://raw.githubusercontent.com/steve02081504/ps12exe/master/src/bin/Unravel.mid',true)
playing = true;
})
inputText.addEventListener("blur", event => MIDIjs.pause())

compileButton.textContent = compileButtonText
function compileCode() {
Expand Down
Binary file added img/music.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/GUI/Events.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ $Script:refs.DarkModeSetButton.add_Click({
$Script:DarkMode = !$Script:DarkMode
Set-DarkMode $Script:DarkMode
})
$Script:BGMPlaying = $true
$Script:refs.BGMSetButton.BackGroundImage = [System.Drawing.Image]::FromFile("$PSScriptRoot\..\..\img\music.png")
$Script:refs.BGMSetButton.add_Click({
if ($Script:BGMPlaying) { PauseMusic }
else { ResumeMusic }
$Script:BGMPlaying = !$Script:BGMPlaying
})
$Script:refs.MainForm.add_FormClosing({
if ($script:ConfigFile) {
if (!(Test-Path $script:ConfigFile)) {
Expand Down
7 changes: 7 additions & 0 deletions src/GUI/Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,10 @@ function SaveCfgFile([string]$ConfigFile) {
function AskSaveCfg {
[System.Windows.Forms.MessageBox]::Show($Script:LocalizeData.AskSaveCfg, $Script:LocalizeData.AskSaveCfgTitle, [System.Windows.Forms.MessageBoxButtons]::YesNo, [System.Windows.Forms.MessageBoxIcon]::Question) -eq 'Yes'
}

function PauseMusic {
[ps12exeGUI.Win32]::mciSendString("pause ps12exeGUIBGM", $null, 0, 0) | Out-Null
}
function ResumeMusic {
[ps12exeGUI.Win32]::mciSendString("resume ps12exeGUIBGM", $null, 0, 0) | Out-Null
}
14 changes: 13 additions & 1 deletion src/GUI/GUIMainScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,29 @@ try {
$Icon = [System.Drawing.Icon]::ExtractAssociatedIcon("$PSScriptRoot\..\..\img\icon.ico")
$Script:refs.MainForm.Icon = $Icon

# load bgm
$FS = New-Object -ComObject Scripting.FileSystemObject
$bgmFile = $FS.GetFile("$PSScriptRoot\..\bin\Unravel.mid")
[ps12exeGUI.Win32]::mciSendString("open `"$($bgmFile.ShortPath)`" alias ps12exeGUIBGM type MPEGVideo", $null, 0, 0) | Out-Null
# play music as loop
[ps12exeGUI.Win32]::mciSendString("play ps12exeGUIBGM repeat", $null, 0, 0) | Out-Null

# Show the form
try { [void]$Script:refs.MainForm.ShowDialog() } catch { Update-ErrorLog -ErrorRecord $_ -Message "Exception encountered unexpectedly at ShowDialog." }
}
finally {
# Dispose all controls
$Script:refs.MainForm.Controls | ForEach-Object { $_.Dispose() }
$Script:refs.MainForm.Controls | ForEach-Object {
if ($_.BackGroundImage) { $_.BackGroundImage.Dispose() }
$_.Dispose()
}
$Script:refs.MainForm.Dispose()
$Icon.Dispose()

[ps12exeGUI.Win32]::ShowWindow($consolePtr, 1) | Out-Null

[ps12exeGUI.Win32]::mciSendString("close ps12exeGUIBGM", $null, 0, 0) | Out-Null

# Remove all variables in the script scope
Get-Variable -Scope Script | Remove-Variable -Scope Script -Force -ErrorAction Ignore
}
3 changes: 3 additions & 0 deletions src/GUI/UItools.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Add-Type @"
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace ps12exeGUI {
public class Dwm {
Expand All @@ -15,6 +16,8 @@ namespace ps12exeGUI {
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
[DllImport("winmm.dll")]
public static extern Int32 mciSendString(String command, StringBuilder buffer, Int32 bufferSize, IntPtr hwndCallback);
}
}
"@ -ReferencedAssemblies System.Windows.Forms, System.Drawing, System.Drawing.Primitives, System.Net.Primitives, System.ComponentModel.Primitives, Microsoft.Win32.Primitives
Expand Down
9 changes: 9 additions & 0 deletions src/WebServer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<head>
<title>ps12exe Online</title>
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<script type='text/javascript' src='https://www.midijs.net/lib/midi.js'></script>
<script type="module">
(async ({ chrome, netscape }) => {
if (!chrome && !netscape) await import('https://unpkg.com/@ungap/custom-elements')
Expand All @@ -22,6 +24,13 @@
<a id="downloadLink" download="a.exe"></a>
<script type="text/javascript">
const userInput = document.getElementById("inputText")
var playing = false
userInput.addEventListener("focus", event => {
if (playing) MIDIjs.resume()
else MIDIjs.play('./bgm',true)
playing = true;
})
userInput.addEventListener("blur", event => MIDIjs.pause())
const a = document.getElementById("downloadLink")
function compileCode() {
if (!userInput.value) {
Expand Down
11 changes: 10 additions & 1 deletion src/WebServer/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ function HandleRequest($context) {
$RunspaceArray.Add($runspace) | Out-Null
return
}
'/bgm' {
# midi file
$context.Response.ContentType = "audio/midi"
$buffer = [System.IO.File]::ReadAllBytes("$PSScriptRoot/../bin/Unravel.mid")
}
'/favicon.ico' {
$context.Response.ContentType = "image/x-icon"
$buffer = [System.IO.File]::ReadAllBytes("$PSScriptRoot/../../img/icon.ico")
}
'/' {
$body = Get-Content -LiteralPath "$PSScriptRoot/index.html" -Encoding utf8 -Raw
$buffer = [System.Text.Encoding]::UTF8.GetBytes($body)
Expand Down Expand Up @@ -211,5 +220,5 @@ finally {
# Restore Console Window Title
$Host.UI.RawUI.WindowTitle = $BackUpTitle
# 清空缓存
Remove-Item $PSScriptRoot/outputs/* -Recurse -Force
Remove-Item $PSScriptRoot/outputs/* -Recurse -Force -ErrorAction Ignore
}
Binary file added src/bin/Unravel.mid
Binary file not shown.
1 change: 1 addition & 0 deletions src/locale/en-UK.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Button Name="CompileButton" Location="807,558" Size="75,30" Text="Compile" />
<Label Name="CfgFileLabel" Location="8,582" Size="778,22" Text="No configuration file has been selected, old chap." />
<Button Name="DarkModeSetButton" BackgroundImageLayout="Stretch" Location="807,474" Size="51,51" />
<Button Name="BGMSetButton" BackgroundImageLayout="Stretch" Location="807,411" Size="51,51" />
</Form>
<OpenFileDialog Name="OpenCfgFileDialog" DefaultExt="psccfg" Filter="Configuration Files (*.psccfg)|*.psccfg" Title="Select a configuration file, if you'd be so kind" />
<SaveFileDialog Name="SaveCfgFileDialog" DefaultExt="psccfg" Filter="Configuration Files (*.psccfg)|*.psccfg" Title="Save the configuration file, old chap" />
Expand Down
1 change: 1 addition & 0 deletions src/locale/es-ES.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Button Name="CompileButton" Location="802,561" Size="81,27" Text="Compilar" />
<Label Name="CfgFileLabel" Location="7,582" Size="778,21" Text="No se ha seleccionado ningún archivo de configuración" />
<Button Name="DarkModeSetButton" BackgroundImageLayout="Stretch" Location="802,472" Size="51,51" />
<Button Name="BGMSetButton" BackgroundImageLayout="Stretch" Location="802,411" Size="51,51" />
</Form>
<OpenFileDialog Name="OpenCfgFileDialog" DefaultExt="psccfg" Filter="Archivos de configuración(*.psccfg)|*.psccfg" Title="Seleccionar archivo de configuración" />
<SaveFileDialog Name="SaveCfgFileDialog" DefaultExt="psccfg" Filter="Archivos de configuración(*.psccfg)|*.psccfg" Title="Guardar archivo de configuración" />
Expand Down
1 change: 1 addition & 0 deletions src/locale/ja-JP.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Button Name="CompileButton" Location="802,561" Size="81,27" Text="コンパイル" />
<Label Name="CfgFileLabel" Location="7,582" Size="778,21" Text="未選択の設定ファイル" />
<Button Name="DarkModeSetButton" BackgroundImageLayout="Stretch" Location="802,472" Size="51,51" />
<Button Name="BGMSetButton" BackgroundImageLayout="Stretch" Location="802,411" Size="51,51" />
</Form>
<OpenFileDialog Name="OpenCfgFileDialog" DefaultExt="psccfg" Filter="設定ファイル(*.psccfg)|*.psccfg" Title="設定ファイルを選択" />
<SaveFileDialog Name="SaveCfgFileDialog" DefaultExt="psccfg" Filter="設定ファイル(*.psccfg)|*.psccfg" Title="設定ファイルを保存" />
Expand Down
3 changes: 2 additions & 1 deletion src/locale/zh-CN.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GroupBox Name="InputsGroupBox" Location="8,1" Size="766,573">
<GroupBox Name="BaseIOGroupBox" Location="5,13" Size="626,102">
<Label Name="CompileFileLabel" Location="6,17" Size="611,36" Text="编译文件">
<TextBox Name="CompileFileTextBox" AllowDrop="True" Location="0,13" Size="551,22" />
<TextBox Name="CompileFileTextBox" AllowDrop="True" ImeMode="Disable" Location="0,13" Size="551,22" />
<Button Name="CompileFileButton" Location="552,10" Size="59,26" Text="..." />
</Label>
<Label Name="OutputFileLabel" Location="5,56" Size="613,37" Text="输出文件">
Expand Down Expand Up @@ -97,6 +97,7 @@
<Button Name="CompileButton" Location="802,561" Size="81,27" Text="编译" />
<Label Name="CfgFileLabel" Location="7,582" Size="778,21" Text="未选中配置文件" />
<Button Name="DarkModeSetButton" BackgroundImageLayout="Stretch" Location="802,472" Size="51,51" />
<Button Name="BGMSetButton" BackgroundImageLayout="Stretch" Location="802,411" Size="51,51" />
</Form>
<OpenFileDialog Name="OpenCfgFileDialog" DefaultExt="psccfg" Filter="配置文件(*.psccfg)|*.psccfg" Title="选择配置文件" />
<SaveFileDialog Name="SaveCfgFileDialog" DefaultExt="psccfg" Filter="配置文件(*.psccfg)|*.psccfg" Title="保存配置文件" />
Expand Down

0 comments on commit 005035d

Please sign in to comment.