【删除按钮操作】

This commit is contained in:
weizhihong 2023-09-13 10:29:04 +08:00
parent 6c8b2e7711
commit 9d37273d91
3 changed files with 1 additions and 120 deletions

View File

@ -1,15 +0,0 @@
package components
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/components/cstate"
)
// 按钮状态组件
var ButtonStateComponent = ecs.NewComponentType[cstate.ButtonState]()
// 按钮操作组件
var ButtonPressOperatingComponent = ecs.NewComponentType[cstate.ButtonPressOperating]()
// 按钮确认组件
var ButtonConfirmOperatingComponent = ecs.NewComponentType[cstate.ButtonConfirmOperating]()

@ -1 +1 @@
Subproject commit c3b9d965c607a2f29e0bdc586aba6851d4f29f13
Subproject commit 8ffea356da60f2811eed5735c5733c0a24b0fbea

View File

@ -1,104 +0,0 @@
package system
import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
)
// 按钮系统
type ButtonSystem struct {
}
// 按钮组件
var btnIdCom, btnStaCom, btnPreOperCom, btnConOperCom = components.DeviceIdentityComponent,
components.ButtonStateComponent, components.ButtonPressOperatingComponent, components.ButtonConfirmOperatingComponent
// 查询
var btnIdQuery = ecs.NewQuery(filter.Contains(btnIdCom))
var btnUpdateQuery = ecs.NewQuery(filter.Contains(btnStaCom, btnPreOperCom, btnConOperCom))
func NewButtonSystem() *ButtonSystem {
return &ButtonSystem{}
}
// 按钮操作
func PressDownAndUpButton(w ecs.World, btnId string, down bool) bool {
buttonEntry := queryButton(w, btnId)
if buttonEntry == nil {
return false
}
t, b := getButtonBaseInfo(btnId)
if !buttonEntry.HasComponent(btnPreOperCom) { // 操作组件
buttonEntry.AddComponent(btnPreOperCom)
}
preOper := btnPreOperCom.Get(buttonEntry)
preOper.Start, preOper.Down, preOper.NeedConfirm, preOper.OperateTime = true, down, b, t
return true
}
// 确认操作
func ConfirmButton(w ecs.World, btnId string, confirm bool) bool {
buttonEntry := queryButton(w, btnId)
if buttonEntry == nil {
return false
}
if !buttonEntry.HasComponent(btnConOperCom) { // 确认组件
buttonEntry.AddComponent(btnConOperCom)
}
conOper := btnConOperCom.Get(buttonEntry)
conOper.Confirm, conOper.Cancel = confirm, !confirm
return true
}
// 更新按钮状态
func (bs *ButtonSystem) Update(w ecs.World) {
btnUpdateQuery.Each(w, func(e *ecs.Entry) {
if e.HasComponent(btnPreOperCom) {
btnPreOper := btnPreOperCom.Get(e)
if btnPreOper.Start { // 按钮开始操作
if btnPreOper.OperateTime <= 0 { // 按钮操作时间大于0
btnPreOper.Start, btnPreOper.OperateTime = false, 0
} else {
btnPreOper.OperateTime -= int64(w.Tick())
if btnPreOper.NeedConfirm {
conOper := btnConOperCom.Get(e)
if e.HasComponent(btnConOperCom) && (conOper.Cancel || conOper.Confirm) {
if conOper.Confirm {
btnSta := btnStaCom.Get(e)
btnSta.PressDown = btnPreOper.Down
}
btnPreOper.Start, btnPreOper.OperateTime = false, 0
conOper.Cancel, conOper.Confirm = false, false
e.RemoveComponent(btnPreOperCom)
e.RemoveComponent(btnConOperCom)
}
} else {
btnSta := btnStaCom.Get(e)
btnSta.PressDown = btnPreOper.Down
btnPreOper.Start, btnPreOper.OperateTime = false, 0
e.RemoveComponent(btnPreOperCom)
}
}
} else {
e.RemoveComponent(btnPreOperCom)
}
}
})
}
// 查找按钮
func queryButton(w ecs.World, btnId string) *ecs.Entry {
var buttonEntry *ecs.Entry = nil
btnIdQuery.Each(w, func(e *ecs.Entry) {
if id := btnIdCom.Get(e).Id; id == btnId {
buttonEntry = e
}
})
return buttonEntry
}
// 获取按钮设置信息
func getButtonBaseInfo(btnId string) (int64, bool) {
return 15, false
}