Improving on this? (An on-screen (HUD) menu) in Developer Help
|
|
client var obj/hud/cursor/cursor cursecanhorz=1 cursorx=2 cursory=9 North() if(cursor) if(cursory==9) return cursory++ del(cursor) cursor=new(src) cursor.screen_loc="[cursorx],[cursory]" else ..() South() if(cursor) if(cursory==2) return cursory-- del(cursor) cursor=new(src) cursor.screen_loc="[cursorx],[cursory]" Center() if(cursor) world<<"HAHA " West() if(cursor && cursecanhorz) if(cursorx<=2) return else cursorx-=5 del(cursor) cursor=new(src) cursor.screen_loc="[cursorx],[cursory]" East() if(cursor && cursecanhorz) if(cursorx>=7) return else cursorx+=5 del(cursor) cursor=new(src) cursor.screen_loc="[cursorx],[cursory]" Southeast() var/obj/hud/border/ bordernorth=new(src) bordersouth=new(src) bordersouthwest=new(src) bordersoutheast=new(src) borderwest=new(src) bordereast=new(src) bordernorthwest=new(src) bordernortheast=new(src) cursor=new(src) cursor.screen_loc="2,9" bordernorth.dir=NORTH bordersouth.dir=SOUTH bordersouthwest.dir=SOUTHWEST bordersoutheast.dir=SOUTHEAST borderwest.dir=WEST bordereast.dir=EAST bordernorthwest.dir=NORTHWEST bordernortheast.dir=NORTHEAST bordernorth.screen_loc="3,9 to 8,9" bordersouth.screen_loc="3,2 to 8,2" bordersouthwest.screen_loc="2,2" bordersoutheast.screen_loc="9,2" borderwest.screen_loc="2,3 to 2,8" bordereast.screen_loc="9,3 to 9,8" bordernorthwest.screen_loc="2,9" bordernortheast.screen_loc="9,9" Northwest() for(var/i in src.screen) src.cursorx=initial(src.cursorx) src.cursory=initial(src.cursory) del(i)
|
It looks like a completely mangled mess and something tells me there's a better way of doing this...
Pressing Southeast brings up the menu, while North and South will move the cursor up and down until they hit the borders of the menu (which are the limits that I set), and West and East do a similar thing but they move it by a bigger amount (5 tiles).
|
Also, make sure you group together similar aspects of your code: I think the cursor movement function could be handled by one proc rather than spread out like that, for example (the opposite could also be advised: make sure to distance dissimilar aspects of your code, but this is not something for here).
I think the bulk of your displeasure is to do with the Southeast() verb, which opens the menu. If you don't want to manually type out the coordinates, consider using a .dmm file to lay out the menu like you would a map, then copying it to the player's screen. I'm pretty sure there is a demo for it under the 'Dantom' key somewhere (edit: here you go).
What else? I dislike how you delete and recreate the cursor all the time. Why not just redraw it to the screen?
Also note that "how can I improve this" and "a better way of doing this" are vague questions. Improve in what way? Better how? To get more concrete answers, you should first answer these questions.