Web版吉里吉里SDL2の[edit]タグで日本語入力ができない問題を一応解決する、LinkEditLayerを誇張するマクロ(TJSスクリプト)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Licence CC0 / author:@xyx0no646 | |
;ご自由にお使いください | |
[iscript] | |
// LinkEditLayerを誇張する。 | |
// Emscriptenの場合は、ClickされたらJavaScriptのPromptを出す | |
// それ以外はただのLinkEditLayer | |
// 2021/8/26 更新 文字列のEvalを避け、windowコンテキストを持って来るようにする | |
// キャンセル時の挙動を改善 | |
class LinkEditLayer extends EditLayer | |
{ | |
// メッセージレイヤに「リンク」として管理されるための | |
// 単一行編集レイヤ | |
var linkNum; // リンク番号 | |
var exp; // 式 | |
function onClick(){ | |
// 全吉里吉里共通のクリック処理 | |
super.onClick(...); | |
// Emscriptenの場合は特別処理! | |
if(System.platformName=="Emscripten") { | |
var words = Edit_text; | |
while(this.Edit_selStart !== 0) { | |
this.deleteBeforeCaret(); | |
} | |
var js = KirikiriEmscriptenInterface.evalJS('window'); | |
var result = js.prompt('入力してください',words); | |
if (typeof result == 'String') { | |
words = result; | |
} | |
this.insertCharacter(words); | |
} | |
} | |
function LinkEditLayer(win, par) | |
{ | |
// コンストラクタ | |
super.EditLayer(...); | |
joinFocusChain = false; // フォーカスチェーンには参加しない | |
hint = ""; | |
} | |
function finalize() | |
{ | |
super.finalize(...); | |
} | |
function assign(src) | |
{ | |
super.assign(src); | |
linkNum = src.linkNum; | |
exp = src.exp; | |
} | |
function onKeyDown(key, shift, process) | |
{ | |
// 縦書きの時は右と左を入れ替える | |
if(Edit_vertical) | |
{ | |
if(key == VK_LEFT) key = VK_RIGHT; | |
else if(key == VK_RIGHT) key = VK_LEFT; | |
} | |
super.onKeyDown(key, shift, process); | |
} | |
function onSearchPrevFocusable(layer) | |
{ | |
super.onSearchPrevFocusable(parent.findPrevFocusable(this, layer)); | |
} | |
function onSearchNextFocusable(layer) | |
{ | |
super.onSearchNextFocusable(parent.findNextFocusable(this, layer)); | |
} | |
function onFocus(prevfocused, direction) | |
{ | |
parent.keyLink = linkNum; | |
super.onFocus(...); | |
} | |
function commit() | |
{ | |
kag.inputTemp = text; | |
Scripts.eval(("(" + exp + ") = kag.inputTemp")); | |
} | |
} | |
[endscript] | |
;コピペ時は重複注意 | |
[return] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment