Advertisement
P3NG3R

uiStatusUp.py

Apr 14th, 2015
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.47 KB | None | 0 0
  1. ## #UNTESTED# Only for python 2.6 and higher
  2. ## If you want to use this with lower python version you have to replace
  3. ## the str.format conversion to "%" with their right syntax
  4. ## Line 6 is the first line of the uiStatusUp.py file
  5. ## Line 73 is the first line of the StatusUpWindow.py file
  6. import ui
  7. import player
  8. import m2net#net!!
  9. import wndMgr
  10.  
  11. class StatusUp(ui.ScriptWindow):
  12.     MAXSTAT = 90
  13.  
  14.     def __init__(self):
  15.         ui.ScriptWindow.__init__(self)
  16.         self.editLineDict = {}
  17.         self.valueDict = {}
  18.         self.gaugeDict = {}
  19.         self.Keys = {
  20.             "HTH" : "ht",
  21.             "INT" : "iq",
  22.             "STR" : "st",
  23.             "DEX" : "dx",
  24.         }
  25.         self.__LoadWindow()
  26.  
  27.     def __del__(self):
  28.         ui.ScriptWindow.__del__(self)
  29.  
  30.     def OnPressEscapeKey(self):
  31.         self.Hide()
  32.         return True
  33.  
  34.     def Destroy(self):
  35.         self.ClearDictionary()
  36.  
  37.     def __LoadWindow(self):
  38.         try:
  39.             pyScrLoader = ui.PythonScriptLoader()
  40.             pyScrLoader.LoadScriptFile(self, "UIScript/StatusUpWindow.py")
  41.         except:
  42.             import exception
  43.             exception.Abort("StatusUp.LoadWindow.LoadObject")
  44.  
  45.         try:
  46.             self.GetChild("TitleBar").SetCloseEvent(ui.__mem_func__(self.Hide))
  47.  
  48.             for key, val in self.Keys.iteritems():
  49.                 self.editLineDict[val] = self.GetChild("{0}_Add".format(key))
  50.                 self.valueDict[val] = self.GetChild("{0}_Value".format(key))
  51.                 self.gaugeDict[val] = self.GetChild("{0}_Gauge".format(key))
  52.                 self.GetChild("{0}_Plus".format(key)).SetEvent(lambda stat=val: self.AddStat(stat))
  53.  
  54.         except:
  55.             import exception
  56.             exception.Abort("StatusUp.LoadWindow.BindObject")
  57.  
  58.     def OnUpdate(self):
  59.         for key, val in self.Keys.iteritems():
  60.             tmp = player.GetStatus(eval("player.{0}".format(val.upper())))
  61.             self.valueDict[val].SetText("{0}/{1}".format(tmp, self.MAXSTAT))
  62.             self.gaugeDict[val].SetPercentage(tmp, self.MAXSTAT)
  63.  
  64.     def AddStat(self, stat):
  65.         points = int(self.editLineDict[stat].GetText())
  66.         if player.GetStatus(player.STAT) >= points:
  67.             m2net.SendChatPacket("/stat {0} {1}".format(stat, points))#net
  68.         #else:
  69.         #   chat.AppendChat(1, "Fuck off, idiot.")
  70. #
  71. ###
  72. #
  73. BOARD_HEIGHT = 250
  74. BOARD_WIDTH = 250
  75. ROOT_PATH = "d:/ymir work/ui/game/windows/"
  76. SMALL_VALUE_FILE = "d:/ymir work/ui/public/Parameter_Slot_00.sub"
  77.  
  78. window = {
  79.     "name" : "StatusupWindow",
  80.  
  81.     "x" : (SCREEN_WIDTH / 2) - (BOARD_WIDTH / 2),
  82.     "y" : (SCREEN_HEIGHT / 2) - (BOARD_HEIGHT / 2),
  83.  
  84.     "style" : ("movable", "float",),
  85.  
  86.     "width" : BOARD_WIDTH,
  87.     "height" : BOARD_HEIGHT,
  88.  
  89.     "children" :
  90.     (
  91.         {
  92.             "name" : "board",
  93.             "type" : "board",
  94.            
  95.             "x" : 0,
  96.             "y" : 0,
  97.  
  98.             "width" : BOARD_WIDTH,
  99.             "height" : BOARD_HEIGHT,
  100.  
  101.             "children" :
  102.             (
  103.                 ## Titlebar
  104.                 {
  105.                     "name" : "TitleBar",
  106.                     "type" : "titlebar",
  107.                     "style" : ("attach",),
  108.  
  109.                     "x" : 6,
  110.                     "y" : 6,
  111.  
  112.                     "width" : BOARD_WIDTH - 10,
  113.                     "color" : "yellow",
  114.  
  115.                     "children" :
  116.                     (
  117.                         {
  118.                             "name" : "TitleName",
  119.                             "type" : "text",
  120.  
  121.                             "x" : 0,
  122.                             "y" : 3,
  123.  
  124.                             "text" : "Statuspunkte",
  125.                             "horizontal_align" : "center",
  126.                             "text_horizontal_align" : "center",
  127.                         },
  128.                     ),
  129.                 },
  130.                 ## STR
  131.                 {
  132.                     "name" : "STR_Label",
  133.                     "type" : "window",
  134.                     "x" : 20,
  135.                     "y" : 32,
  136.                     "width" : BOARD_WIDTH - 20,
  137.                     "height" : 45,
  138.                     "children" :
  139.                     (
  140.                         {
  141.                             "name" : "STR_Text",
  142.                             "type" : "text",
  143.  
  144.                             "x" : 0,
  145.                             "y" : 3,
  146.  
  147.                             "text" : "Stärke (STR)",
  148.                         },
  149.                         {
  150.                             "name" : "STR_Value",
  151.                             "type" : "text",
  152.                             "x" : 0,
  153.                             "y" : 23,
  154.                             "text":"999",
  155.                             "r" : 1.0,
  156.                             "g" : 1.0,
  157.                             "b" : 1.0,
  158.                             "a" : 1.0,
  159.                         },
  160.                         {
  161.                             "name" : "STR_Plus",
  162.                             "type" : "button",
  163.                             "x" : 197,
  164.                             "y" : 23,
  165.                             "default_image" : ROOT_PATH+"btn_plus_up.sub",
  166.                             "over_image" : ROOT_PATH+"btn_plus_over.sub",
  167.                             "down_image" : ROOT_PATH+"btn_plus_down.sub",
  168.                         },
  169.                         {
  170.                             "name":"STR_Slot",
  171.                             "type":"image",
  172.  
  173.                             "x":125,
  174.                             "y":20,
  175.  
  176.                             "image" : "d:/ymir work/ui/public/parameter_slot_02.sub",
  177.                            
  178.                             "children" :
  179.                             (
  180.                                 {
  181.                                     "name" : "STR_Add",
  182.                                     "type" : "editline",
  183.  
  184.                                     "x" : 61/2,
  185.                                     "y" : 3,
  186.  
  187.                                     "width" : 20,
  188.                                     "height" : 18,
  189.  
  190.                                     "text" : "0",
  191.                                     "only_number" : 1,
  192.                                     "input_limit" : 2,
  193.                                     "enable_codepage" : 0,
  194.  
  195.                                     "r" : 1.0,
  196.                                     "g" : 1.0,
  197.                                     "b" : 1.0,
  198.                                     "a" : 1.0,
  199.                                     "text_horizontal_align" : "center",
  200.                                 },
  201.                             ),
  202.                         },
  203.                         {
  204.                             "name" : "STR_Gauge",
  205.                             "type" : "gauge",
  206.  
  207.                             "x" : 110,
  208.                             "y" : 7,
  209.  
  210.                             "width" : 100,
  211.                             "color" : "purple",
  212.                         },
  213.                     ),
  214.                 },
  215.                 {
  216.                     "name" : "DEX_Label",
  217.                     "type" : "window",
  218.                     "x" : 20,
  219.                     "y" : 82,
  220.                     "width" : BOARD_WIDTH - 20,
  221.                     "height" : 45,
  222.                     "children" :
  223.                     (
  224.                         {
  225.                             "name" : "DEX_Text",
  226.                             "type" : "text",
  227.  
  228.                             "x" : 0,
  229.                             "y" : 3,
  230.  
  231.                             "text" : "Beweglichkeit (DEX)",
  232.                         },
  233.                         {
  234.                             "name" : "DEX_Value",
  235.                             "type" : "text",
  236.                             "x" : 0,
  237.                             "y" : 23,
  238.                             "text":"999",
  239.                             "r" : 1.0,
  240.                             "g" : 1.0,
  241.                             "b" : 1.0,
  242.                             "a" : 1.0,
  243.                         },
  244.                         {
  245.                             "name" : "DEX_Plus",
  246.                             "type" : "button",
  247.                             "x" : 197,
  248.                             "y" : 23,
  249.                             "default_image" : ROOT_PATH+"btn_plus_up.sub",
  250.                             "over_image" : ROOT_PATH+"btn_plus_over.sub",
  251.                             "down_image" : ROOT_PATH+"btn_plus_down.sub",
  252.                         },
  253.                         {
  254.                             "name":"DEX_Slot",
  255.                             "type":"image",
  256.  
  257.                             "x":125,
  258.                             "y":20,
  259.  
  260.                             "image" : "d:/ymir work/ui/public/parameter_slot_02.sub",
  261.                            
  262.                             "children" :
  263.                             (
  264.                                 {
  265.                                     "name" : "DEX_Add",
  266.                                     "type" : "editline",
  267.  
  268.                                     "x" : 61/2,
  269.                                     "y" : 3,
  270.  
  271.                                     "width" : 20,
  272.                                     "height" : 18,
  273.  
  274.                                     "text" : "0",
  275.                                     "only_number" : 1,
  276.                                     "input_limit" : 2,
  277.                                     "enable_codepage" : 0,
  278.  
  279.                                     "r" : 1.0,
  280.                                     "g" : 1.0,
  281.                                     "b" : 1.0,
  282.                                     "a" : 1.0,
  283.                                     "text_horizontal_align" : "center",
  284.                                 },
  285.                             ),
  286.                         },
  287.                         {
  288.                             "name" : "DEX_Gauge",
  289.                             "type" : "gauge",
  290.  
  291.                             "x" : 110,
  292.                             "y" : 7,
  293.  
  294.                             "width" : 100,
  295.                             "color" : "blue",
  296.                         },
  297.                     ),
  298.                 },
  299.                 {
  300.                     "name" : "HTH_Label",
  301.                     "type" : "window",
  302.                     "x" : 20,
  303.                     "y" : 132,
  304.                     "width" : BOARD_WIDTH - 20,
  305.                     "height" : 45,
  306.                     "children" :
  307.                     (
  308.                         {
  309.                             "name" : "HTH_Text",
  310.                             "type" : "text",
  311.  
  312.                             "x" : 0,
  313.                             "y" : 3,
  314.  
  315.                             "text" : "Vitalität (VIT)",
  316.                         },
  317.                         {
  318.                             "name" : "HTH_Value",
  319.                             "type" : "text",
  320.                             "x" : 0,
  321.                             "y" : 23,
  322.                             "text":"999",
  323.                             "r" : 1.0,
  324.                             "g" : 1.0,
  325.                             "b" : 1.0,
  326.                             "a" : 1.0,
  327.                         },
  328.                         {
  329.                             "name" : "HTH_Plus",
  330.                             "type" : "button",
  331.                             "x" : 197,
  332.                             "y" : 23,
  333.                             "default_image" : ROOT_PATH+"btn_plus_up.sub",
  334.                             "over_image" : ROOT_PATH+"btn_plus_over.sub",
  335.                             "down_image" : ROOT_PATH+"btn_plus_down.sub",
  336.                         },
  337.                         {
  338.                             "name":"HTH_Slot",
  339.                             "type":"image",
  340.  
  341.                             "x":125,
  342.                             "y":20,
  343.  
  344.                             "image" : "d:/ymir work/ui/public/parameter_slot_02.sub",
  345.                            
  346.                             "children" :
  347.                             (
  348.                                 {
  349.                                     "name" : "HTH_Add",
  350.                                     "type" : "editline",
  351.  
  352.                                     "x" : 61/2,
  353.                                     "y" : 3,
  354.  
  355.                                     "width" : 20,
  356.                                     "height" : 18,
  357.  
  358.                                     "text" : "0",
  359.                                     "only_number" : 1,
  360.                                     "input_limit" : 2,
  361.                                     "enable_codepage" : 0,
  362.  
  363.                                     "r" : 1.0,
  364.                                     "g" : 1.0,
  365.                                     "b" : 1.0,
  366.                                     "a" : 1.0,
  367.                                     "text_horizontal_align" : "center",
  368.                                 },
  369.                             ),
  370.                         },
  371.                         {
  372.                             "name" : "HTH_Gauge",
  373.                             "type" : "gauge",
  374.  
  375.                             "x" : 110,
  376.                             "y" : 7,
  377.  
  378.                             "width" : 100,
  379.                             "color" : "red",
  380.                         },
  381.                     ),
  382.                 },
  383.                 {
  384.                     "name" : "INT_Label",
  385.                     "type" : "window",
  386.                     "x" : 20,
  387.                     "y" : 182,
  388.                     "width" : BOARD_WIDTH - 20,
  389.                     "height" : 45,
  390.                     "children" :
  391.                     (
  392.                         {
  393.                             "name" : "INT_Text",
  394.                             "type" : "text",
  395.  
  396.                             "x" : 0,
  397.                             "y" : 3,
  398.  
  399.                             "text" : "Intelligenz (INT)",
  400.                         },
  401.                         {
  402.                             "name" : "INT_Value",
  403.                             "type" : "text",
  404.                             "x" : 0,
  405.                             "y" : 23,
  406.                             "text":"999",
  407.                             "r" : 1.0,
  408.                             "g" : 1.0,
  409.                             "b" : 1.0,
  410.                             "a" : 1.0,
  411.                         },
  412.                         {
  413.                             "name" : "INT_Plus",
  414.                             "type" : "button",
  415.                             "x" : 197,
  416.                             "y" : 23,
  417.                             "default_image" : ROOT_PATH+"btn_plus_up.sub",
  418.                             "over_image" : ROOT_PATH+"btn_plus_over.sub",
  419.                             "down_image" : ROOT_PATH+"btn_plus_down.sub",
  420.                         },
  421.                         {
  422.                             "name":"INT_Slot",
  423.                             "type":"image",
  424.  
  425.                             "x":125,
  426.                             "y":20,
  427.  
  428.                             "image" : "d:/ymir work/ui/public/parameter_slot_02.sub",
  429.                            
  430.                             "children" :
  431.                             (
  432.                                 {
  433.                                     "name" : "INT_Add",
  434.                                     "type" : "editline",
  435.  
  436.                                     "x" : 61/2,
  437.                                     "y" : 3,
  438.  
  439.                                     "width" : 20,
  440.                                     "height" : 18,
  441.  
  442.                                     "text" : "0",
  443.                                     "only_number" : 1,
  444.                                     "input_limit" : 2,
  445.                                     "enable_codepage" : 0,
  446.  
  447.                                     "r" : 1.0,
  448.                                     "g" : 1.0,
  449.                                     "b" : 1.0,
  450.                                     "a" : 1.0,
  451.                                     "text_horizontal_align" : "center",
  452.                                 },
  453.                             ),
  454.                         },
  455.                         {
  456.                             "name" : "INT_Gauge",
  457.                             "type" : "gauge",
  458.  
  459.                             "x" : 110,
  460.                             "y" : 7,
  461.  
  462.                             "width" : 100,
  463.                             "color" : "pink",
  464.                         },
  465.                     ),
  466.                 },
  467.             ),
  468.         },
  469.     ),
  470. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement