@@ -104,15 +104,10 @@ function drawRectangle(ctx, coordsA, coordsB, color) {
104104
105105
106106function refreshPlanetList ( ) {
107+ console . log ( "refreshPlanet" ) ;
107108 if ( cursorMode === CursorMode . ALL ) {
108109 showPlanetList = [ ] ;
109110 const planets = df . getMyPlanets ( ) ;
110- if ( minLevel > maxLevel ) {
111- let tmp = minLevel ;
112- minLevel = maxLevel ;
113- maxLevel = tmp ;
114- }
115-
116111 for ( let i in planets ) {
117112 let p = planets [ i ] ;
118113 if ( ! p ?. location ?. coords ) continue ;
@@ -124,7 +119,6 @@ function refreshPlanetList() {
124119 } else if ( cursorMode === CursorMode . RANGE ) {
125120 if ( planetRange . beginCoords === null ) return ;
126121 if ( planetRange . endCoords === null ) return ;
127- console . log ( "refreshPlanet" ) ;
128122 showPlanetList = [ ] ;
129123 let coordsA = planetRange . beginCoords ;
130124 let coordsB = planetRange . endCoords ;
@@ -138,7 +132,6 @@ function refreshPlanetList() {
138132 if ( ! p ?. location ?. coords ) continue ;
139133 if ( p . planetLevel < minLevel ) continue ;
140134 if ( p . planetLevel > maxLevel ) continue ;
141-
142135 let coords = p . location . coords ;
143136 if ( coords . x >= beginX && coords . y >= beginY && coords . x <= endX && coords . y <= endY ) {
144137 showPlanetList . push ( p ) ;
@@ -147,12 +140,18 @@ function refreshPlanetList() {
147140 }
148141}
149142
150-
151143function giftAreaPlanets ( ) {
152144 const [ toAddress , setToAddress ] = useState ( undefined ) ;
153145 const [ inMinLevel , setInMinLevel ] = useState ( minLevel ) ;
154146 const [ inMaxLevel , setInMaxLevel ] = useState ( maxLevel ) ;
155147
148+ let divStyle = {
149+ textAlign : 'center' ,
150+ justifyContent : "space-around" ,
151+ width : "100%" ,
152+ marginTop : "10px" ,
153+ } ;
154+
156155 let warningStyle = {
157156 color : 'red'
158157 } ;
@@ -173,24 +172,25 @@ function giftAreaPlanets() {
173172 let [ input , setInput ] = useState ( undefined ) ;
174173
175174 let toAddressPart = toAddress === undefined ?
176- html `< div style =${ { color :'#AED6F1' } } > not choose yet</ div > ` :
177- html `< div style =${ { color :'#F1C40F' } } > ${ toAddress } </ div > ` ;
175+ html `< div style =${ { color : '#AED6F1' } } > not choose yet</ div > ` :
176+ html `< div style =${ { color : '#F1C40F' } } > ${ toAddress } </ div > ` ;
178177
179178 let toAddressComponent =
180179 html `< div >
181-
182- < div style =${ { marginTop : "16px" , marginBottom :"16px" } } >
183-
184- < input style =${ { width : '250px' } }
185- placeholder =${ 'input lowercase address :0' }
180+ < div style =${ { marginTop : "16px" , marginBottom : "16px" } } >
181+ < input style =${ { width : '245px' } }
182+ placeholder =${ 'input receiver address :0' }
186183 onChange=${ e => {
187184 setInput ( e . target . value ) ;
188-
189185 } } > </ input >
190- ${ ' ' }
191- < button onClick =${ ( ) => {
186+
187+ < button
188+ style =${ { marginLeft : '10px' } }
189+ onClick =${ ( ) => {
192190 setToAddress ( input . toLowerCase ( ) ) ;
193191 } } > choose </ button >
192+
193+
194194 </ div >
195195 < button
196196
@@ -216,17 +216,16 @@ function giftAreaPlanets() {
216216 borderRadius : "3px" ,
217217 } ;
218218
219-
220219 const minLevelSelect = html `
221220 < select
222221 style =${ selectStyle }
223222 value =${ inMinLevel }
224223 onChange=${ async ( e ) => {
225- minLevel = Number ( e . target . value ) ;
226-
224+ let value = Number ( e . target . value ) ;
225+ minLevel = Math . min ( value , inMaxLevel ) ;
226+ maxLevel = Math . max ( value , inMaxLevel ) ;
227227 refreshPlanetList ( ) ;
228-
229- setInMinLevel ( Number ( e . target . value ) ) ;
228+ setInMinLevel ( value ) ;
230229 }
231230 }
232231 >
@@ -240,10 +239,11 @@ function giftAreaPlanets() {
240239 style =${ selectStyle }
241240 value =${ inMaxLevel }
242241 onChange=${ ( e ) => {
243- maxLevel = Number ( e . target . value ) ;
242+ let value = Number ( e . target . value ) ;
243+ minLevel = Math . min ( inMinLevel , value ) ;
244+ maxLevel = Math . max ( inMinLevel , value ) ;
244245 refreshPlanetList ( ) ;
245- setInMaxLevel ( Number ( e . target . value ) ) ;
246-
246+ setInMaxLevel ( value ) ;
247247 }
248248 }
249249 >
@@ -264,21 +264,16 @@ function giftAreaPlanets() {
264264 </ div >
265265 ` ;
266266
267-
268267 let [ selectInfo , setSelectInfo ] =
269268 useState ( "select the planet(s) you want to share" ) ;
270-
271-
269+ let [ giftInfo , setGiftInfo ] = useState ( '' ) ;
272270
273271 function selectSinglePlanet ( ) {
274-
275272 console . log ( "Select Single Planet" ) ;
276-
277273 setCursorMode ( CursorMode . SINGLE ) ;
278-
279274 showPlanetList = [ ] ;
280-
281275 setSelectInfo ( "please click one planet to share" ) ;
276+ setGiftInfo ( '' ) ;
282277 return ;
283278 }
284279
@@ -294,7 +289,9 @@ function giftAreaPlanets() {
294289 console . log ( "Select Range Planet" ) ;
295290 setCursorMode ( CursorMode . RANGE ) ;
296291 showPlanetList = [ ] ;
297- setSelectInfo ( "determine the area of planet(s) will level filter" ) ;
292+ setSelectInfo ( "determine the area of planet(s) with level filter" ) ;
293+ setGiftInfo ( '' ) ;
294+ return ;
298295 }
299296
300297
@@ -309,9 +306,11 @@ function giftAreaPlanets() {
309306
310307 function selectAllPlanet ( ) {
311308 console . log ( "Select All Planet" ) ;
312- setCursorMode ( CursorMode . All ) ;
313- showPlanetList = df . getMyPlanets ( ) ;
314- setSelectInfo ( "determine the area of planet(s) with level filter" ) ;
309+ setCursorMode ( CursorMode . ALL ) ;
310+ showPlanetList = df . getMyPlanets ( ) ;
311+ console . log ( "test=========================" ) ;
312+ setSelectInfo ( "determine all planet(s) with level filter" ) ;
313+ setGiftInfo ( '' ) ;
315314 }
316315 let selectAllButton = html `
317316 < div style =${ { marginLeft : "8px" , width : "100px" } } >
@@ -326,7 +325,6 @@ function giftAreaPlanets() {
326325 } ;
327326
328327 let selectComponent = html `< div >
329-
330328 < div style =${ { ...flexRow , marginTop : "16px" } } >
331329 ${ selectSinglePlanetButton }
332330 ${ selectRangeButton }
@@ -335,39 +333,33 @@ function giftAreaPlanets() {
335333 ${ selectInfo }
336334 </ div > ` ;
337335
338- let [ giftInfo , setGiftInfo ] = useState ( '' ) ;
339336
340- function giftPlanet ( ) {
341- console . log ( showPlanetList ) ;
342337
343- for ( let i in showPlanetList ) {
344- let p = showPlanetList [ i ] ;
338+ function giftPlanet ( ) {
339+ console . log ( showPlanetList ) ;
340+ for ( let i in showPlanetList ) {
341+ let p = showPlanetList [ i ] ;
345342 df . transferOwnership ( p . locationId , toAddress ) ;
346-
347343 }
348-
349- setGiftInfo ( "the " + showPlanetList . length + " cicled planet(s) will be shared" ) ;
350-
344+ setGiftInfo ( "the " + showPlanetList . length + " cicled planet(s) will be shared" ) ;
351345 }
352346
353-
354347 let giftComponent = html `
355- < div style =${ { marginTop : "16px" } } >
348+ < div style =${ { marginTop : "16px" } } >
356349 < button
357350 onClick =${ giftPlanet }
358351 > Gift the Planet(s)</ button >
359-
360352 < div
361- style =${ { color :"pink" } }
353+ style =${ { color : "pink" } }
362354 > ${ giftInfo } </ div >
363355 </ div > ` ;
364356
365357 return html `
366- < div >
358+ < div style = ${ divStyle } >
367359 ${ toAddressComponent }
368360 ${ selectLevelComponent }
369361 ${ selectComponent }
370- ${ giftComponent }
362+ ${ giftComponent }
371363 </ div > ` ;
372364
373365}
@@ -381,7 +373,9 @@ class Plugin {
381373 constructor ( ) {
382374 minLevel = 4 ;
383375 maxLevel = 9 ;
376+ cursorMode === CursorMode . ALL ;
384377 showPlanetList = df . getMyPlanets ( ) ;
378+ refreshPlanetList ( ) ;
385379 this . container = null ;
386380 }
387381
@@ -417,7 +411,6 @@ class Plugin {
417411 let begin = planetRange . beginCoords ;
418412 let end = planetRange . endCoords || ui . getHoveringOverCoords ( ) ;
419413
420-
421414 drawRectangle ( ctx , begin , end , "red" ) ;
422415 if ( begin != null && end != null ) {
423416 let coordsA = begin ; //planetRange.beginCoords;
@@ -429,6 +422,13 @@ class Plugin {
429422
430423 const planets = df . getMyPlanets ( ) ;
431424
425+ if ( minLevel > maxLevel ) {
426+ let tmp = minLevel ;
427+ minLevel = maxLevel ;
428+ maxLevel = tmp ;
429+ }
430+
431+
432432 for ( let i in planets ) {
433433 let p = planets [ i ] ;
434434 if ( ! p ?. location ?. coords ) continue ;
@@ -442,7 +442,6 @@ class Plugin {
442442 drawRound ( ctx , p , color , 0.7 ) ;
443443 }
444444 }
445-
446445 }
447446 }
448447 for ( let i in showPlanetList ) {
@@ -454,8 +453,8 @@ class Plugin {
454453
455454 async render ( container ) {
456455 this . container = container ;
457- container . style . width = "360px " ;
458- container . style . height = "440px " ;
456+ container . style . width = "350px " ;
457+ container . style . height = "420px " ;
459458 window . addEventListener ( "click" , this . onClick ) ;
460459 render ( html `< ${ App } /> ` , container ) ;
461460 }
0 commit comments