From VisualWorks®, Release 5i.4 of August 9, 2001 on June 28, 2002 at 4:19:47 pm
CormasModelGameInterface
CormasNS.Kernel
UI.SimpleDialog
false
none
blocks validity model selectedPlayer playersScheduling
CormasKernel-Interface
CormasNS.Kernel.CormasModelGameInterface class interface specs
decisionsSheetsControl
"UIPainter new openOnClass: self andSelector: #decisionsSheetsControl"
<resource: #canvas>
^#(#FullSpec #window: #(#WindowSpec #label: '' #min: #(#Point 152 312) #max: #(#Point 152 312) #bounds: #(#Rectangle 277 285 429 597) #flags: 4 #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue #black) #setBackgroundColor: #(#ColorValue #white)) #isEventDriven: true) #component: #(#SpecCollection #collection: #(#(#ActionButtonSpec #layout: #(#Rectangle 35 259 118 295) #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue #red)) #model: #go #label: 'Go' #style: #large #defaultable: true) #(#LabelSpec #layout: #(#Point 5 -1) #label: 'Ordonnancement des fiches' #style: #pixelDefault) #(#SequenceViewSpec #layout: #(#Rectangle 29 17 124 138) #flags: 12 #model: #playersScheduling #useModifierKeys: true #selectionType: #highlight) #(#ActionButtonSpec #layout: #(#Rectangle 3 39 25 61) #model: #moveUp #label: #up #hasCharacterOrientedLabel: false) #(#ActionButtonSpec #layout: #(#Rectangle 3 68 25 90) #model: #moveDown #label: #down #hasCharacterOrientedLabel: false) #(#InputFieldSpec #layout: #(#Rectangle 61 202 91 227) #model: #validity #alignment: #center #type: #number #formatString: '1') #(#LabelSpec #layout: #(#Point 47 182) #label: 'du modele)' #style: #pixelDefault) #(#LabelSpec #layout: #(#Point 8 171) #label: '(nombre de pas de temps' #style: #pixelDefault) #(#CompositeSpecCollection #collection: #(#(#LabelSpec #layout: #(#Point 0 0) #label: 'Duree de validite des fiches' #style: #pixelDefault)) #compositeSpec: #(#CompositeSpec #layout: #(#Rectangle 5 161 147 181))))))
decisionsSheetValidation
"UIPainter new openOnClass: self andSelector: #decisionsSheetValidation"
<resource: #canvas>
^#(#FullSpec #window: #(#WindowSpec #label: '' #min: #(#Point 262 53) #max: #(#Point 262 53) #bounds: #(#Rectangle 234 326 496 379) #flags: 4 #colors: #(#LookPreferences #setForegroundColor: #(#ColorValue #black) #setBackgroundColor: #(#ColorValue #white)) #isEventDriven: true) #component: #(#SpecCollection #collection: #(#(#ActionButtonSpec #layout: #(#Rectangle 155 5 259 35) #model: #delete #label: 'Effacer la fiche' #style: #pixelDefault #defaultable: true) #(#ActionButtonSpec #layout: #(#Rectangle 4 5 108 35) #model: #validate #label: 'Enregistrer la fiche' #style: #pixelDefault #defaultable: true))))
CormasNS.Kernel.CormasModelGameInterface class resources
down
"UIMaskEditor new openOnClass: self andSelector: #down"
<resource: #image>
^CachedImage on: (Image extent: 32@32 depth: 1 bitsPerPixel: 1 palette: MonoMappedPalette blackWhite usingBits: #[255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 224 7 255 255 240 15 255 255 248 31 255 255 252 63 255 255 254 127 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255])
menuDecisionsSheet
"MenuEditor new openOnClass: self andSelector: #menuDecisionsSheet"
<resource: #menu>
^#(#Menu #(
#(#MenuItem
#rawLabel: ''
#labelImage: #(#ResourceRetriever #UIPalette #selectIconImage ) )
#(#MenuItem
#rawLabel: 'Decisions sheet'
#enabled: false
#nameKey: #DecisionsSheet
#submenu: #(#Menu #(
#(#MenuItem
#rawLabel: 'Events'
#nameKey: #Events
#value: #events ) ) #(1 ) nil ) ) ) #(2 ) nil ) decodeAsLiteralArray
up
"UIMaskEditor new openOnClass: self andSelector: #up"
<resource: #image>
^CachedImage on: (Image extent: 32@32 depth: 1 bitsPerPixel: 1 palette: MonoMappedPalette blackWhite usingBits: #[255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 254 127 255 255 252 63 255 255 248 31 255 255 240 15 255 255 224 7 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 252 63 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255])
CormasNS.Kernel.CormasModelGameInterface blocks
initBlocks
| inputFields labels |
self blocks: Dictionary new.
(self builder namedComponents values
select: [:x | x widget class = CompositePart]) do:
[:x |
self blocks at: x spec name put: Dictionary new.
inputFields := OrderedCollection new.
labels := OrderedCollection new.
x widget components do:
[:i |
i spec name notNil ifTrue:
[(i widget class = InputFieldView
or: [i widget class inheritsFrom: CheckButtonView])
ifTrue: [inputFields add: i spec name]
ifFalse: [labels add: i spec name]]].
(self blocks at: x spec name) at: #inputFields put: inputFields.
(self blocks at: x spec name) at: #labels put: labels].
"check consistency for blocks names"
self model playersNames do:
[:pn |
(self model playersBlocks at: pn)
do: [:bn | (self blocks keys includes: bn) ifFalse: [self halt]]]
majBlock: aBlockName
((self blocks at: aBlockName) at: #inputFields) do:
[:aSpecName |
(self model decisionsSheets at: self selectedPlayer) at: aSpecName
put: (self perform: aSpecName) value].
mazBlock2: aBlockName
| nullValue |
((self blocks at: aBlockName) at: #inputFields) do:
[:aSpecName |
((self builder namedComponents at: aSpecName) widget model value
isKindOf: Number) ifTrue: [nullValue := 0].
((self builder namedComponents at: aSpecName) widget model value
isKindOf: String) ifTrue: [nullValue := ''].
((self builder namedComponents at: aSpecName) widget model value
isKindOf: Symbol) ifTrue: [nullValue := #?].
((self builder namedComponents at: aSpecName) widget model value
isKindOf: Boolean) ifTrue: [nullValue := false].
nullValue isNil
ifTrue: [self halt]
ifFalse: [(self perform: aSpecName) value: nullValue]]
mazBlock: aBlockName
| nullValue |
((self blocks at: aBlockName) at: #inputFields) do:
[:aSpecName |
((self builder namedComponents at: aSpecName) widget model value
isKindOf: Number) ifTrue: [nullValue := 0].
((self builder namedComponents at: aSpecName) widget model value
isKindOf: String) ifTrue: [nullValue := ''].
((self builder namedComponents at: aSpecName) widget model value
isKindOf: Symbol) ifTrue: [nullValue := #?].
((self builder namedComponents at: aSpecName) widget model value
isKindOf: Boolean) ifTrue: [nullValue := false].
nullValue isNil
ifTrue: [self halt]
ifFalse: [(self perform: aSpecName) value: nullValue]]
resetBlock: aBlockName
(self model decisionsSheets at: self selectedPlayer) isEmpty ifFalse: [((self blocks at: aBlockName)
at: #inputFields)
do: [:aSpecName | (self perform: aSpecName)
value: ((self model decisionsSheets at: self selectedPlayer)
at: aSpecName)]]
setInvisibleBlock: aBlockName
(self blocks at: aBlockName)
do: [:list | list do: [:specName | (self builder namedComponents at: specName) beInvisible]]
setVisibleBlock: aBlockName
aBlockName ~= #Events
ifTrue:
[(self blocks at: aBlockName) do:
[:list |
list
do: [:specName | (self builder namedComponents at: specName) beVisible]]]
ifFalse:
[self blocks keysAndValuesDo:
[:k :v |
k = #Events
ifTrue: [v do: [:list | list do: [:specName | (self builder namedComponents at: specName) beVisible]]]
ifFalse: [v do: [:list | list do: [:specName | (self builder namedComponents at: specName) beInvisible]]]]]
CormasNS.Kernel.CormasModelGameInterface initialize
initialize
super initialize.
self playersScheduling selectionIndexHolder onChangeSend: #resetDecisionsSheet to: self
initPlayersBlocks
self subclassResponsibility
postBuildWith: aBuilder
self initBlocks.
self buildMenuDecisionsSheet.
super postBuildWith: aBuilder
CormasNS.Kernel.CormasModelGameInterface actions
delete
| newList |
self selectedPlayer notNil ifTrue:
[self blocks keys do: [:b | self mazBlock: b].
self updateDecisionsSheet: self selectedPlayer.
(self playersScheduling list includes: self selectedPlayer) ifTrue:
[newList := self playersScheduling list.
newList remove: self selectedPlayer.
self selectedPlayer = 'Events' ifTrue:
[(newList includes: self lineSep)
ifTrue: [newList remove: self lineSep]
ifFalse: [self halt]].
self playersScheduling list: newList.
(((self builder menuAt: #menuDecisionsSheet) atNameKey: #DecisionsSheet)
submenu atNameKey: self selectedPlayer asSymbol) enable.
self selectedPlayer: nil]]
go
self model runDecisionsSheets.
self model repetitionDecisionsSheets: self validity value - 1.
self accept value: true
moveDown
| selection orderedList indice itemSuiv extra |
selection := self playersScheduling selection.
(selection = 'Events' or: [selection = self lineSep]) ifFalse:
[indice := self playersScheduling selectionIndexHolder value.
extra := (self playersScheduling list includes: self lineSep) ifTrue: [2] ifFalse: [0].
(selection notNil and: [indice < (self playersScheduling list size - extra)])
ifTrue:
[orderedList := self playersScheduling list asOrderedCollection.
itemSuiv := orderedList at: indice + 1.
orderedList remove: selection.
orderedList add: selection after: itemSuiv.
self playersScheduling list: orderedList.
self playersScheduling selection: selection]]
moveUp
| selection orderedList indice itemPrec |
selection := self playersScheduling selection.
(selection = 'Events' or: [selection = self lineSep]) ifFalse:
[indice := self playersScheduling selectionIndexHolder value.
(selection notNil and: [indice ~= 1]) ifTrue:
[orderedList := self playersScheduling list asOrderedCollection.
itemPrec := orderedList at: indice - 1.
orderedList remove: selection.
orderedList add: selection before: itemPrec.
self playersScheduling list: orderedList.
self playersScheduling selection: selection]]
open
accept := false asValue.
cancel := false asValue.
close := false asValue.
super open
quit
self accept value: true
validate
| newList sp |
self selectedPlayer notNil
ifTrue:
[sp := self selectedPlayer.
self updateDecisionsSheet: sp.
(self playersScheduling list includes: self selectedPlayer)
ifFalse:
[newList := self playersScheduling list.
self selectedPlayer = 'Events'
ifTrue:
[newList add: self lineSep.
newList add: sp]
ifFalse: [newList addFirst: sp].
self playersScheduling list: newList.
self selectedPlayer: sp.
self playersScheduling selection: self selectedPlayer.
(((self builder menuAt: #menuDecisionsSheet)
atNameKey: #DecisionsSheet) submenu atNameKey: self selectedPlayer asSymbol) disable]]
CormasNS.Kernel.CormasModelGameInterface aspects
lineSep
^'-----------'
playersScheduling
"This method was generated by UIDefiner. Any edits made here
may be lost whenever methods are automatically defined. The
initialization provided below may have been preempted by an
initialize method."
^playersScheduling isNil
ifTrue: [playersScheduling := SelectionInList new]
ifFalse: [playersScheduling]
validity
^validity isNil ifTrue: [validity := 1 asValue] ifFalse: [validity]
CormasNS.Kernel.CormasModelGameInterface decisions sheets
eraseDecisionsSheet
self model updateName.
self blocks keys do:
[:bn |
self setInvisibleBlock: bn.
self mazBlock: bn]
events
(self blocks includesKey: #Events)
ifTrue:
[self model updateName: 'Events'.
self blocks keys do: [:bn | self setInvisibleBlock: bn].
self setVisibleBlock: #Events.
self resetBlock: #Events]
ifFalse: [self halt]
resetDecisionsSheet
self playersScheduling selection = self lineSep
ifTrue: [^self playersScheduling selection: nil].
self playersScheduling selection isNil
ifTrue: [self eraseDecisionsSheet]
ifFalse: [self resetDecisionsSheet: self playersScheduling selection]
resetDecisionsSheet: aName
self model updateName: aName.
(self model playersBlocks includesKey: aName)
ifTrue:
[(self blocks includesKey: 'Events')
ifTrue: [self setInvisibleBlock: 'Events'].
self blocks keys do: [:bn | ((self model playersBlocks at: aName)
includes: bn)
ifTrue:
[self setVisibleBlock: bn.
self resetBlock: bn]
ifFalse: [self setInvisibleBlock: bn]]]
ifFalse: [aName = 'Events'
ifTrue:
[self setVisibleBlock: #Events.
self resetBlock: #Events]
ifFalse: [self halt]]
updateDecisionsSheet: playerName
playerName = 'Events'
ifTrue: [self majBlock: #Events]
ifFalse:
[(self model playersBlocks at: playerName)
do: [:b | self majBlock: b asSymbol]]
CormasNS.Kernel.CormasModelGameInterface accessing
blocks
^blocks isNil ifTrue: [Dictionary new] ifFalse: [blocks]
blocks: anObject
blocks := anObject
model
^model
model: anObject
model := anObject
selectedPlayer
^selectedPlayer
selectedPlayer: anObject
selectedPlayer := anObject
CormasNS.Kernel.CormasModelGameInterface menu
buildMenuDecisionsSheet
| updatedMenu |
updatedMenu := ((self builder menuAt: #menuDecisionsSheet) atNameKey: #DecisionsSheet)
submenu.
self model playersNames do:
[:pn |
updatedMenu addItem: (MenuItem labeled: pn asString)
value: [self resetDecisionsSheet: pn]
nameKey: pn asSymbol]