制作一款打飛機游戲27:精靈編輯器UI

繼續開發我們的編輯器——Sprit Edit。我們已經創建了這個小編輯器,它可以顯示很多精靈(sprites),并且我們可以遍歷所有精靈。這真的很棒,我們可以創建新的精靈,這也不錯。但是,唉,我們目前還不能編輯單個精靈。這就是我們要做的事情——創建一個用戶界面(UI)來編輯單個精靈。

編輯器的設計理念

這次,我的想法是,當你跳轉到一個精靈時,我想看到精靈的所有值,并且能夠單獨編輯每個值。這有點像垂直布局,而不是水平布局,因為水平布局最終會因為空間不足而顯得混亂,特別是當數字很長時。而且,我認為重要的是,當你編輯時,你應該能看到你正在編輯的內容,這樣才有即時的反饋。

實現過程

首先,我們要在頂部菜單添加一個項目,顯示當前正在編輯的精靈的名稱。然后,我們要列出當前精靈的所有值。我們需要至少顯示八個值,并且要檢查是否有nil值。

接下來,我們要為每個值添加一個文本框,并在文本框后顯示對應的標簽(如X、Y、高度等),以便用戶知道每個值代表什么。

遇到的問題與解決

在開發過程中,我遇到了一些問題。例如,當我在不同模式之間切換時,程序有時會崩潰。原因是我在切換模式后沒有刷新界面。我通過添加刷新函數解決了這個問題。

另一個問題是,當編輯nil值時,我想在文本框中顯示一個空字符串,而不是nil。這需要我在獲取數據時做一些額外的檢查。

后續計劃

現在,我們的編輯器已經可以基本工作了,但還有一些小細節需要調整。例如,我們還需要添加刪除精靈的功能,以及處理一些可能導致程序崩潰的邊界情況(如設置下一個精靈為當前精靈時導致的無限循環)。

我希望大家能發揮自己的創造力,思考如何設計自己的UI,并嘗試實現這些功能。

pico-8 cartridge // http://www.pico-8.com
version 41
__lua__
function _init()--- customize here ---#include shmup_myspr.txtfile="shmup_myspr.txt"arrname="myspr"data=mysprreload(0x0,0x0,0x2000,"cowshmup.p8")----------------------debug={}msg={}_drw=draw_list_upd=update_listmenuitem(1,"export",export)curx=1cury=1scrolly=0scrollx=0poke(0x5f2d, 1)
endfunction _draw()_drw()if #msg>0 thenbgprint(msg[1].txt,64-#msg[1].txt*2,80,14)msg[1].t-=1if msg[1].t<=0 thendeli(msg,1)end  end-- debug --cursor(4,4)color(8)for txt in all(debug) doprint(txt)end
endfunction _update60()dokeys()mscroll=stat(36)_upd()
endfunction dokeys()if stat(30) thenkey=stat(31)if key=="p" thenpoke(0x5f30,1)endelsekey=nilendend
-->8
--draw
function draw_edit()-- backgroundfillp(0b11001100001100111100110000110011)rectfill(0,0,127,127,33)fillp(?)line(63,0,63,127,13)line(0,63,127,63,13)fillp()draw_menu()-- draw spriteif selspr thenmspr(selspr,63,63)end-- blinking dotif (time()*2)%1<0.5 thenpset(63,63,rnd({8,13,7,15}))end
endfunction draw_list()fillp(0b11001100001100111100110000110011)rectfill(0,0,127,127,33)fillp(?)line(63,0,63,127,13)line(0,63,127,63,13)fillp()draw_menu()if (time()*2)%1<0.5 thenpset(63,63,rnd({8,13,7,15}))end
endfunction draw_table()cls(2)draw_menu()
endfunction draw_menu()--spr(0,0,0,16,16)if menu thenfor i=1,#menu dofor j=1,#menu[i] dolocal mymnu=menu[i][j]local c=mymnu.c or 13if i==cury and j==curx thenc=7if _upd==upd_type thenc=0endendbgprint(mymnu.w,mymnu.x+scrollx,mymnu.y+scrolly,13)   bgprint(mymnu.txt,mymnu.x+scrollx,mymnu.y+scrolly,c) endendendif _upd==upd_type thenlocal mymnu=menu[cury][curx]local txt_bef=sub(typetxt,1,typecur-1)local txt_cur=sub(typetxt,typecur,typecur)local txt_aft=sub(typetxt,typecur+1)txt_cur=txt_cur=="" and " " or txt_cur if (time()*2)%1<0.5 thentxt_cur="\^i"..txt_cur.."\^-i"endlocal txt=txt_bef..txt_cur..txt_aftbgprint(txt,mymnu.x+scrollx,mymnu.y+scrolly,7)endend-->8
--update
function update_edit()refresh_edit()if btnp(??) thencury-=1endif btnp(??) thencury+=1endcury=(cury-1)%#menu+1cury-=mscrollcury=mid(1,cury,#menu)if cury==1 thencurx=1if btnp(??) thenselspr-=1elseif btnp(??) thenselspr+=1endselspr=mid(1,selspr,#data)	elsecurx=2endif btnp(🅾?) then_drw=draw_list_upd=update_listrefresh_list()cury=selsprcurx=1returnendif btnp(?) thenlocal mymnu=menu[cury][curx]if mymnu.cmd=="editval" then_upd=upd_typelocal s=tostr(data[mymnu.cmdy][mymnu.cmdx])if s==nil thens=""endtypetxt=stypecur=#typetxt+1typecall=enter_editendend
endfunction update_list()refresh_list()if btnp(??) thencury-=1endif btnp(??) thencury+=1endcury=(cury-1)%#menu+1cury-=mscrollcury=mid(1,cury,#menu)curx=1local mymnu=menu[cury][curx]if mymnu.y+scrolly>110 thenscrolly-=4endif mymnu.y+scrolly<10 thenscrolly+=4endscrolly=min(0,scrolly)if mymnu.x+scrollx>110 thenscrollx-=2endif mymnu.x+scrollx<20 thenscrollx+=2endscrollx=min(0,scrollx)if btnp(?) thenlocal mymnu=menu[cury][curx]if mymnu.cmd=="newline" thenadd(data,{0,0,0,0,0,0})elseif mymnu.cmd=="editspr" thenselspr=mymnu.cmdy_upd=update_edit_drw=draw_editrefresh_edit()cury=1endend
endfunction update_table()refresh_table()if btnp(??) thencury-=1endif btnp(??) thencury+=1endcury=(cury-1)%#menu+1cury-=mscrollcury=mid(1,cury,#menu)if btnp(??) thencurx-=1endif btnp(??) thencurx+=1endif cury<#menu thencurx=(curx-2)%(#menu[cury]-1)+2elsecurx=1endlocal mymnu=menu[cury][curx]if mymnu.y+scrolly>110 thenscrolly-=4endif mymnu.y+scrolly<10 thenscrolly+=4endscrolly=min(0,scrolly)if mymnu.x+scrollx>110 thenscrollx-=2endif mymnu.x+scrollx<20 thenscrollx+=2endscrollx=min(0,scrollx)if btnp(?) thenlocal mymnu=menu[cury][curx]if mymnu.cmd=="edit" then_upd=upd_typetypetxt=tostr(mymnu.txt)typecur=#typetxt+1typecall=enter_tableelseif mymnu.cmd=="newline" thenadd(data,{0})  elseif mymnu.cmd=="newcell" thenadd(data[mymnu.cmdy],0)endend
endfunction upd_type()if key thenif key=="\r" then-- enter   poke(0x5f30,1)typecall()returnelseif key=="\b" then--backspaceif typecur>1 thenif typecur>#typetxt thentypetxt=sub(typetxt,1,#typetxt-1)elselocal txt_bef=sub(typetxt,1,typecur-2)local txt_aft=sub(typetxt,typecur)typetxt=txt_bef..txt_aftendtypecur-=1endelseif typecur>#typetxt thentypetxt..=keyelselocal txt_bef=sub(typetxt,1,typecur-1)local txt_aft=sub(typetxt,typecur)typetxt=txt_bef..key..txt_aftendtypecur+=1endendif btnp(??) thentypecur-=1endif btnp(??) thentypecur+=1endtypecur=mid(1,typecur,#typetxt+1)
end
-->8
--toolsfunction bgprint(txt,x,y,c)print("\#0"..txt,x,y,c)
endfunction split2d(s)local arr=split(s,"|",false)for k, v in pairs(arr) doarr[k] = split(v)endreturn arr
endfunction mspr(si,sx,sy)local ms=myspr[si]sspr(ms[1],ms[2],ms[3],ms[4],sx-ms[5],sy-ms[6],ms[3],ms[4],ms[7]==1)if ms[7]==2 thensspr(ms[1],ms[2],ms[3],ms[4],sx-ms[5]+ms[3],sy-ms[6],ms[3],ms[4],true)endif ms[8] thenmspr(ms[8],sx,sy)end
endfunction spacejam(n)local ret=""for i=1,n doret..=" "endreturn ret
end
-->8
--i/o
function export()local s=arrname.."=split2d\""for i=1,#data doif i>1 thens..="|"endfor j=1,#data[i] doif j>1 thens..=","ends..=data[i][j]endends..="\""printh(s,file,true)add(msg,{txt="exported!",t=120})--debug[1]="exported!"
end
-->8
--ui
function refresh_edit()menu={}add(menu,{{txt="< sprite "..selspr.." >",w="",cmd="sprhead",x=2,y=2}})local lab={"  x:","  y:","wid:","hgt:"," ox:"," oy:"," fx:","nxt:"}for i=1,8 dolocal s=tostr(data[selspr][i])if s==nil thens="[nil]"endadd(menu,{{txt=lab[i],w="    ",x=2,y=3+i*7},{txt=s,w=spacejam(#s),cmd="editval",cmdy=selspr,cmdx=i,x=2+16,y=3+i*7}}) endendfunction refresh_list()menu={}for i=1,#data dolocal lne={}local linemax=#data[i]if i==cury thenlinemax+=1  endadd(lne,{txt="spr "..i,w="",cmd="editspr",cmdy=i,x=2,y=-4+6*i})add(menu,lne)endadd(menu,{{txt=" + ",w="   ",cmd="newline",x=2,y=-4+6*(#data+1)+2, }})
endfunction refresh_table()menu={}for i=1,#data dolocal lne={}local linemax=#data[i]if i==cury thenlinemax+=1  endadd(lne,{txt=i,w="   ",cmd="",x=4,y=-4+8*i,c=2  })for j=1,linemax doif j==#data[i]+1 thenadd(lne,{txt="+",w=" ",cmd="newcell",cmdy=i,x=-10+14*(j+1),y=-4+8*i, })elseadd(lne,{txt=data[i][j],cmd="edit",cmdx=j,cmdy=i,x=-10+14*(j+1),y=-4+8*i,w="   "})endendadd(menu,lne)endadd(menu,{{txt=" + ",w="   ",cmd="newline",x=4,y=-4+8*(#data+1), }})
endfunction enter_table()local mymnu=menu[cury][curx]local typeval=tonum(typetxt)if typeval==nil thenif mymnu.cmdx==#data[mymnu.cmdy] and typetxt=="" then--delete celldeli(data[mymnu.cmdy],mymnu.cmdx)if mymnu.cmdx==1 thendeli(data,mymnu.cmdy)end_upd=update_tablereturnend  typeval=0enddata[mymnu.cmdy][mymnu.cmdx]=typeval_upd=update_tablerefresh_table()
endfunction enter_edit()local mymnu=menu[cury][curx]local typeval=tonum(typetxt)if typeval==nil thentypeval=0enddata[mymnu.cmdy][mymnu.cmdx]=typeval_upd=update_editrefresh_edit()
end
__gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
0000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/903287.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/903287.shtml
英文地址,請注明出處:http://en.pswp.cn/news/903287.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

k8s(9) — zookeeper集群部署(親和性、污點與容忍測試)

一、部署思路 1、前期設想 zookeeper集群至少需要運行3個pod集群才能夠正常運行&#xff0c;考慮到節點會有故障的風險這個3個pod最好分別運行在&#xff13;個不同的節點上(為了實現這一需要用到親和性和反親和性概念)&#xff0c;在部署的時候對zookeeper運行的pod打標簽加…

WXT+Vue3+sass+antd+vite搭建項目開發chrome插件

WXTVue3sassantdvite搭建項目開發chrome插件 前言一、初始化項目二、項目配置調整三、options頁面配置四、集成antd五、集成sass六、環境配置七、代碼注入 vue3&#xff1a;https://cn.vuejs.org/ axios&#xff1a;https://www.axios-http.cn/docs/api_intro antd&#xff1a;…

JSAPI2.4——正則表達式

一、語法 const str 一二三四五六七八九十 //判斷內容 const reg /二/ //判斷條件 console.log(reg.test(str)); //檢查 二、test與exec方法的區別 test方法&#xff1a;用于判斷是否符合規則的字符串&#xff0c;返回值是布爾值 exec方法&…

燃氣用戶檢修工考試精選題

燃氣用戶檢修工考試精選題&#xff1a; 我國國家標準規定民用天然氣中硫化氫含量最高允許濃度是&#xff08; &#xff09;。 A. 20mg/m B. 15mg/m C. 5mg/m D. 50mg/m 答案&#xff1a;A 城市燃氣應具有可以察覺的臭味&#xff0c;當無毒燃氣泄漏到空氣中&#xff0c;達到爆炸…

【前端】1h 搞定 TypeScript 教程_只說重點

不定期更新&#xff0c;建議關注收藏點贊。 目錄 簡介使用基本類型、類型推斷和類型注解接口、類型別名、聯合類型類與繼承泛型GenericsReact 與 TS 進階高級類型裝飾器Decorators模塊系統TypeScript 編譯選項 簡介 TypeScript&#xff08;簡稱 TS&#xff09;是一種由微軟開發…

MyBatis 參數綁定

一、MyBatis 參數綁定機制 1.1 核心概念 當 Mapper 接口方法接收多個參數時&#xff0c;MyBatis 提供三種參數綁定方式&#xff1a; 默認參數名&#xff1a;arg0、arg1&#xff08;Java 8&#xff09;或 param1、param2Param 注解&#xff1a;顯式指定參數名稱POJO/DTO 對象…

【解決方案】Linux解決CUDA安裝過程中GCC版本不兼容

Linux解決CUDA安裝過程中GCC版本不兼容 目錄 問題描述 解決方法 安裝后配置 問題描述 Linux環境下安裝 CUDA 時&#xff0c;運行sudo sh cuda_10.2.89_440.33.01_linux.run命令出現 “Failed to verify gcc version.” 的報錯&#xff0c;提示 GCC 版本不兼容&#xff0c;查…

人工智能數學基礎(一):人工智能與數學

在人工智能領域&#xff0c;數學是不可或缺的基石。無論是算法的設計、模型的訓練還是結果的評估&#xff0c;都離不開數學的支持。接下來&#xff0c;我將帶大家深入了解人工智能數學基礎&#xff0c;包括微積分、線性代數、概率論、數理統計和最優化理論&#xff0c;并通過 P…

Shell腳本-嵌套循環應用案例

在Shell腳本編程中&#xff0c;嵌套循環是一種強大的工具&#xff0c;可以用于處理復雜的任務和數據結構。通過在一個循環內部再嵌套另一個循環&#xff0c;我們可以實現對多維數組、矩陣操作、文件處理等多種高級功能。本文將通過幾個實際的應用案例來展示如何使用嵌套循環解決…

勘破養生偽常識,開啟科學養生新篇

?在養生潮流風起云涌的當下&#xff0c;各種養生觀點和方法層出不窮。但其中有不少是缺乏科學依據的偽常識&#xff0c;若不加分辨地盲目跟從&#xff0c;不僅難以實現養生目的&#xff0c;還可能損害健康。因此&#xff0c;勘破這些養生偽常識&#xff0c;是邁向科學養生的關…

Nacos-3.0.0適配PostgreSQL數據庫

&#x1f9d1; 博主簡介&#xff1a;CSDN博客專家&#xff0c;歷代文學網&#xff08;PC端可以訪問&#xff1a;https://literature.sinhy.com/#/?__c1000&#xff0c;移動端可微信小程序搜索“歷代文學”&#xff09;總架構師&#xff0c;15年工作經驗&#xff0c;精通Java編…

機器學習第三篇 模型評估(交叉驗證)

Sklearn:可以做數據預處理、分類、回歸、聚類&#xff0c;不能做神經網絡。原始的工具包文檔&#xff1a;scikit-learn: machine learning in Python — scikit-learn 1.6.1 documentation數據集:使用的是MNIST手寫數字識別技術&#xff0c;大小為70000&#xff0c;數據類型為7…

如何在 IntelliJ IDEA 中編寫 Speak 程序

在當今數字化時代&#xff0c;語音交互技術越來越受到開發者的關注。如果你想在 IntelliJ IDEA&#xff08;一個強大的集成開發環境&#xff09;中編寫一個語音交互&#xff08;Speak&#xff09;程序&#xff0c;那么本文將為你提供詳細的步驟和指南。 一、環境準備 在開始編…

AI大模型學習十四、白嫖騰訊Cloud Studio AI環境 通過Ollama+Dify+DeepSeek構建生成式 AI 應用-接入DeepSeek大模型

一、說明 需要閱讀 AI大模型學習十三、白嫖騰訊Cloud Studio AI環境 通過OllamaDifyDeepSeek構建生成式 AI 應用-安裝-CSDN博客https://blog.csdn.net/jiangkp/article/details/147580344?spm1011.2415.3001.5331 我們今天干點啥呢&#xff0c;跟著官網走 模型類型 在 Dify…

《Astro 3.0島嶼架構讓內容網站“脫胎換骨”》

內容優先的網站越來越成為主流。無論是新聞資訊、知識博客&#xff0c;還是電商產品展示&#xff0c;用戶都希望能快速獲取所需內容&#xff0c;這對網站的性能和體驗提出了極高要求。而Astro 3.0的島嶼架構&#xff0c;就像是為內容優先網站量身定制的一把神奇鑰匙&#xff0c…

在 UniApp 中實現 App 與 H5 頁面的跳轉及通信

在移動應用開發中&#xff0c;內嵌 H5 頁面或與外部網頁交互是常見需求。UniApp 作為跨平臺框架&#xff0c;提供了靈活的方式實現 App 與 H5 的跳轉和雙向通信。本文將詳細講解實現方法&#xff0c;并提供可直接復用的代碼示例。 文章目錄 一、 App 內嵌 H5 頁面&#xff08;使…

springboot 實現敏感信息脫敏

記錄于2025年4月28號晚上--梧州少帥 1. 定義枚舉類&#xff1a; public enum DesensitizeType {NAME, EMAIL } 2. 創建自定義注解&#xff1a; 用于標記需要脫敏的字段及其類型。 Retention(RetentionPolicy.RUNTIME) JacksonAnnotationsInside JsonSerialize(using Desen…

SNMP協議之詳解(Detailed Explanation of SNMP Protocol)

SNMP協議之詳解 一、前言 SNMP&#xff0c;被形象地喻為網絡世界大的工具箱&#xff0c;使他們能的“智慧守護者”&#xff0c;它為網絡管理員裝備了一套功能強夠實現對網絡設備狀態的實時監控、性能數據的全面收集、遠程配置的靈活管理以及故障事件的即時響應。借助SNMP&…

SpeedyAutoLoot

SpeedyAutoLoot自動拾取插件 SpeedyAutoLoot.lua local AutoLoot CreateFrame(Frame)SpeedyAutoLootDB SpeedyAutoLootDB or {} SpeedyAutoLootDB.global SpeedyAutoLootDB.global or {}local BACKPACK_CONTAINER BACKPACK_CONTAINER local LOOT_SLOT_CURRENCY LOOT_SLOT…

xe-upload上傳文件插件

1.xe-upload地址&#xff1a;文件選擇、文件上傳組件&#xff08;圖片&#xff0c;視頻&#xff0c;文件等&#xff09; - DCloud 插件市場 2.由于開發app要用到上傳文件組件&#xff0c;uni.chooseFile在app上不兼容&#xff0c;所以找到了xe-upload&#xff0c;兼容性很強&a…